org.apache.olingo.server.api.ServiceMetadata Java Examples
The following examples show how to use
org.apache.olingo.server.api.ServiceMetadata.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DemoServlet.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { HttpSession session = req.getSession(true); Storage storage = (Storage) session.getAttribute(Storage.class.getName()); if (storage == null) { storage = new Storage(); session.setAttribute(Storage.class.getName(), storage); } // create odata handler and configure it with EdmProvider and Processor OData odata = OData.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>()); ODataHttpHandler handler = odata.createHandler(edm); handler.register(new DemoEntityCollectionProcessor(storage)); handler.register(new DemoEntityProcessor(storage)); handler.register(new DemoPrimitiveProcessor(storage)); // let the handler do the work handler.process(req, resp); } catch (RuntimeException e) { LOG.error("Server Error occurred in ExampleServlet", e); throw new ServletException(e); } }
Example #2
Source File: EdmAssistedJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void metadataMin() throws Exception { final ServiceMetadata metadata = oData.createServiceMetadata(null, Collections.<EdmxReference> emptyList(), new MetadataETagSupport("W/\"42\"")); Entity entity = new Entity(); entity.setType("Namespace.EntityType"); entity.setId(URI.create("ID")); entity.setETag("W/\"1000\""); Link link = new Link(); link.setHref("editLink"); entity.setEditLink(link); entity.setMediaContentSource(URI.create("media")); entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, UUID.fromString("12345678-ABCD-1234-CDEF-123456789012"))); EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(entity); Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1)\"," + "\"@odata.metadataEtag\":\"W/\\\"42\\\"\",\"value\":[{" + "\"@odata.etag\":\"W/\\\"1000\\\"\"," + "\"Property1\":\"12345678-abcd-1234-cdef-123456789012\"," + "\"@odata.editLink\":\"editLink\"," + "\"@odata.mediaReadLink\":\"editLink/$value\"}]}", serialize(serializerMin, metadata, null, entityCollection, null)); }
Example #3
Source File: DemoServlet.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { HttpSession session = req.getSession(true); Storage storage = (Storage) session.getAttribute(Storage.class.getName()); if (storage == null) { storage = new Storage(); session.setAttribute(Storage.class.getName(), storage); } // create odata handler and configure it with EdmProvider and Processor OData odata = OData.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>()); ODataHttpHandler handler = odata.createHandler(edm); handler.register(new DemoEntityCollectionProcessor(storage)); handler.register(new DemoEntityProcessor(storage)); handler.register(new DemoPrimitiveProcessor(storage)); handler.register(new DemoActionProcessor(storage)); // let the handler do the work handler.process(req, resp); } catch (RuntimeException e) { LOG.error("Server Error occurred in ExampleServlet", e); throw new ServletException(e); } }
Example #4
Source File: ServiceDocumentXmlSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void writeServiceWithEmptyMockedEdm() throws Exception { final Edm edm = mock(Edm.class); EdmEntityContainer container = mock(EdmEntityContainer.class); when(container.getFullQualifiedName()).thenReturn(new FullQualifiedName("service", "test")); when(container.getEntitySets()).thenReturn(Collections.<EdmEntitySet> emptyList()); when(container.getFunctionImports()).thenReturn(Collections.<EdmFunctionImport> emptyList()); when(container.getSingletons()).thenReturn(Collections.<EdmSingleton> emptyList()); when(edm.getEntityContainer()).thenReturn(container); ServiceMetadata metadata = mock(ServiceMetadata.class); when(metadata.getEdm()).thenReturn(edm); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<app:service xmlns:atom=\"http://www.w3.org/2005/Atom\" " + "xmlns:app=\"http://www.w3.org/2007/app\" " + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "metadata:context=\"http://host/svc/$metadata\">" + "<app:workspace><atom:title>service.test</atom:title></app:workspace>" + "</app:service>", IOUtils.toString(serializer.serviceDocument(metadata, "http://host/svc").getContent())); }
Example #5
Source File: ODataHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void handlerExtTest() throws Exception { final OData odata = OData.newInstance(); final ServiceMetadata serviceMetadata = odata.createServiceMetadata( new CsdlAbstractEdmProvider() { @Override public CsdlEntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName) throws ODataException { throw new ODataException("msg"); } }, Collections.<EdmxReference> emptyList()); ODataRequest request = new ODataRequest(); request.setMethod(HttpMethod.GET); request.setRawODataPath("EdmException"); ODataHandlerImpl handler = new ODataHandlerImpl(odata, serviceMetadata, new ServerCoreDebugger(odata)); Processor extension = new TechnicalActionProcessor(null, serviceMetadata); handler.register(extension); assertNull(handler.getLastThrownException()); assertNull(handler.getUriInfo()); }
Example #6
Source File: ODataJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected EdmEntityType resolveEntityType(final ServiceMetadata metadata, final EdmEntityType baseType, final String derivedTypeName) throws SerializerException { if (derivedTypeName == null || baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) { return baseType; } EdmEntityType derivedType = metadata.getEdm().getEntityType(new FullQualifiedName(derivedTypeName)); if (derivedType == null) { throw new SerializerException("EntityType not found", SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName); } EdmEntityType type = derivedType.getBaseType(); while (type != null) { if (type.getFullQualifiedName().equals(baseType.getFullQualifiedName())) { return derivedType; } type = type.getBaseType(); } throw new SerializerException("Wrong base type", SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType.getFullQualifiedName().getFullQualifiedNameAsString()); }
Example #7
Source File: CarsServlet.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { HttpSession session = req.getSession(true); DataProvider dataProvider = (DataProvider) session.getAttribute(DataProvider.class.getName()); if (dataProvider == null) { dataProvider = new DataProvider(); session.setAttribute(DataProvider.class.getName(), dataProvider); LOG.info("Created new data provider."); } OData odata = OData.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(new CarsEdmProvider(), new ArrayList<EdmxReference>()); ODataHttpHandler handler = odata.createHandler(edm); handler.register(new CarsProcessor(dataProvider)); handler.process(req, resp); } catch (RuntimeException e) { LOG.error("Server Error", e); throw new ServletException(e); } }
Example #8
Source File: MetadataDocumentXmlSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
/** Writes simplest (empty) Schema. */ @Test public void writeMetadataWithEmptySchema() throws Exception { EdmSchema schema = mock(EdmSchema.class); when(schema.getNamespace()).thenReturn("MyNamespace"); Edm edm = mock(Edm.class); when(edm.getSchemas()).thenReturn(Arrays.asList(schema)); ServiceMetadata serviceMetadata = mock(ServiceMetadata.class); when(serviceMetadata.getEdm()).thenReturn(edm); InputStream metadata = serializer.metadataDocument(serviceMetadata).getContent(); assertNotNull(metadata); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" + "<edmx:DataServices>" + "<Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"MyNamespace\"></Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>", IOUtils.toString(metadata)); }
Example #9
Source File: DemoServlet.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { HttpSession session = req.getSession(true); Storage storage = (Storage) session.getAttribute(Storage.class.getName()); if (storage == null) { storage = new Storage(); session.setAttribute(Storage.class.getName(), storage); } // create odata handler and configure it with EdmProvider and Processor OData odata = OData.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>()); ODataHttpHandler handler = odata.createHandler(edm); handler.register(new DemoEntityCollectionProcessor(storage)); handler.register(new DemoEntityProcessor(storage)); handler.register(new DemoPrimitiveProcessor(storage)); // let the handler do the work handler.process(req, resp); } catch (RuntimeException e) { LOG.error("Server Error occurred in ExampleServlet", e); throw new ServletException(e); } }
Example #10
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType, final AbstractEntityCollection entitySet, final ExpandOption expand, final SelectOption select, final boolean onlyReference, String name, final JsonGenerator json, boolean isFullRepresentation) throws IOException, SerializerException { if (entitySet instanceof AbstractEntityCollection) { AbstractEntityCollection entities = (AbstractEntityCollection)entitySet; json.writeStartArray(); for (final Entity entity : entities) { if (onlyReference) { json.writeStartObject(); json.writeStringField(Constants.JSON_ID, getEntityId(entity, entityType, null)); json.writeEndObject(); } else { if (entity instanceof DeletedEntity) { writeDeletedEntity(entity, json); } else { writeAddedUpdatedEntity(metadata, entityType, entity, expand, select, null, false, name, json, isFullRepresentation); } } } json.writeEndArray(); } }
Example #11
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writeComplexCollection(final ServiceMetadata metadata, final EdmComplexType type, final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException { json.writeStartArray(); for (Object value : property.asCollection()) { switch (property.getValueType()) { case COLLECTION_COMPLEX: json.writeStartObject(); if (isODataMetadataFull) { json.writeStringField(Constants.JSON_TYPE, "#" + type.getFullQualifiedName().getFullQualifiedNameAsString()); } writeComplexValue(metadata, type, ((ComplexValue) value).getValue(), selectedPaths, json); json.writeEndObject(); break; default: throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName()); } } json.writeEndArray(); }
Example #12
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected EdmEntityType resolveEntityType(final ServiceMetadata metadata, final EdmEntityType baseType, final String derivedTypeName) throws SerializerException { if (derivedTypeName == null || baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) { return baseType; } EdmEntityType derivedType = metadata.getEdm().getEntityType(new FullQualifiedName(derivedTypeName)); if (derivedType == null) { throw new SerializerException("EntityType not found", SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName); } EdmEntityType type = derivedType.getBaseType(); while (type != null) { if (type.getFullQualifiedName().getFullQualifiedNameAsString() .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) { return derivedType; } type = type.getBaseType(); } throw new SerializerException("Wrong base type", SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType .getFullQualifiedName().getFullQualifiedNameAsString()); }
Example #13
Source File: ODataHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ODataResponse dispatchToValidateHeaders(final HttpMethod method, final String path, final String query, final Map<String, String> headers, final Processor processor) throws ODataHandlerException { ODataRequest request = new ODataRequest(); request.setMethod(method); request.setRawBaseUri(BASE_URI); for (Entry<String, String> header : headers.entrySet()) { request.addHeader(header.getKey(), header.getValue()); } if (path.isEmpty()) { request.setRawRequestUri(BASE_URI); } request.setRawODataPath(path); request.setRawQueryPath(query); final OData odata = OData.newInstance(); final ServiceMetadata metadata = odata.createServiceMetadata( new EdmTechProvider(), Collections.<EdmxReference> emptyList()); ODataHandlerImpl handler = new ODataHandlerImpl(odata, metadata, new ServerCoreDebugger(odata)); if (processor != null) { handler.register(processor); } final ODataResponse response = handler.process(request); return response; }
Example #14
Source File: PrimitiveValueResponse.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private PrimitiveValueResponse(ServiceMetadata metadata, FixedFormatSerializer serializer, ODataResponse response, boolean collection, EdmProperty type, Map<String, String> preferences) { super(metadata, response, preferences); this.returnCollection = collection; this.type = type; this.serializer = serializer; }
Example #15
Source File: TechnicalServlet.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected void service(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { OData odata = OData.newInstance(); EdmxReference reference = new EdmxReference(URI.create("../v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")); reference.addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core")); final ServiceMetadata serviceMetadata = odata.createServiceMetadata( new EdmTechProvider(), Collections.singletonList(reference), new MetadataETagSupport(metadataETag)); HttpSession session = request.getSession(true); DataProvider dataProvider = (DataProvider) session.getAttribute(DataProvider.class.getName()); if (dataProvider == null) { dataProvider = new DataProvider(odata, serviceMetadata.getEdm()); session.setAttribute(DataProvider.class.getName(), dataProvider); LOG.info("Created new data provider."); } ODataHttpHandler handler = odata.createHandler(serviceMetadata); // Register processors. handler.register(new TechnicalEntityProcessor(dataProvider, serviceMetadata)); handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider, serviceMetadata)); handler.register(new TechnicalActionProcessor(dataProvider, serviceMetadata)); handler.register(new TechnicalBatchProcessor(dataProvider)); // Register helpers. handler.register(new ETagSupport()); handler.register(new DefaultDebugSupport()); // Process the request. handler.process(request, response); } catch (final RuntimeException e) { LOG.error("Server Error", e); throw new ServletException(e); } }
Example #16
Source File: ODataAdapter.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * This method return the entity which is able to navigate from the parent entity (source) using uri navigation properties. * <p/> * In this method we check the parent entities foreign keys and return the entity according to the values. * we use ODataDataHandler, navigation properties to get particular foreign keys. * * @param metadata Service Metadata * @param parentEntity Entity (Source) * @param navigation UriResourceNavigation (Destination) * @return Entity (Destination) * @throws ODataApplicationException * @throws ODataServiceFault * @see ODataDataHandler#getNavigationProperties() */ private Entity getNavigableEntity(ServiceMetadata metadata, Entity parentEntity, EdmNavigationProperty navigation, String baseUrl) throws ODataApplicationException, ODataServiceFault { EdmEntityType type = metadata.getEdm().getEntityType(new FullQualifiedName(parentEntity.getType())); String linkName = navigation.getName(); List<Property> properties = new ArrayList<>(); Map<String, EdmProperty> propertyMap = new HashMap<>(); for (NavigationKeys keys : this.dataHandler.getNavigationProperties().get(linkName) .getNavigationKeys(type.getName())) { Property property = parentEntity.getProperty(keys.getForeignKey()); if (property != null && !property.isNull()) { propertyMap.put(keys.getPrimaryKey(), (EdmProperty) type.getProperty(property.getName())); property.setName(keys.getPrimaryKey()); properties.add(property); } } EntityCollection results = null; if (!properties.isEmpty()) { results = createEntityCollectionFromDataEntryList(linkName, dataHandler .readTableWithKeys(linkName, wrapPropertiesToDataEntry(type, properties, propertyMap)), baseUrl); } if (results != null && !results.getEntities().isEmpty()) { return results.getEntities().get(0); } else { if (log.isDebugEnabled()) { log.debug("Reference is not found."); } return null; } }
Example #17
Source File: PrimitiveValueResponse.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private PrimitiveValueResponse(ServiceMetadata metadata, FixedFormatSerializer serializer, ODataResponse response, boolean collection, EdmReturnType type, Map<String, String> preferences) { super(metadata, response, preferences); this.returnCollection = collection; this.returnType = type; this.serializer = serializer; }
Example #18
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected void writeComplexValue(final ServiceMetadata metadata, final EdmComplexType type, final List<Property> properties, final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException { for (final String propertyName : type.getPropertyNames()) { final Property property = findProperty(propertyName, properties); if (selectedPaths == null || ExpandSelectHelper.isSelected(selectedPaths, propertyName)) { writeProperty(metadata, (EdmProperty) type.getProperty(propertyName), property, selectedPaths == null ? null : ExpandSelectHelper.getReducedSelectedPaths(selectedPaths, propertyName), json); } } }
Example #19
Source File: ODataServiceHandler.java From micro-integrator with Apache License 2.0 | 5 votes |
public ODataServiceHandler(ODataDataHandler dataHandler, String namespace, String configID) throws ODataServiceFault { ODataAdapter processor = new ODataAdapter(dataHandler, namespace, configID); OData odata = OData4Impl.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(processor.getEdmProvider(), new ArrayList<EdmxReference>()); this.handler = odata.createHandler(edm); this.handler.register(processor); }
Example #20
Source File: ODataNettyHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void testNettyReqResp_GetMethod() { MetadataProcessor processor = mock(MetadataProcessor.class); final ODataNetty odata = ODataNetty.newInstance(); final ServiceMetadata metadata = odata.createServiceMetadata( new EdmTechProvider(), Collections.<EdmxReference> emptyList()); ODataNettyHandler handler = odata.createNettyHandler(metadata); handler.register(processor); DefaultFullHttpRequest nettyRequest = mock(DefaultFullHttpRequest.class); io.netty.handler.codec.http.HttpMethod httpMethod = mock(io.netty.handler.codec.http.HttpMethod.class); when(httpMethod.name()).thenReturn("GET"); when(nettyRequest.method()).thenReturn(httpMethod); HttpVersion httpVersion = mock(HttpVersion.class); when(httpVersion.text()).thenReturn("HTTP/1.0"); when(nettyRequest.protocolVersion()).thenReturn(httpVersion); when(nettyRequest.uri()).thenReturn("/odata.svc/$metadata"); HttpHeaders headers = mock(HttpHeaders.class); headers.add("Accept", "application/atom+xml"); Set<String> set = new HashSet<String>(); set.add("Accept"); when(headers.names()).thenReturn(set); when(nettyRequest.headers()).thenReturn(headers); when(nettyRequest.content()).thenReturn(Unpooled.buffer()); DefaultFullHttpResponse nettyResponse = mock(DefaultFullHttpResponse.class); when(nettyResponse.status()).thenReturn(HttpResponseStatus.OK); when(nettyResponse.headers()).thenReturn(headers); when(nettyResponse.content()).thenReturn(Unpooled.buffer()); Map<String, String> requestParams = new HashMap<String, String>(); requestParams.put("contextPath", "/odata.svc"); handler.processNettyRequest(nettyRequest, nettyResponse, requestParams); nettyResponse.status(); assertEquals(HttpStatusCode.OK.getStatusCode(), HttpResponseStatus.OK.code()); }
Example #21
Source File: ODataHandlerImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public ODataHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata, final ServerCoreDebugger debugger) { this.odata = odata; this.serviceMetadata = serviceMetadata; this.debugger = debugger; register(new DefaultRedirectProcessor()); register(new DefaultProcessor()); }
Example #22
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public ODataDeserializer createDeserializer(final ContentType contentType, ServiceMetadata metadata) throws DeserializerException { if (contentType != null && contentType.isCompatible(ContentType.JSON)) { return new ODataJsonDeserializer(contentType, metadata); } else if (contentType != null && (contentType.isCompatible(ContentType.APPLICATION_XML) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML))) { return new ODataXmlDeserializer(metadata); } else { throw new DeserializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); } }
Example #23
Source File: PropertyResponse.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private PropertyResponse(ServiceMetadata metadata, ODataSerializer serializer, ODataResponse response, ComplexSerializerOptions options, ContentType contentType, boolean collection, Map<String, String> preferences) { super(metadata, response, preferences); this.serializer = serializer; this.complexOptions = options; this.responseContentType = contentType; this.collection = collection; }
Example #24
Source File: ODataJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
void writeMetadataETag(final ServiceMetadata metadata, final JsonGenerator json) throws IOException { if (!isODataMetadataNone && metadata != null && metadata.getServiceMetadataETagSupport() != null && metadata.getServiceMetadataETagSupport().getMetadataETag() != null) { json.writeStringField(constants.getMetadataEtag(), metadata.getServiceMetadataETagSupport().getMetadataETag()); } }
Example #25
Source File: DemoServlet.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { OData odata = OData.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>()); try { HttpSession session = req.getSession(true); Storage storage = (Storage) session.getAttribute(Storage.class.getName()); if (storage == null) { storage = new Storage(odata, edm.getEdm()); session.setAttribute(Storage.class.getName(), storage); } // create odata handler and configure it with EdmProvider and Processor ODataHttpHandler handler = odata.createHandler(edm); handler.register(new DemoEntityCollectionProcessor(storage)); handler.register(new DemoEntityProcessor(storage)); handler.register(new DemoPrimitiveProcessor(storage)); handler.register(new DemoActionProcessor(storage)); handler.register(new DemoBatchProcessor(storage)); // let the handler do the work handler.process(req, resp); } catch (RuntimeException e) { LOG.error("Server Error occurred in ExampleServlet", e); throw new ServletException(e); } }
Example #26
Source File: ODataWritableContent.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public StreamContentForJson(EntityIterator iterator, EdmEntityType entityType, ODataJsonSerializer jsonSerializer, ServiceMetadata metadata, EntityCollectionSerializerOptions options) { super(iterator, entityType, metadata, options); this.jsonSerializer = jsonSerializer; }
Example #27
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void writeComplex(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set<List<String>> selectedPaths, final String xml10InvalidCharReplacement, final XMLStreamWriter writer, Set<List<String>> expandedPaths, Linked linked, ExpandOption expand) throws XMLStreamException, SerializerException{ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, "#" + complexType(metadata, (EdmComplexType) edmProperty.getType(), property.getType())); String derivedName = property.getType(); final EdmComplexType resolvedType = resolveComplexType(metadata, (EdmComplexType) edmProperty.getType(), derivedName); if (null != linked) { if (linked instanceof Entity) { linked = ((Entity)linked).getProperty(property.getName()).asComplex(); } else if (linked instanceof ComplexValue) { List<Property> complexProperties = ((ComplexValue)linked).getValue(); for (Property prop : complexProperties) { if (prop.getName().equals(property.getName())) { linked = prop.asComplex(); break; } } } expandedPaths = expandedPaths == null || expandedPaths.isEmpty() ? null : ExpandSelectHelper.getReducedExpandItemsPaths(expandedPaths, property.getName()); } writeComplexValue(metadata, resolvedType, property.asComplex().getValue(), selectedPaths, xml10InvalidCharReplacement, writer, expandedPaths, linked, expand, property.getName()); }
Example #28
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void writePropertyValue(final ServiceMetadata metadata, final EdmProperty edmProperty, final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException { final EdmType type = edmProperty.getType(); try { if (edmProperty.isPrimitive() || type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) { if (edmProperty.isCollection()) { writePrimitiveCollection((EdmPrimitiveType) type, property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json); } else { writePrimitive((EdmPrimitiveType) type, property, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json); } } else if (property.isComplex()) { if (edmProperty.isCollection()) { writeComplexCollection(metadata, (EdmComplexType) type, property, selectedPaths, json); } else { writeComplex(metadata, (EdmComplexType) type, property, selectedPaths, json); } } else { throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName()); } } catch (final EdmPrimitiveTypeException e) { throw new SerializerException("Wrong value for property!", e, SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), property.getValue().toString()); } }
Example #29
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public Entity readFunctionImportEntity(final UriResourceFunction uriResourceFunction, final ServiceMetadata serviceMetadata) throws ODataApplicationException { final EntityCollection entityCollection = readFunctionImportCollection(uriResourceFunction, serviceMetadata); final EdmEntityType edmEntityType = (EdmEntityType) uriResourceFunction.getFunction().getReturnType().getType(); return Util.findEntity(edmEntityType, entityCollection, uriResourceFunction.getKeyPredicates()); }
Example #30
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public EntityCollection readFunctionImportCollection(final UriResourceFunction uriResourceFunction, final ServiceMetadata serviceMetadata) throws ODataApplicationException { if(DemoEdmProvider.FUNCTION_COUNT_CATEGORIES.equals(uriResourceFunction.getFunctionImport().getName())) { // Get the parameter of the function final UriParameter parameterAmount = uriResourceFunction.getParameters().get(0); // Try to convert the parameter to an Integer. // We have to take care, that the type of parameter fits to its EDM declaration int amount; try { amount = Integer.parseInt(parameterAmount.getText()); } catch(NumberFormatException e) { throw new ODataApplicationException("Type of parameter Amount must be Edm.Int32", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH); } final EdmEntityType productEntityType = serviceMetadata.getEdm().getEntityType(DemoEdmProvider.ET_PRODUCT_FQN); final List<Entity> resultEntityList = new ArrayList<Entity>(); // Loop over all categories and check how many products are linked for(final Entity category : categoryList) { final EntityCollection products = getRelatedEntityCollection(category, productEntityType); if(products.getEntities().size() == amount) { resultEntityList.add(category); } } final EntityCollection resultCollection = new EntityCollection(); resultCollection.getEntities().addAll(resultEntityList); return resultCollection; } else { throw new ODataApplicationException("Function not implemented", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); } }