From cc712845b930f3df49d160c65deda6e98ef0ddf6 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 23 Jun 2011 16:20:49 +0000 Subject: Take a look at the sequence of interceptors that gets called when an exception is thrown. Seems to be OK at first view when we depend on InterceptorAsyncImpl. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1138966 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/helloworld/HelloWorld.java | 2 + .../src/main/java/helloworld/HelloWorldClient.java | 16 +++++- .../main/java/helloworld/HelloWorldException.java | 34 +++++++++++++ .../main/java/helloworld/HelloWorldService.java | 14 +++-- .../TestBindingWSPolicyProviderReference.java | 4 +- .../TestBindingWSPolicyProviderService.java | 2 + .../test/java/interceptors/HelloworldTestCase.java | 59 ++++++++++++++++++++-- 7 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldException.java (limited to 'sca-java-2.x/trunk/testing/itest/policy') diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.java index 295d8fee53..1f5b8b365d 100644 --- a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.java +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.java @@ -25,5 +25,7 @@ import org.oasisopen.sca.annotation.Remotable; public interface HelloWorld { String getGreetings(String s); + + String getGreetingsException(String s) throws HelloWorldException; } diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java index 797f3a6a43..7a94a90b19 100644 --- a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java @@ -29,9 +29,21 @@ public class HelloWorldClient implements HelloWorld { public HelloWorld helloWorldWS; public String getGreetings(String s) { + StatusImpl.appendStatus("At client.getGreetings() pre-invoke", s); String response = helloWorldWS.getGreetings(s); - StatusImpl.appendStatus("At client", response); + StatusImpl.appendStatus("At client.getGreetings() post-invoke", response); return response; } - + + public String getGreetingsException(String s) throws HelloWorldException { + StatusImpl.appendStatus("At client.getGreetingsException() pre-invoke", s); + try { + String response = helloWorldWS.getGreetingsException(s); + StatusImpl.appendStatus("At client.getGreetingsException() post-invoke", response); + return response; + } catch (HelloWorldException ex){ + StatusImpl.appendStatus("At client.getGreetingsException() post-exception", ex.getMessage()); + throw ex; + } + } } diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldException.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldException.java new file mode 100644 index 0000000000..b4a9fec640 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldException.java @@ -0,0 +1,34 @@ +/* + * 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; + + +public class HelloWorldException extends Exception { + + private static final long serialVersionUID = 4608283774062947117L; + + public HelloWorldException(){ + } + + public HelloWorldException(String message){ + super(message); + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java index 6040132f2c..40c0c7618a 100644 --- a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java @@ -29,10 +29,16 @@ public class HelloWorldService implements HelloWorld { @Context protected RequestContext requestContext; - public String getGreetings(String name) { - Subject subject = requestContext.getSecuritySubject(); - String response = "Hello " + name; - StatusImpl.appendStatus("At service", response); + public String getGreetings(String s) { + //Subject subject = requestContext.getSecuritySubject(); + String response = "Hello " + s; + StatusImpl.appendStatus("At service.getGreetings()", response); return response; } + + public String getGreetingsException(String s) throws HelloWorldException { + String response = "Hello " + s; + StatusImpl.appendStatus("At service.getGreetingsException()", response); + throw new HelloWorldException(response); + } } diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderReference.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderReference.java index ea79792523..489c069ea8 100644 --- a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderReference.java +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderReference.java @@ -51,7 +51,9 @@ public class TestBindingWSPolicyProviderReference extends BasePolicyProvider outPhases = axisConfiguration.getOutFlowPhases(); outPhases.get(0).addHandler(new TestBindingWSAxisHandler("Reference OutFlow Handler")); List inPhases = axisConfiguration.getInFlowPhases(); - inPhases.get(0).addHandler(new TestBindingWSAxisHandler("Reference InFlow Handler")); + inPhases.get(0).addHandler(new TestBindingWSAxisHandler("Reference InFlow Handler")); + List inFaultPhases = axisConfiguration.getInFaultFlowPhases(); + inFaultPhases.get(0).addHandler(new TestBindingWSAxisHandler("Reference InFaultFlow Handler")); } public PhasedInterceptor createBindingInterceptor() { diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderService.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderService.java index 5124974279..9880bf04b0 100644 --- a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderService.java +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testbindingwspolicy/TestBindingWSPolicyProviderService.java @@ -52,6 +52,8 @@ public class TestBindingWSPolicyProviderService extends BasePolicyProvider outPhases = axisConfiguration.getOutFlowPhases(); outPhases.get(0).addHandler(new TestBindingWSAxisHandler("Service OutFlow Handler")); + List outFaultPhases = axisConfiguration.getOutFaultFlowPhases(); + outFaultPhases.get(0).addHandler(new TestBindingWSAxisHandler("Service OutFaultFlow Handler")); } public PhasedInterceptor createBindingInterceptor() { diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java index 39112f0f12..e34e4c6a35 100644 --- a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java @@ -25,6 +25,7 @@ import junit.framework.Assert; import junit.framework.TestCase; import helloworld.HelloWorld; +import helloworld.HelloWorldException; import helloworld.StatusImpl; import org.apache.tuscany.sca.assembly.Component; @@ -50,7 +51,7 @@ public class HelloworldTestCase extends TestCase { helloWorld = node.getService(HelloWorld.class, "HelloWorldClient/HelloWorld"); } - public void testCalculator() throws Exception { + public void testHelloWorld() throws Exception { // check response from application assertEquals("Hello fred", helloWorld.getGreetings("fred")); @@ -61,6 +62,7 @@ public class HelloworldTestCase extends TestCase { "TestPolicyInterceptor.processRequest() - HelloWorldClient#reference-binding($self$.HelloWorld/HelloWorld) @ reference.policy\n" + "TestPolicyInterceptor.processRequest() - HelloWorldClient#service-binding(HelloWorld/HelloWorld) @ service.policy\n" + "TestPolicyInterceptor.processRequest() - null @ implementation.policy\n" + + "At client.getGreetings() pre-invoke - fred\n" + "TestBindingWSPolicyProviderReference.configureBinding() - org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingProvider\n" + "TestPolicyInterceptor.processRequest() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.policy\n" + "TestBindingWSPolicyInterceptor.processRequest() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.binding.policy\n" + @@ -69,7 +71,7 @@ public class HelloworldTestCase extends TestCase { "TestBindingWSPolicyInterceptor.processRequest() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.binding.policy\n" + "TestPolicyInterceptor.processRequest() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.policy\n" + "TestPolicyInterceptor.processRequest() - null @ implementation.policy\n" + - "At service - Hello fred\n" + + "At service.getGreetings() - Hello fred\n" + "TestPolicyInterceptor.processResponse() - null @ implementation.policy\n" + "TestPolicyInterceptor.processResponse() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.policy\n" + "TestBindingWSPolicyInterceptor.processResponse() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.binding.policy\n" + @@ -77,7 +79,7 @@ public class HelloworldTestCase extends TestCase { "TestAxisHandler.invoke() - Reference InFlow Handler\n" + "TestBindingWSPolicyInterceptor.processResponse() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.binding.policy\n" + "TestPolicyInterceptor.processResponse() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.policy\n" + - "At client - Hello fred\n" + + "At client.getGreetings() post-invoke - Hello fred\n" + "TestPolicyInterceptor.processResponse() - null @ implementation.policy\n" + "TestPolicyInterceptor.processResponse() - HelloWorldClient#service-binding(HelloWorld/HelloWorld) @ service.policy\n" + "TestPolicyInterceptor.processResponse() - HelloWorldClient#reference-binding($self$.HelloWorld/HelloWorld) @ reference.policy\n", @@ -94,6 +96,57 @@ public class HelloworldTestCase extends TestCase { } + public void testHelloWorldException() throws Exception { + + // check response from application + try { + helloWorld.getGreetingsException("fred"); + Assert.fail(); + } catch (HelloWorldException ex){ + assertEquals("Hello fred", ex.getMessage()); + } + + // check sequences of interceptors + System.out.println(StatusImpl.statusString); + assertEquals("TestBindingWSPolicyProviderService.configureBinding() - org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceBindingProvider\n" + + "TestBindingWSPolicyProviderService.configureBinding() - org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceBindingProvider\n" + + "TestPolicyInterceptor.processRequest() - HelloWorldClient#reference-binding($self$.HelloWorld/HelloWorld) @ reference.policy\n" + + "TestPolicyInterceptor.processRequest() - HelloWorldClient#service-binding(HelloWorld/HelloWorld) @ service.policy\n" + + "TestPolicyInterceptor.processRequest() - null @ implementation.policy\n" + + "At client.getGreetingsException() pre-invoke - fred\n" + + "TestBindingWSPolicyProviderReference.configureBinding() - org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingProvider\n" + + "TestPolicyInterceptor.processRequest() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.policy\n" + + "TestBindingWSPolicyInterceptor.processRequest() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.binding.policy\n" + + "TestAxisHandler.invoke() - Reference OutFlow Handler\n" + + "TestAxisHandler.invoke() - Service InFlow Handler\n" + + "TestBindingWSPolicyInterceptor.processRequest() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.binding.policy\n" + + "TestPolicyInterceptor.processRequest() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.policy\n" + + "TestPolicyInterceptor.processRequest() - null @ implementation.policy\n" + + "At service.getGreetingsException() - Hello fred\n" + + "TestPolicyInterceptor.processResponse() - null @ implementation.policy\n" + + "TestPolicyInterceptor.processResponse() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.policy\n" + + "TestBindingWSPolicyInterceptor.processResponse() - HelloWorldService2#service-binding(HelloWorld/BindingWS) @ service.binding.policy\n" + + "TestAxisHandler.invoke() - Service OutFaultFlow Handler\n" + + "TestAxisHandler.invoke() - Reference InFaultFlow Handler\n" + + "TestBindingWSPolicyInterceptor.processResponse() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.binding.policy\n" + + "TestPolicyInterceptor.processResponse() - HelloWorldClient#reference-binding(helloWorldWS/BindingWS) @ reference.policy\n" + + "At client.getGreetingsException() post-exception - Hello fred\n" + + "TestPolicyInterceptor.processResponse() - null @ implementation.policy\n" + + "TestPolicyInterceptor.processResponse() - HelloWorldClient#service-binding(HelloWorld/HelloWorld) @ service.policy\n" + + "TestPolicyInterceptor.processResponse() - HelloWorldClient#reference-binding($self$.HelloWorld/HelloWorld) @ reference.policy\n", + StatusImpl.statusString); + + // check final intents on endpoint reference to see if the matching process + // results on the right set + Composite domainComposite = ((NodeImpl)node).getDomainComposite(); + List policySets = domainComposite.getComponents().get(0).getReferences().get(0).getEndpointReferences().get(0).getPolicySets(); + + assertEquals(2, policySets.size()); + assertEquals("TestInteractonPolicySet2", policySets.get(0).getName().getLocalPart()); + assertEquals("TestInteractonPolicySet1", policySets.get(1).getName().getLocalPart()); + + } + @Override protected void tearDown() throws Exception { node.stop(); -- cgit v1.2.3