Search code examples
javaweb-servicessoappayload

How to use Holder<Payload> holder in SOAP web client


I am trying to figure out how to use a webservice which was generated from a wsdl file. In this project I am going send request by using the generated webservice client. The interface is shown below:

public interface IConnectService {
public void processMessage(
    @WebParam(name = "payload", mode = 
WebParam.Mode.INOUT)
    Holder<Payload> payload);
}

The client is like this:

public class ConnectService
extends Service
{
private final static URL CONNECTSERVICE_WSDL_LOCATION;
private final static WebServiceException CONNECTSERVICE_EXCEPTION;
private final static QName CONNECTSERVICE_QNAME = new 
QName("http://xxxxxx-asi.com/services", "ConnectService");
static {
    URL url = null;
    WebServiceException e = null;
    try {
        url = new URL("http://localhost/wsdl/xxxxx"); 
    } catch (MalformedURLException ex) {
        e = new WebServiceException(ex);
    }
    CONNECTSERVICE_WSDL_LOCATION = url;
    CONNECTSERVICE_EXCEPTION = e;
 }

 public ConnectService() {
    super(__getWsdlLocation(), CONNECTSERVICE_QNAME);
 }

 public ConnectService(WebServiceFeature... features) {
    super(__getWsdlLocation(), CONNECTSERVICE_QNAME, features);
 }

 public ConnectService(URL wsdlLocation) {
    super(wsdlLocation, CONNECTSERVICE_QNAME);
 }

 public ConnectService(URL wsdlLocation, WebServiceFeature... 
features) {
    super(wsdlLocation, CONNECTSERVICE_QNAME, features);
}

 public ConnectService(URL wsdlLocation, QName serviceName) {
    super(wsdlLocation, serviceName);
  }

 public ConnectService(URL wsdlLocation, QName serviceName, 
 WebServiceFeature... features) {
    super(wsdlLocation, serviceName, features);
}
@WebEndpoint(name = "BasicHttpBinding_IConnectService")
public IConnectService getBasicHttpBindingIConnectService() {
    return super.getPort(new QName("http://xxxxxxx- 
asi.com/services", "BasicHttpBinding_IConnectService"), 
IConnectService.class);
}

@WebEndpoint(name = "BasicHttpBinding_IConnectService")
public IConnectService 
getBasicHttpBindingIConnectService(WebServiceFeature... features) {
    return super.getPort(new QName("http://xxxxxx-asi.com/services", 
"BasicHttpBinding_IConnectService"), IConnectService.class, 
features);
}

private static URL __getWsdlLocation() {
    if (CONNECTSERVICE_EXCEPTION!= null) {
        throw CONNECTSERVICE_EXCEPTION;
    }
    return CONNECTSERVICE_WSDL_LOCATION;
 }

}

The soap request message structure is going to be like in the picture: enter image description here

So my question is how can I use the client to make call which includes my soapmessage using the interface method? To my understand, the Holder object can only take Payload object, which is an childelement of ProcessMessege (as shown in the structure), and ProcessMessage is a childelement of SOAP body. I need to put the security credentials in the SOAP header and I already did that. So right now if I use the webservice method, I only can pass the payload object, but the web server will not accept the request because no credentials inside of the payload part. Anybody can help out for this problem? I really appreciate your help!


Solution

  • I solved this problem by using soapmessage handler and handler resolver. The handler can insert the credentials in the soap header and modifier the soap body to satisfy all my requirements for the soap message.