title: Webservice returns java.lang.reflect.InvocationTargetException
body: <p>I am receiving the above message when making a request to a java webservice.</p>
  
  <p>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. </p>
  
  <p>What the application is doing is taking an xml file and unmarshalling this to an object using:</p>
  
  <pre><code> 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;
   }
  </code></pre>
  
  <p>Some processing is carried out on the file and then an object is marshalled to xml as follows:</p>
  
  <pre><code> 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();
   }
  </code></pre>
  
  <p>The following is the line of code that seems to be causing an issue as the logger displays the message prior to this:</p>
  
  <pre><code>JAXBContext jc = JAXBContext.newInstance("ContextPathName");
  </code></pre>
  
  <p>The webservice never gets to the next line - the following is the body of the SOAP message:</p>
  
  <pre><code>  &lt;soapenv:Fault&gt;
       &lt;faultcode&gt;soapenv:Server.userException&lt;/faultcode&gt;
       &lt;faultstring&gt;java.lang.reflect.InvocationTargetException&lt;/faultstring&gt;
       &lt;detail&gt;
          &lt;ns1:hostname xmlns:ns1="http://xml.apache.org/axis/"&gt;servername&lt;/ns1:hostname&gt;
       &lt;/detail&gt;
    &lt;/soapenv:Fault&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>jaxb-api.jar
  jsr173_1.0_api.jar
  jaxb-impl.jar
  </code></pre>
  
  <p>I have added these to the lib folder in the WEB-INF file of the dynamic project.</p>
  
  <p>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.</p>
  
  <p>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!</p>