Webservice returns java.lang.reflect.InvocationTargetException

Posted by Damian on Stack Overflow See other posts from Stack Overflow or by Damian
Published on 2010-06-08T19:25:05Z Indexed on 2010/06/08 19:32 UTC
Read the original article Hit count: 632

Filed under:
|

Hi,

I am receiving the above message when making a request to a java webservice.

We originally created a Java Console application and manually submitted an xml file. When running this as a Java Application the response is successfully created and displayed by using System.out.println. We are creating the web service by selecting the java file that contains the methods and choosing "create webservice" specifying the dynamic project that the webservice is to be created in and the methods to be exposed.

What the application is doing is taking an xml file and unmarshalling this to an object using:

 public static Object unmarshalToObject(Class classToBeBound,
   String xmlRequest) {
  Object obj = new Object();
  try {
   JAXBContext jc = JAXBContext.newInstance(classToBeBound);
   Unmarshaller um = jc.createUnmarshaller();
   obj = um.unmarshal(new StringReader(xmlRequest));
  } catch (Exception e) {
   e.printStackTrace()
  }
  return obj;
 }

Some processing is carried out on the file and then an object is marshalled to xml as follows:

 public static String marshalToXML(Object data) {
  StringWriter sw = new StringWriter();
  try {
   logger.info("Create new Marshall");
   JAXBContext jc = JAXBContext.newInstance("ContextPathName");
   logger.info("Marshalled to xmlObjects");
   Marshaller marshaller = jc.createMarshaller();
   marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
   marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
   marshaller.marshal(data, sw);
  } catch (Exception e) {
   logException(logger, e);
  }
  return sw.toString();
 }

The following is the line of code that seems to be causing an issue as the logger displays the message prior to this:

JAXBContext jc = JAXBContext.newInstance("ContextPathName");

The webservice never gets to the next line - the following is the body of the SOAP message:

  <soapenv:Fault>
     <faultcode>soapenv:Server.userException</faultcode>
     <faultstring>java.lang.reflect.InvocationTargetException</faultstring>
     <detail>
        <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">servername</ns1:hostname>
     </detail>
  </soapenv:Fault>

I have added Try/Catch around this section of code even as far as looking for JAXBExceptions but this does not seem to catch anything - nor does the general exception.

This issue does not occur when running the console application. The build path for this includes the following contents of sun\jwsdp-2.0\jaxb\lib:

jaxb-api.jar
jsr173_1.0_api.jar
jaxb-impl.jar

I have added these to the lib folder in the WEB-INF file of the dynamic project.

I am running the webservice in JBuilder 2008 R2 and using SOAPUI to submit the request - this points to the wsdl generated when creating the webservice.

If anyone has any help or ideas on how to solve this could they please reply - thanks for taking the time to read this post!

© Stack Overflow or respective owner

Related posts about java

Related posts about webservices