本文整理汇总了Java中org.apache.olingo.odata2.api.ODataService类的典型用法代码示例。如果您正苦于以下问题:Java ODataService类的具体用法?Java ODataService怎么用?Java ODataService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataService类属于org.apache.olingo.odata2.api包,在下文中一共展示了ODataService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createService
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
@Override
public ODataService createService(ODataContext ctx) throws ODataException
{
ODataService res = null;
// Gets the last `root` segment of the URL
// Stores this value in the `serviceName` variable
// if the URL is http://dhus.gael.fr/odata/v1/Products/...
// \__________________________/\_________...
// ROOT ODATA
// serviceName:="v1"
// The length of the `root` part of the URL can be extended with the servlet's split parameter.
// see http://http://olingo.apache.org/doc/odata2/index.html
List<PathSegment> pathSegs = ctx.getPathInfo().getPrecedingSegments();
String serviceName = pathSegs.get(pathSegs.size() - 1).getPath();
if (serviceName.equals(SERVICE_NAME))
{
EdmProvider edmProvider = new Model();
ODataSingleProcessor oDataProcessor = new Processor();
res = createODataSingleProcessorService(edmProvider, oDataProcessor);
}
return res;
}
示例2: createService
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
/**
* Creates an OData Service based on the values set in
* {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext} and
* {@link org.apache.olingo.odata2.api.processor.ODataContext}.
*/
@Override
public final ODataService createService(final ODataContext ctx) throws ODataException {
oDataContext = ctx;
// Initialize OData JPA Context
oDataJPAContext = initializeODataJPAContext();
validatePreConditions();
ODataJPAFactory factory = ODataJPAFactory.createFactory();
ODataJPAAccessFactory accessFactory = factory.getODataJPAAccessFactory();
// OData JPA Processor
if (oDataJPAContext.getODataContext() == null) {
oDataJPAContext.setODataContext(ctx);
}
ODataSingleProcessor odataJPAProcessor = new ODataJPAProcessor(oDataJPAContext);
// OData Entity Data Model Provider based on JPA
EdmProvider edmProvider = accessFactory.createJPAEdmProvider(oDataJPAContext);
return createODataSingleProcessorService(edmProvider, odataJPAProcessor);
}
示例3: createService
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
@Override
public ODataService createService(final ODataContext ctx) throws ODataException {
assertNotNull(ctx);
assertNotNull(ctx.getAcceptableLanguages());
assertNotNull(ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT));
final Map<String, List<String>> requestHeaders = ctx.getRequestHeaders();
final String host = requestHeaders.get("Host").get(0);
String tmp[] = host.split(":", 2);
String port = (tmp.length == 2 && tmp[1] != null) ? tmp[1] : "80";
// access and validation in synchronized block
final JanosServiceFactory service = PORT_2_SERVICE.get(port);
return service.createService(ctx);
}
示例4: handle
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
private Response handle(final ODataHttpMethod method) throws ODataException {
request = ODataRequest.fromRequest(request).method(method).build();
ODataContextImpl context = new ODataContextImpl(request, serviceFactory);
context.setParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT, httpRequest);
ODataService service = serviceFactory.createService(context);
if(service == null){
return returnNoServiceResponse(ODataInternalServerErrorException.NOSERVICE);
}
service.getProcessor().setContext(context);
context.setService(service);
ODataRequestHandler requestHandler = new ODataRequestHandler(serviceFactory, service, context);
final ODataResponse odataResponse = requestHandler.handle(request);
final Response response = RestUtil.convertResponse(odataResponse);
return response;
}
示例5: serviceInstance
import org.apache.olingo.odata2.api.ODataService; //导入依赖的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));
}
示例6: executeAndValidateRequest
import org.apache.olingo.odata2.api.ODataService; //导入依赖的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());
}
示例7: setupBatchHandler
import org.apache.olingo.odata2.api.ODataService; //导入依赖的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);
}
示例8: createService
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
@Override
public ODataService createService(final ODataContext ctx) throws ODataException {
assertNotNull(ctx);
assertNotNull(ctx.getAcceptableLanguages());
assertNotNull(ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT));
final Map<String, List<String>> requestHeaders = ctx.getRequestHeaders();
final String host = requestHeaders.get("Host").get(0);
String tmp[] = host.split(":", 2);
String port = (tmp.length == 2 && tmp[1] != null) ? tmp[1] : "80";
// access and validation in synchronized block
synchronized (PORT_2_SERVICE) {
final ODataService service = PORT_2_SERVICE.get(port);
// if (service == null) {
// throw new IllegalArgumentException("no static service set for JUnit test");
// }
return service;
}
}
示例9: createService
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
@Override
public ODataService createService(ODataContext ctx) throws ODataException {
List<Class<?>> edmClasses = new ArrayList<Class<?>>();
edmClasses.add(com.sap.jam.samples.jira.plugin.odata.server.models.ODataIssue.class);
edmClasses.add(com.sap.jam.samples.jira.plugin.odata.server.models.ODataFilter.class);
return RuntimeDelegate.createODataSingleProcessorService(
new AnnotationEdmProvider(edmClasses),
new JiraODataProcessor(ctx));
}
示例10: createAnnotationService
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ODataService createAnnotationService(final String modelPackage) throws ODataException {
AnnotationEdmProvider edmProvider = new AnnotationEdmProvider(modelPackage);
AnnotationInMemoryDs dataSource = new AnnotationInMemoryDs(modelPackage);
AnnotationValueAccess valueAccess = new AnnotationValueAccess();
// Edm via Annotations and ListProcessor via AnnotationDS with AnnotationsValueAccess
return RuntimeDelegate.createODataSingleProcessorService(edmProvider,
new ListsProcessor(dataSource, valueAccess));
}
示例11: createFromPackage
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
@Test
public void createFromPackage() throws ODataException {
AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
ODataService service = factory.createAnnotationService(Building.class.getPackage().getName());
Assert.assertNotNull(service);
}
示例12: createFromAnnotatedClasses
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
@Test
public void createFromAnnotatedClasses() throws ODataException {
AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
annotatedClasses.add(RefBase.class);
annotatedClasses.add(Building.class);
annotatedClasses.add(Employee.class);
annotatedClasses.add(Manager.class);
annotatedClasses.add(Photo.class);
annotatedClasses.add(Room.class);
annotatedClasses.add(Team.class);
ODataService service = factory.createAnnotationService(annotatedClasses);
Assert.assertNotNull(service);
}
示例13: createFromClasses
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
@Test(expected = ODataException.class)
public void createFromClasses() throws ODataException {
AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
final Collection<Class<?>> notAnnotatedClasses = new ArrayList<Class<?>>();
notAnnotatedClasses.add(String.class);
notAnnotatedClasses.add(Long.class);
ODataService service = factory.createAnnotationService(notAnnotatedClasses);
Assert.assertNotNull(service);
}
示例14: mock
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
public ODataService mock() throws ODataException {
ODataService odataService = EasyMock.createMock(ODataService.class);
EasyMock.expect(odataService.getEntityDataModel()).andReturn(mockEdm());
EasyMock.replay(odataService);
return odataService;
}
示例15: createService
import org.apache.olingo.odata2.api.ODataService; //导入依赖的package包/类
/**
* Creates an OData Service based on the values set in
* {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext} and
* {@link org.apache.olingo.odata2.api.processor.ODataContext}.
*/
@Override
public final ODataService createService(final ODataContext ctx) throws ODataException {
oDataContext = ctx;
// Initialize OData JPA Context
oDataJPAContext = initializeODataJPAContext();
validatePreConditions();
ODataJPAFactory factory = ODataJPAFactory.createFactory();
ODataJPAAccessFactory accessFactory = factory.getODataJPAAccessFactory();
// OData JPA Processor
if (oDataJPAContext.getODataContext() == null) {
oDataJPAContext.setODataContext(ctx);
}
ODataSingleProcessor odataJPAProcessor = createCustomODataProcessor(oDataJPAContext);
if(odataJPAProcessor == null) {
odataJPAProcessor = accessFactory.createODataProcessor(oDataJPAContext);
}
// OData Entity Data Model Provider based on JPA
EdmProvider edmProvider = accessFactory.createJPAEdmProvider(oDataJPAContext);
return createODataSingleProcessorService(edmProvider, odataJPAProcessor);
}