I have a WSDL First Apache CXF web service that works as expected, except that the exceptions that I throw on the server side are not received as such on the client.
Instead on the client side I get an exception of type SOAPFaultException in which only the detailMessage contains the message from the original server side Exception, but I'd like to receive the exact exception type I threw on the server side, including the cause chain.
I expected this to work like this by default, but it certainly doesn't in my system. I have been checking the CXF documentation to find hints about how to achieve this, but so far I haven't found anything useful.
The SOAP reference does not support stacktrace. If you want that you will need to copy the stacktrace as the message returned by the SoapFault.
With CXF you can do it by add a Interceptor on the income interceptor chain. Please refer to this question to see how to create a interceptor.
You should put it on the POST_INVOKE Phase.
Related
I communicate with a SOAP-service that throws that exception because of my message.
com.sun.xml.wss.XWSSecurityException: java.lang.ClassCastException: com.sun.xml.messaging.saaj.soap.impl.SOAPTextImpl cannot be cast to javax.xml.soap.SOAPElement
I think it is Java JAX-WS and the problem is somewhere in the XML of the SOAP.
Now I think of building also a simple service that gives me the chance to parse my own message.
Is there a fast an simple way with JAX-WS to parse a string that represents a SOAP-message?
Or do I need to build it full up (WSDL, ...).
Or is there maybe a SOAP-validator that uses JAX-WS?
I just have the problem with this one service. I communiacate with a bunch of others that are fine with my message. So I think it is specific to Java and implementation.
Thanks for help.
Chris
The Jersey documentation explains how to convert an Exception to a Response, but it fails in detailing what will happen if my code throws an Exception that isn't mapped or derived from WebApplicationException.
This link says:
If the thrown exception is not handled by a mapper, it is propagated and handled by the container (i.e., servlet) JAX-RS is running within.
But this only explains how JAX-RS 2.0 is supposed to behave in general terms and not how Jersey, which is the container in this case, is going to handle this Exception.
I know some people will just say Well, why don't you try it out and see what happens?... and the answer is: Because I like to know the documentation and I try to avoid empirical results, since they can be contaminated with coincidences and exceptional cases.
So, the question is:
How Jersey deals with not mapped Exceptions, like SQLException or IllegalArgumentException? Exceptions that are thrown by one of my Resources and not handled by my code.
Jersey is always deployed somewhere. Usually, it's a servlet container (in an application server or Tomcat for instance), but in Java SE only environment it can be for instance Grizzly or even JDK HTTP server. See documentation for deployment options.
What happens to exception uncaught (or thrown) by Jersey is up to this deployment environment. For instance, the servlet container usually catch the Exception, logs it and returns http status 500.
I am building Java application for Online Web Services and let's call it application A . I got the WSDL file form the second party so I can communicate with their application and let's call it application B.
From the WSDL file I generate the Java classes needed which are Requests and Responses classes. Application A will send some request object after setting the needed parameters and excepting response object from application B.
The connection is established and both applications A and B are communicating with each other.
Question:
From application A how can I get the xml data(file or text) for the request object before sending it to application B?
As described the connection is done by passing Java object as request and I know that in some point this request will be converted to xml file. How to get it?
--- EDIT ----
Important Information is missing that may cause confusion.
I am generated the Java Classed have been generated using Axis framework
I don't have much reputation to post a comment, so here is my answer: If you aren't yet using some framework use Apache CXF, If you want to capture the request before sending it application , you can either use cxf interceptors there are some inbuilt interceptors which can do this or you can create a custom interceptor with correct phase ( e.g. post marshal)
The problem is solved by adding the following statements in the bindingStub class that has been auto generated from the WSDL file for the web-services you are trying to access.
String request = _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
String response = _call.getMessageContext().getResponseMessage().getSOAPPartAsString();
These statements should be placed after the following method call _call.invoke otherwise you will get NullPointerException .
_call is a variable of type org.apache.axis.client.Cal and it is auto generated by Axis
I want to run a java application which calls a web service. Everything works fine from the netbeans ide, but fails when I run the .jar generated. What could be the problem?
How can I check the content type that the error is pointing at?
the error says: "SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message. com.sun.xml.messaging.saaj.MessageImpl identifyContentType"
EDIT
I am realizing that the problem could be originated by the fact that the web service that Im consuming uses a custom data type, but I have no idea where to look.
Please help
Your question lacks the details that would help identify your problem (like, what web container are you using, some source code, etc) but I've encountered and resolved this same problem. I'm using Tomcat with Eclipse and apparently, the problem occurs because for some reason, Tomcat can't find some JARs even though I have specified them in my build path. The resolution is to put the JARs in the actual lib directory of Tomcat instead of in some project-specific location. (See this same case with log4j.)
What happens is this missing JAR causes the servlet to produce an internal server error when called. Tomcat generates an error page---which is of type "text/html"---and sends it back to client. So, client reads "text/html" instead of the expected "text/xml".
For a test this SOAP tutorial produces the specified error due to jaxm-api.jar but can be fixed with the solution I described above. I have verified this with Tomcat 7.
How can I check the content type that the error is pointing at?
A bit difficult to answer without some code. But if you are using javax.xml.soap.SOAPPart, it has methods to check the headers of the SOAP transaction. Check the javadocs. Shame it does not override toString(). But personally, I did not arrive at this answer with Java debug methods but via looking at TCP dumps.
I have a web service using jar-rs. How do I throw a custom http error code to the calling application?
Thanks
The Response class lets you create a response with a specific HTTP Status. You can also extend WebApplicationException.
There are a couple of examples in the JAX-RS 1.0 features overview docs, in the 'Building Responses' and 'WebApplicationException and mapping Exceptions to Responses' sections that will tell you all you need to know to get started.