Updated Branches: refs/heads/master 37bfa9e7c -> 2da5f5e3b
camel-sap-netweaver component. Work in progress. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2da5f5e3 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2da5f5e3 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2da5f5e3 Branch: refs/heads/master Commit: 2da5f5e3b0d2f9a195f7fc0316e6ad41395d9d83 Parents: 37bfa9e Author: Claus Ibsen <davscl...@apache.org> Authored: Wed May 29 12:46:39 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed May 29 16:13:21 2013 +0200 ---------------------------------------------------------------------- apache-camel/pom.xml | 4 + apache-camel/src/main/descriptors/common-bin.xml | 1 + components/camel-sap-netweaver/pom.xml | 13 +++- .../sap/netweaver/NetWeaverComponent.java | 20 ++++++ .../component/sap/netweaver/NetWeaverEndpoint.java | 18 +++++ .../component/sap/netweaver/NetWeaverProducer.java | 27 +++++--- .../sap/netweaver/NetWeaverFlightDataTest.java | 12 +++- .../netweaver/NetWeaverFlightDataVelocityTest.java | 53 +++++++++++++++ .../src/test/resources/flight-info.vm | 11 +++ components/pom.xml | 1 + parent/pom.xml | 5 ++ .../karaf/features/src/main/resources/features.xml | 6 ++ .../camel/itest/karaf/CamelSapNetweaverTest.java | 40 +++++++++++ 13 files changed, 199 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/apache-camel/pom.xml ---------------------------------------------------------------------- diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml index a1ca22e..0aeafe4 100644 --- a/apache-camel/pom.xml +++ b/apache-camel/pom.xml @@ -436,6 +436,10 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-sap-netweaver</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-saxon</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/apache-camel/src/main/descriptors/common-bin.xml ---------------------------------------------------------------------- diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml index 0ebd556..3d08587 100644 --- a/apache-camel/src/main/descriptors/common-bin.xml +++ b/apache-camel/src/main/descriptors/common-bin.xml @@ -120,6 +120,7 @@ <include>org.apache.camel:camel-rss</include> <include>org.apache.camel:camel-ruby</include> <include>org.apache.camel:camel-rx</include> + <include>org.apache.camel:camel-sap-netweaver</include> <include>org.apache.camel:camel-saxon</include> <include>org.apache.camel:camel-scala</include> <include>org.apache.camel:camel-script</include> http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/camel-sap-netweaver/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-sap-netweaver/pom.xml b/components/camel-sap-netweaver/pom.xml index c0b0c99..71494cf 100644 --- a/components/camel-sap-netweaver/pom.xml +++ b/components/camel-sap-netweaver/pom.xml @@ -33,8 +33,7 @@ <properties> <camel.osgi.export.pkg>org.apache.camel.component.sap.netweaver.*</camel.osgi.export.pkg> - <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=sap-netweaver - </camel.osgi.export.service> + <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=sap-netweaver</camel.osgi.export.service> </properties> <dependencies> @@ -59,6 +58,16 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-velocity</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverComponent.java b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverComponent.java index 9ff0539..28f7d09 100644 --- a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverComponent.java +++ b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverComponent.java @@ -24,6 +24,8 @@ import org.apache.camel.impl.DefaultComponent; public class NetWeaverComponent extends DefaultComponent { private boolean json = true; + private boolean jsonAsMap = true; + private boolean flatternMap = true; private String username; private String password; @@ -34,6 +36,8 @@ public class NetWeaverComponent extends DefaultComponent { endpoint.setUsername(username); endpoint.setPassword(password); endpoint.setJson(json); + endpoint.setJsonAsMap(jsonAsMap); + endpoint.setFlatternMap(flatternMap); setProperties(endpoint, parameters); return endpoint; } @@ -61,4 +65,20 @@ public class NetWeaverComponent extends DefaultComponent { public void setJson(boolean json) { this.json = json; } + + public boolean isJsonAsMap() { + return jsonAsMap; + } + + public void setJsonAsMap(boolean jsonAsMap) { + this.jsonAsMap = jsonAsMap; + } + + public boolean isFlatternMap() { + return flatternMap; + } + + public void setFlatternMap(boolean flatternMap) { + this.flatternMap = flatternMap; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java index 1ab003c..0e4e638 100644 --- a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java +++ b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java @@ -25,6 +25,8 @@ import org.apache.camel.impl.DefaultEndpoint; public class NetWeaverEndpoint extends DefaultEndpoint { private boolean json; + private boolean jsonAsMap; + private boolean flatternMap; private String url; private String username; private String password; @@ -79,4 +81,20 @@ public class NetWeaverEndpoint extends DefaultEndpoint { public void setJson(boolean json) { this.json = json; } + + public boolean isJsonAsMap() { + return jsonAsMap; + } + + public void setJsonAsMap(boolean jsonAsMap) { + this.jsonAsMap = jsonAsMap; + } + + public boolean isFlatternMap() { + return flatternMap; + } + + public void setFlatternMap(boolean flatternMap) { + this.flatternMap = flatternMap; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverProducer.java b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverProducer.java index 82ec838..faa0f54 100644 --- a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverProducer.java +++ b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverProducer.java @@ -23,6 +23,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Producer; import org.apache.camel.impl.DefaultProducer; import org.apache.camel.util.ExchangeHelper; +import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ServiceHelper; import org.codehaus.jackson.map.ObjectMapper; @@ -43,23 +44,31 @@ public class NetWeaverProducer extends DefaultProducer { public void process(Exchange exchange) throws Exception { String command = ExchangeHelper.getMandatoryHeader(exchange, NetWeaverConstants.COMMAND, String.class); - Exchange dummy = getEndpoint().createExchange(); - dummy.getIn().setHeader(Exchange.HTTP_PATH, command); + Exchange httpExchange = getEndpoint().createExchange(); + httpExchange.getIn().setHeader(Exchange.HTTP_PATH, command); if (getEndpoint().isJson()) { - dummy.getIn().setHeader("Accept", "application/json"); + httpExchange.getIn().setHeader("Accept", "application/json"); } log.debug("Calling SAP Net-Weaver {} with command {}", http, command); - http.process(dummy); + http.process(httpExchange); - String json = dummy.hasOut() ? dummy.getOut().getBody(String.class) : dummy.getIn().getBody(String.class); + String data = httpExchange.getOut().getBody(String.class); - // map json string to json map - if (json != null) { + if (data != null && getEndpoint().isJsonAsMap()) { + // map json string to json map ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(json, Map.class); + Map map = mapper.readValue(data, Map.class); - exchange.getIn().setBody(map); + // if we only have one entry in the map, then put that as root (as it tends to return a single instance "d" + if (map.size() == 1 && getEndpoint().isFlatternMap()) { + exchange.getIn().setBody(map.values().iterator().next()); + } else { + exchange.getIn().setBody(map); + } + } else { + // store data as is + exchange.getIn().setBody(data); } } http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataTest.java ---------------------------------------------------------------------- diff --git a/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataTest.java b/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataTest.java index 76752de..9933014 100644 --- a/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataTest.java +++ b/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataTest.java @@ -25,7 +25,8 @@ public class NetWeaverFlightDataTest extends CamelTestSupport { private String username = "P1909969254"; private String password = "TODO"; private String url = "https://sapes1.sapdevcenter.com/sap/opu/odata/IWBEP/RMTSAMPLEFLIGHT_2/"; - private String command = "FlightCollection(AirLineID='AA',FlightConnectionID='0017',FlightDate=datetime'2012-08-29T00%3A00%3A00')/FlightBooking"; + private String command = "FlightCollection(AirLineID='AA',FlightConnectionID='0017',FlightDate=datetime'2012-08-29T00%3A00%3A00')"; + private String command2 = "FlightCollection(AirLineID='AA',FlightConnectionID='0017',FlightDate=datetime'2012-08-29T00%3A00%3A00')/FlightBooking"; @Test public void testNetWeaverFlight() throws Exception { @@ -36,6 +37,15 @@ public class NetWeaverFlightDataTest extends CamelTestSupport { assertMockEndpointsSatisfied(); } + @Test + public void testNetWeaverFlight2() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "Dummy", NetWeaverConstants.COMMAND, command2); + + assertMockEndpointsSatisfied(); + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataVelocityTest.java ---------------------------------------------------------------------- diff --git a/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataVelocityTest.java b/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataVelocityTest.java new file mode 100644 index 0000000..a45ec05 --- /dev/null +++ b/components/camel-sap-netweaver/src/test/java/org/apache/camel/component/sap/netweaver/NetWeaverFlightDataVelocityTest.java @@ -0,0 +1,53 @@ +/** + * 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. + */ +package org.apache.camel.component.sap.netweaver; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class NetWeaverFlightDataVelocityTest extends CamelTestSupport { + + private String username = "P1909969254"; + private String password = "TODO"; + private String url = "https://sapes1.sapdevcenter.com/sap/opu/odata/IWBEP/RMTSAMPLEFLIGHT_2/"; + private String command = "FlightCollection(AirLineID='AA',FlightConnectionID='0017',FlightDate=datetime'2012-08-29T00%3A00%3A00')"; + + @Test + public void testNetWeaverFlight() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "Dummy", NetWeaverConstants.COMMAND, command); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start").streamCaching() + .toF("sap-netweaver:%s?username=%s&password=%s", url, username, password) + .to("log:response?showStreams=true") + .to("velocity:flight-info.vm") + .to("log:info") + .to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/camel-sap-netweaver/src/test/resources/flight-info.vm ---------------------------------------------------------------------- diff --git a/components/camel-sap-netweaver/src/test/resources/flight-info.vm b/components/camel-sap-netweaver/src/test/resources/flight-info.vm new file mode 100644 index 0000000..fa52603 --- /dev/null +++ b/components/camel-sap-netweaver/src/test/resources/flight-info.vm @@ -0,0 +1,11 @@ +<html> + <body> + Flight information: + + <p/> + <br/>Airline ID: $body["AirLineID"] + <br/>Aircraft Type: $body["AirCraftType"] + <br/>Departure city: $body["FlightDetails"]["DepartureCity"] + <br/>Departure airport: $body["FlightDetails"]["DepartureAirPort"] + <br/>Destination city: $body["FlightDetails"]["DestinationCity"] + <br/>Destination airport: $body["FlightDetails"]["DestinationAirPort"] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index abd5f99..8a4b7d4 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -141,6 +141,7 @@ <module>camel-rss</module> <module>camel-ruby</module> <module>camel-rx</module> + <module>camel-sap-netweaver</module> <module>camel-saxon</module> <module>camel-script</module> <module>camel-servlet</module> http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 8e35217..8492f9f 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -958,6 +958,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-sap-netweaver</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-saxon</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/platforms/karaf/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index 8dab5f0..094b3e0 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -731,6 +731,12 @@ <bundle>mvn:com.netflix.rxjava/rxjava-core/${rxjava-version}</bundle> <bundle>mvn:org.apache.camel/camel-rx/${project.version}</bundle> </feature> + <feature name='camel-sap-netweaver' version='${project.version}' resolver='(obr)' start-level='50'> + <feature version='${project.version}'>camel-http</feature> + <bundle dependency='true'>mvn:org.codehaus.jackson/jackson-core-asl/${jackson-version}</bundle> + <bundle dependency='true'>mvn:org.codehaus.jackson/jackson-mapper-asl/${jackson-version}</bundle> + <bundle>mvn:org.apache.camel/camel-sap-netweaver/${project.version}</bundle> + </feature> <feature name='camel-saxon' version='${project.version}' resolver='(obr)' start-level='50'> <feature version='${project.version}'>camel-core</feature> <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xmlresolver/${xmlresolver-bundle-version}</bundle> http://git-wip-us.apache.org/repos/asf/camel/blob/2da5f5e3/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelSapNetweaverTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelSapNetweaverTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelSapNetweaverTest.java new file mode 100644 index 0000000..cdeee15 --- /dev/null +++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelSapNetweaverTest.java @@ -0,0 +1,40 @@ +/** + * 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. + */ +package org.apache.camel.itest.karaf; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.Configuration; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; + +@RunWith(JUnit4TestRunner.class) +public class CamelSapNetweaverTest extends AbstractFeatureTest { + + public static final String COMPONENT = extractName(CamelSapNetweaverTest.class); + + @Test + public void test() throws Exception { + testComponent(COMPONENT); + } + + @Configuration + public static Option[] configure() { + return configure(COMPONENT); + } + +} \ No newline at end of file