JAVA WS-SECURITY SOAP DHL 追踪服务
我已经成功地从 FedEx 和 UPS API 获得了回复,但是 dhl 的 API 快让我发疯了。 下面是我的代码,它正在生成以下请求。
<?xml version="1.0" encoding="http://schemas.xmlsoap.org/soap/envelope/" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:trackShipmentRequest xmlns:ns2="http://scxgxtt.phx-dc.dhl.com/glDHLExpressTrack/providers/services/trackShipment">
<trackingRequest>
<TrackingRequest xmlns="http://www.dhl.com">
<Request xmlns="">
<ServiceHeader>
<MessageTime>2011-09-01T20:40:36.334+02:00</MessageTime>
<MessageReference>123456789012345678901234567890</MessageReference>
</ServiceHeader>
</Request>
<LevelOfDetails xmlns="">ALL_CHECK_POINTS</LevelOfDetails>
</TrackingRequest>
</trackingRequest>
</ns2:trackShipmentRequest>
</soapenv:Body>
</soapenv:Envelope>
我实际上缺少的是像这样的标头部分(在 SOAP-UI 中测试):
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-12">
<wsse:Username>xxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxx</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header
我需要在代码中添加什么才能获取发送到 DHL 服务器的 SOAP 请求中的标头部分?
下面是我的实际代码。 这是标准的axis2 wsdl2java:
public class abc {
/**
* @param args
* @param String ref
* @throws IOException
*/
public static void main(String[] args) throws IOException {
System.setProperty("javax.net.ssl.trustStore","F:\\eclipse\\terefere\\testkeystore");
System.setProperty("javaxdhlrequest2.net.ssl.trustStorePassword","123456");
GblDHLExpressTrackStub stub = new GblDHLExpressTrackStub();
System.out.println("3");
System.out.println("5");
TrackShipmentRequest trackShipmentRequest = new TrackShipmentRequest();
TrackShipmentRequestE trackshipmentrequeste = new TrackShipmentRequestE();
PubTrackingRequest pubtrackingequest = new PubTrackingRequest();
System.out.println("6");
TrackingRequest dhlrequest = new TrackingRequest();
System.out.println("7");
Request request = new Request();
ServiceHeader header =new ServiceHeader();
System.out.println("8");
Calendar rightNow = Calendar.getInstance();
AWBNumber awbnumber = new AWBNumber();
awbnumber.setAWBNumber("2510305906");
LevelOfDetails level = null;
level= LevelOfDetails.ALL_CHECK_POINTS;
MessageReference message = new MessageReference();
message.setMessageReference("123456789012345678901234567890");
header.setMessageReference(message);
header.setMessageTime(rightNow);
request.setServiceHeader(header);
//dhlrequest.setAWBNumber(awb);
dhlrequest.setLevelOfDetails(level);
dhlrequest.setRequest(request);
pubtrackingequest.setTrackingRequest(dhlrequest);
trackShipmentRequest.setTrackingRequest(pubtrackingequest);
trackshipmentrequeste.setTrackShipmentRequest(trackShipmentRequest);
GblDHLExpressTrackCallbackHandler callb = new GblDHLExpressTrackCallbackHandler() {
};
stub._getServiceClient().getOptions().setUserName("abc");
stub._getServiceClient().getOptions().setPassword("abc");
stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, false);
stub._getServiceClient().engageModule("rampart");
stub.starttrackShipmentRequest(trackshipmentrequeste, callb);
System.out.println("11,5");
stub.trackShipmentRequest(trackshipmentrequeste);
System.out.println("13");
}
}
I've successfully managed to get the responses from FedEx and UPS APIs, however dhl ones is driving me crazy.
Well below is my code, which is generating following request.
<?xml version="1.0" encoding="http://schemas.xmlsoap.org/soap/envelope/" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:trackShipmentRequest xmlns:ns2="http://scxgxtt.phx-dc.dhl.com/glDHLExpressTrack/providers/services/trackShipment">
<trackingRequest>
<TrackingRequest xmlns="http://www.dhl.com">
<Request xmlns="">
<ServiceHeader>
<MessageTime>2011-09-01T20:40:36.334+02:00</MessageTime>
<MessageReference>123456789012345678901234567890</MessageReference>
</ServiceHeader>
</Request>
<LevelOfDetails xmlns="">ALL_CHECK_POINTS</LevelOfDetails>
</TrackingRequest>
</trackingRequest>
</ns2:trackShipmentRequest>
</soapenv:Body>
</soapenv:Envelope>
What I am actually missing is the header section like this (tested in SOAP-UI):
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-12">
<wsse:Username>xxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxx</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header
What do I need to add to the code in order to get the header section in the SOAP request being sent to DHL server?
Below is my actual code.
It's standard axis2 wsdl2java:
public class abc {
/**
* @param args
* @param String ref
* @throws IOException
*/
public static void main(String[] args) throws IOException {
System.setProperty("javax.net.ssl.trustStore","F:\\eclipse\\terefere\\testkeystore");
System.setProperty("javaxdhlrequest2.net.ssl.trustStorePassword","123456");
GblDHLExpressTrackStub stub = new GblDHLExpressTrackStub();
System.out.println("3");
System.out.println("5");
TrackShipmentRequest trackShipmentRequest = new TrackShipmentRequest();
TrackShipmentRequestE trackshipmentrequeste = new TrackShipmentRequestE();
PubTrackingRequest pubtrackingequest = new PubTrackingRequest();
System.out.println("6");
TrackingRequest dhlrequest = new TrackingRequest();
System.out.println("7");
Request request = new Request();
ServiceHeader header =new ServiceHeader();
System.out.println("8");
Calendar rightNow = Calendar.getInstance();
AWBNumber awbnumber = new AWBNumber();
awbnumber.setAWBNumber("2510305906");
LevelOfDetails level = null;
level= LevelOfDetails.ALL_CHECK_POINTS;
MessageReference message = new MessageReference();
message.setMessageReference("123456789012345678901234567890");
header.setMessageReference(message);
header.setMessageTime(rightNow);
request.setServiceHeader(header);
//dhlrequest.setAWBNumber(awb);
dhlrequest.setLevelOfDetails(level);
dhlrequest.setRequest(request);
pubtrackingequest.setTrackingRequest(dhlrequest);
trackShipmentRequest.setTrackingRequest(pubtrackingequest);
trackshipmentrequeste.setTrackShipmentRequest(trackShipmentRequest);
GblDHLExpressTrackCallbackHandler callb = new GblDHLExpressTrackCallbackHandler() {
};
stub._getServiceClient().getOptions().setUserName("abc");
stub._getServiceClient().getOptions().setPassword("abc");
stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, false);
stub._getServiceClient().engageModule("rampart");
stub.starttrackShipmentRequest(trackshipmentrequeste, callb);
System.out.println("11,5");
stub.trackShipmentRequest(trackshipmentrequeste);
System.out.println("13");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论