summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-01 00:19:41 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-01 00:19:41 +0000
commit75e7d7c9999fbb11021cfbe27a802cd9fe4ad9ba (patch)
tree8b981d58d5b5497506c7aec386527f664bf741c7 /java
parent06ae9eb2432a82145225bff1b2b50f3240da5efd (diff)
Bring up the reference binding with the WeatherForecast web service
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@760744 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/binding-ws-jaxws/META-INF/MANIFEST.MF1
-rw-r--r--java/sca/modules/binding-ws-jaxws/pom.xml157
-rw-r--r--java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java73
-rw-r--r--java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSReferenceBindingProvider.java13
-rw-r--r--java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastClient.java67
-rw-r--r--java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastImpl.java43
6 files changed, 322 insertions, 32 deletions
diff --git a/java/sca/modules/binding-ws-jaxws/META-INF/MANIFEST.MF b/java/sca/modules/binding-ws-jaxws/META-INF/MANIFEST.MF
index 31e002e6ec..fabf1652a2 100644
--- a/java/sca/modules/binding-ws-jaxws/META-INF/MANIFEST.MF
+++ b/java/sca/modules/binding-ws-jaxws/META-INF/MANIFEST.MF
@@ -42,7 +42,6 @@ Import-Package: javax.security.auth.callback;resolution:=optional,
org.apache.tuscany.sca.policy.authentication.basic;version="2.0.0",
org.apache.tuscany.sca.policy.security;version="2.0.0",
org.apache.tuscany.sca.policy.util;version="2.0.0",
- org.apache.tuscany.sca.policy.xml.ws;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.provider;version="2.0.0",
org.apache.tuscany.sca.runtime;version="2.0.0",
org.apache.tuscany.sca.xsd;version="2.0.0",
diff --git a/java/sca/modules/binding-ws-jaxws/pom.xml b/java/sca/modules/binding-ws-jaxws/pom.xml
index dbe8662bb0..a878f65b3b 100644
--- a/java/sca/modules/binding-ws-jaxws/pom.xml
+++ b/java/sca/modules/binding-ws-jaxws/pom.xml
@@ -34,6 +34,7 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-core</artifactId>
<version>2.0-SNAPSHOT</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
@@ -53,6 +54,7 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-assembly-xml</artifactId>
<version>2.0-SNAPSHOT</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
@@ -84,8 +86,9 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-databinding-axiom</artifactId>
+ <artifactId>tuscany-databinding-jaxb</artifactId>
<version>2.0-SNAPSHOT</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
@@ -99,18 +102,14 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-http</artifactId>
<version>2.0-SNAPSHOT</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-interface-java-jaxws</artifactId>
<version>2.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-policy-xml-ws</artifactId>
- <version>2.0-SNAPSHOT</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
@@ -125,7 +124,149 @@
<version>2.5</version>
<scope>provided</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-impl</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+ <build>
+ <plugins>
+ <!-- comment out the following to build offline -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.1</version>
+
+ <executions>
+ <execution>
+ <id>install-wsdl</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <mkdir dir="${project.build.directory}/jaxws-source/wsdl/" />
+ <get src="http://www.webservicex.net/WeatherForecast.asmx?wsdl"
+ dest="${project.build.directory}/jaxws-source/wsdl/WeatherForecast.wsdl" verbose="true"
+ usetimestamp="true" />
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- end of offline excluded section -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>-Djava.endorsed.dirs=target/endorsed</argLine>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>javax.xml.ws</groupId>
+ <artifactId>jaxws-api</artifactId>
+ <version>2.1</version>
+ <type>jar</type>
+ </artifactItem>
+ <artifactItem>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.1</version>
+ <type>jar</type>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>${project.build.directory}/endorsed</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/jaxws-source</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jaxws-maven-plugin</artifactId>
+ <version>1.11</version>
+ <!-- Explicitly add the transitive dependencies for jaxws-api
+ http://jira.codehaus.org/browse/MEV-498
+ -->
+ <dependencies>
+ <dependency>
+ <groupId>javax.jws</groupId>
+ <artifactId>jsr181-api</artifactId>
+ <version>1.0-MR1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>wsimport</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>wsimport</goal>
+ </goals>
+ <configuration>
+ <packageName>com.example.weather</packageName>
+ <wsdlDirectory>${project.build.directory}/jaxws-source/wsdl</wsdlDirectory>
+ <wsdlFiles>
+ <wsdlFile>WeatherForecast.wsdl</wsdlFile>
+ </wsdlFiles>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <target>2.1</target>
+ <sourceDestDir>${project.build.directory}/jaxws-source</sourceDestDir>
+ <verbose>false</verbose>
+ <xnocompile>true</xnocompile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
</project>
diff --git a/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java b/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java
index 7b9f108e88..ecb3b4f87b 100644
--- a/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java
+++ b/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java
@@ -18,9 +18,16 @@
*/
package org.apache.tuscany.sca.binding.ws.jaxws;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Iterator;
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.extensions.soap12.SOAP12Operation;
import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
@@ -29,11 +36,11 @@ import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.soap.SOAPFaultException;
-import org.apache.axis2.addressing.AddressingConstants;
import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
@@ -49,9 +56,6 @@ import org.w3c.dom.Node;
public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics {
private final static String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
- public static final QName QNAME_WSA_FROM =
- new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM,
- AddressingConstants.WSA_DEFAULT_PREFIX);
public static final String TUSCANY_PREFIX = "tuscany";
public static final QName CALLBACK_ID_REFPARM_QN = new QName(SCA11_TUSCANY_NS, "CallbackID", TUSCANY_PREFIX);
public static final QName CONVERSATION_ID_REFPARM_QN =
@@ -62,16 +66,33 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics {
private Operation operation;
private WebServiceBinding wsBinding;
- public JAXWSBindingInvoker(Dispatch<SOAPMessage> dispatch,
- Operation operation,
+ public JAXWSBindingInvoker(Operation operation,
WebServiceFeature[] features,
MessageFactory messageFactory,
WebServiceBinding wsBinding) {
- this.dispatch = dispatch;
this.messageFactory = messageFactory;
this.operation = operation;
this.wsBinding = wsBinding;
+ this.dispatch = createDispatch(wsBinding);
+ }
+ private Dispatch<SOAPMessage> createDispatch(WebServiceBinding wsBinding) {
+ // FIXME: What should we do if the WSDL is generated in memory?
+ URL wsdlLocation = null;
+ try {
+ wsdlLocation = new URL(wsBinding.getWSDLDocument().getDocumentBaseURI());
+ } catch (MalformedURLException e) {
+ try {
+ wsdlLocation = wsBinding.getWSDLDefinition().getLocation().toURL();
+ } catch (MalformedURLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ Service service = Service.create(wsdlLocation, wsBinding.getServiceName());
+ return service.createDispatch(new QName(wsBinding.getServiceName().getNamespaceURI(), wsBinding.getPortName()),
+ SOAPMessage.class,
+ Service.Mode.MESSAGE);
}
public Message invoke(Message msg) {
@@ -88,8 +109,8 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics {
}
}
- msg.setBody(resp);
} catch (SOAPFaultException e) {
+ e.printStackTrace();
setFault(msg, e.getFault());
} catch (WebServiceException e) {
msg.setFaultBody(e);
@@ -103,23 +124,53 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics {
}
private void setFault(Message msg, SOAPFault fault) {
- for (Iterator i = fault.getDetail().getDetailEntries(); i.hasNext();) {
+ Detail detail = fault.getDetail();
+ if (detail == null) {
+ return;
+ }
+ for (Iterator i = detail.getDetailEntries(); i.hasNext();) {
DetailEntry entry = (DetailEntry)i.next();
msg.setFaultBody(entry);
}
}
+ protected String getSOAPAction(String operationName) {
+ Binding binding = wsBinding.getBinding();
+ if (binding != null) {
+ for (Object o : binding.getBindingOperations()) {
+ BindingOperation bop = (BindingOperation)o;
+ if (bop.getName().equalsIgnoreCase(operationName)) {
+ for (Object o2 : bop.getExtensibilityElements()) {
+ if (o2 instanceof SOAPOperation) {
+ return ((SOAPOperation)o2).getSoapActionURI();
+ } else if (o2 instanceof SOAP12Operation) {
+ return ((SOAP12Operation)o2).getSoapActionURI();
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
protected SOAPMessage invokeTarget(Message msg) throws SOAPException {
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
javax.xml.soap.SOAPEnvelope envelope = soapPart.getEnvelope();
- javax.xml.soap.SOAPBody body = envelope.addBody();
- body.addDocument(((Node)msg.getBody()).getOwnerDocument());
+ javax.xml.soap.SOAPBody body = envelope.getBody();
+ Object[] args = (Object[])msg.getBody();
+ body.addDocument(((Node)args[0]).getOwnerDocument());
soapMessage.saveChanges();
if (operation.isNonBlocking()) {
dispatch.invokeOneWay(soapMessage);
return null;
}
+
+ // FIXME: We need to find out the soapAction
+ String action = getSOAPAction(operation.getName());
+ if (action != null) {
+ dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, action);
+ }
SOAPMessage response = dispatch.invoke(soapMessage);
return response;
}
diff --git a/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSReferenceBindingProvider.java b/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSReferenceBindingProvider.java
index a57c5a726f..13f38044af 100644
--- a/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSReferenceBindingProvider.java
+++ b/java/sca/modules/binding-ws-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSReferenceBindingProvider.java
@@ -18,12 +18,6 @@
*/
package org.apache.tuscany.sca.binding.ws.jaxws;
-import javax.xml.bind.JAXBContext;
-import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.ws.Dispatch;
-import javax.xml.ws.Service;
-
import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
@@ -40,7 +34,6 @@ public class JAXWSReferenceBindingProvider implements ReferenceBindingProvider {
private javax.xml.soap.MessageFactory messageFactory;
private WebServiceBinding wsBinding;
- private Dispatch<SOAPMessage> dispatch;
public JAXWSReferenceBindingProvider(RuntimeComponent component,
RuntimeComponentReference reference,
@@ -61,10 +54,6 @@ public class JAXWSReferenceBindingProvider implements ReferenceBindingProvider {
if (contract.getInterface() != null) {
contract.getInterface().resetDataBinding(Node.class.getName());
}
-
- Service service = Service.create(wsBinding.getServiceName());
- JAXBContext context = null;
- Dispatch<Object> dispath = service.createDispatch(new QName(wsBinding.getServiceName().getNamespaceURI(), wsBinding.getPortName()), context,Service.Mode.MESSAGE);
}
public void start() {
@@ -82,7 +71,7 @@ public class JAXWSReferenceBindingProvider implements ReferenceBindingProvider {
}
public Invoker createInvoker(Operation operation) {
- return new JAXWSBindingInvoker(dispatch, null, null, messageFactory, wsBinding);
+ return new JAXWSBindingInvoker(operation, null, messageFactory, wsBinding);
}
}
diff --git a/java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastClient.java b/java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastClient.java
new file mode 100644
index 0000000000..40b0b8f6dc
--- /dev/null
+++ b/java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastClient.java
@@ -0,0 +1,67 @@
+/*
+ * 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 weather;
+
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+
+import com.example.weather.GetWeatherByZipCodeResponse;
+import com.example.weather.WeatherForecastSoap;
+import com.example.weather.WeatherForecasts;
+
+/**
+ * This client program to invoke the Mortgage LoanApproval service
+ */
+public class WeatherForecastClient {
+
+ public static void main(String[] args) throws Exception {
+
+ String location = ContributionLocationHelper.getContributionLocation("WeatherForecast.composite");
+ Node node = NodeFactory.newInstance().createNode("WeatherForecast.composite", new Contribution("c1", location));
+ node.start();
+ WeatherForecastSoap weatherService = node.getService(WeatherForecastSoap.class, "WeatherForecastService");
+
+ WeatherForecasts result = weatherService.getWeatherByZipCode("94555");
+
+ // Dump the result as XML
+
+ // Wrap the result so that it can be marshaled
+ GetWeatherByZipCodeResponse response = new GetWeatherByZipCodeResponse();
+ response.setGetWeatherByZipCodeResult(result);
+
+ // Marshal the JAXB object into XML
+ JAXBContext context = JAXBContext.newInstance(GetWeatherByZipCodeResponse.class);
+ StringWriter writer = new StringWriter();
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.marshal(response, writer);
+
+ String xml = writer.toString();
+ System.out.println(xml);
+
+ node.stop();
+ }
+}
diff --git a/java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastImpl.java b/java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastImpl.java
new file mode 100644
index 0000000000..d3b44450a7
--- /dev/null
+++ b/java/sca/modules/binding-ws-jaxws/src/test/java/weather/WeatherForecastImpl.java
@@ -0,0 +1,43 @@
+/*
+ * 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 weather;
+
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Service;
+
+import com.example.weather.WeatherForecastSoap;
+import com.example.weather.WeatherForecasts;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Service(WeatherForecastSoap.class)
+public class WeatherForecastImpl implements WeatherForecastSoap{
+ @Reference
+ protected WeatherForecastSoap weatherForecast;
+
+ public WeatherForecasts getWeatherByPlaceName(String placeName) {
+ return weatherForecast.getWeatherByPlaceName(placeName);
+ }
+
+ public WeatherForecasts getWeatherByZipCode(String zipCode) {
+ return weatherForecast.getWeatherByZipCode(zipCode);
+ }
+}