本文整理汇总了Java中org.apache.olingo.odata2.api.processor.ODataContext类的典型用法代码示例。如果您正苦于以下问题:Java ODataContext类的具体用法?Java ODataContext怎么用?Java ODataContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataContext类属于org.apache.olingo.odata2.api.processor包,在下文中一共展示了ODataContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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");
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
示例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);
}
示例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());
}
示例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;
}
}