java wsimport https,wsimport使用小结二

那些很纠结要不要直接用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();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值