Repository: camel Updated Branches: refs/heads/master 88b8e447b -> 34c26df6e
CAMEL-9093: Provide an unparsed read mode for olingo2 Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/34c26df6 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/34c26df6 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/34c26df6 Branch: refs/heads/master Commit: 34c26df6eece4eef288e455e7604971ac0696abf Parents: 88b8e44 Author: Akitoshi Yoshida <a...@apache.org> Authored: Thu Aug 20 16:51:02 2015 +0200 Committer: Akitoshi Yoshida <a...@apache.org> Committed: Fri Aug 21 10:52:35 2015 +0200 ---------------------------------------------------------------------- .../camel/component/olingo2/api/Olingo2App.java | 12 + .../olingo2/api/impl/Olingo2AppImpl.java | 19 +- .../camel-olingo2-component/pom.xml.bak | 328 +++++++++++++++++++ .../component/olingo2/Olingo2Endpoint.java | 7 +- .../src/signatures/olingo-api-signature.txt | 1 + .../component/olingo2/Olingo2AppAPITest.java | 50 ++- 6 files changed, 412 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/34c26df6/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/Olingo2App.java ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/Olingo2App.java b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/Olingo2App.java index 751b798..4bddbf6 100644 --- a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/Olingo2App.java +++ b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/Olingo2App.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.olingo2.api; +import java.io.InputStream; import java.util.List; import java.util.Map; @@ -81,6 +82,17 @@ public interface Olingo2App { Olingo2ResponseHandler<T> responseHandler); /** + * Reads an OData resource and invokes callback with the unparsed input stream. + * @param edm Service Edm, read from calling <code>read(null, "$metdata", null, responseHandler)</code> + * @param resourcePath OData Resource path + * @param queryParams OData query params + * from http://www.odata.org/documentation/odata-version-2-0/uri-conventions#SystemQueryOptions + * @param responseHandler callback handler + */ + void uread(Edm edm, String resourcePath, Map<String, String> queryParams, + Olingo2ResponseHandler<InputStream> responseHandler); + + /** * Deletes an OData resource and invokes callback * with {@link org.apache.olingo.odata2.api.commons.HttpStatusCodes} on success, or with exception on failure. * @param resourcePath resource path for Entry http://git-wip-us.apache.org/repos/asf/camel/blob/34c26df6/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java index 7b82e69..7f6a80e 100644 --- a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java +++ b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java @@ -191,9 +191,7 @@ public final class Olingo2AppImpl implements Olingo2App { new AbstractFutureCallback<T>(responseHandler) { @Override - @SuppressWarnings("unchecked") public void onCompleted(HttpResponse result) throws IOException { - readContent(uriInfo, result.getEntity() != null ? result.getEntity().getContent() : null, responseHandler); } @@ -201,6 +199,23 @@ public final class Olingo2AppImpl implements Olingo2App { }); } + @Override + public void uread(final Edm edm, final String resourcePath, final Map<String, String> queryParams, + final Olingo2ResponseHandler<InputStream> responseHandler) { + + final UriInfoWithType uriInfo = parseUri(edm, resourcePath, queryParams); + + execute(new HttpGet(createUri(resourcePath, queryParams)), getResourceContentType(uriInfo), + new AbstractFutureCallback<InputStream>(responseHandler) { + + @Override + public void onCompleted(HttpResponse result) throws IOException { + responseHandler.onResponse(result.getEntity() != null ? result.getEntity().getContent() : null); + } + + }); + } + private ContentType getResourceContentType(UriInfoWithType uriInfo) { ContentType resourceContentType; switch (uriInfo.getUriType()) { http://git-wip-us.apache.org/repos/asf/camel/blob/34c26df6/components/camel-olingo2/camel-olingo2-component/pom.xml.bak ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-component/pom.xml.bak b/components/camel-olingo2/camel-olingo2-component/pom.xml.bak new file mode 100644 index 0000000..a133cdc --- /dev/null +++ b/components/camel-olingo2/camel-olingo2-component/pom.xml.bak @@ -0,0 +1,328 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>camel-olingo2-parent</artifactId> + <version>2.16-SNAPSHOT</version> + </parent> + + <artifactId>camel-olingo2</artifactId> + <packaging>bundle</packaging> + <name>Camel :: Olingo2 :: Component</name> + <description>Camel Olingo2 component</description> + + <properties> + <schemeName>olingo2</schemeName> + <componentName>Olingo2</componentName> + <componentPackage>org.apache.camel.component.olingo2</componentPackage> + <outPackage>org.apache.camel.component.olingo2.internal</outPackage> + + <camel.osgi.export.pkg>${componentPackage}</camel.osgi.export.pkg> + <camel.osgi.private.pkg>${outPackage}</camel.osgi.private.pkg> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-olingo2-api</artifactId> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>${commons-lang-version}</version> + </dependency> + + <!-- Camel annotations in provided scope to avoid compile errors in IDEs --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>spi-annotations</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + + <!-- Component API javadoc in provided scope to read API signatures --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-olingo2-api</artifactId> + <version>${project.version}</version> + <classifier>javadoc</classifier> + <scope>provided</scope> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>olingo-odata2-core</artifactId> + <version>${olingo2-version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>olingo-odata2-api-annotation</artifactId> + <version>${olingo2-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>olingo-odata2-annotation-processor-api</artifactId> + <version>${olingo2-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>olingo-odata2-annotation-processor-core</artifactId> + <version>${olingo2-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>${cxf-version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <version>${jetty9-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${jetty9-version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.eclipse.jetty.orbit</groupId> + <artifactId>javax.servlet</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-webapp</artifactId> + <version>${jetty9-version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <defaultGoal>install</defaultGoal> + + <plugins> + + <!-- generate Component source and test source --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <executions> + <execution> + <id>generate-test-component-classes</id> + <goals> + <goal>fromApis</goal> + </goals> + <configuration> + <apis> + <api> + <apiName /> + <proxyClass>org.apache.camel.component.olingo2.api.Olingo2App</proxyClass> + <fromSignatureFile>src/signatures/olingo-api-signature.txt</fromSignatureFile> + <excludeConfigNames>edm|responseHandler</excludeConfigNames> + <extraOptions> + <extraOption> + <name>keyPredicate</name> + <type>java.lang.String</type> + </extraOption> + </extraOptions> + <nullableOptions> + <nullableOption>queryParams</nullableOption> + </nullableOptions> + </api> + </apis> + </configuration> + </execution> + </executions> + </plugin> + + <!-- add generated source and test source to build --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-generated-sources</id> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-sources/camel-component</source> + </sources> + </configuration> + </execution> + <execution> + <id>add-generated-test-sources</id> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-test-sources/camel-component</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + <!-- add the olingo odata2 sample service source. See profile get-olingo2-sample below --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-test-source</id> + <phase>generate-test-sources</phase> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/olingo2-my-car-service/src/main/java</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <scheme>${schemeName}</scheme> + <componentName>${componentName}</componentName> + <componentPackage>${componentPackage}</componentPackage> + <outPackage>${outPackage}</outPackage> + </configuration> + </plugin> + </plugins> + </pluginManagement> + + </build> + + <reporting> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <scheme>${schemeName}</scheme> + <componentName>${componentName}</componentName> + <componentPackage>${componentPackage}</componentPackage> + <outPackage>${outPackage}</outPackage> + </configuration> + </plugin> + </plugins> + </reporting> + + <profiles> + <profile> + <!-- REVISIT as of now, the olingo odata2 sample service that is used in the tests + is not available in nexus and needs to be generated and built using its architype plugin. + If the sample service jar becomes available, we can use it directly --> + <id>get-olingo2-sample</id> + <activation> + <file> + <missing>target/olingo2-my-car-service</missing> + </file> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <executions> + <execution> + <id>generate-sources</id> + <phase>generate-test-sources</phase> + <goals> + <goal>exec</goal> + </goals> + </execution> + </executions> + <configuration> + <executable>mvn</executable> + <workingDirectory>${project.build.directory}</workingDirectory> + <arguments> + <argument>archetype:generate</argument> + <argument>-DinteractiveMode=false</argument> + <argument>-Dversion=${project.version}</argument> + <argument>-DgroupId=org.apache.camel</argument> + <argument>-DartifactId=olingo2-my-car-service</argument> + <argument>-DarchetypeGroupId=org.apache.olingo</argument> + <argument>-DarchetypeArtifactId=olingo-odata2-sample-cars-annotation-archetype</argument> + <argument>-DarchetypeVersion=${olingo2-version}</argument> + </arguments> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/34c26df6/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java b/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java index d8a2065..130d6b1 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java +++ b/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java @@ -52,6 +52,9 @@ public class Olingo2Endpoint extends AbstractApiEndpoint<Olingo2ApiName, Olingo2 private static final String DATA_PROPERTY = "data"; private static final String DELETE_METHOD = "delete"; + // unparsed variants + private static final String UREAD_METHOD = "uread"; + private final Set<String> endpointPropertyNames; @UriParam @@ -81,7 +84,7 @@ public class Olingo2Endpoint extends AbstractApiEndpoint<Olingo2ApiName, Olingo2 throw new IllegalArgumentException("Option inBody is not supported for consumer endpoint"); } // only read method is supported - if (!READ_METHOD.equals(methodName)) { + if (!READ_METHOD.equals(methodName) && !UREAD_METHOD.equals(methodName)) { throw new IllegalArgumentException("Only read method is supported for consumer endpoints"); } final Olingo2Consumer consumer = new Olingo2Consumer(this, processor); @@ -110,7 +113,7 @@ public class Olingo2Endpoint extends AbstractApiEndpoint<Olingo2ApiName, Olingo2 @Override protected void afterConfigureProperties() { // set default inBody - if (!(READ_METHOD.equals(methodName) || DELETE_METHOD.equals(methodName)) + if (!(READ_METHOD.equals(methodName) || DELETE_METHOD.equals(methodName) || UREAD_METHOD.equals(methodName)) && inBody == null) { inBody = DATA_PROPERTY; } http://git-wip-us.apache.org/repos/asf/camel/blob/34c26df6/components/camel-olingo2/camel-olingo2-component/src/signatures/olingo-api-signature.txt ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-component/src/signatures/olingo-api-signature.txt b/components/camel-olingo2/camel-olingo2-component/src/signatures/olingo-api-signature.txt index f4bdace..006fba7 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/signatures/olingo-api-signature.txt +++ b/components/camel-olingo2/camel-olingo2-component/src/signatures/olingo-api-signature.txt @@ -1,4 +1,5 @@ void read(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> queryParams, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler); +void uread(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> queryParams, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler); void delete(String resourcePath, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler); void create(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, Object data, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler); void update(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, Object data, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler); http://git-wip-us.apache.org/repos/asf/camel/blob/34c26df6/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java ---------------------------------------------------------------------- diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java index e502c6a..3d1bdd2 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.olingo2; +import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -41,6 +42,8 @@ import org.apache.http.entity.ContentType; import org.apache.olingo.odata2.api.commons.HttpStatusCodes; import org.apache.olingo.odata2.api.edm.Edm; import org.apache.olingo.odata2.api.edm.EdmEntitySetInfo; +import org.apache.olingo.odata2.api.ep.EntityProvider; +import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties; import org.apache.olingo.odata2.api.ep.entry.ODataEntry; import org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed; import org.apache.olingo.odata2.api.ep.feed.ODataFeed; @@ -95,6 +98,7 @@ public class Olingo2AppAPITest { // private static final String TEST_SERVICE_URL = "http://localhost:8080/cars-annotations-sample/MyFormula.svc"; // private static final ContentType TEST_FORMAT = ContentType.APPLICATION_XML_CS_UTF_8; private static final ContentType TEST_FORMAT = ContentType.APPLICATION_JSON; + private static final String TEST_FORMAT_STRING = TEST_FORMAT.toString(); // private static final Pattern LINK_PATTERN = Pattern.compile("[^(]+\\('([^']+)'\\)"); private static final String ID_PROPERTY = "Id"; @@ -128,7 +132,7 @@ public class Olingo2AppAPITest { protected static void setupClient() throws Exception { olingoApp = new Olingo2AppImpl(TEST_SERVICE_URL + "/"); - olingoApp.setContentType(TEST_FORMAT.toString()); + olingoApp.setContentType(TEST_FORMAT_STRING); LOG.info("Read Edm "); final TestOlingo2ResponseHandler<Edm> responseHandler = new TestOlingo2ResponseHandler<Edm>(); @@ -171,6 +175,20 @@ public class Olingo2AppAPITest { } @Test + public void testReadUnparsedFeed() throws Exception { + final TestOlingo2ResponseHandler<InputStream> responseHandler = new TestOlingo2ResponseHandler<InputStream>(); + + olingoApp.uread(edm, MANUFACTURERS, null, responseHandler); + + final InputStream rawfeed = responseHandler.await(); + assertNotNull("Data feed", rawfeed); + // for this test, we just let EP to verify the stream data + final ODataFeed dataFeed = EntityProvider.readFeed(TEST_FORMAT_STRING, edm.getEntitySets().get(2), + rawfeed, EntityProviderReadProperties.init().build()); + LOG.info("Entries: {}", prettyPrint(dataFeed)); + } + + @Test public void testReadEntry() throws Exception { final TestOlingo2ResponseHandler<ODataEntry> responseHandler = new TestOlingo2ResponseHandler<ODataEntry>(); @@ -195,6 +213,36 @@ public class Olingo2AppAPITest { } @Test + public void testReadUnparsedEntry() throws Exception { + final TestOlingo2ResponseHandler<InputStream> responseHandler = new TestOlingo2ResponseHandler<InputStream>(); + + olingoApp.uread(edm, TEST_MANUFACTURER, null, responseHandler); + InputStream rawentry = responseHandler.await(); + ODataEntry entry = EntityProvider.readEntry(TEST_FORMAT_STRING, edm.getEntitySets().get(2), + rawentry, EntityProviderReadProperties.init().build()); + LOG.info("Single Entry: {}", prettyPrint(entry)); + + responseHandler.reset(); + + olingoApp.uread(edm, TEST_CAR, null, responseHandler); + rawentry = responseHandler.await(); + entry = EntityProvider.readEntry(TEST_FORMAT_STRING, edm.getEntitySets().get(0), + rawentry, EntityProviderReadProperties.init().build()); + LOG.info("Single Entry: {}", prettyPrint(entry)); + + responseHandler.reset(); + final Map<String, String> queryParams = new HashMap<String, String>(); + queryParams.put(SystemQueryOption.$expand.toString(), CARS); + + olingoApp.uread(edm, TEST_MANUFACTURER, queryParams, responseHandler); + + rawentry = responseHandler.await(); + ODataEntry entryExpanded = EntityProvider.readEntry(TEST_FORMAT_STRING, edm.getEntitySets().get(2), + rawentry, EntityProviderReadProperties.init().build()); + LOG.info("Single Entry with expanded Cars relation: {}", prettyPrint(entryExpanded)); + } + + @Test public void testReadUpdateProperties() throws Exception { // test simple property Manufacturer.Founded final TestOlingo2ResponseHandler<Map<String, Object>> propertyHandler =