我是 Web 服务的新手,我正在尝试使用 Eclipse Web 服务客户端使用 Axis2 自动生成的存根来创建 Java 客户端。以下是我的
client code. public static void main(String[] args) {
new wsClient2().runService();
}
public void runService(){
try {
CoreStub.COREEnvelopeRealTimeRequest req = new CoreStub.COREEnvelopeRealTimeRequest();
CoreStub.COREEnvelopeRealTimeResponse res = new CoreStub.COREEnvelopeRealTimeResponse();
req.setCORERuleVersion("2.2.0");
req.setPayload("....some data over here...... Can't disclose");
req.setPayloadID("..payload id goes here... can't disclose");
req.setPayloadType("X12_276_Request_005010X212");
RealTimeMode rtm = new RealTimeMode();
rtm.setRealTimeMode("RealTime");
req.setProcessingMode(rtm);
req.setReceiverID("myreceiverid");
req.setSenderID("mysenderid");
req.setTimeStamp("2015-04-14 10:27:47");
HttpTransportProperties.Authenticator basicAuthentication = new HttpTransportProperties.Authenticator();
basicAuthentication.setUsername("myusername");
basicAuthentication.setPassword("mypassword");
basicAuthentication.setPreemptiveAuthentication(true);
CoreStub _stub = new CoreStub();
ServiceClient clientservice = _stub._getServiceClient();
_stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, basicAuthentication);
_stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, "false");
OMFactory factory2 = OMAbstractFactory.getOMFactory();
OMNamespace SecurityElementNamespace = factory2.createOMNamespace("http://schemas.xmlsoap.org/ws/2002/12/secext", "wsse");
OMElement omSecurityElement = factory2.createOMElement(new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"), null);
//OMElement usernameEl = factory2.createOMElement(new QName("", "Username", "wsse"), null);
OMElement usernameEl = factory2.createOMElement(new QName("", "Username", "wsse"), null);
usernameEl.setText("myusername");
OMElement passwordEl = factory2.createOMElement(new QName("", "Password", "wsse"), null);
passwordEl.addAttribute("Type","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText",null );
passwordEl.setText("mypassword");
OMElement usernameTokenEl = factory2.createOMElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu"), null);
usernameTokenEl.addChild(usernameEl);
usernameTokenEl.addChild(passwordEl);
omSecurityElement.addChild(usernameTokenEl);
clientservice.addHeader(omSecurityElement);
try {
DisableSSLCertificateCheck();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Test");
//System.out.println(clientservice.getLastOperationContext().getMessageContext("Out").getEnvelope().toString());
System.out.println("Request created as: " + req.toString());
res = _stub.realTimeTransaction(req);
System.out.println("Version : " + res.getCORERuleVersion());
System.out.println("Error Code :" + res.getErrorCode());
System.out.println("Error Message:" + res.getErrorMessage());
//System.out.println("Pay Load :" + res.getPayload());
//System.out.println("Pay Load Type :" + res.getPayloadType());
System.out.println("Receiver Id :" + res.getReceiverID());
System.out.println("Sender Id :" + res.getSenderID());
} catch (Exception e) {
e.printStackTrace();
}
}
我得到以下异常
java.lang.IllegalArgumentException:无法在 org.apache.axiom.om.impl.llom.OMElementImpl.handleNamespace(OMElementImpl.java:186) 在 org.apache.axiom.om.impl 中创建具有空命名空间名称的前缀元素。 llom.OMElementImpl.(OMElementImpl.java:161) at org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory.createOMElement(OMLinkedListImplFactory.java:126) at org.myownpackage.www.soap.wsdl.wsClient2.runService (wsClient2.java:81) 在 org.myownpackage.www.soap.wsdl.wsClient2.main(wsClient2.java:37)
在以下行中,不允许使用空白字符串。我应该有什么来解决这个问题
OMElement usernameEl = factory2.createOMElement(
new QName("", "Username", "wsse"), null
);
更快的帮助将不胜感激。先感谢您。