|
| Apache Geronimo > Discussion Forums | User List | Dev List | Wiki | Issue Tracker |
|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
WebFault does not work exampleHello,
in Geronimo 2.1.4, I can't find what I'm doing wrong in the following example: - - - Server project - EJB module - - - package time.ejb; import javax.ejb.Stateless; import javax.jws.WebMethod; import javax.jws.WebService; @WebService( serviceName = "TimeService", portName = "TimeServicePort", endpointInterface = "time.ejb.TimeBeanRemote", targetNamespace = "http://ws.time.org") @Stateless public class TimeBean implements TimeBeanLocal, TimeBeanRemote { @WebMethod public String getTime() throws TimeFault { StringBuilder sb = new StringBuilder(); sb.append(new java.util.Date().toString()).append(": "); if (true){ TimeFaultDetail detail = new TimeFaultDetail(); detail.setCode(234); TimeFault timeFault = new TimeFault(detail); throw timeFault; } return sb.toString(); } } package time.ejb; import javax.jws.WebMethod; import javax.jws.WebService; @WebService( name = "TimeRemote", targetNamespace = "http://ws.time.org") public interface TimeBeanRemote { @WebMethod public java.lang.String getTime() throws TimeFault; } package time.ejb; import javax.ejb.Local; @Local public interface TimeBeanLocal { public java.lang.String getTime() throws TimeFault; } package time.ejb; @javax.xml.ws.WebFault( faultBean = "time.ejb.TimeFaultDetail", name = "TimeFault", targetNamespace = "http://ws.time.org") public class TimeFault extends Exception { private static final long serialVersionUID = 1L; private TimeFaultDetail timeFaultDetail; public TimeFault(TimeFaultDetail detail) { this.setTimeFaultDetail(detail); } public TimeFaultDetail getTimeFaultDetail() { return timeFaultDetail; } public void setTimeFaultDetail(TimeFaultDetail timeFaultDetail) { this.timeFaultDetail = timeFaultDetail; } public TimeFaultDetail getFaultInfo(){ return timeFaultDetail; } } package time.ejb; public class TimeFaultDetail { private int code; public int getCode() { return code; } public void setCode(int code) { this.code = code; } } - - - Client project - Ant to generate webservice client - - - (adjust to your environment) buildWs.properties: JAVA_HOME=C://Program Files//Java//jdk1.6.0_16/ JAXWS_TOOLS=D://Development//Geronimo//geronimo-jetty6-javaee5-2.1.4//bin//jaxws-tools.bat SOURCE_DEST_DIR=../src WSDL_TIME_SERVICE=http://localhost:8080/TimeService/TimeRemote?wsdl buildWs.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <project name="TimeClient" basedir="." default="all"> <property file="buildWs.properties" /> <target name="all" depends="init,wsdlAll" /> <target name="init"> <tstamp /> <delete dir="org" /> <delete dir="../src/org/time/ws" /> </target> <target name="wsdlAll"> <antcall target="wsdl"></antcall> <antcall target="refresh"/> </target> <target name="wsdl"> <echo>jaxwstools wsimport: ${url}</echo> <exec executable="${JAXWS_TOOLS}"> <env key="JAVA_HOME" value="${JAVA_HOME}" /> <arg line="wsimport" /> <arg line="-s" /> <arg line="${SOURCE_DEST_DIR}" /> <arg line="${url}" /> </exec> </target> <target name="refresh"> <eclipse.refreshLocal resource="TimeClient" depth="infinite"/> </target> </project> - - - Client project - unit test - - - package time.client; import javax.xml.ws.soap.SOAPFaultException; import org.junit.After; import org.junit.Before; import org.time.ws.TimeFault; import org.time.ws.TimeRemote; import org.time.ws.TimeService; import com.sun.xml.internal.ws.client.ClientTransportException; public class TimeTester { @org.junit.Test public void testGetTime(){ try { TimeRemote timeService = new TimeService().getTimeServicePort(); String time = timeService.getTime(); System.out.println(time); } catch (TimeFault tfe) { System.out.println("Time fault exception: " +tfe.getFaultInfo()); } catch (ClientTransportException exc) { System.out.println("ClientTransportException error"); } catch (SOAPFaultException sfe) { System.out.println("Soap fault exception cause: " +sfe.getMessage()); } catch (Exception e){ System.out.println("Exception: "+e.getMessage()); } } } - - - PROBLEM - - - The client should catch TimeFault shouldn't it? But it catches SOAPFaultException instead: "Soap fault exception message: time.ejb.TimeFault: null", but why? (If I add a realm protection to openejb-jar.xml and BindingProvider to client call, then ClientTransportException works correct if wrong credentials provided, just to be complete). It must be some tiny little thing forgotten somewhere. Thanks for any help Karel |
| Free embeddable forum powered by Nabble | Forum Help |
