TUSCANY-3984: Support binding.ws, interface.wsdl and policySets for serialized service references git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk@1210165 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/itest/serialization-ws-basicauth/pom.xml b/itest/serialization-ws-basicauth/pom.xml new file mode 100644 index 0000000..4b1302e --- /dev/null +++ b/itest/serialization-ws-basicauth/pom.xml
@@ -0,0 +1,65 @@ +<?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> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-itest</artifactId> + <version>1.7-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>itest-serialization-ws-basicauth</artifactId> + <name>Apache Tuscany SCA iTest Serialized Service Reference Using HTTP Basic Auth</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.7-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.ws.security</groupId> + <artifactId>wss4j</artifactId> + <version>1.5.3</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>1.7-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-tomcat</artifactId> + <version>1.7-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-axis2</artifactId> + <version>1.7-SNAPSHOT</version> + <scope>test</scope> + </dependency> + </dependencies> +</project>
diff --git a/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldImpl.java b/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000..4cdcc1f --- /dev/null +++ b/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldImpl.java
@@ -0,0 +1,33 @@ +/* + * 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 helloworld; + +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String getGreetings(String name) { + return "Hello " + name; + } + +}
diff --git a/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldService.java b/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000..c0259c6 --- /dev/null +++ b/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldService.java
@@ -0,0 +1,29 @@ +/* + * 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 helloworld; + +import org.osoa.sca.annotations.Remotable; + +/** + * The interface for the helloworld service + */ +@Remotable +public interface HelloWorldService { + public String getGreetings(String name); +}
diff --git a/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldServiceComponent.java b/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldServiceComponent.java new file mode 100644 index 0000000..4d35fba --- /dev/null +++ b/itest/serialization-ws-basicauth/src/main/java/helloworld/HelloWorldServiceComponent.java
@@ -0,0 +1,80 @@ +/* + * 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 helloworld; + +import java.io.IOException; +import java.io.StringReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Reference; + +/** + * The HelloWorld service implementation + */ +public class HelloWorldServiceComponent implements HelloWorldService { + + ServiceReference<HelloWorldService> helloWorldService; + + public String getGreetings(String name) { + System.out.println("Called getGreetings"); + //return helloWorldService.getService().getGreetings(name); + String xml = null; + try { + xml = serializeServiceReferenceXML(helloWorldService); + } catch (IOException e) { + e.printStackTrace(); + return "serialization failure"; + } + System.out.println(xml); + ServiceReference<HelloWorldService> srCopy = null; + try { + srCopy = deserializeServiceReferenceXML(xml); + } catch (Exception e) { + e.printStackTrace(); + return "deserialization failure"; + } + return srCopy.getService().getGreetings(name); + } + + private String serializeServiceReferenceXML(ServiceReference<HelloWorldService> sr) throws IOException { + ServiceReferenceImpl<HelloWorldService> sri = (ServiceReferenceImpl<HelloWorldService>) sr; + return sri.toXMLString(); + } + + private ServiceReference<HelloWorldService> deserializeServiceReferenceXML(String serializedSR) throws Exception { + StringReader reader = new StringReader(serializedSR); + XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(reader); + ServiceReferenceImpl<HelloWorldService> sri + = new ServiceReferenceImpl<HelloWorldService>(/*HelloWorldService.class, */xmlReader); + return sri; + } + + public ServiceReference<HelloWorldService> getHelloWorldService() { + System.out.println("Got Injected helloWorldService"); + return helloWorldService; + } + + @Reference + public void setHelloWorldService(ServiceReference<HelloWorldService> helloWorldService) { + System.out.println("Injected helloWorldService"); + this.helloWorldService = helloWorldService; + } +} \ No newline at end of file
diff --git a/itest/serialization-ws-basicauth/src/main/resources/definitions.xml b/itest/serialization-ws-basicauth/src/main/resources/definitions.xml new file mode 100644 index 0000000..463229c --- /dev/null +++ b/itest/serialization-ws-basicauth/src/main/resources/definitions.xml
@@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="ASCII"?> +<definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://helloworld" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" > + + <sca:policySet name="ClientBasicAuthenticationPolicySet" + provides="authentication" + appliesTo="sca:reference/sca:binding.ws"> + <tuscany:basicAuthentication> + <tuscany:userName>TuscanyWsUser</tuscany:userName> + <tuscany:password>TuscanyWsUserPasswd</tuscany:password> + </tuscany:basicAuthentication> + </sca:policySet> + + <sca:policySet name="ServerBasicAuthenticationPolicySet" + provides="authentication" + appliesTo="sca:service/sca:binding.ws"> + <tuscany:basicAuthentication> + <tuscany:userName>TuscanyWsUser</tuscany:userName> + <tuscany:password>TuscanyWsUserPasswd</tuscany:password> + </tuscany:basicAuthentication> + </sca:policySet> + +</definitions>
diff --git a/itest/serialization-ws-basicauth/src/main/resources/helloworldws.composite b/itest/serialization-ws-basicauth/src/main/resources/helloworldws.composite new file mode 100644 index 0000000..949d7d4 --- /dev/null +++ b/itest/serialization-ws-basicauth/src/main/resources/helloworldws.composite
@@ -0,0 +1,35 @@ +<?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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://helloworld" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + xmlns:hw="http://helloworld" + name="helloworldws"> + + <service name="HelloWorldService" requires="authentication" promote="HelloWorldServiceComponent/HelloWorldService"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws uri="http://localhost:8085/HelloWorldService"/> + </service> + + <component name="HelloWorldServiceComponent"> + <implementation.java class="helloworld.HelloWorldImpl" /> + </component> + +</composite> \ No newline at end of file
diff --git a/itest/serialization-ws-basicauth/src/main/resources/helloworldwsclient.composite b/itest/serialization-ws-basicauth/src/main/resources/helloworldwsclient.composite new file mode 100644 index 0000000..9bfcf80 --- /dev/null +++ b/itest/serialization-ws-basicauth/src/main/resources/helloworldwsclient.composite
@@ -0,0 +1,37 @@ +<?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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://helloworld" + xmlns:hw="http://helloworld" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + name="helloworldwsclient"> + + <!-- A component with an embedded reference definition connecting to an external webservice + The wsdl interface for the reference is derived from the information specified by the 'wsdlElement' + --> + <component name="HelloTuscanyServiceComponent"> + <implementation.java class="helloworld.HelloWorldServiceComponent"/> + <reference name="helloWorldService" requires="authentication"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)"/> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort)"/> + </reference> + </component> + +</composite>
diff --git a/itest/serialization-ws-basicauth/src/main/resources/wsdl/helloworld.wsdl b/itest/serialization-ws-basicauth/src/main/resources/wsdl/helloworld.wsdl new file mode 100644 index 0000000..e6fcc6f --- /dev/null +++ b/itest/serialization-ws-basicauth/src/main/resources/wsdl/helloworld.wsdl
@@ -0,0 +1,85 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" + name="helloworld"> + + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns="http://www.w3.org/2001/XMLSchema"> + + <element name="getGreetings"> + <complexType> + <sequence> + <element name="name" type="xsd:string"/> + </sequence> + </complexType> + </element> + + <element name="getGreetingsResponse"> + <complexType> + <sequence> + <element name="getGreetingsReturn" type="xsd:string"/> + </sequence> + </complexType> + </element> + + </schema> + </wsdl:types> + + <wsdl:message name="getGreetingsRequest"> + <wsdl:part element="tns:getGreetings" name="parameters"/> + </wsdl:message> + + <wsdl:message name="getGreetingsResponse"> + <wsdl:part element="tns:getGreetingsResponse" name="parameters"/> + </wsdl:message> + + <wsdl:portType name="HelloWorld"> + <wsdl:operation name="getGreetings"> + <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest"/> + <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse"/> + </wsdl:operation> + </wsdl:portType> + + <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld"> + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="getGreetings"> + <wsdlsoap:operation soapAction=""/> + <wsdl:input name="getGreetingsRequest"> + <wsdlsoap:body use="literal"/> + </wsdl:input> + <wsdl:output name="getGreetingsResponse"> + <wsdlsoap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + + <wsdl:service name="HelloWorldService"> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort"> + <wsdlsoap:address location="http://localhost:8085/HelloWorldService"/> + </wsdl:port> + </wsdl:service> + + <wsdl:service name="HelloWorldWsPolicyService"> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort"> + <wsdlsoap:address location="http://localhost:8085/HelloWorldWsPolicyService"/> + </wsdl:port> + </wsdl:service> + +</wsdl:definitions>
diff --git a/itest/serialization-ws-basicauth/src/test/java/helloworld/HelloWorldClientTestCase.java b/itest/serialization-ws-basicauth/src/test/java/helloworld/HelloWorldClientTestCase.java new file mode 100644 index 0000000..6b9ede4 --- /dev/null +++ b/itest/serialization-ws-basicauth/src/test/java/helloworld/HelloWorldClientTestCase.java
@@ -0,0 +1,66 @@ +/* + * 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 helloworld; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.host.embedded.SCATestCaseRunner; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for helloworld web service client + */ +public class HelloWorldClientTestCase { + + private HelloWorldService helloTuscanyService; + private SCADomain scaDomain; + + private SCATestCaseRunner server; + + @Before + public void startClient() throws Exception { + try { + scaDomain = SCADomain.newInstance("helloworldwsclient.composite"); + helloTuscanyService = scaDomain.getService(HelloWorldService.class, "HelloTuscanyServiceComponent"); + + server = new SCATestCaseRunner(HelloWorldTestServer.class); + server.before(); + + } catch (Throwable e) { + e.printStackTrace(); + } + } + + @Test + public void testEmbeddedReferenceClient() throws Exception { + String msg = helloTuscanyService.getGreetings("Tuscany"); + Assert.assertEquals("Hello Tuscany", msg); + } + + @After + public void stopClient() throws Exception { + server.after(); + scaDomain.close(); + } + +}
diff --git a/itest/serialization-ws-basicauth/src/test/java/helloworld/HelloWorldTestServer.java b/itest/serialization-ws-basicauth/src/test/java/helloworld/HelloWorldTestServer.java new file mode 100644 index 0000000..21f2166 --- /dev/null +++ b/itest/serialization-ws-basicauth/src/test/java/helloworld/HelloWorldTestServer.java
@@ -0,0 +1,55 @@ +/* + * 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 helloworld; + +import java.io.IOException; +import java.net.Socket; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Starts up the SCA runtime which starts listening for service requests + */ +public class HelloWorldTestServer { + + private SCADomain scaDomain; + + @Before + public void startServer() throws Exception { + try { + scaDomain = SCADomain.newInstance("helloworldws.composite"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testPing() throws IOException { + new Socket("127.0.0.1", 8085); + } + + @After + public void stopServer() throws Exception { + scaDomain.close(); + } + +}
diff --git a/itest/serialization-ws/pom.xml b/itest/serialization-ws/pom.xml new file mode 100644 index 0000000..b41e314 --- /dev/null +++ b/itest/serialization-ws/pom.xml
@@ -0,0 +1,87 @@ +<?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> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-itest</artifactId> + <version>1.7-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>itest-serialization-ws</artifactId> + <name>Apache Tuscany SCA iTest Serialized Service Reference Using Web Services</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.7-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.ws.security</groupId> + <artifactId>wss4j</artifactId> + <version>1.5.4</version> + <exclusions> + <exclusion> + <groupId>org.apache.santuario</groupId> + <artifactId>xmlsec</artifactId> + </exclusion> + <exclusion> + <groupId>bouncycastle</groupId> + <artifactId>bcprov-jdk13</artifactId> + </exclusion> + <exclusion> + <groupId>bouncycastle</groupId> + <artifactId>bcprov-jdk15</artifactId> + </exclusion> + <exclusion> + <groupId>opensaml</groupId> + <artifactId>opensaml</artifactId> + </exclusion> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>1.7-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-tomcat</artifactId> + <version>1.7-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-axis2</artifactId> + <version>1.7-SNAPSHOT</version> + <scope>test</scope> + </dependency> + </dependencies> +</project>
diff --git a/itest/serialization-ws/src/main/java/helloworld/ClientPWCBHandler.java b/itest/serialization-ws/src/main/java/helloworld/ClientPWCBHandler.java new file mode 100644 index 0000000..0f1ebf4 --- /dev/null +++ b/itest/serialization-ws/src/main/java/helloworld/ClientPWCBHandler.java
@@ -0,0 +1,45 @@ +/* + * 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 helloworld; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + */ +public class ClientPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Client UserId/Password Handler .... "); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + System.out.println("User Id = " + pwcb.getIdentifer()); + pwcb.setPassword("TuscanyWsUserPasswd"); + System.out.println("Set Password = " + pwcb.getPassword()); + } + } + +}
diff --git a/itest/serialization-ws/src/main/java/helloworld/HelloWorldImpl.java b/itest/serialization-ws/src/main/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000..4cdcc1f --- /dev/null +++ b/itest/serialization-ws/src/main/java/helloworld/HelloWorldImpl.java
@@ -0,0 +1,33 @@ +/* + * 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 helloworld; + +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String getGreetings(String name) { + return "Hello " + name; + } + +}
diff --git a/itest/serialization-ws/src/main/java/helloworld/HelloWorldService.java b/itest/serialization-ws/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000..c0259c6 --- /dev/null +++ b/itest/serialization-ws/src/main/java/helloworld/HelloWorldService.java
@@ -0,0 +1,29 @@ +/* + * 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 helloworld; + +import org.osoa.sca.annotations.Remotable; + +/** + * The interface for the helloworld service + */ +@Remotable +public interface HelloWorldService { + public String getGreetings(String name); +}
diff --git a/itest/serialization-ws/src/main/java/helloworld/HelloWorldServiceComponent.java b/itest/serialization-ws/src/main/java/helloworld/HelloWorldServiceComponent.java new file mode 100644 index 0000000..3a8edf3 --- /dev/null +++ b/itest/serialization-ws/src/main/java/helloworld/HelloWorldServiceComponent.java
@@ -0,0 +1,78 @@ +/* + * 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 helloworld; + +import java.io.IOException; +import java.io.StringReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Reference; + +/** + * The HelloWorld service implementation + */ +public class HelloWorldServiceComponent implements HelloWorldService { + + ServiceReference<HelloWorldService> helloWorldService; + + public String getGreetings(String name) { + System.out.println("Called getGreetings"); + String xml = null; + try { + xml = serializeServiceReferenceXML(helloWorldService); + } catch (IOException e) { + e.printStackTrace(); + return "serialization failure"; + } + System.out.println(xml); + ServiceReference<HelloWorldService> srCopy = null; + try { + srCopy = deserializeServiceReferenceXML(xml); + } catch (Exception e) { + e.printStackTrace(); + return "deserialization failure"; + } + return srCopy.getService().getGreetings(name); + } + + public ServiceReference<HelloWorldService> getHelloWorldService() { + System.out.println("Got Injected helloWorldService"); + return helloWorldService; + } + + @Reference + public void setHelloWorldService(ServiceReference<HelloWorldService> helloWorldService) { + System.out.println("Injected helloWorldService"); + this.helloWorldService = helloWorldService; + } + + private String serializeServiceReferenceXML(ServiceReference<HelloWorldService> sr) throws IOException { + ServiceReferenceImpl<HelloWorldService> sri = (ServiceReferenceImpl<HelloWorldService>) sr; + return sri.toXMLString(); + } + + private ServiceReference<HelloWorldService> deserializeServiceReferenceXML(String serializedSR) throws Exception { + StringReader reader = new StringReader(serializedSR); + XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(reader); + ServiceReferenceImpl<HelloWorldService> sri = new ServiceReferenceImpl<HelloWorldService>(xmlReader); + return sri; + } +}
diff --git a/itest/serialization-ws/src/main/java/helloworld/ServerPWCBHandler.java b/itest/serialization-ws/src/main/java/helloworld/ServerPWCBHandler.java new file mode 100644 index 0000000..ded02f0 --- /dev/null +++ b/itest/serialization-ws/src/main/java/helloworld/ServerPWCBHandler.java
@@ -0,0 +1,55 @@ +/* + * 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 helloworld; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + */ +public class ServerPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Server User/Passwd Handler...."); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + System.out.println("User Id = " + pwcb.getIdentifer()); + System.out.println("Password = " + pwcb.getPassword()); + + if ( pwcb.getUsage() == WSPasswordCallback.USERNAME_TOKEN ) { + if ( pwcb.getIdentifer().equals("TuscanyWsUser") && + pwcb.getPassword().equals("TuscanyWsUserPasswd") ){ + return; + } else { + throw new UnsupportedCallbackException(pwcb, "Authentication Failed : UserId - Password mismatch"); + } + } else if ( pwcb.getUsage() == WSPasswordCallback.SIGNATURE ) { + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + } + +}
diff --git a/itest/serialization-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler b/itest/serialization-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler new file mode 100644 index 0000000..8b089c7 --- /dev/null +++ b/itest/serialization-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler
@@ -0,0 +1,21 @@ +# 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. +# +# PolicyHandlerClasses to interpret specific PolicyModels against specific QoS infrastructures +# handler classname;qname=<policy intent addressed>;model=<policy model class> +org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicyHandler;intent=http://helloworld#wsAuthentication,model=org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicy +org.apache.tuscany.sca.policy.security.ws.WSSecurityPolicyHandler;intent=http://helloworld#wsIntegrity,model=org.apache.neethi.Policy \ No newline at end of file
diff --git a/itest/serialization-ws/src/main/resources/definitions.xml b/itest/serialization-ws/src/main/resources/definitions.xml new file mode 100644 index 0000000..db1e2b2 --- /dev/null +++ b/itest/serialization-ws/src/main/resources/definitions.xml
@@ -0,0 +1,203 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> +<sca:definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://helloworld" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + xmlns:hw="http://helloworld"> + + <!-- WS Security POLICY SETS --> + <sca:policySet name="wsClientAuthenticationPolicy" + provides="authentication" + appliesTo="sca:reference/sca:binding.ws"> + <tuscany:wsConfigParam> + <parameter name="OutflowSecurity"> + <action> + <items>UsernameToken</items> + <user>TuscanyWsUser</user> + <passwordCallbackClass>helloworld.ClientPWCBHandler</passwordCallbackClass>" + + <passwordType>PasswordText</passwordType> + </action> + </parameter> + </tuscany:wsConfigParam> + </sca:policySet> + + <!-- A policyset that uses WS Policy --> + <sca:policySet name="wsSecurityPolicyForIntegrity" + provides="integrity" + appliesTo="sca:reference/sca:binding.ws"> + <wsp:Policy wsu:Id="SignOnly" + xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:ExactlyOne> + <wsp:All> + <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> + <wsp:Policy> + <sp:InitiatorToken> + <wsp:Policy> + <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"> + <wsp:Policy> + <sp:WssX509V3Token10/> + </wsp:Policy> + </sp:X509Token> + </wsp:Policy> + </sp:InitiatorToken> + <sp:RecipientToken> + <wsp:Policy> + <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"> + <wsp:Policy> + <sp:WssX509V3Token10/> + </wsp:Policy> + </sp:X509Token> + </wsp:Policy> + </sp:RecipientToken> + <sp:AlgorithmSuite> + <wsp:Policy> + <sp:TripleDesRsa15/> + </wsp:Policy> + </sp:AlgorithmSuite> + <sp:Layout> + <wsp:Policy> + <sp:Strict/> + </wsp:Policy> + </sp:Layout> + <sp:IncludeTimestamp/> + <sp:OnlySignEntireHeadersAndBody/> + </wsp:Policy> + </sp:AsymmetricBinding> + <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> + <wsp:Policy> + <sp:MustSupportRefKeyIdentifier/> + <sp:MustSupportRefIssuerSerial/> + </wsp:Policy> + </sp:Wss10> + <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> + <sp:Body/> + </sp:SignedParts> + + <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> + <ramp:user>TuscanyWsUser</ramp:user> + <ramp:encryptionUser>TuscanyWsUser</ramp:encryptionUser> + <ramp:passwordCallbackClass>helloworld.ClientPWCBHandler</ramp:passwordCallbackClass> + + <ramp:signatureCrypto> + <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin"> + <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</ramp:property> + <ramp:property name="org.apache.ws.security.crypto.merlin.file">helloworldKeys.jks</ramp:property> + <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">TuscanyWsUserPasswd</ramp:property> + </ramp:crypto> + </ramp:signatureCrypto> + </ramp:RampartConfig> + + </wsp:All> + </wsp:ExactlyOne> + </wsp:Policy> + </sca:policySet> + + + <!-- Policysets for unit tests that use the testHelloworldws.composite --> + <!-- Since we use the helloworld-ws-service for the unit testing we need to + declare these policy sets and with the 'provides' set to the intents that the + composite in the helloworld-ws-service uses. --> + <sca:policySet name="wsAuthenticationPolicy" + provides="authentication" + appliesTo="sca:service/sca:binding.ws" + > + <tuscany:wsConfigParam> + <parameter name="InflowSecurity"> + <action> + <items>UsernameToken</items> + <passwordCallbackClass>helloworld.ServerPWCBHandler</passwordCallbackClass> + </action> + </parameter> + </tuscany:wsConfigParam> + </sca:policySet> + + <sca:policySet name="wsServerSecurityPolicyForIntegrity" + provides="integrity" + appliesTo="sca:service/sca:binding.ws"> + <wsp:Policy wsu:Id="SignOnly" + xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:ExactlyOne> + <wsp:All> + <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> + <wsp:Policy> + <sp:InitiatorToken> + <wsp:Policy> + <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"> + <wsp:Policy> + <sp:WssX509V3Token10/> + </wsp:Policy> + </sp:X509Token> + </wsp:Policy> + </sp:InitiatorToken> + <sp:RecipientToken> + <wsp:Policy> + <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"> + <wsp:Policy> + <sp:WssX509V3Token10/> + </wsp:Policy> + </sp:X509Token> + </wsp:Policy> + </sp:RecipientToken> + <sp:AlgorithmSuite> + <wsp:Policy> + <sp:TripleDesRsa15/> + </wsp:Policy> + </sp:AlgorithmSuite> + <sp:Layout> + <wsp:Policy> + <sp:Strict/> + </wsp:Policy> + </sp:Layout> + <sp:IncludeTimestamp/> + <sp:OnlySignEntireHeadersAndBody/> + </wsp:Policy> + </sp:AsymmetricBinding> + <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> + <wsp:Policy> + <sp:MustSupportRefKeyIdentifier/> + <sp:MustSupportRefIssuerSerial/> + </wsp:Policy> + </sp:Wss10> + <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> + <sp:Body/> + </sp:SignedParts> + + <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> + <ramp:user>TuscanyWsUser</ramp:user> + <ramp:encryptionUser>TuscanyWsUser</ramp:encryptionUser> + <ramp:passwordCallbackClass>helloworld.ServerPWCBHandler</ramp:passwordCallbackClass> + + <ramp:signatureCrypto> + <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin"> + <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</ramp:property> + <ramp:property name="org.apache.ws.security.crypto.merlin.file">helloworldKeys.jks</ramp:property> + <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">TuscanyWsUserPasswd</ramp:property> + </ramp:crypto> + </ramp:signatureCrypto> + </ramp:RampartConfig> + </wsp:All> + </wsp:ExactlyOne> + </wsp:Policy> + </sca:policySet> + + </sca:definitions>
diff --git a/itest/serialization-ws/src/main/resources/helloworldKeys.jks b/itest/serialization-ws/src/main/resources/helloworldKeys.jks new file mode 100644 index 0000000..e2184ad --- /dev/null +++ b/itest/serialization-ws/src/main/resources/helloworldKeys.jks Binary files differ
diff --git a/itest/serialization-ws/src/main/resources/helloworldws.composite b/itest/serialization-ws/src/main/resources/helloworldws.composite new file mode 100644 index 0000000..a078067 --- /dev/null +++ b/itest/serialization-ws/src/main/resources/helloworldws.composite
@@ -0,0 +1,42 @@ +<?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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://helloworld" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + xmlns:hw="http://helloworld" + name="helloworldws"> + + <service name="HelloWorldService" requires="authentication" promote="HelloWorldServiceComponent/HelloWorldService"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws uri="http://localhost:8085/HelloWorldService"/> + </service> + + <service name="HelloWorldWsPolicyService" promote="HelloWorldServiceComponent/HelloWorldService" + requires="integrity"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws wsdlElement="http://helloworld#wsdl.binding(HelloWorldSoapBinding)" + uri="http://localhost:8085/HelloWorldWsPolicyService"/> + </service> + + <component name="HelloWorldServiceComponent"> + <implementation.java class="helloworld.HelloWorldImpl" /> + </component> + +</composite>
diff --git a/itest/serialization-ws/src/main/resources/helloworldwsclient.composite b/itest/serialization-ws/src/main/resources/helloworldwsclient.composite new file mode 100644 index 0000000..a57f362 --- /dev/null +++ b/itest/serialization-ws/src/main/resources/helloworldwsclient.composite
@@ -0,0 +1,59 @@ +<?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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://helloworld" + xmlns:hw="http://helloworld" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + name="helloworldwsclient"> + + <!-- A component with an embedded reference definition connecting to an external webservice + The wsdl interface for the reference is derived from the information specified by the 'wsdlElement' + --> + <component name="HelloTuscanyServiceComponent"> + <implementation.java class="helloworld.HelloWorldServiceComponent"/> + <reference name="helloWorldService" requires="authentication"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)"/> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort)"/> + </reference> + </component> + + <!-- A component with a reference promoted as a composite reference --> + <component name="HelloWorldServiceComponent"> + <implementation.java class="helloworld.HelloWorldServiceComponent"/> + </component> + + <!-- A component with a reference promoted as a composite reference with a ws policy --> + <component name="HelloWorldWsPolicyServiceComponent"> + <implementation.java class="helloworld.HelloWorldServiceComponent"/> + </component> + + <reference name="HelloWorldService" promote="HelloWorldServiceComponent/helloWorldService" + requires="authentication"> + <interface.java interface="helloworld.HelloWorldService" /> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort)"/> + </reference> + + <reference name="HelloWorldWsPolicyService" promote="HelloWorldWsPolicyServiceComponent/helloWorldService" + requires="integrity"> + <interface.java interface="helloworld.HelloWorldService" /> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldWsPolicyService/HelloWorldSoapPort)"/> + </reference> + +</composite>
diff --git a/itest/serialization-ws/src/main/resources/wsdl/helloworld.wsdl b/itest/serialization-ws/src/main/resources/wsdl/helloworld.wsdl new file mode 100644 index 0000000..e6fcc6f --- /dev/null +++ b/itest/serialization-ws/src/main/resources/wsdl/helloworld.wsdl
@@ -0,0 +1,85 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" + name="helloworld"> + + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns="http://www.w3.org/2001/XMLSchema"> + + <element name="getGreetings"> + <complexType> + <sequence> + <element name="name" type="xsd:string"/> + </sequence> + </complexType> + </element> + + <element name="getGreetingsResponse"> + <complexType> + <sequence> + <element name="getGreetingsReturn" type="xsd:string"/> + </sequence> + </complexType> + </element> + + </schema> + </wsdl:types> + + <wsdl:message name="getGreetingsRequest"> + <wsdl:part element="tns:getGreetings" name="parameters"/> + </wsdl:message> + + <wsdl:message name="getGreetingsResponse"> + <wsdl:part element="tns:getGreetingsResponse" name="parameters"/> + </wsdl:message> + + <wsdl:portType name="HelloWorld"> + <wsdl:operation name="getGreetings"> + <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest"/> + <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse"/> + </wsdl:operation> + </wsdl:portType> + + <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld"> + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="getGreetings"> + <wsdlsoap:operation soapAction=""/> + <wsdl:input name="getGreetingsRequest"> + <wsdlsoap:body use="literal"/> + </wsdl:input> + <wsdl:output name="getGreetingsResponse"> + <wsdlsoap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + + <wsdl:service name="HelloWorldService"> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort"> + <wsdlsoap:address location="http://localhost:8085/HelloWorldService"/> + </wsdl:port> + </wsdl:service> + + <wsdl:service name="HelloWorldWsPolicyService"> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort"> + <wsdlsoap:address location="http://localhost:8085/HelloWorldWsPolicyService"/> + </wsdl:port> + </wsdl:service> + +</wsdl:definitions>
diff --git a/itest/serialization-ws/src/test/java/helloworld/HelloWorldClientTestCase.java b/itest/serialization-ws/src/test/java/helloworld/HelloWorldClientTestCase.java new file mode 100644 index 0000000..8dabe87 --- /dev/null +++ b/itest/serialization-ws/src/test/java/helloworld/HelloWorldClientTestCase.java
@@ -0,0 +1,82 @@ +/* + * 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 helloworld; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.host.embedded.SCATestCaseRunner; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for helloworld web service client + */ +public class HelloWorldClientTestCase { + + private HelloWorldService helloWorldService; + private HelloWorldService helloTuscanyService; + private HelloWorldService helloWsPolicyService; + private SCADomain scaDomain; + + private SCATestCaseRunner server; + + @Before + public void startClient() throws Exception { + try { + scaDomain = SCADomain.newInstance("helloworldwsclient.composite"); + helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent"); + helloTuscanyService = scaDomain.getService(HelloWorldService.class, "HelloTuscanyServiceComponent"); + helloWsPolicyService = scaDomain.getService(HelloWorldService.class, "HelloWorldWsPolicyServiceComponent"); + + server = new SCATestCaseRunner(HelloWorldTestServer.class); + server.before(); + + } catch (Throwable e) { + e.printStackTrace(); + } + } + + @Test + public void testWSClient() throws Exception { + String msg = helloWorldService.getGreetings("Smith"); + Assert.assertEquals("Hello Smith", msg); + } + + @Test + public void testEmbeddedReferenceClient() throws Exception { + String msg = helloTuscanyService.getGreetings("Tuscany"); + Assert.assertEquals("Hello Tuscany", msg); + } + + @Test + public void testWsPolicyClient() throws Exception { + String msg = helloWsPolicyService.getGreetings("WsPolicyWorld"); + Assert.assertEquals("Hello WsPolicyWorld", msg); + } + + @After + public void stopClient() throws Exception { + server.after(); + scaDomain.close(); + } + +}
diff --git a/itest/serialization-ws/src/test/java/helloworld/HelloWorldTestServer.java b/itest/serialization-ws/src/test/java/helloworld/HelloWorldTestServer.java new file mode 100644 index 0000000..21f2166 --- /dev/null +++ b/itest/serialization-ws/src/test/java/helloworld/HelloWorldTestServer.java
@@ -0,0 +1,55 @@ +/* + * 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 helloworld; + +import java.io.IOException; +import java.net.Socket; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Starts up the SCA runtime which starts listening for service requests + */ +public class HelloWorldTestServer { + + private SCADomain scaDomain; + + @Before + public void startServer() throws Exception { + try { + scaDomain = SCADomain.newInstance("helloworldws.composite"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testPing() throws IOException { + new Socket("127.0.0.1", 8085); + } + + @After + public void stopServer() throws Exception { + scaDomain.close(); + } + +}
diff --git a/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BusinessInterface.java b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BusinessInterface.java new file mode 100644 index 0000000..b721998 --- /dev/null +++ b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BusinessInterface.java
@@ -0,0 +1,39 @@ +/* + * 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.tuscany.sca.runtime; + +/** + * Java business interface for serializing a CallableReference + * + * @version $Rev: 574648 $ $Date: 2007-09-11 18:45:36 +0100 (Tue, 11 Sep 2007) $ + */ +public interface BusinessInterface { + /** + * Get the interface class name + * @return the interface class name + */ + String getInterface(); + + /** + * Set the interface class name + * @param interfaze the interface class name + */ + void setInterface(String interfaze); +}
diff --git a/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/BusinessInterfaceImpl.java b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/BusinessInterfaceImpl.java new file mode 100644 index 0000000..f2fd3c7 --- /dev/null +++ b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/BusinessInterfaceImpl.java
@@ -0,0 +1,74 @@ +/* + * 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.tuscany.sca.core.assembly; + +import org.apache.tuscany.sca.runtime.BusinessInterface; + +/** + * @version $Rev: 574648 $ $Date: 2007-09-11 18:45:36 +0100 (Tue, 11 Sep 2007) $ + */ +public class BusinessInterfaceImpl implements BusinessInterface { + private String interfaze; + + /** + * @return the interface class name + */ + public String getInterface() { + return interfaze; + } + + /** + * @param interfaze the interface class name + */ + public void setInterface(String interfaze) { + this.interfaze = interfaze; + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((interfaze == null) ? 0 : interfaze.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof BusinessInterfaceImpl)) + return false; + final BusinessInterfaceImpl other = (BusinessInterfaceImpl)obj; + if (interfaze == null) { + if (other.interfaze != null) + return false; + } else if (!interfaze.equals(other.interfaze)) + return false; + return true; + } +}
diff --git a/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/BusinessInterfaceProcessor.java b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/BusinessInterfaceProcessor.java new file mode 100644 index 0000000..6d4caeb --- /dev/null +++ b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/BusinessInterfaceProcessor.java
@@ -0,0 +1,97 @@ +/* + * 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.tuscany.sca.core.assembly; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.runtime.BusinessInterface; + +/** + * Artifact processor for reference parameters. + * + * @version $Rev: 658664 $ $Date: 2008-05-21 13:46:26 +0100 (Wed, 21 May 2008) $ + */ +public class BusinessInterfaceProcessor implements StAXArtifactProcessor<BusinessInterface> { + private static final QName BUSINESS_INTERFACE = + new QName("http://tuscany.apache.org/xmlns/sca/1.0", "businessInterface", "tuscany"); + + /** + * Constructs a new processor. + * + * @param modelFactories + */ + public BusinessInterfaceProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#getArtifactType() + */ + public QName getArtifactType() { + return BUSINESS_INTERFACE; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader) + */ + public BusinessInterface read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + BusinessInterface businessInterface = new BusinessInterfaceImpl(); + businessInterface.setInterface(reader.getAttributeValue(null, "interface")); + return businessInterface; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, javax.xml.stream.XMLStreamWriter) + */ + public void write(BusinessInterface model, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + writer.writeStartElement(BUSINESS_INTERFACE.getPrefix(), + BUSINESS_INTERFACE.getLocalPart(), + BUSINESS_INTERFACE.getNamespaceURI()); + writer.writeNamespace(BUSINESS_INTERFACE.getPrefix(), BUSINESS_INTERFACE.getNamespaceURI()); + if (model.getInterface() != null) { + writer.writeAttribute("interface", model.getInterface().toString()); + } + writer.writeEndElement(); + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#getModelType() + */ + public Class<BusinessInterface> getModelType() { + return BusinessInterface.class; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, org.apache.tuscany.sca.contribution.resolver.ModelResolver) + */ + public void resolve(BusinessInterface model, ModelResolver resolver) throws ContributionResolveException { + } + +}
diff --git a/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java index 7d94e73..714268a 100644 --- a/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java +++ b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
@@ -24,6 +24,8 @@ import java.io.ObjectOutput; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import javax.xml.stream.XMLStreamReader; @@ -32,11 +34,16 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ResolverExtension; +import org.apache.tuscany.sca.core.assembly.BusinessInterfaceImpl; import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl; import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; @@ -50,6 +57,9 @@ import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.runtime.BusinessInterface; import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -291,10 +301,13 @@ this.reference.setComponent(this.component); clonedRef = reference; ReferenceParameters parameters = null; + BusinessInterface businessInterfaceExt = null; for (Object ext : reference.getExtensions()) { if (ext instanceof ReferenceParameters) { parameters = (ReferenceParameters)ext; - break; + } else if (ext instanceof BusinessInterface) { + // this extension will always be present + businessInterfaceExt = (BusinessInterface)ext; } } if (parameters != null) { @@ -344,6 +357,10 @@ binding = reference.getBindings().get(0); } } + + ModelResolver resolver = ((ResolverExtension)ComponentContextHelper.getCurrentComponent()).getModelResolver(); + componentContextHelper.resolveInterfaceContract(reference.getInterfaceContract(), resolver); + Interface i = reference.getInterfaceContract().getInterface(); if (i instanceof JavaInterface) { JavaInterface javaInterface = (JavaInterface)i; @@ -360,10 +377,38 @@ javaInterface.getJavaClass()); //FIXME: If the interface needs XSDs to be loaded (e.g., for static SDO), // this needs to be done here. We usually search for XSDs in the current - // contribution at resolve time. Is it possible to locate the current - // contribution at runtime? - } + // contribution at resolve time. If we need to add code here to do this, + // we can resolve XSDs using the model resolver for the current component. + } this.businessInterface = (Class<B>)javaInterface.getJavaClass(); + } else { + // Allow privileged access to get ClassLoader. Requires RuntimePermission in + // security policy. + ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + businessInterface = (Class<B>)classLoader.loadClass(businessInterfaceExt.getInterface()); + reference.setReference(componentContextHelper.createReference(businessInterface)); + } + + componentContextHelper.resolveBinding(binding, resolver); + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + List<PolicySet> policySets = policiedBinding.getPolicySets(); + resolvePolicySets(policySets, resolver); + List<PolicySet> applicablePolicySets = policiedBinding.getApplicablePolicySets(); + applicablePolicySets.addAll(policySets); + } + if (binding instanceof OperationsConfigurator) { + OperationsConfigurator opConfigurator = (OperationsConfigurator)binding; + for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) { + List<PolicySet> policySets = confOp.getPolicySets(); + resolvePolicySets(policySets, resolver); + List<PolicySet> applicablePolicySets = confOp.getApplicablePolicySets(); + applicablePolicySets.addAll(policySets); + } } if (binding instanceof BindingBuilderExtension) { ((BindingBuilderExtension)binding).getBuilder().build(component, reference, binding, null); @@ -377,6 +422,26 @@ } } } + + /** + * Resolve policy sets attached to a specific SCA Construct + * @param policySets list of attached policy sets + * @param resolver + */ + private void resolvePolicySets(List<PolicySet> policySets, ModelResolver resolver) { + List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>(); + PolicySet resolvedPolicySet = null; + for (PolicySet policySet : policySets) { + if (policySet.isUnresolved()) { + resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet); + resolvedPolicySets.add(resolvedPolicySet); + } else { + resolvedPolicySets.add(policySet); + } + } + policySets.clear(); + policySets.addAll(resolvedPolicySets); + } /** * Follow a service promotion chain down to the inner most (non composite) @@ -432,6 +497,9 @@ } catch (CloneNotSupportedException e) { // will not happen } + BusinessInterface bizInterface = new BusinessInterfaceImpl(); + bizInterface.setInterface(businessInterface.getName()); + clonedRef.getExtensions().add(bizInterface); } if (refParams == null) { refParams = new ReferenceParametersImpl(); @@ -443,7 +511,6 @@ toRemove = extension; } } - if (toRemove != null){ clonedRef.getExtensions().remove(toRemove); }
diff --git a/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java index 78b0887..5a93a4d 100644 --- a/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java +++ b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
@@ -45,6 +45,7 @@ import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; import org.apache.tuscany.sca.interfacedef.Interface; @@ -260,6 +261,34 @@ return read(streamReader); } + public void resolveInterfaceContract(InterfaceContract interfaceContract, ModelResolver resolver) throws Exception { + StAXArtifactProcessor processor = staxProcessors.getProcessor(interfaceContract.getClass()); + processor.resolve(interfaceContract, resolver); + } + + public void resolveBinding(Binding binding, ModelResolver resolver) throws Exception { + StAXArtifactProcessor processor = staxProcessors.getProcessor(binding.getClass()); + processor.resolve(binding, resolver); + } + + public Reference createReference(Class<?> businessInterface) throws InvalidInterfaceException { + InterfaceContract interfaceContract = createJavaInterfaceContract(businessInterface); + Reference reference = assemblyFactory.createReference(); + reference.setInterfaceContract(interfaceContract); + return reference; + } + + private InterfaceContract createJavaInterfaceContract(Class<?> businessInterface) throws InvalidInterfaceException { + InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(businessInterface); + interfaceContract.setInterface(callInterface); + if (callInterface.getCallbackClass() != null) { + interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface( + callInterface.getCallbackClass())); + } + return interfaceContract; + } + public static RuntimeComponent getCurrentComponent() { Message message = ThreadMessageContext.getMessageContext(); if (message != null) {
diff --git a/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor index 5f54178..dd67278 100644 --- a/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ b/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -17,3 +17,4 @@ # Implementation class for the artifact processor extension org.apache.tuscany.sca.core.assembly.ReferenceParameterProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#referenceParameters,model=org.apache.tuscany.sca.runtime.ReferenceParameters +org.apache.tuscany.sca.core.assembly.BusinessInterfaceProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#businessInterface,model=org.apache.tuscany.sca.runtime.BusinessInterface