简体   繁体   中英

Getting Invocation Target Exception when calling class in a jarfile

I am running Tomcat8 on a MacBook Pro running Yosemite. I created a web service in Eclipse Luna that works IF I do not reference a class in one of my other projects. The class name is Token. It is resolved in the IDE. In the web service I expect a parameter "userToken" which currently is of the form 'S:m:n:userId:name:organization:role:state'. If I leave out one of the items in the parameter, I get a StringTokenizer exception that tells me that the web service is passing the parameter to the Token class where the StringTokenizer runs out of tokens prematurely. I add this because it appears that the class is being found and is being processed. If I provide a valid parameter with the correct number of items for the tokenizer, I get an Invocation Target Exception that I cannot figure out.

Here is a part of the stack trace I get in the console of the IDE:

java.lang.reflect.InvocationTargetException
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.shoulderscorp.services.StateMachineWSSoapBindingStub.getUsersApplicationsAndProcesses(StateMachineWSSoapBindingStub.java:106)
    at com.shoulderscorp.services.StateMachineWSProxy.getUsersApplicationsAndProcesses(StateMachineWSProxy.java:50)
    at org.apache.jsp.home_jsp._jspService(home_jsp.java:322)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

If I provide the part of the parameter that this method 'getUsersApplicationsAndProcesses' needs, namely the organization, and don't do the parsing, then the method works fine and returns xml that is presented correctly in the browser.

  1. Can someone give me a hint about what might be happening. BTW, if I run the method with the parameter from a 'main' program, it works correctly.

  2. How can I track down the error? I can't seem to get the debugger to work right and step into the code when it is running in my IDE.

Zounds! I found the problem. I think asking on this site helped me to think about it more in order to explain it and that helped to solve the problem.

I had NOT included the other project into the deployment assembly in the IDE. Thus it compiled correctly and ran correctly in the IDE, but would not be able to find the class, which was in another project when deployed. I found a hint when I placed a Class.forName("Token").newInstance() in the web service code.

Since this was the first web service I had tried with references from another project, it was the first time I had this problem. I have not seen an example where there were references to another project anywhere.

I believe some examples with a little more real world feel to them could be helpful on sites instead of the very simple, almost 'Hello, World' ones we find everywhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM