我已經實現的Web服務中獲得的XML性反應:如何使用JAX-WS SOAP處理程序
@WebServiceClient(//parameters//)
@HandlerChain(file = "handlers.xml")
public class MyWebServiceImpl {...}
而且我已經實現了ObjectFactory用類列表創建我的請求和響應。例如class test。
我需要得到xml的響應。
我嘗試使用JAX-WS SOAP處理程序,因此我添加了這個@HandlerChain(file = "handlers.xml")
附加值。 我handlers.xml樣子:
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>java.com.webservice.service.LoggingHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
我LoggingHandler類是:
import java.io.PrintWriter;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class LoggingHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
public void close(MessageContext messagecontext) {
}
public Set<QName> getHeaders() {
return null;
}
public boolean handleFault(SOAPMessageContext messagecontext) {
return true;
}
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
System.out.println("\nOutbound message:");
} else {
System.out.println("\nInbound message:");
}
SOAPMessage message = smc.getMessage();
try {
PrintWriter writer = new PrintWriter("soap_responce" + System.currentTimeMillis(), "UTF-8");
writer.println(message);
writer.close();
message.writeTo(System.out);
System.out.println(""); // just to add a newline
} catch (Exception e) {
System.out.println("Exception in handler: " + e);
}
return outboundProperty;
}
}
我已經測試類創建要求,下面是部分代碼:
MyWebServiceImpl impl = new MyWebServiceImpl(url, qName);
ws = impl.getMyWebServicePort();
Test req = new Test();
我想在文件「soap_responce」+ System.currentTimeMillis中獲得xml響應)。但是這樣的文件甚至沒有創建。請建議如何獲得XML響應,我是新來的Web服務,並可能做錯了什麼。謝謝