2014-10-06 98 views
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方法?

+0

嘗試在catch塊中打印stacktrace並查看。 – Renjith 2014-10-06 11:55:39

回答

1

Tyr將您的方法的public void改爲public string,並在函數結尾處返回一些字符串。例如,嘗試在最後返回strMessage