当我向Java Web服务发出请求时,我收到了上述消息。
我们最初创建了一个Java控制台应用程序,并手动提交了一个xml文件。当将其作为Java应用程序运行时,通过使用System.out.println成功创建和显示响应。我们通过选择包含方法的Java文件并选择“创建Web服务”,指定要在其中创建Web服务的动态项目以及要公开的方法来创建Web服务。
该应用程序所做的是使用以下方法将xml文件解组到对象中:
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;
}
对文件进行一些处理,然后将对象编组为XML,如下所示:
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();
}
以下是似乎引起问题的代码行,因为记录器在此之前显示了消息:
JAXBContext jc = JAXBContext.newInstance("ContextPathName");
这个webservice无法继续执行下一行代码——以下是SOAP消息体:
<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>
我已经在这段代码周围添加了Try/Catch,甚至寻找JAXBExceptions,但似乎没有捕获任何异常 - 通用异常也是如此。
运行控制台应用程序时不会出现此问题。其中包括sun\jwsdp-2.0\jaxb\lib文件夹下的以下内容的构建路径:
jaxb-api.jar
jsr173_1.0_api.jar
jaxb-impl.jar
我已经将它们添加到动态项目的WEB-INF文件夹中的lib文件夹中。
我正在JBuilder 2008 R2中运行webservice,并使用SOAPUI提交请求 - 这指向创建webservice时生成的wsdl。
如果有人对如何解决此问题有任何帮助或想法,请回复 - 感谢您抽出时间阅读此帖!