I'm using Axis2 1.5.2 and Eclipse. I'm using Eclipse to generate the WSDL and client code from generated WSDL.
I created a custom exception that my service can throw. Everything looks ok when creating the webservice. The webservice starts successfully and I can view the generated WSDL by pointing my web browser.
But when I tell Eclipse to generate the Client code using the generated WSDL I get this error from Eclipse:
Error in generating Java from WSDL: java.io.IOException: ERROR: Missing <soap:fault> element inFault "InsertUserException" in operation "InsertUserException", in binding insertUser
java.io.IOException: ERROR: Missing <soap:fault> element inFault "InsertUserException" in operation "InsertUserException", in binding insertUser
at org.apache.axis.wsdl.symbolTable.SymbolTable.faultsFromSOAPFault(SymbolTable.java:2858)
My custom exception is "InsertUserException":
public class InsertUserException extends Exception{
private String errorCode;
public InsertUserException(String errorCode){.....}
public String getErrorCode(){...}
public void setErrorCode(String errorCode){...}
}
My service action that clients can call is "insertUser":
public void insertUser() throws InsertUserException{
.....
}
Any help is appreciated.
Axis2 doesn't know how to send Exceptions over the wire unless they are AxisFaults.
Here's a link to an article on how to use AxisFault with custom exception information.
http://wso2.org/library/171
Related
I have an application based on Jax-RS using CXF and Tomcat.
When my application throw a Exception, an ExceptionMapper is call :
#Component
public class MyExceptionHandler implements ExceptionMapper<MyException> {
#Override
public Response toResponse(MyException exception) {
return Response
.status(500)
.entity(new ExceptionBodyResponse(exception))
.build();
}
}
Then I except a response with a custom XML message. But what I get is the Tomcat HTML error page (containing the wanted message inside).
I try to figure out how to receive the response without the Tomcat error page, only the XML.
I found another thread about this problematic, but for Jersey, nothing for CXF : Dropwizard Response.status(Response.Status.NOT_FOUND).build() returns html
I am struggling big time offering a web service based on some WSDL file received from a customer. As described in details here, the WSDL file returned when appending a ?wsdl to the service URL like
http://never.mind/SomeService?wsdl
seems to be misinterpreted by SoapUI and this again prevents the customer from using the service!
I was now hoping that someone could help me understand if it is possible to make the get WSDL endpoint return the original WSDL file instead of some Apache CXF digested version?
Update: I just read somewhere that there is a WSDLGetInterceptor taking care of the get WSDL requests - can I maybe override that one?
I chose to override the getDocument method of the WSDLGetUtils class being used by the WSDLGetInterceptor. My version of the utils class MyWSDLGetUtilsis put into action via this interceptor:
public class WsdlGetSoapInterceptor extends AbstractSoapInterceptor {
public WsdlGetSoapInterceptor() {
super(Phase.READ);
addBefore(WSDLGetInterceptor.class.getName());
}
/** {#inheritDoc} */
#Override
public void handleMessage(final SoapMessage message) throws Fault {
message.setContextualProperty(WSDLGetUtils.class.getName(), MyWSDLGetUtils.Instance);
}
}
I have simple web service :
I have the same problem. when I don't append "?wsdl" I have soap faylt. how can I avoid this exception?
#WebService
#SOAPBinding(style = Style.RPC)
public interface TimeServer {
#WebMethod
#WebResult(partName = "time_response")
String getTimeAsString();
#WebMethod
#WebResult(partName = "time_response")
long getTimeAsElapsed();
}
and impl:
#WebService(endpointInterface = "x.y.z.TimeServer")
public class TimeServiceImpl implements TimeServer {
public TimeServiceImpl() {}
#Override
public String getTimeAsString() {return new Date().toString();}
#Override
public long getTimeAsElapsed() {return new Date().getTime();}
}
I run this web service in Jboss As 7.0.1.
Everything works well!
When I open link localhost:8080/project/time?wsdl
everything works well - I have wsdl.
but when I don't append "?wsdl" I have exception.
14:26:58,192 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (http-localhost-127.0.0.1-8080-1) Interceptor for {http://x.z.y/}HelloWorld has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: No such operation: null (HTTP GET PATH_INFO: /project/timenull)
at org.apache.cxf.interceptor.URIMappingInterceptor.handleMessage(URIMappingInterceptor.java:88)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
and I have this response from server:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>
No such operation: null (HTTP GET PATH_INFO: /soap-service/timenull)
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
how can I avoid this exception?
It will be better , if client will see another message, instead of this error response? how can I send another XML when client opens link without "?wsdl"?
thnaks
Webservices won't support HTTP GET. If you enter the service url its directly making a HTTP GET. Thats the reason it responds with the error No such operation
Instead you need to make a SOAP POST to get response from webservice. Write a webservice client for this. You can refer this link for creating webservice clients
#grep
I see this post as bit old, but still will try to answer if anyone else with similar problem is able to. Well, I had the same issue and wondered what were the reasons behind those. here are the two steps that i tried and fixed up the issue. make sure you are able to access the wsdl in browser.
Close the SOAPUI, delete the soapui_workspace.xml created in user folder under C:/users.
Restart the Soap_ui and open up preferences>Proxy setting.
Change from automatic to None.
Create new project.
This did solved my issue and got the response from webservice in SOAPUI.
Secondly, in this case, make sure you have deployed the webservice correctly as mentioned by #Dinal.
I have a Spring webservice which throws a custom exception for any error scenerio. I have configured the exception class like this:
#SoapFault(faultCode = FaultCode.CUSTOM, customFaultCode="{http://com/examples/webservice/utils/AppConstants}"+AppConstants.FAULT_CODE)
public class ConfigurationException extends Exception {/**Codes**/}
Throwing exception as below:
throw new ConfigurationException("Validation exception");
and in Spring config xml I have added this:
<bean class="org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver"/>
It is working fine if I call this service from SOAPUI. I'm getting proper SOAP fault with faultcode and faultString.
But, when I'm invoking the service from java spring client. I'm getting SOAP fault as exception.My requirement is to get SOAP fault message object so that I can get the faultCode and faultString.
Thanks in advance for any help in this regard.
You can catch the fault in the client code, and in the catch block retrieve the fault code and string with exception.getFaultCode() and exception.getFaultString(), have a look at the javadoc for further details.
I'm developing a REST-ful web service using RESTEasy deployed on Tomcat. I've configured an error page which takes the exception's message and generates an XML based on it when any exception occurs during the request.
This works fine for any application generated exceptions. However, if client sends an invalid XML which cannot be unmarshalled correctly, an javax.xml.bind.UnmarshalException is thrown and Tomcat's default error page is used instead of mine.
I have configured my error page to the error-code 500 in web.xml.
Is using error pages the correct way to handle errors when using RESTEasy or is there an alternative way?
The best way is to use an ExceptionMapper. You create a class UnmarshalExceptionMapper that implements ExceptionMapper. You annotate this with "#Provider" and in your Application constructor you do "classes.add(UnmarshalExceptionMapper.class)" or "singletons.add(new UnmarshalExceptionMapper())".
Your exception mapper will look something like this:
#provider
public class UnmarshalExceptionMapper
implements ExceptionMapper<UnmarshalException> {
public Response toResponse(UnmarshalException exception) {
ResponseBuilder rb =
Response.status(
Response.Status.BAD_REQUEST) // Most appropriate HTTP status code
.entity(your xml goes here)
.type("application/xml");
return rb.build();
}
}
Note that you must set the type to "application/xml" because currently content negotiation is NOT done for exception mappers. To do your own content negotiation, get the HttpHeaders from the request, find the "accept" header, and set the type accordingly.