• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ODataContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.olingo.odata2.api.processor.ODataContext的典型用法代码示例。如果您正苦于以下问题:Java ODataContext类的具体用法?Java ODataContext怎么用?Java ODataContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ODataContext类属于org.apache.olingo.odata2.api.processor包,在下文中一共展示了ODataContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createService

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的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;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:27,代码来源:ServiceFactory.java


示例2: createService

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的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);
}
 
开发者ID:sapmentors,项目名称:lemonaid,代码行数:31,代码来源:JPAServiceFactory.java


示例3: updateEntityMedia

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Override
public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final String contentType) throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments()).getFirst();

  if (!appliesFilter(data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");

  final byte[] value = EntityProvider.readBinary(content);

  context.stopRuntimeMeasurement(timingHandle);

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));

  return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
}
 
开发者ID:mibo,项目名称:janos,代码行数:27,代码来源:DataSourceProcessor.java


示例4: writeEntry

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
    final T data, final String contentType) throws ODataException {
  final EdmEntityType entityType = entitySet.getEntityType();
  final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);

  ODataContext context = getContext();
  EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .expandSelectTree(expandSelectTree)
      .callbacks(getCallbacks(data, entityType))
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");

  final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return response;
}
 
开发者ID:mibo,项目名称:janos,代码行数:21,代码来源:DataSourceProcessor.java


示例5: parseEntry

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
    final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");

  ODataEntry entryValues;
  try {
    entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
  } catch (final EntityProviderException e) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
  }

  context.stopRuntimeMeasurement(timingHandle);

  return entryValues;
}
 
开发者ID:mibo,项目名称:janos,代码行数:17,代码来源:DataSourceProcessor.java


示例6: parseLinkUri

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
private Map<String, Object> parseLinkUri(final EdmEntitySet targetEntitySet, final String uriString)
    throws EdmException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("UriParser", "getKeyPredicatesFromEntityLink");

  List<KeyPredicate> key = null;
  try {
    key = UriParser.getKeyPredicatesFromEntityLink(targetEntitySet, uriString,
        context.getPathInfo().getServiceRoot());
  } catch (ODataException e) {
    // We don't understand the link target. This could also be seen as an error.
  }

  context.stopRuntimeMeasurement(timingHandle);

  return key == null ? null : mapKey(key);
}
 
开发者ID:mibo,项目名称:janos,代码行数:18,代码来源:DataSourceProcessor.java


示例7: createService

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的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);
}
 
开发者ID:mibo,项目名称:janos,代码行数:18,代码来源:FitStaticServiceFactory.java


示例8: testBaseUriWithEncoding

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Test
public void testBaseUriWithEncoding() throws IOException, ODataException,
    URISyntaxException {
  server.setPathSplit(3);
  startServer();

  final URI uri =
      new URI(server.getEndpoint().getScheme(), null, server.getEndpoint().getHost(), server.getEndpoint().getPort(),
          server.getEndpoint().getPath() + "/aaa/äдержb;n=2, 3;m=1/c c/", null, null);

  final HttpGet get = new HttpGet(uri);
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext context = service.getProcessor().getContext();
  assertNotNull(context);
  validateServiceRoot(context.getPathInfo().getServiceRoot().toASCIIString(),
      server.getEndpoint() + "aaa/%C3%A4%D0%B4%D0%B5%D1%80%D0%B6b;", "/c%20c/", "n=2,%203", "m=1");
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:ServiceResolutionTest.java


示例9: writeEntry

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
    final T data, final String contentType) throws ODataException, EntityProviderException {
  final EdmEntityType entityType = entitySet.getEntityType();
  final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);

  ODataContext context = getContext();
  EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .expandSelectTree(expandSelectTree)
      .callbacks(getCallbacks(data, entityType))
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");

  final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return response;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:ListsProcessor.java


示例10: parseLink

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
public final UriInfo parseLink(final EdmEntitySet entitySet, final InputStream content, final String contentType)
    throws ODataJPARuntimeException {

  String uriString = null;
  UriInfo uri = null;
  try {
    uriString = EntityProvider.readLink(contentType, entitySet, content);
    ODataContext odataContext = context.getODataContext();
    final String svcRoot = odataContext.getPathInfo().getServiceRoot().toString();
    final String path =
        uriString.startsWith(svcRoot.toString()) ? uriString.substring(svcRoot.length()) : uriString;
    final List<PathSegment> pathSegment = getPathSegment(path);
    edm = getEdm();
    uri = UriParser.parse(edm, pathSegment, Collections.<String, String> emptyMap());
  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
  }
  return uri;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:ODataEntityParser.java


示例11: testMetadataUriWithMatrixParameter

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Test
public void testMetadataUriWithMatrixParameter() throws IOException, ODataException,
    URISyntaxException {
  server.setPathSplit(3);
  startServer();

  final String endpoint = server.getEndpoint().toString();
  final HttpGet get = new HttpGet(URI.create(endpoint + "aaa/bbb;n=2,3;m=1/ccc/$metadata"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);
  validateServiceRoot(ctx.getPathInfo().getServiceRoot().toASCIIString(),
      endpoint + "aaa/bbb;", "/ccc/", "n=2,3", "m=1");
  assertEquals("$metadata", ctx.getPathInfo().getODataSegments().get(0).getPath());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:19,代码来源:ServiceResolutionTest.java


示例12: testSplit2

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Test
public void testSplit2() throws IOException, ODataException {
  server.setPathSplit(2);
  startServer();

  final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "/aaa/bbb/$metadata"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);

  assertEquals("aaa", ctx.getPathInfo().getPrecedingSegments().get(0).getPath());
  assertEquals("bbb", ctx.getPathInfo().getPrecedingSegments().get(1).getPath());
  assertEquals("$metadata", ctx.getPathInfo().getODataSegments().get(0).getPath());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:18,代码来源:ServiceResolutionTest.java


示例13: testMatrixParameterInNonODataPath

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Test
public void testMatrixParameterInNonODataPath() throws IOException, ODataException {
  server.setPathSplit(1);
  startServer();

  final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "aaa;n=2/"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);

  assertEquals("", ctx.getPathInfo().getODataSegments().get(0).getPath());
  assertEquals("aaa", ctx.getPathInfo().getPrecedingSegments().get(0).getPath());

  assertNotNull(ctx.getPathInfo().getPrecedingSegments().get(0).getMatrixParameters());

  String key, value;
  key = ctx.getPathInfo().getPrecedingSegments().get(0).getMatrixParameters().keySet().iterator().next();
  assertEquals("n", key);
  value = ctx.getPathInfo().getPrecedingSegments().get(0).getMatrixParameters().get(key).get(0);
  assertEquals("2", value);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:25,代码来源:ServiceResolutionTest.java


示例14: testSplit1

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Test
public void testSplit1() throws IOException, ODataException {
  server.setPathSplit(1);
  startServer();

  final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "/aaa/$metadata"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);

  assertEquals("aaa", ctx.getPathInfo().getPrecedingSegments().get(0).getPath());
  assertEquals("$metadata", ctx.getPathInfo().getODataSegments().get(0).getPath());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:17,代码来源:ServiceResolutionTest.java


示例15: getLanguages

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
private List<Locale> getLanguages(final ODataContext context) {
  try {
    if (context.getAcceptableLanguages().isEmpty()) {
      return Arrays.asList(DEFAULT_RESPONSE_LOCALE);
    }
    return context.getAcceptableLanguages();
  } catch (WebApplicationException e) {
    if (e.getCause() != null && e.getCause().getClass() == ParseException.class) {
      // invalid accept-language string in http header
      // compensate exception with using default locale
      return Arrays.asList(DEFAULT_RESPONSE_LOCALE);
    }
    // not able to compensate exception -> re-throw
    throw e;
  }
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:17,代码来源:ODataExceptionWrapper.java


示例16: handle

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的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;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:ODataSubLocator.java


示例17: minimal

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Test
public void minimal() throws Exception {
  final ODataContext context = mockContext(ODataHttpMethod.PUT);
  final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.NO_CONTENT, null, null);

  ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse();
  final String actualJson = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertEquals(EXPECTED.replace(ODataHttpMethod.GET.name(), ODataHttpMethod.PUT.name())
      .replace(Integer.toString(HttpStatusCodes.OK.getStatusCode()),
          Integer.toString(HttpStatusCodes.NO_CONTENT.getStatusCode()))
      .replace(HttpStatusCodes.OK.getInfo(), HttpStatusCodes.NO_CONTENT.getInfo()),
      actualJson);

  response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse();
  final String html = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertTrue(html.contains(HttpStatusCodes.NO_CONTENT.getInfo()));
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:ODataDebugResponseWrapperTest.java


示例18: server

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Test
public void server() throws Exception {
  ODataContext context = mockContext(ODataHttpMethod.GET);
  HttpServletRequest servletRequest = mock(HttpServletRequest.class);
  when(servletRequest.getServerPort()).thenReturn(12345);
  when(context.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT)).thenReturn(servletRequest);

  final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null);
  ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse();
  String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertEquals(EXPECTED.replace("null}}", "null,\"environment\":{\"serverPort\":\"12345\"}}}"),
      entity);

  response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse();
  entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertTrue(entity.contains("<td class=\"name\">serverPort</td><td class=\"value\">12345</td>"));
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:ODataDebugResponseWrapperTest.java


示例19: serviceInstance

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的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


示例20: updateEntityMedia

import org.apache.olingo.odata2.api.processor.ODataContext; //导入依赖的package包/类
@Override
public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final String contentType) throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  if (!appliesFilter(entitySet, data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");

  final byte[] value = EntityProvider.readBinary(content);

  context.stopRuntimeMeasurement(timingHandle);

  dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));

  return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:27,代码来源:ListsProcessor.java



注:本文中的org.apache.olingo.odata2.api.processor.ODataContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WebClient类代码示例发布时间:2022-05-22
下一篇:
Java MemberRef类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap