• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Create Custom SoapFault

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm completely new to webservices.
I have to implement a quite straightforward web service.

I want my webservice to return a custom Exception and thus a custom SoapFault.

I'm currently Using EJB, JAXWS, WEBLOGIC 10.3 and the bottom up approach (which I know is not really good).


My Problem is that I do not succeed in achieving that. I get a exception.
java.lang.NoSuchMethodException on my custom exception class.


Here is the complete stack followed by my code.

Any help on solution or path to investigate would be quite useful
Thanks a lot.

Olivier


The Exception:


<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header />
<env:Body>
<echo xmlns="http://api.service.myproject.ox/">
<arg0 xmlns="">true</arg0>
</echo>
</env:Body>
</env:Envelope>


<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>java.lang.NoSuchMethodException: ox.myproject.service.api.jaxws.HelloWorldServiceExceptionBean.setCode(int)</faultstring>
<detail>
<ns2:exception xmlns:ns2="http://jax-ws.dev.java.net/" class="com.sun.xml.ws.encoding.soap.SerializationException" note="To disable

this feature, set com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false">
<message>java.lang.NoSuchMethodException: ox.myproject.service.api.jaxws.HelloWorldServiceExceptionBean.setCode(int)</message>
<ns2:stackTrace>
<ns2:frame class="com.sun.xml.ws.fault.SOAPFaultBuilder" file="SOAPFaultBuilder.java" line="328"

method="createDetailFromUserDefinedException" />
<ns2:frame class="com.sun.xml.ws.fault.SOAPFaultBuilder" file="SOAPFaultBuilder.java" line="306" method="getFaultDetail" />
<ns2:frame class="com.sun.xml.ws.fault.SOAPFaultBuilder" file="SOAPFaultBuilder.java" line="170" method="createSOAPFaultMessage"

/>
<ns2:frame class="com.sun.xml.ws.server.sei.EndpointMethodHandler" file="EndpointMethodHandler.java" line="265" method="invoke"

/>
<ns2:frame class="com.sun.xml.ws.server.sei.SEIInvokerTube" file="SEIInvokerTube.java" line="93" method="processRequest" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="598" method="__doRun" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="557" method="_doRun" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="542" method="doRun" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="439" method="runSync" />
<ns2:frame class="com.sun.xml.ws.server.WSEndpointImpl$2" file="WSEndpointImpl.java" line="243" method="process" />
<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit" file="HttpAdapter.java" line="444" method="handle" />
<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter" file="HttpAdapter.java" line="244" method="handle" />
<ns2:frame class="com.sun.xml.ws.transport.http.servlet.ServletAdapter" file="ServletAdapter.java" line="134" method="handle" />
<ns2:frame class="weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke" file="HttpServletAdapter.java" line="272"

method="run" />
<ns2:frame class="weblogic.wsee.jaxws.HttpServletAdapter" file="HttpServletAdapter.java" line="185" method="post" />
<ns2:frame class="weblogic.wsee.jaxws.JAXWSServlet" file="JAXWSServlet.java" line="180" method="doPost" />
<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="727" method="service" />
<ns2:frame class="weblogic.wsee.jaxws.JAXWSServlet" file="JAXWSServlet.java" line="64" method="service" />
<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="820" method="service" />
<ns2:frame class="weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction" file="StubSecurityHelper.java" line="227"

method="run" />
<ns2:frame class="weblogic.servlet.internal.StubSecurityHelper" file="StubSecurityHelper.java" line="125" method="invokeServlet"

/>
<ns2:frame class="weblogic.servlet.internal.ServletStubImpl" file="ServletStubImpl.java" line="292" method="execute" />
<ns2:frame class="weblogic.servlet.internal.ServletStubImpl" file="ServletStubImpl.java" line="175" method="execute" />
<ns2:frame class="weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction" file="WebAppServletContext.java"

line="3498" method="run" />
<ns2:frame class="weblogic.security.acl.internal.AuthenticatedSubject" file="AuthenticatedSubject.java" line="321" method="doAs"

/>
<ns2:frame class="weblogic.security.service.SecurityManager" line="unknown" method="runAs" />
<ns2:frame class="weblogic.servlet.internal.WebAppServletContext" file="WebAppServletContext.java" line="2180"

method="securedExecute" />
<ns2:frame class="weblogic.servlet.internal.WebAppServletContext" file="WebAppServletContext.java" line="2086" method="execute"

/>
<ns2:frame class="weblogic.servlet.internal.ServletRequestImpl" file="ServletRequestImpl.java" line="1406" method="run" />
<ns2:frame class="weblogic.work.ExecuteThread" file="ExecuteThread.java" line="201" method="execute" />
<ns2:frame class="weblogic.work.ExecuteThread" file="ExecuteThread.java" line="173" method="run" />
</ns2:stackTrace>
<ns2:cause class="java.lang.NoSuchMethodException" note="To disable this feature, set

com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false">
<message>ox.myproject.service.api.jaxws.HelloWorldServiceExceptionBean.setCode(int)</message>
<ns2:stackTrace>
<ns2:frame class="java.lang.Class" file="Class.java" line="1605" method="getMethod" />
<ns2:frame class="com.sun.xml.ws.fault.SOAPFaultBuilder" file="SOAPFaultBuilder.java" line="323"

method="createDetailFromUserDefinedException" />
<ns2:frame class="com.sun.xml.ws.fault.SOAPFaultBuilder" file="SOAPFaultBuilder.java" line="306" method="getFaultDetail" />
<ns2:frame class="com.sun.xml.ws.fault.SOAPFaultBuilder" file="SOAPFaultBuilder.java" line="170"

method="createSOAPFaultMessage" />
<ns2:frame class="com.sun.xml.ws.server.sei.EndpointMethodHandler" file="EndpointMethodHandler.java" line="265"

method="invoke" />
<ns2:frame class="com.sun.xml.ws.server.sei.SEIInvokerTube" file="SEIInvokerTube.java" line="93" method="processRequest" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="598" method="__doRun" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="557" method="_doRun" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="542" method="doRun" />
<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="439" method="runSync" />
<ns2:frame class="com.sun.xml.ws.server.WSEndpointImpl$2" file="WSEndpointImpl.java" line="243" method="process" />
<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit" file="HttpAdapter.java" line="444" method="handle" />
<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter" file="HttpAdapter.java" line="244" method="handle" />
<ns2:frame class="com.sun.xml.ws.transport.http.servlet.ServletAdapter" file="ServletAdapter.java" line="134" method="handle"

/>
<ns2:frame class="weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke" file="HttpServletAdapter.java" line="272"

method="run" />
<ns2:frame class="weblogic.wsee.jaxws.HttpServletAdapter" file="HttpServletAdapter.java" line="185" method="post" />
<ns2:frame class="weblogic.wsee.jaxws.JAXWSServlet" file="JAXWSServlet.java" line="180" method="doPost" />
<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="727" method="service" />
<ns2:frame class="weblogic.wsee.jaxws.JAXWSServlet" file="JAXWSServlet.java" line="64" method="service" />
<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="820" method="service" />
<ns2:frame class="weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction" file="StubSecurityHelper.java" line="227"

method="run" />
<ns2:frame class="weblogic.servlet.internal.StubSecurityHelper" file="StubSecurityHelper.java" line="125"

method="invokeServlet" />
<ns2:frame class="weblogic.servlet.internal.ServletStubImpl" file="ServletStubImpl.java" line="292" method="execute" />
<ns2:frame class="weblogic.servlet.internal.ServletStubImpl" file="ServletStubImpl.java" line="175" method="execute" />
<ns2:frame class="weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction" file="WebAppServletContext.java"

line="3498" method="run" />
<ns2:frame class="weblogic.security.acl.internal.AuthenticatedSubject" file="AuthenticatedSubject.java" line="321"

method="doAs" />
<ns2:frame class="weblogic.security.service.SecurityManager" line="unknown" method="runAs" />
<ns2:frame class="weblogic.servlet.internal.WebAppServletContext" file="WebAppServletContext.java" line="2180"

method="securedExecute" />
<ns2:frame class="weblogic.servlet.internal.WebAppServletContext" file="WebAppServletContext.java" line="2086"

method="execute" />
<ns2:frame class="weblogic.servlet.internal.ServletRequestImpl" file="ServletRequestImpl.java" line="1406" method="run" />
<ns2:frame class="weblogic.work.ExecuteThread" file="ExecuteThread.java" line="201" method="execute" />
<ns2:frame class="weblogic.work.ExecuteThread" file="ExecuteThread.java" line="173" method="run" />
</ns2:stackTrace>
</ns2:cause>
</ns2:exception>
</detail>
</S:Fault>
</S:Body>
</S:Envelope>







The code:

package ox.myproject.service.impl;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebService;
import javax.xml.soap.SOAPFault;

import org.apache.log4j.Logger;

import ox.myproject.exception.HelloWorldServiceException;
import ox.myproject.service.api.IHelloWorldService;

@Remote
@Stateless(name = "HelloWorldService", mappedName = "ox/HelloWorldService")
@WebService(endpointInterface = "ox.myproject.service.api.IHelloWorldService", serviceName = "OxHelloWorld")
public class HelloWordServiceImpl implements IHelloWorldService {

private static Logger LOG = Logger.getLogger(HelloWordServiceImpl.class);

@Override
public String echo(boolean withHelloWorldServiceException) throws HelloWorldServiceException {

if (withHelloWorldServiceException) {
throw new HelloWorldServiceException(1, "test1");
}

return "This is a HELLOWORLD service in OX/MYPROJECT project";
}

}







package ox.myproject.exception;

import java.io.Serializable;

public class HelloWorldServiceException extends Exception implements Serializable {


private int code;
private String description;

public HelloWorldServiceException(int code, String description)
{
this.code = code;
this.description = description;
}

public int getCode() {
return code;
}

public String getDescription() {
return description;
}

public void setCode(int code) {
this.code = code;
}

public void setDescription(String description) {
this.description = description;
}

}











 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you could use javax.xml.ws.WebFault. You can use it like annotations.

@WebFault(name = "MyException", targetNamespace = "some.exception")
public class MyException
extends Exception
{}

Consider using Metro Framework for building web services. There you can create faults through graphic interface and generate code automatically.

hope this will help a bit.
 
Olivier Cleyman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Pawel.

Thanks a lot for you comment.
I tried to google a bit with the javax.xml.ws.WebFault and found indeed a solution to my problem with that annotation.

I helped me well.

Olivier
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic