Author: jlmonteiro Date: Fri Sep 25 15:59:19 2009 New Revision: 818895 URL: http://svn.apache.org/viewvc?rev=818895&view=rev Log: OPENEJB-965: http://www.nabble.com/exceptions-handling-with-Webservices-td19668275.html TODO: create a test case for that ... I only have a sample/itest.
The EjbMethodInvoker will probably change when going to CXF 2.x, so we definitely have to enhance all tests around our web service implementation. Added: openejb/trunk/openejb3/server/openejb-cxf/server/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/java/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/java/org/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/java/org/apache/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/java/org/apache/openejb/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/java/org/apache/openejb/server/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ openejb/trunk/openejb3/server/openejb-cxf/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CxfJaxWsProviderTest.java openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorService.java openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBean.java openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBeanNoHandler.java openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/DummyInterceptor.java openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordException.java openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordRuntimeException.java openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/META-INF/ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/META-INF/ejb-jar.xml openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/fault/ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/fault/handler.xml Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CxfJaxWsProviderTest.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CxfJaxWsProviderTest.java?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CxfJaxWsProviderTest.java (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CxfJaxWsProviderTest.java Fri Sep 25 15:59:19 2009 @@ -0,0 +1,124 @@ +/** + * 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.openejb.server.cxf; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.xml.namespace.QName; +import javax.xml.ws.Service; + +import junit.framework.TestCase; + +import org.apache.openejb.server.cxf.fault.AuthenticatorService; +import org.apache.openejb.server.cxf.fault.WrongPasswordException; +import org.apache.openejb.server.cxf.fault.WrongPasswordRuntimeException; + +/** + * @version $Rev$ + */ +public class CxfJaxWsProviderTest extends TestCase { + + //START SNIPPET: setup + private InitialContext initialContext; + + protected void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); + properties.setProperty("openejb.embedded.remotable", "true"); + + initialContext = new InitialContext(properties); + } + //END SNIPPET: setup + + public void test00_runCheckedException() { + try { + AuthenticatorService withHandler = Service.create( + new URL("http://localhost:4204/AuthenticatorServiceBean?wsdl"), + new QName("http://superbiz.org/wsdl", "AuthenticatorServiceBeanService")) + .getPort(AuthenticatorService.class); + assertNotNull(withHandler); + + AuthenticatorService noHandler = Service.create( + new URL("http://localhost:4204/AuthenticatorServiceBeanNoHandler?wsdl"), + new QName("http://superbiz.org/wsdl", "AuthenticatorServiceBeanNoHandlerService")) + .getPort(AuthenticatorService.class); + assertNotNull(noHandler); + + try { + withHandler.authenticate("John", "Doe"); + } catch (WrongPasswordException e) { + System.out.println("My lovely checked exception..."); + } catch (Throwable e) { + fail("A throwable instead of a checked exception..."); + } + + try { + noHandler.authenticate("John", "Doe"); + } catch (WrongPasswordException e) { + System.out.println("My lovely checked exception..."); + } catch (Throwable e) { + fail("A throwable instead of a checked exception..."); + } + + } catch (MalformedURLException e) { + fail("?!? invalid URL ???"); + } + + } + + public void test01_runRuntimeException() { + try { + AuthenticatorService withHandler = Service.create( + new URL("http://localhost:4204/AuthenticatorServiceBean?wsdl"), + new QName("http://superbiz.org/wsdl", "AuthenticatorServiceBeanService")) + .getPort(AuthenticatorService.class); + assertNotNull(withHandler); + + AuthenticatorService noHandler = Service.create( + new URL("http://localhost:4204/AuthenticatorServiceBeanNoHandler?wsdl"), + new QName("http://superbiz.org/wsdl", "AuthenticatorServiceBeanNoHandlerService")) + .getPort(AuthenticatorService.class); + assertNotNull(noHandler); + + try { + withHandler.authenticateRuntime("John", "Doe"); + } catch (WrongPasswordRuntimeException e) { + fail("My checked exception instead of a throwableS..."); + } catch (Throwable e) { + System.out.println("A throwable exception..."); + } + + + try { + noHandler.authenticateRuntime("John", "Doe"); + } catch (WrongPasswordRuntimeException e) { + fail("My checked exception instead of a throwableS..."); + } catch (Throwable e) { + System.out.println("A throwable exception..."); + } + + } catch (MalformedURLException e) { + fail("?!? invalid URL ???"); + } + + } + +} Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorService.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorService.java?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorService.java (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorService.java Fri Sep 25 15:59:19 2009 @@ -0,0 +1,31 @@ +/** + * 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.openejb.server.cxf.fault; + +import javax.jws.WebService; + +/** + * @version $Rev$ + */ +...@webservice(targetNamespace="http://superbiz.org/wsdl") +public interface AuthenticatorService { + + boolean authenticate(String name, String password) throws WrongPasswordException; + + boolean authenticateRuntime(String name, String password); + +} \ No newline at end of file Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBean.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBean.java?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBean.java (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBean.java Fri Sep 25 15:59:19 2009 @@ -0,0 +1,41 @@ +/** + * 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.openejb.server.cxf.fault; + +import javax.ejb.Stateless; +import javax.jws.HandlerChain; +import javax.jws.WebService; + +/** + * @version $Rev$ + */ +...@stateless +...@webservice(targetNamespace="http://superbiz.org/wsdl") +...@handlerchain(file="handler.xml") +public class AuthenticatorServiceBean implements AuthenticatorService { + + public boolean authenticate(String name, String password) throws WrongPasswordException { + System.out.println(String.format("AuthenticatorServiceBean.authenticate(%s, %s)", name, password)); + throw new WrongPasswordException("Checked exception"); + } + + public boolean authenticateRuntime(String name, String password) { + System.out.println(String.format("AuthenticatorServiceBean.authenticateRuntime(%s, %s)", name, password)); + throw new WrongPasswordRuntimeException("Runtime exception"); + } + +} \ No newline at end of file Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBeanNoHandler.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBeanNoHandler.java?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBeanNoHandler.java (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/AuthenticatorServiceBeanNoHandler.java Fri Sep 25 15:59:19 2009 @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.server.cxf.fault; + +import javax.ejb.Stateless; +import javax.jws.WebService; + +/** + * @version $Rev$ + */ +...@stateless +...@webservice(targetNamespace="http://superbiz.org/wsdl") +//@HandlerChain(file="handler.xml") +public class AuthenticatorServiceBeanNoHandler implements AuthenticatorService { + + public boolean authenticate(String name, String password) throws WrongPasswordException { + System.out.println(String.format("AuthenticatorServiceBeanNoHandler.authenticate(%s, %s)", name, password)); + throw new WrongPasswordException("Checked exception"); + } + + public boolean authenticateRuntime(String name, String password) { + System.out.println(String.format("AuthenticatorServiceBeanNoHandler.authenticateRuntime(%s, %s)", name, password)); + throw new WrongPasswordRuntimeException("Runtime exception"); + } + +} \ No newline at end of file Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/DummyInterceptor.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/DummyInterceptor.java?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/DummyInterceptor.java (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/DummyInterceptor.java Fri Sep 25 15:59:19 2009 @@ -0,0 +1,49 @@ +/** + * 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.openejb.server.cxf.fault; + +import java.util.Collections; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPHandler; +import javax.xml.ws.handler.soap.SOAPMessageContext; + +/** + * @version $Rev$ + */ +public class DummyInterceptor implements SOAPHandler<SOAPMessageContext> { + public DummyInterceptor() { + super(); + } + + public Set<QName> getHeaders() { + return Collections.emptySet(); + } + + public void close(MessageContext mc) { + } + + public boolean handleFault(SOAPMessageContext mc) { + return true; + } + + public boolean handleMessage(SOAPMessageContext mc) { + return true; + } +} \ No newline at end of file Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordException.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordException.java?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordException.java (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordException.java Fri Sep 25 15:59:19 2009 @@ -0,0 +1,42 @@ +/** + * 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.openejb.server.cxf.fault; + +import javax.xml.ws.WebFault; + +/** + * @version $Rev$ + */ +...@webfault +public class WrongPasswordException extends Exception { + + public WrongPasswordException() { + super(); + } + + public WrongPasswordException(String message, Throwable cause) { + super(message, cause); + } + + public WrongPasswordException(String message) { + super(message); + } + + public WrongPasswordException(Throwable cause) { + super(cause); + } +} \ No newline at end of file Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordRuntimeException.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordRuntimeException.java?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordRuntimeException.java (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/fault/WrongPasswordRuntimeException.java Fri Sep 25 15:59:19 2009 @@ -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 org.apache.openejb.server.cxf.fault; + +import javax.ejb.ApplicationException; + +/** + * @version $Rev$ + */ +...@applicationexception +//@WebFault // Not possible: a web fault must by a checked exception +public class WrongPasswordRuntimeException extends RuntimeException { + + public WrongPasswordRuntimeException() { + super(); + } + + public WrongPasswordRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public WrongPasswordRuntimeException(String message) { + super(message); + } + + public WrongPasswordRuntimeException(Throwable cause) { + super(cause); + } +} \ No newline at end of file Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/META-INF/ejb-jar.xml URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/META-INF/ejb-jar.xml?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/META-INF/ejb-jar.xml (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/META-INF/ejb-jar.xml Fri Sep 25 15:59:19 2009 @@ -0,0 +1,19 @@ +<!-- + 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. +--> +<ejb-jar/> \ No newline at end of file Added: openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/fault/handler.xml URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/fault/handler.xml?rev=818895&view=auto ============================================================================== --- openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/fault/handler.xml (added) +++ openejb/trunk/openejb3/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/fault/handler.xml Fri Sep 25 15:59:19 2009 @@ -0,0 +1,27 @@ +<?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. +--> +<handler-chains xmlns="http://java.sun.com/xml/ns/javaee"> + <handler-chain> + <handler> + <handler-name>org.apache.openejb.server.cxf.fault.DummyInterceptor</handler-name> + <handler-class>org.apache.openejb.server.cxf.fault.DummyInterceptor</handler-class> + </handler> + </handler-chain> +</handler-chains> \ No newline at end of file