org.apache.olingo.server.api.OData Java Examples
The following examples show how to use
org.apache.olingo.server.api.OData.
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 { OData odata = OData.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>()); 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); } 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: 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 #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)); // let the handler do the work handler.process(req, resp); } catch (RuntimeException e) { LOG.error("Server Error occurred in DemoServlet", e); throw new ServletException(e); } }
Example #4
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 #5
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 { OData odata = OData.newInstance(); ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>()); 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); } 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 #6
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 #7
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 #8
Source File: JaxrsODataService.java From cxf with Apache License 2.0 | 6 votes |
@GET @Path("{id:.*}") public Response service(@Context HttpServletRequest req, @Context HttpServletResponse resp) { String requestMapping = req.getContextPath() + req.getServletPath() + "/DemoService.svc"; req.setAttribute("requestMapping", requestMapping); // 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()); // let the handler do the work handler.process(req, resp); return Response.ok().build(); }
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 DemoServlet", e); throw new ServletException(e); } }
Example #10
Source File: ODataHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void uriParserExceptionResultsInRightResponseEdmCause() 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"); final ODataResponse response = new ODataHandlerImpl(odata, serviceMetadata, new ServerCoreDebugger(odata)).process(request); assertNotNull(response); assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode()); }
Example #11
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 #12
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private EntityCollection createESBase(final Edm edm, final OData odata) { final EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyInt16", (short) 111)) .addProperty(createPrimitive("PropertyString", "TEST A")) .addProperty(createPrimitive("AdditionalPropertyString_5", "TEST A 0815"))); entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyInt16", (short) 222)) .addProperty(createPrimitive("PropertyString", "TEST B")) .addProperty(createPrimitive("AdditionalPropertyString_5", "TEST C 0815"))); entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyInt16", (short) 333)) .addProperty(createPrimitive("PropertyString", "TEST C")) .addProperty(createPrimitive("AdditionalPropertyString_5", "TEST E 0815"))); setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETBase)); createEntityId(edm, odata, "ESBase", entityCollection); createOperations("ESBase", entityCollection, EntityTypeProvider.nameETBase); return entityCollection; }
Example #13
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private EntityCollection createESFourKeyAlias(final Edm edm, final OData odata) { final EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyInt16", (short) 1)) .addProperty(createComplex("PropertyComp", ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 11), createPrimitive("PropertyString", "Num11") )) .addProperty(createComplex("PropertyCompComp", ComplexTypeProvider.nameCTCompComp.getFullQualifiedNameAsString(), createComplex("PropertyComp", ComplexTypeProvider.nameCTBase.getFullQualifiedNameAsString(), createPrimitive("PropertyInt16", (short) 111), createPrimitive("PropertyString", "Num111"), createPrimitive("AdditionalPropString", "Test123") ) )) ); setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETFourKeyAlias)); createEntityId(edm, odata, "ESFourKeyAlias", entityCollection); createOperations("ESFourKeyAlias", entityCollection, EntityTypeProvider.nameETFourKeyAlias); return entityCollection; }
Example #14
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 #15
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void createEntityId(final Edm edm, final OData odata, final String entitySetName, final EntityCollection entities) { final EdmEntitySet entitySet = edm.getEntityContainer().getEntitySet(entitySetName); final UriHelper helper = odata.createUriHelper(); for (Entity entity : entities.getEntities()) { try { entity.setId(URI.create(helper.buildCanonicalURL(entitySet, entity))); } catch (final SerializerException e) { entity.setId(null); } } }
Example #16
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public Storage(final OData odata, final Edm edm) { this.odata = odata; this.edm = edm; manager = new TransactionalEntityManager(edm); final List<Entity> productList = manager.getEntityCollection(DemoEdmProvider.ES_PRODUCTS_NAME); // creating some sample data initProductSampleData(); initCategorySampleData(); initAdvertisementSampleData(); linkProductsAndCategories(productList.size()); }
Example #17
Source File: ExpressionParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void testPropertyPathExp() throws Exception { final String entitySetName = "ESName"; final String keyPropertyName = "a"; EdmProperty keyProperty = mockProperty(keyPropertyName, OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String)); EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty); EdmEntityType entityType = mockEntityType(keyPropertyName, keyPropertyRef); Mockito.when(entityType.getPropertyNames()).thenReturn(Collections.singletonList(keyPropertyName)); Mockito.when(entityType.getProperty(keyPropertyName)).thenReturn(keyProperty); EdmEntitySet entitySet = mockEntitySet(entitySetName, entityType); EdmEntityContainer container = mockContainer(entitySetName, entitySet); Edm mockedEdm = Mockito.mock(Edm.class); Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container); UriTokenizer tokenizer = new UriTokenizer("a eq \'abc\'"); Expression expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, entityType, null, null); assertNotNull(expression); assertEquals("{[a] EQ \'abc\'}", expression.toString()); tokenizer = new UriTokenizer("a in (\'abc\', \'xyz\')"); expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, entityType, null, null); assertNotNull(expression); assertEquals("{[a] IN [\'abc\', \'xyz\']}", expression.toString()); try { tokenizer = new UriTokenizer("a in (\'abc\', 10)"); expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, entityType, null, null); } catch (UriParserSemanticException e) { assertEquals("Incompatible types.", e.getMessage()); } }
Example #18
Source File: TechnicalAsyncService.java From olingo-odata4 with Apache License 2.0 | 5 votes |
static void wrapToAsyncHttpResponse(final ODataResponse odResponse, final HttpServletResponse response) throws SerializerException, IOException { OData odata = OData.newInstance(); InputStream odResponseStream = odata.createFixedFormatSerializer().asyncResponse(odResponse); response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_HTTP.toContentTypeString()); response.setHeader(HttpHeader.CONTENT_ENCODING, "binary"); response.setStatus(HttpStatusCode.OK.getStatusCode()); writeToResponse(response, odResponseStream); }
Example #19
Source File: ODataXMLDeserializerActionParametersTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private Map<String, Parameter> deserialize(final String input, final String actionName, final String bindingTypeName) throws DeserializerException { return OData.newInstance().createDeserializer(ContentType.APPLICATION_XML, metadata) .actionParameters(new ByteArrayInputStream(input.getBytes()), bindingTypeName == null ? edm.getUnboundAction(new FullQualifiedName(NAMESPACE, actionName)) : edm.getBoundAction(new FullQualifiedName(NAMESPACE, actionName), new FullQualifiedName(NAMESPACE, bindingTypeName), false)) .getActionParameters(); }
Example #20
Source File: UriResourceImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void uriResourceLambdaAllImpl() { Expression expression = new LiteralImpl("Expression", null); UriResourceLambdaAllImpl impl = new UriResourceLambdaAllImpl("A", expression); assertEquals(UriResourceKind.lambdaAll, impl.getKind()); assertFalse(impl.isCollection()); assertEquals(expression, impl.getExpression()); assertEquals("A", impl.getLambdaVariable()); assertEquals(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean), impl.getType()); assertEquals("all", impl.toString()); }
Example #21
Source File: ParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void navPropertySameNameAsEntitySet() throws Exception { final String namespace = "namespace"; final String entityTypeName = "ETNavProp"; final FullQualifiedName nameETNavProp = new FullQualifiedName(namespace, entityTypeName); final String entitySetName = "ESNavProp"; final String keyPropertyName = "a"; EdmProperty keyProperty = Mockito.mock(EdmProperty.class); Mockito.when(keyProperty.getType()) .thenReturn(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte)); EdmKeyPropertyRef keyPropertyRef = Mockito.mock(EdmKeyPropertyRef.class); Mockito.when(keyPropertyRef.getName()).thenReturn(keyPropertyName); Mockito.when(keyPropertyRef.getProperty()).thenReturn(keyProperty); EdmNavigationProperty navProperty = Mockito.mock(EdmNavigationProperty.class); Mockito.when(navProperty.getName()).thenReturn(entitySetName); Mockito.when(navProperty.isCollection()).thenReturn(true); EdmEntityType entityType = Mockito.mock(EdmEntityType.class); Mockito.when(entityType.getFullQualifiedName()).thenReturn(nameETNavProp); Mockito.when(entityType.getKeyPredicateNames()).thenReturn(Collections.singletonList(keyPropertyName)); Mockito.when(entityType.getKeyPropertyRefs()).thenReturn(Collections.singletonList(keyPropertyRef)); Mockito.when(entityType.getNavigationProperty(entitySetName)).thenReturn(navProperty); Mockito.when(navProperty.getType()).thenReturn(entityType); EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); Mockito.when(entitySet.getName()).thenReturn(entitySetName); Mockito.when(entitySet.getEntityType()).thenReturn(entityType); EdmEntityContainer container = Mockito.mock(EdmEntityContainer.class); Mockito.when(container.getEntitySet(entitySetName)).thenReturn(entitySet); Edm mockedEdm = Mockito.mock(Edm.class); Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container); new TestUriValidator().setEdm(mockedEdm) .run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp") .goPath() .at(0).isEntitySet(entitySetName) .at(0).isKeyPredicate(0, keyPropertyName, "1") .at(1).isNavProperty(entitySetName, nameETNavProp, false) .at(1).isKeyPredicate(0, keyPropertyName, "2") .at(2).isNavProperty(entitySetName, nameETNavProp, false) .at(2).isKeyPredicate(0, keyPropertyName, "3") .at(3).isNavProperty(entitySetName, nameETNavProp, true); }
Example #22
Source File: ODataHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ODataResponse dispatch(final HttpMethod method, final String path, final String query, final String headerName, final String headerValue, final Processor processor) { ODataRequest request = new ODataRequest(); request.setMethod(method); request.setRawBaseUri(BASE_URI); if (path.isEmpty()) { request.setRawRequestUri(BASE_URI); } request.setRawODataPath(path); request.setRawQueryPath(query); if (headerName != null) { request.addHeader(headerName, Collections.singletonList(headerValue)); } if (headerName != HttpHeader.CONTENT_TYPE) { request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList( ContentType.JSON.toContentTypeString())); } 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); assertNotNull(response); return response; }
Example #23
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 #24
Source File: ContextURLBuilderTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void buildPrimitiveType() { ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot) .type(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String)) .build(); assertEquals(serviceRoot + "$metadata#Edm.String", ContextURLBuilder.create(contextURL).toASCIIString()); contextURL = ContextURL.with().serviceRoot(serviceRoot) .type(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String)).asCollection() .build(); assertEquals(serviceRoot + "$metadata#Collection(Edm.String)", ContextURLBuilder.create(contextURL).toString()); }
Example #25
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private EntityCollection createESAllKey(final Edm edm, final OData odata) { EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyString", "First")) .addProperty(createPrimitive("PropertyBoolean", true)) .addProperty(createPrimitive("PropertyByte", (short) 255)) .addProperty(createPrimitive("PropertySByte", Byte.MAX_VALUE)) .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE)) .addProperty(createPrimitive("PropertyInt32", Integer.MAX_VALUE)) .addProperty(createPrimitive("PropertyInt64", Long.MAX_VALUE)) .addProperty(createPrimitive("PropertyDecimal", BigDecimal.valueOf(34))) .addProperty(createPrimitive("PropertyDate", getDate(2012, 12, 3))) .addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23))) .addProperty(createPrimitive("PropertyDuration", BigDecimal.valueOf(6))) .addProperty(createPrimitive("PropertyGuid", GUID)) .addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21)))); entityCollection.getEntities().add(new Entity() .addProperty(createPrimitive("PropertyString", "Second")) .addProperty(createPrimitive("PropertyBoolean", true)) .addProperty(createPrimitive("PropertyByte", (short) 254)) .addProperty(createPrimitive("PropertySByte", (byte) 124)) .addProperty(createPrimitive("PropertyInt16", (short) 32764)) .addProperty(createPrimitive("PropertyInt32", 2147483644)) .addProperty(createPrimitive("PropertyInt64", 9223372036854775804L)) .addProperty(createPrimitive("PropertyDecimal", BigDecimal.valueOf(34))) .addProperty(createPrimitive("PropertyDate", getDate(2012, 12, 3))) .addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23))) .addProperty(createPrimitive("PropertyDuration", BigDecimal.valueOf(6))) .addProperty(createPrimitive("PropertyGuid", GUID)) .addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21)))); setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETAllKey)); createEntityId(edm, odata, "ESAllKey", entityCollection); createOperations( "ESAllKey", entityCollection, EntityTypeProvider.nameETAllKey); return entityCollection; }
Example #26
Source File: JsonDeltaSerializerWithNavigationsTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void testDeltaTokenWithBothVersions() throws Exception { List<String> versions = new ArrayList<String>(); versions.add("4.01"); versions.add("4.0"); ser = OData.newInstance().createEdmDeltaSerializer(ContentType.JSON, versions); final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta"); Delta delta = new Delta(); List<DeltaLink> addedLinks = new ArrayList<DeltaLink>(); DeltaLink link1 = new DeltaLink(); link1.setRelationship("NavPropertyETAllPrimOne"); link1.setSource(new URI("ESDelta(100)")); link1.setTarget(new URI("ESAllPrim(0)")); addedLinks.add(link1 ); delta.getAddedLinks().addAll(addedLinks ); delta.setDeltaLink(new URI("23042017")); InputStream stream = ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta , EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) .build()).getContent(); String jsonString = IOUtils.toString(stream); final String expectedResult = "{" + "\"@context\":\"$metadata#ESDelta/$delta\",\"value\":[{" + "\"@context\":\"#ESDelta/$link\",\"source\":\"ESDelta(100)\"," + "\"relationship\":\"NavPropertyETAllPrimOne\"," + "\"target\":\"ESAllPrim(0)\"}]," + "\"@deltaLink\":\"23042017\"" + "}"; Assert.assertNotNull(jsonString); Assert.assertEquals(expectedResult, jsonString); }
Example #27
Source File: Storage.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public Storage(final OData odata, final Edm edm) { this.odata = odata; this.edm = edm; this.manager = new TransactionalEntityManager(edm); initProductSampleData(); initCategorySampleData(); linkProductsAndCategories(); }
Example #28
Source File: OData4Impl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public static OData newInstance() { try { final Class<?> clazz = Class.forName(OData4Impl.class.getName()); final Object object = clazz.newInstance(); return (OData) object; } catch (final Exception e) { throw new ODataRuntimeException(e); } }
Example #29
Source File: DataRequest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public ContextURL getContextURL(OData odata) throws SerializerException { ContextURL.Builder builder = ContextURL.with().suffix(Suffix.REFERENCE); if (isCollection()) { builder.asCollection(); } setServiceRoot(builder, getODataRequest()); return builder.build(); }
Example #30
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); }