本文整理汇总了Java中org.apache.olingo.odata2.api.ODataServiceFactory类的典型用法代码示例。如果您正苦于以下问题:Java ODataServiceFactory类的具体用法?Java ODataServiceFactory怎么用?Java ODataServiceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataServiceFactory类属于org.apache.olingo.odata2.api包,在下文中一共展示了ODataServiceFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createContextHandler
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
private ServletContextHandler createContextHandler(final Class<? extends ODataServiceFactory> factoryClass)
throws Exception {
ServletHolder odataServletHolder = null;
String odataServlet = "org.apache.olingo.odata2.core.servlet.ODataServlet";
final HttpServlet httpServlet = (HttpServlet) Class.forName(odataServlet).newInstance();
odataServletHolder = new ServletHolder(httpServlet);
odataServletHolder.setInitParameter(ODataServiceFactory.FACTORY_LABEL, factoryClass.getCanonicalName());
if (pathSplit > 0) {
odataServletHolder.setInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL, Integer.toString(pathSplit));
}
final ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/abc");
contextHandler.addServlet(odataServletHolder, path + "/*");
return contextHandler;
}
开发者ID:mibo,项目名称:janos,代码行数:19,代码来源:TestServer.java
示例2: service
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
// We have to create the Service Factory here because otherwise we do not have access to the error callback
ODataServiceFactory serviceFactory = getServiceFactory(req);
if(serviceFactory == null) {
throw new ODataRuntimeException("Unable to get Service Factory. Check either '" +
ODataServiceFactory.FACTORY_LABEL + "' or '" + ODataServiceFactory.FACTORY_INSTANCE_LABEL + "' config.");
}
String xHttpMethod = req.getHeader("X-HTTP-Method");
String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override");
if (xHttpMethod != null && xHttpMethodOverride != null) {
if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory);
createResponse(resp, wrapper.wrapInExceptionResponse(
new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD)));
return;
}
}
if (req.getPathInfo() != null) {
handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory);
} else {
handleRedirect(req, resp, serviceFactory);
}
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:27,代码来源:ODataServlet.java
示例3: handleHttpTunneling
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
private boolean handleHttpTunneling(final HttpServletRequest req, final HttpServletResponse resp,
final String xHttpMethod, ODataServiceFactory serviceFactory) throws IOException {
if (ODataHttpMethod.MERGE.name().equals(xHttpMethod)) {
handleRequest(req, ODataHttpMethod.MERGE, resp, serviceFactory);
} else if (ODataHttpMethod.PATCH.name().equals(xHttpMethod)) {
handleRequest(req, ODataHttpMethod.PATCH, resp, serviceFactory);
} else if (ODataHttpMethod.DELETE.name().equals(xHttpMethod)) {
handleRequest(req, ODataHttpMethod.DELETE, resp, serviceFactory);
} else if (ODataHttpMethod.PUT.name().equals(xHttpMethod)) {
handleRequest(req, ODataHttpMethod.PUT, resp, serviceFactory);
} else if (ODataHttpMethod.GET.name().equals(xHttpMethod)) {
handleRequest(req, ODataHttpMethod.GET, resp, serviceFactory);
} else if (HTTP_METHOD_HEAD.equals(xHttpMethod)) {
handleRequest(req, ODataHttpMethod.GET, resp, serviceFactory);
} else if (ODataHttpMethod.POST.name().equals(xHttpMethod)) {
handleRequest(req, ODataHttpMethod.POST, resp, serviceFactory);
} else if (HTTP_METHOD_OPTIONS.equals(xHttpMethod)) {
createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp, serviceFactory);
} else {
createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp, serviceFactory);
}
return true;
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:24,代码来源:ODataServlet.java
示例4: handleRedirect
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
protected void handleRedirect(final HttpServletRequest req, final HttpServletResponse resp,
ODataServiceFactory serviceFactory) throws IOException {
String method = req.getMethod();
if (ODataHttpMethod.GET.name().equals(method) ||
ODataHttpMethod.POST.name().equals(method) ||
ODataHttpMethod.PUT.name().equals(method) ||
ODataHttpMethod.DELETE.name().equals(method) ||
ODataHttpMethod.PATCH.name().equals(method) ||
ODataHttpMethod.MERGE.name().equals(method) ||
HTTP_METHOD_HEAD.equals(method) ||
HTTP_METHOD_OPTIONS.equals(method)) {
ODataResponse odataResponse = ODataResponse.status(HttpStatusCodes.TEMPORARY_REDIRECT)
.header(HttpHeaders.LOCATION, createLocation(req))
.build();
createResponse(resp, odataResponse);
} else {
createNotImplementedResponse(req, ODataHttpException.COMMON, resp, serviceFactory);
}
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:ODataServlet.java
示例5: createServiceFactoryFromContext
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
public static ODataServiceFactory createServiceFactoryFromContext(final Application app,
final HttpServletRequest servletRequest,
final ServletConfig servletConfig) {
try {
Class<?> factoryClass;
if (app instanceof AbstractODataApplication) {
factoryClass = ((AbstractODataApplication) app).getServiceFactoryClass();
} else {
final String factoryClassName = servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL);
if (factoryClassName == null) {
throw new ODataRuntimeException("Servlet config missing: " + ODataServiceFactory.FACTORY_LABEL);
}
ClassLoader cl = (ClassLoader) servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL);
if (cl == null) {
factoryClass = Class.forName(factoryClassName);
} else {
factoryClass = Class.forName(factoryClassName, true, cl);
}
}
return (ODataServiceFactory) factoryClass.newInstance();
} catch (Exception e) {
throw new ODataRuntimeException("Exception during ODataServiceFactory creation occured.", e);
}
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:26,代码来源:ODataRootLocator.java
示例6: serviceInstance
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
@Test
public void serviceInstance() throws Exception {
ODataServlet servlet = new ODataServlet();
prepareServlet(servlet);
prepareRequest(reqMock, "", "/servlet-path");
Mockito.when(reqMock.getPathInfo()).thenReturn("/request-path-info");
Mockito.when(reqMock.getRequestURI()).thenReturn("http://localhost:8080/servlet-path/request-path-info");
ODataServiceFactory factory = Mockito.mock(ODataServiceFactory.class);
ODataService service = Mockito.mock(ODataService.class);
Mockito.when(factory.createService(Mockito.any(ODataContext.class))).thenReturn(service);
ODataProcessor processor = Mockito.mock(ODataProcessor.class);
Mockito.when(service.getProcessor()).thenReturn(processor);
Mockito.when(reqMock.getAttribute(ODataServiceFactory.FACTORY_INSTANCE_LABEL)).thenReturn(factory);
Mockito.when(respMock.getOutputStream()).thenReturn(Mockito.mock(ServletOutputStream.class));
servlet.service(reqMock, respMock);
Mockito.verify(factory).createService(Mockito.any(ODataContext.class));
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:ODataServletTest.java
示例7: serviceClassloader
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
@Test
public void serviceClassloader() throws Exception {
ODataServlet servlet = new ODataServlet();
prepareServlet(servlet);
prepareRequest(reqMock, "", "/servlet-path");
Mockito.when(reqMock.getPathInfo()).thenReturn("/request-path-info");
Mockito.when(reqMock.getRequestURI()).thenReturn("http://localhost:8080/servlet-path/request-path-info");
Mockito.when(respMock.getOutputStream()).thenReturn(Mockito.mock(ServletOutputStream.class));
servlet.service(reqMock, respMock);
Mockito.verify(configMock).getInitParameter(ODataServiceFactory.FACTORY_LABEL);
Mockito.verify(reqMock).getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL);
Assert.assertEquals(ODataServiceFactoryImpl.class, servlet.getServiceFactory(reqMock).getClass());
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:17,代码来源:ODataServletTest.java
示例8: testWithNoPathAfterServletPath
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
@Test
public void testWithNoPathAfterServletPath() throws Exception {
ODataServlet servlet = new ODataServlet();
prepareServlet(servlet);
prepareRequestWithNoPathAfterServletPath(reqMock, "", "/servlet-path");
Mockito.when(reqMock.getPathInfo()).thenReturn("/Collection");
Mockito.when(reqMock.getRequestURI()).thenReturn("http://localhost:8080/servlet-path;v=1/Collection");
Mockito.when(servlet.getInitParameter("org.apache.olingo.odata2.path.split")).thenReturn("1");
Mockito.when(respMock.getOutputStream()).thenReturn(Mockito.mock(ServletOutputStream.class));
servlet.service(reqMock, respMock);
Mockito.verify(configMock).getInitParameter(ODataServiceFactory.FACTORY_LABEL);
Mockito.verify(reqMock).getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL);
Assert.assertEquals(ODataServiceFactoryImpl.class, servlet.getServiceFactory(reqMock).getClass());
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:18,代码来源:ODataServletTest.java
示例9: executeAndValidateRequest
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
private void executeAndValidateRequest(final ODataHttpMethod method,
final List<String> pathSegments,
final Map<String, String> queryParameters,
final String httpHeaderName, final String httpHeaderValue,
final String requestContentType,
final HttpStatusCodes expectedStatusCode) throws ODataException {
ODataServiceFactory serviceFactory = mock(ODataServiceFactory.class);
final ODataService service = mockODataService(serviceFactory);
when(serviceFactory.createService(any(ODataContext.class))).thenReturn(service);
final ODataRequest request = mockODataRequest(method, pathSegments, queryParameters,
httpHeaderName, httpHeaderValue, requestContentType);
final ODataContextImpl context = new ODataContextImpl(request, serviceFactory);
final ODataResponse response = new ODataRequestHandler(serviceFactory, service, context).handle(request);
assertNotNull(response);
assertEquals(expectedStatusCode == null ? HttpStatusCodes.PAYMENT_REQUIRED : expectedStatusCode,
response.getStatus());
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:ODataRequestHandlerValidationTest.java
示例10: testExtendedODataErrorContext
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
@Test
public void testExtendedODataErrorContext() throws Exception {
MultivaluedMap<String, String> value = new MultivaluedHashMap<String, String>();
value.putSingle("Accept", "AcceptValue");
value.put("AcceptMulti", Arrays.asList("AcceptValue_1", "AcceptValue_2"));
when(exceptionMapper.httpHeaders.getRequestHeaders()).thenReturn(value);
when(exceptionMapper.servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn(
ODataServiceFactoryWithCallbackImpl.class.getName());
when(exceptionMapper.servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL)).thenReturn(null);
Response response = exceptionMapper.toResponse(new Exception());
// verify
assertNotNull(response);
assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus());
String errorMessage = (String) response.getEntity();
assertEquals("bla", errorMessage);
String contentTypeHeader = response.getHeaderString(org.apache.olingo.odata2.api.commons.HttpHeaders.CONTENT_TYPE);
assertEquals("text/html", contentTypeHeader);
//
assertEquals(uri.toASCIIString(), response.getHeaderString("RequestUri"));
assertEquals("[AcceptValue]", response.getHeaderString("Accept"));
assertEquals("[AcceptValue_1, AcceptValue_2]", response.getHeaderString("AcceptMulti"));
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:24,代码来源:ODataExceptionMapperImplTest.java
示例11: servletRequestWithClassloader
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
@Test
public void servletRequestWithClassloader() throws Exception {
MultivaluedMap<String, String> value = new MultivaluedHashMap<String, String>();
value.putSingle("Accept", "AcceptValue");
value.put("AcceptMulti", Arrays.asList("AcceptValue_1", "AcceptValue_2"));
when(exceptionMapper.httpHeaders.getRequestHeaders()).thenReturn(value);
when(exceptionMapper.servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn(
ODataServiceFactoryWithCallbackImpl.class.getName());
when(exceptionMapper.servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL)).thenReturn(
ODataServiceFactoryWithCallbackImpl.class.getClassLoader());
Response response = exceptionMapper.toResponse(new Exception());
// verify
assertNotNull(response);
assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus());
String errorMessage = (String) response.getEntity();
assertEquals("bla", errorMessage);
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:19,代码来源:ODataExceptionMapperImplTest.java
示例12: setupBatchHandler
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
@Before
public void setupBatchHandler() throws Exception {
ODataProcessor processor = new LocalProcessor();
ODataService serviceMock = mock(ODataService.class);
when(serviceMock.getBatchProcessor()).thenReturn((BatchProcessor) processor);
when(serviceMock.getEntitySetProcessor()).thenReturn((EntitySetProcessor) processor);
when(serviceMock.getEntitySimplePropertyProcessor()).thenReturn((EntitySimplePropertyProcessor) processor);
when(serviceMock.getProcessor()).thenReturn(processor);
Edm mockEdm = MockFacade.getMockEdm();
when(serviceMock.getEntityDataModel()).thenReturn(mockEdm);
List<String> supportedContentTypes = Arrays.asList(
HttpContentType.APPLICATION_JSON_UTF8, HttpContentType.APPLICATION_JSON);
when(serviceMock.getSupportedContentTypes(EntityMediaProcessor.class)).thenReturn(supportedContentTypes);
when(serviceMock.getSupportedContentTypes(EntityProcessor.class)).thenReturn(supportedContentTypes);
when(serviceMock.getSupportedContentTypes(EntitySimplePropertyProcessor.class)).thenReturn(supportedContentTypes);
handler = new BatchHandlerImpl(mock(ODataServiceFactory.class), serviceMock);
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:18,代码来源:BatchHandlerTest.java
示例13: startServer
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
public void startServer(final Class<? extends ODataServiceFactory> factoryClass, final int fixedPort) {
try {
final ServletContextHandler contextHandler = createContextHandler(factoryClass);
final InetSocketAddress isa = new InetSocketAddress(DEFAULT_HOST, fixedPort);
server = new Server(isa);
server.setHandler(contextHandler);
server.start();
endpoint = new URI(DEFAULT_SCHEME, null, DEFAULT_HOST, isa.getPort(), "/abc" + path, null, null);
log.trace("Started server at endpoint " + endpoint.toASCIIString());
} catch (final Exception e) {
log.error("server start failed", e);
throw new ServerRuntimeException(e);
}
}
开发者ID:mibo,项目名称:janos,代码行数:16,代码来源:TestServer.java
示例14: getServiceFactory
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
/**
* Get the service factory instance which is used for creation of the
* <code>ODataService</code> which handles the processing of the request.
*
* @param request the http request which is processed as an OData request
* @return an instance of an ODataServiceFactory
*/
protected ODataServiceFactory getServiceFactory(HttpServletRequest request) {
try {
ODataServiceFactory factoryInstance = getODataServiceFactoryInstance(request);
if(factoryInstance == null) {
return createODataServiceFactory(request);
}
return factoryInstance;
} catch (Exception e) {
throw new ODataRuntimeException(e);
}
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:ODataServlet.java
示例15: createNotImplementedResponse
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
private void createNotImplementedResponse(final HttpServletRequest req, final MessageReference messageReference,
final HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
// RFC 2616, 5.1.1: "An origin server SHOULD return the status code [...]
// 501 (Not Implemented) if the method is unrecognized [...] by the origin server."
ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
ODataResponse response =
exceptionWrapper.wrapInExceptionResponse(new ODataNotImplementedException(messageReference));
createResponse(resp, response);
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:10,代码来源:ODataServlet.java
示例16: createMethodNotAllowedResponse
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
private void createMethodNotAllowedResponse(final HttpServletRequest req, final MessageReference messageReference,
final HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
ODataResponse response =
exceptionWrapper.wrapInExceptionResponse(new ODataMethodNotAllowedException(messageReference));
createResponse(resp, response);
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:8,代码来源:ODataServlet.java
示例17: createNotAcceptableResponse
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
private void createNotAcceptableResponse(final HttpServletRequest req, final MessageReference messageReference,
final HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
ODataResponse response =
exceptionWrapper.wrapInExceptionResponse(new ODataNotAcceptableException(messageReference));
createResponse(resp, response);
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:8,代码来源:ODataServlet.java
示例18: createServiceUnavailableResponse
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
private void createServiceUnavailableResponse(HttpServletRequest req, MessageReference messageReference,
HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
ODataResponse response =
exceptionWrapper.wrapInExceptionResponse(new ODataInternalServerErrorException(messageReference));
createResponse(resp, response);
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:8,代码来源:ODataServlet.java
示例19: createODataServiceFactory
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
/**
* Create an instance of a ODataServiceFactory via factory class
* from servlet init parameter ODataServiceFactory.FACTORY_LABEL
* and ODataServiceFactory.FACTORY_CLASSLOADER_LABEL (if set).
*
* @see ODataServiceFactory#FACTORY_LABEL
* @see ODataServiceFactory#FACTORY_CLASSLOADER_LABEL
*
* @param req http servlet request
* @return instance of a ODataServiceFactory
*/
private ODataServiceFactory createODataServiceFactory(HttpServletRequest req)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
final String factoryClassName = getInitParameter(ODataServiceFactory.FACTORY_LABEL);
if(factoryClassName == null) {
return null;
}
ClassLoader cl = (ClassLoader) req.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL);
if (cl == null) {
return (ODataServiceFactory) Class.forName(factoryClassName).newInstance();
} else {
return (ODataServiceFactory) Class.forName(factoryClassName, true, cl).newInstance();
}
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:26,代码来源:ODataServlet.java
示例20: getODataServiceFactoryInstance
import org.apache.olingo.odata2.api.ODataServiceFactory; //导入依赖的package包/类
/**
* Get an instance of a ODataServiceFactory from request attribute
* ODataServiceFactory.FACTORY_INSTANCE_LABEL
*
* @see ODataServiceFactory#FACTORY_INSTANCE_LABEL
*
* @param req http servlet request
* @return instance of a ODataServiceFactory
*/
private ODataServiceFactory getODataServiceFactoryInstance(HttpServletRequest req) {
Object factory = req.getAttribute(ODataServiceFactory.FACTORY_INSTANCE_LABEL);
if(factory == null) {
return null;
} else if(factory instanceof ODataServiceFactory) {
return (ODataServiceFactory) factory;
}
throw new ODataRuntimeException("Invalid service factory instance of type " + factory.getClass());
}
开发者ID:apache,项目名称:olingo-odata2,代码行数:19,代码来源:ODataServlet.java
注:本文中的org.apache.olingo.odata2.api.ODataServiceFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论