diff options
Diffstat (limited to '')
19 files changed, 442 insertions, 29 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference.java index c70d4521ba..f4f1cd2a8d 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference.java @@ -123,6 +123,17 @@ public interface EndpointReference extends Base, PolicySubject, Cloneable, Seria * @param endpoint the target endpoint */ void setTargetEndpoint(Endpoint targetEndpoint); + + /** + * Get the deployed URI of the corresponding service endpoint + * @return The deployed URI + */ + String getDeployedURI(); + /** + * Set the deployed URI + * @param deployedURI + */ + void setDeployedURI(String deployedURI); /** * Returns the interface contract defining the interface diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReferenceImpl.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReferenceImpl.java index ebcc1e3e63..ac0c7c93a8 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReferenceImpl.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReferenceImpl.java @@ -48,6 +48,7 @@ public class EndpointReferenceImpl implements EndpointReference { protected transient ContractBuilder contractBuilder; protected boolean unresolved = true; protected String uri; + protected String deployedURI; protected Component component; protected ComponentReference reference; protected Binding binding; @@ -231,6 +232,29 @@ public class EndpointReferenceImpl implements EndpointReference { this.status = status; } + @Override + public String getDeployedURI() { + String targetURI = deployedURI; + if (targetURI != null) { + return targetURI; + } + if (getTargetEndpoint() != null) { + targetURI = getTargetEndpoint().getDeployedURI(); + } + if (targetURI != null) { + return targetURI; + } + if (binding != null) { + targetURI = binding.getURI(); + } + return targetURI; + } + + @Override + public void setDeployedURI(String deployedURI) { + this.deployedURI = deployedURI; + } + /** * Indicates whether this EndpointReference is connected to a target service which is asynchronous. * This can be marked in one of 3 ways: diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java index 024705803f..83c26c7c21 100644 --- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java @@ -77,6 +77,7 @@ class AtomReferenceBindingProvider implements ReferenceBindingProvider { public Invoker createInvoker(Operation operation) { String operationName = operation.getName(); + String uri = endpointReference.getDeployedURI(); if (operationName.equals("get")) { // Determine the collection item type @@ -87,25 +88,25 @@ class AtomReferenceBindingProvider implements ReferenceBindingProvider { supportsFeedEntries = true; } - return new AtomBindingInvoker.GetInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.GetInvoker(operation, uri, httpClient, authorizationHeader, this); } else if (operationName.equals("post")) { - return new AtomBindingInvoker.PostInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.PostInvoker(operation, uri, httpClient, authorizationHeader, this); } else if (operationName.equals("put")) { - return new AtomBindingInvoker.PutInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.PutInvoker(operation, uri, httpClient, authorizationHeader, this); } else if (operationName.equals("delete")) { - return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.DeleteInvoker(operation, uri, httpClient, authorizationHeader, this); } else if (operationName.equals("getFeed") || operationName.equals("getAll")) { - return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.GetAllInvoker(operation, uri, httpClient, authorizationHeader, this); } else if (operationName.equals("postMedia")) { - return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.PostMediaInvoker(operation, uri, httpClient, authorizationHeader, this); } else if (operationName.equals("putMedia")) { - return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.PutMediaInvoker(operation, uri, httpClient, authorizationHeader, this); } else if (operationName.equals("query")) { - return new AtomBindingInvoker.QueryInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker.QueryInvoker(operation, uri, httpClient, authorizationHeader, this); } - return new AtomBindingInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + return new AtomBindingInvoker(operation, uri, httpClient, authorizationHeader, this); } public InterfaceContract getBindingInterfaceContract() { diff --git a/sca-java-2.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPInvoker.java b/sca-java-2.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPInvoker.java index 6b0bfec213..bda4ccf217 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPInvoker.java @@ -65,7 +65,7 @@ public class JSONPInvoker implements Invoker { } public Message doInvoke(Message msg) throws JsonGenerationException, JsonMappingException, IOException, EncoderException { - String uri = endpoint.getBinding().getURI() + "/" + operation.getName(); + String uri = endpoint.getDeployedURI() + "/" + operation.getName(); //String[] jsonArgs = objectsToJSON((Object[])msg.getBody()); String[] jsonArgs = objectsToJSONStrings((Object[])msg.getBody()); diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java index 713122f479..ca21599b14 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java @@ -70,7 +70,7 @@ public class JsonRpcInvoker implements Invoker, DataExchangeSemantics { public JsonRpcInvoker(EndpointReference endpointReference, Operation operation, HttpClient httpClient) { this.endpointReference = endpointReference; this.operation = operation; - this.uri = endpointReference.getBinding().getURI(); + this.uri = endpointReference.getDeployedURI(); this.httpClient = httpClient; } diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTargetTestCase.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTargetTestCase.java new file mode 100644 index 0000000000..383a862945 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTargetTestCase.java @@ -0,0 +1,117 @@ +/* + * 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.binding.jsonrpc; + +import java.util.Arrays; + +import junit.framework.Assert; + +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 org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import bean.TestBean; +import echo.Echo; + +public class JSONRPCReferenceTargetTestCase { + private static final String ECHO_COMPONENT_WITH_REFERENCE = "EchoComponentWithReferenceTarget"; + private static Node node; + + @BeforeClass + public static void setUp() throws Exception { + try { + String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTargetTestCase.class); + node = + NodeFactory.newInstance().createNode(new Contribution("testClient", contribution)); + node.start(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testInvokeReference() throws Exception { + Echo echoComponent = node.getService(Echo.class, ECHO_COMPONENT_WITH_REFERENCE); + String result = echoComponent.echo("ABC"); + Assert.assertEquals("echo: ABC", result); + } + + @Test + public void testInvokeBeanReference() throws Exception { + Echo echoComponent = node.getService(Echo.class, ECHO_COMPONENT_WITH_REFERENCE); + TestBean bean = new TestBean(); + bean.setTestInt(1); + bean.setTestString("123"); + bean.setStringArray(Arrays.asList("A", "B")); + TestBean result = echoComponent.echoBean(bean); + Assert.assertEquals(bean, result); + } + + @Test + public void testInvokeReferenceVoidOperation() throws Exception { + Echo echoComponent = node.getService(Echo.class, ECHO_COMPONENT_WITH_REFERENCE); + echoComponent.echoVoid(); + } + + @Test(expected = Exception.class) + public void testInvokeReferenceException() throws Exception { + Echo echoComponent = node.getService(Echo.class, ECHO_COMPONENT_WITH_REFERENCE); + try { + echoComponent.echoBusinessException(); + } catch (Exception e) { + System.err.println(e); + throw e; + } + } + + @Test + public void testInvokeReference20() throws Exception { + Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20"); + String result = echoComponent.echo("ABC"); + Assert.assertEquals("echo: ABC", result); + } + + @Test + public void testInvokeReferenceVoidOperation20() throws Exception { + Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20"); + echoComponent.echoVoid(); + } + + @Test(expected = Exception.class) + public void testInvokeReferenceException20() throws Exception { + Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20"); + try { + echoComponent.echoBusinessException(); + } catch (Exception e) { + System.err.println(e); + throw e; + } + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite index 0c588cf137..44de429713 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite @@ -36,4 +36,12 @@ </service>
</component>
+ <component name="EchoComponent1">
+ <implementation.java class="echo.EchoComponentImpl"/>
+ <service name="Echo">
+ <tuscany:binding.jsonrpc name="jsonrpc" uri="/services/EchoService"/>
+ <tuscany:binding.jsonrpc version="2.0" name="jsonrpc20" uri="/services/EchoService20"/>
+ </service>
+ </component>
+
</composite>
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite index 5391416510..3679e259a4 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite @@ -38,4 +38,11 @@ </reference> </component> + <component name="EchoComponentWithReferenceTarget"> + <implementation.java class="echo.EchoClientImpl" /> + <reference name="echoReference" target="EchoComponent1/Echo/jsonrpc"> + </reference> + </component> + + </composite> diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF index eb4ea5fb41..a2f938de64 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF @@ -30,6 +30,7 @@ Import-Package: javax.jws, org.apache.tuscany.sca.databinding.xml;version="2.0.0", org.apache.tuscany.sca.extensibility;version="2.0.0", org.apache.tuscany.sca.host.http;version="2.0.0", + org.apache.tuscany.sca.host.http.client;version="2.0.0", org.apache.tuscany.sca.interfacedef;version="2.0.0", org.apache.tuscany.sca.interfacedef.impl;version="2.0.0", org.apache.tuscany.sca.interfacedef.java;version="2.0.0", diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java index 36beb707d7..7827092501 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java @@ -55,6 +55,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.apache.http.client.HttpClient; +import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.binding.rest.RESTBinding; import org.apache.tuscany.sca.binding.rest.wireformat.json.JSONWireFormat; @@ -77,15 +78,17 @@ import org.apache.wink.client.handlers.BasicAuthSecurityHandler; */ public class RESTBindingInvoker implements Invoker { private ExtensionPointRegistry registry; + private EndpointReference endpointReference; private RESTBinding binding; private Operation operation; private RestClient restClient; private String httpMethod; private Class<?> responseType; - public RESTBindingInvoker(ExtensionPointRegistry registry, RESTBinding binding, Operation operation, HttpClient httpClient) { + public RESTBindingInvoker(ExtensionPointRegistry registry, EndpointReference endpointReference, RESTBinding binding, Operation operation, HttpClient httpClient) { super(); this.registry = registry; + this.endpointReference = endpointReference; this.binding = binding; this.operation = operation; this.restClient = createRestClient(httpClient); @@ -165,7 +168,7 @@ public class RESTBindingInvoker implements Invoker { Object entity = null; Object[] args = msg.getBody(); - URI uri = URI.create(binding.getURI()); + URI uri = URI.create(endpointReference.getDeployedURI()); UriBuilder uriBuilder = UriBuilder.fromUri(uri); Method method = ((JavaOperation)operation).getJavaMethod(); diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java index 71d7aa79ba..07dbeafce6 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java @@ -50,7 +50,7 @@ public class RESTReferenceBindingProvider implements EndpointReferenceProvider { } public Invoker createInvoker(Operation operation) { - return new RESTBindingInvoker(registry, (RESTBinding)endpointReference.getBinding(), operation, httpClient); + return new RESTBindingInvoker(registry, endpointReference, (RESTBinding)endpointReference.getBinding(), operation, httpClient); } public InterfaceContract getBindingInterfaceContract() { diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTReferenceTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTReferenceTestCase.java new file mode 100644 index 0000000000..a2cc984f77 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTReferenceTestCase.java @@ -0,0 +1,65 @@ +/* + * 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.binding.rest; + +import java.util.Arrays; + +import junit.framework.Assert; + +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 org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import services.echo.jaxrs.Echo; + +public class RESTReferenceTestCase { + private static final String ECHO_COMPONENT_WITH_REFERENCE = "EchoClientComponent/Echo"; + private static Node node; + + @BeforeClass + public static void setUp() throws Exception { + try { + String contribution = ContributionLocationHelper.getContributionLocation(RESTReferenceTestCase.class); + node = + NodeFactory.newInstance().createNode("rest-reference.composite", + new Contribution("testClient", contribution)); + node.start(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testInvokeReference() throws Exception { + Echo echoComponent = node.getService(Echo.class, ECHO_COMPONENT_WITH_REFERENCE); + String result = echoComponent.echo("ABC"); + Assert.assertEquals("echo: ABC", result); + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/Echo.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/Echo.java new file mode 100644 index 0000000000..5554a3d572 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/Echo.java @@ -0,0 +1,47 @@ +/* + * 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 services.echo.jaxrs; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Interface of our sample JSONRPC service. + * + * @version $Rev$ $Date$ + */ +@Remotable +@Path("") +public interface Echo { + @GET + String echo(@QueryParam("msg") String msg); + + @GET + int echoInt(@QueryParam("param") int param); + + @GET + String [] echoArrayString(@QueryParam("msgArray") String[] stringArray); + + @GET + int [] echoArrayInt(@QueryParam("intArray") int[] intArray); + +} diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/EchoClientImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/EchoClientImpl.java new file mode 100644 index 0000000000..f0b62523d7 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/EchoClientImpl.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 services.echo.jaxrs; + +import org.oasisopen.sca.annotation.Reference; + +public class EchoClientImpl implements Echo { + @Reference + private Echo echoService; + + public String echo(String msg) { + return "echo: "+ echoService.echo(msg); + } + + public int echoInt(int param) { + return echoService.echoInt(param); + } + + public String[] echoArrayString(String[] stringArray) { + return echoService.echoArrayString(stringArray); + } + + public int[] echoArrayInt(int[] intArray) { + return echoService.echoArrayInt(intArray); + } +} diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/EchoImpl.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/EchoImpl.java new file mode 100644 index 0000000000..54bc9004c7 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/echo/jaxrs/EchoImpl.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 services.echo.jaxrs; + + +/** + * A simple client component that uses a reference with an REST binding. + * + * @version $Rev$ $Date$ + */ +public class EchoImpl implements Echo { + + public String echo(String msg) { + return msg; + } + + public int echoInt(int param) { + int value = param; + return value; + } + + public String[] echoArrayString(String[] stringArray) { + return stringArray; + } + + public int[] echoArrayInt(int[] intArray) { + return intArray; + } +} diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/rest-reference.composite b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/rest-reference.composite new file mode 100644 index 0000000000..2da58b4270 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/rest-reference.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://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://rest" + xmlns:rest="http://rest" + name="RESTReference"> + + <component name="EchoClientComponent"> + <implementation.java class="services.echo.jaxrs.EchoClientImpl" /> + <reference name="echoService" target="EchoComponent/Echo"> + </reference> + </component> + + <component name="EchoComponent"> + <implementation.java class="services.echo.jaxrs.EchoImpl" /> + <service name="Echo"> + <tuscany:binding.rest name="rest" uri="/EchoService/rest"> + </tuscany:binding.rest> + </service> + + </component> + + +</composite> diff --git a/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.java index 8d13b0a24f..52ce74f3d5 100644 --- a/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.java @@ -40,11 +40,13 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentReference; public class RMIReferenceBindingProvider implements ReferenceBindingProvider { private RuntimeComponentReference reference; + private EndpointReference endpointReference; private RMIBinding binding; private RMIHost rmiHost; public RMIReferenceBindingProvider(EndpointReference endpointReference, RMIHost rmiHost) { + this.endpointReference = endpointReference; this.reference = (RuntimeComponentReference)endpointReference.getReference(); this.binding = (RMIBinding)endpointReference.getBinding(); this.rmiHost = rmiHost; @@ -63,7 +65,7 @@ public class RMIReferenceBindingProvider implements ReferenceBindingProvider { throw new IllegalArgumentException(e); } - return new RMIBindingInvoker(rmiHost, binding.getURI(), remoteMethod); + return new RMIBindingInvoker(rmiHost, endpointReference.getDeployedURI(), remoteMethod); } public void start() { diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java index 42471411e3..5d6b3aeb64 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java @@ -128,7 +128,7 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics { QName serviceName = wsBinding.getService().getQName(); QName portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPort().getName()); Service service = Service.create(serviceName); - service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, wsBinding.getURI()); + service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointReference.getDeployedURI()); return service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE); } @@ -154,7 +154,7 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics { if (wsdlLocation != null) { return createDispatchFromWSDL(wsdlLocation); } else { - return createDispatchFromURI(wsBinding.getURI()); + return createDispatchFromURI(endpointReference.getDeployedURI()); } } @@ -321,7 +321,7 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics { if (dynamicDispatchForCallback) { Endpoint ep = msg.getTo(); if (ep != null && ep.getBinding() != null) { - String address = ep.getBinding().getURI(); + String address = ep.getDeployedURI(); invocationDispatch = createDynamicDispatch(address); } else { throw new ServiceRuntimeException("[BWS20025] Unable to determine destination endpoint for endpoint reference " + endpointReference); @@ -365,7 +365,7 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics { // addWSAFromHeader(sh, fromEPR); SOAPHeaderElement fromH = sh.addHeaderElement(QNAME_WSA_FROM); SOAPElement fromAddress = fromH.addChildElement(QNAME_WSA_ADDRESS); - fromAddress.setTextContent(callbackEndpoint.getBinding().getURI()); + fromAddress.setTextContent(callbackEndpoint.getDeployedURI()); addWSAActionHeader(sh, action); @@ -406,7 +406,7 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics { if (to == null) { Endpoint ep = msg.getTo(); if (ep != null && ep.getBinding() != null) { - address = ep.getBinding().getURI(); + address = ep.getDeployedURI(); } else { throw new ServiceRuntimeException( "[BWS20025] Unable to determine destination endpoint for endpoint reference " + endpointReference); @@ -435,7 +435,7 @@ public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics { } } if (ep == null || ep.equals("")) { - ep = wsBinding.getURI(); + ep = endpointReference.getDeployedURI(); } return ep; } diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java index 0a504d4dba..f90dc2d1d9 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java @@ -505,15 +505,12 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { } else { endpointReference.setTargetEndpoint(matchedEndpoint); Binding binding = matchedEndpoint.getBinding(); - // Reverted the change, see https://issues.apache.org/jira/browse/TUSCANY-4029 - /* try { - endpointReference.setBinding((Binding) binding.clone()); - } catch (CloneNotSupportedException e) { - // shouldn't happen - throw new RuntimeException(e); - } - */ + endpointReference.setBinding((Binding)binding.clone()); + } catch (CloneNotSupportedException e) { + // shouldn't happen + throw new RuntimeException(e); + } endpointReference.setBinding(binding); // TUSCANY-3873 - add policy from the service // we don't care about intents at this stage |