当我们在本地服务器中调用服务时,我们已经完成了使用JAXWS服务的开发。表示请求的正确标题和正文已创建并获得相应的正确响应。
当我们在远程服务器(unix)中部署相同的代码时,请求将在没有标头的情况下触发。请帮助我们在这里做错了。
public ABCPortType initABCCheckStub(String sEndpointUrl) throws AxisFault, Exception{
System.out.println( "endpointUrl : " + sEndpointUrl );
URL baseUrl;
baseUrl = com.def.xmlns.ABC.class.getResource("META-INF/wsdls/ABCCheck.wsdl");
ABCCheck ABCCheckInfo = new ABCCheck(baseUrl,new QName("http://xmlns.ABC.com/", "Untitled"));
ABCPortType abcPort = ABCCheckInfo.getSOAPEventSource();
((BindingProvider) abcPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,sEndpointUrl);
@SuppressWarnings("rawtypes")
List<Handler> handlerChain = new ArrayList<Handler>();
handlerChain.add(new WSSecurityHeaderSOAPHandler());
((BindingProvider) abcPort).getBinding().setHandlerChain(handlerChain);
System.out.println( "exiting initKAMCheckStub( )");
return abcPort;
}
WebserviceSecurityHeader
package com.abcd.webservice.handler;
import java.util.Set;
import javax.xml.soap.SOAPHeader;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class WSSecurityHeaderSOAPHandler implements SOAPHandler<SOAPMessageContext> {
private static final String SOAP_ELEMENT_FROM = "From";
private static final String SOAP_ELEMENT_ACTION = "Action";
private static final String SOAP_ELEMENT_MESSAGEHEADER = "MessageHeader";
private static final String NAMESPACE_SECURITY = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
private static final String PREFIX_SECURITY = "env";
public WSSecurityHeaderSOAPHandler() {
}
public boolean handleMessage(SOAPMessageContext soapMessageContext) {
System.out.println("Start -> handleMessage()");
Boolean outboundProperty = (Boolean) soapMessageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
try {
SOAPEnvelope soapEnvelope = soapMessageContext.getMessage().getSOAPPart().getEnvelope();
SOAPHeader header = soapEnvelope.getHeader();
if (header == null) {
header = soapEnvelope.addHeader();
}
SOAPElement soapElementSecurityHeader = header.addChildElement(SOAP_ELEMENT_MESSAGEHEADER, PREFIX_SECURITY,NAMESPACE_SECURITY);
//From
SOAPElement soapElementFrom = soapElementSecurityHeader.addChildElement(SOAP_ELEMENT_FROM, PREFIX_SECURITY);
SOAPElement soapElementPartyID = soapElementFrom.addChildElement(SOAP_ELEMENT_PARTYID, PREFIX_SECURITY);
soapElementPartyID.addTextNode("INTERSHOP");
System.out.println("Exit -> handleMessage()");
} catch (Exception e) {
System.out.println("Error on wsSecurityHandler ->"+e.getMessage());
}
}
return true;
}
@Override
public void close(MessageContext context) {
// TODO Auto-generated method stub
}
@Override
public boolean handleFault(SOAPMessageContext context) {
// TODO Auto-generated method stub
return true;
}
@Override
public Set<QName> getHeaders() {
// TODO Auto-generated method stub
return null;
}
}