0
我是一名Java初学者,我试图构建一个需要从XML文件读取数据的Web服务。我使用这个示例XML:Java Web服务异常 - NullPointException
<message>Customer Name</message>
这是我的Web方法来读取内部XML文本:
@WebMethod(operationName = "ProcessMessage")
public void ProcessMessage(@WebParam(name = "name") String strXML){
String strMessage="";
try {
String xmlString = strXML;
JAXBContext jc = JAXBContext.newInstance(String.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
StreamSource xmlSource = new StreamSource(new StringReader(xmlString));
JAXBElement<String> je = unmarshaller.unmarshal(xmlSource, String.class);
strMessage = je.getValue();
Response response = Response.status(200).build();
} catch (JAXBException ex) {
Logger.getLogger(service.class.getName()).log(Level.SEVERE, null, ex);
}
}
当运行Web服务,XML输入例如从上面并单击该按钮它抛出一个异常:
WS00041: Service invocation threw an exception with message : null;
什么是错我的Web方法?
尝试在catch块中打印stacktrace并查看。 – Renjith 2014-10-06 11:55:39