简体   繁体   中英

SOAP JAVA WSDL - Add a value in the request header

I have a problem with a request to a SOAP service, I generated the client ( SWDL ) with JAVA and at the moment of making the request it returns an error message: " org.apache.axis.AxisFault: THE SERVICE REQUIRES API KEY ".

How can I add a token to the header in the following code?

ServiceImplSynchronization service = new ServiceSynchronizationLocator();
ServiceSynchronization ws = new ServiceSynchronizationSoapBindingStub(new URL(service.getServiceFacturacionSynchronizationPortAddress()), service);
ws.verifyCommunication();

Result:

org.apache.axis.AxisFault: THE SERVICE REQUIRES API KEY" 

I solved my problem by overwriting the method in my service locator.

@Override
public Call createCall() throws ServiceException {
_call = new org.apache.axis.client.Call(this) {

    @Override
    public void setRequestMessage(Message msg) {
        super.setRequestMessage(msg);

        MimeHeaders mimeHeaders = msg.getMimeHeaders();
        mimeHeaders.addHeader("headerName", Value);


    }

};

return _call;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM