那些很纠结要不要直接用wsimport生成的pojo,因为我没能找到很好的办法去转xmlGregorianCalendar到date或者java.util.Calendar,我觉得在pojo依赖ws是不可接受的,奋战了一晚上找到了在wsimport时转换的办法,为了方便日后记忆,贴上配置清单,此清单还包括了禁用 ws的wrapper style和异步方式的调用等,截获soap消息,打印log,已经使用本地的wsdl等。
先上一个命令行
wsimport -b ReaderServices-building.xml -p com.xxx.ws.stub.reader -wsdllocation ReaderServices.wsdl -Xnocompile ReaderServices.wsdl 在上building.xml
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://java.sun.com/xml/ns/jaxws">
false
false
parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
printMethod="javax.xml.bind.DatatypeConverter.printDate"/>
parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
printMethod="javax.xml.bind.DatatypeConverter.printDate"/>
fromwsdlhandler.common.LoggingHandler
LoggingHandler是直接从ws sample下面里拿的,小改了下源码
import java.io.PrintStream;
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.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
/*
* This simple SOAPHandler will output the contents of incoming
* and outgoing messages.
*/
public class LoggingHandler implements SOAPHandler {
// change this to redirect output if desired
private static PrintStream out = System.out;
public Set getHeaders() {
return null;
}
public boolean handleMessage(SOAPMessageContext smc) {
logToSystemOut(smc);
return true;
}
public boolean handleFault(SOAPMessageContext smc) {
logToSystemOut(smc);
return true;
}
// nothing to clean up
public void close(MessageContext messageContext) {
}
/*
* Check the MESSAGE_OUTBOUND_PROPERTY in the context
* to see if this is an outgoing or incoming message.
* Write a brief message to the print stream and
* output the message. The writeTo() method can throw
* SOAPException or IOException
*/
private void logToSystemOut(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean)
smc.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
out.println("\nHandler Log -> Outbound message:");
} else {
out.println("\nHandler Log -> Inbound message:");
}
SOAPMessage message = smc.getMessage();
try {
message.writeTo(out);
out.println();
} catch (Exception e) {
e.printStackTrace();
}
}
}