Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How enable WSA-Addresing for client? #63

Open
michmzr opened this issue Dec 28, 2015 · 8 comments
Open

How enable WSA-Addresing for client? #63

michmzr opened this issue Dec 28, 2015 · 8 comments

Comments

@michmzr
Copy link

michmzr commented Dec 28, 2015

I imported classes from xsd file with configuration, but server require WSA-Attributes in soap header("wsa:action", "wsa:to"). Unfortunettly client service dont inject these attributes and server return http code 400. How could I repair my code?

Configuration in Config.groovy

    birCompanyDataEndPoint {
            wsdl = "wsdl/UslugaBIRzewnPubl.xsd"
            namespace = "pl.truesoftware.crm.company.regon"

            client = true

            contentType = "application/soap+xml"
            mtomEnabled = true
            exsh = true

            or = true

            wsdlArgs = ['-autoNameResolution']

            clientInterface = IUslugaBIRzewnPubl
            serviceEndpointAddress = "https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc"
        }

Main xsd file: https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl.xsd
I use grails 2.5.0

Update:
I used annotation javax.xml.ws.soap.Addressing for actions and soap request header included WS-Addresing, but was wrong for webserver.

@ctoestreich
Copy link
Member

I think you need to use an out interceptor and modify the header in the interceptor. Here is some pseudo code for one I have done in the past.

package com.foo.bar

import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SmartApiMetaOutInterceptor extends AbstractPhaseInterceptor<Message> {

    @Autowired
    EndpointConfiguration endpointConfiguration;

    public SmartApiMetaOutInterceptor() {
        super(Phase.PREPARE_SEND);
    }

    @Override
    public void handleMessage(Message message) {
        if(message != null) {
            Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
            if (headers == null) {
                headers = new HashMap<>();
                message.put(Message.PROTOCOL_HEADERS, headers);
            }
            headers.put("X-Cache-Enabled", Collections.singletonList(endpointConfiguration.isCacheEnabled().toString()));
            headers.put("X-Cache-Remote-Url", Collections.singletonList(endpointConfiguration.getFopBaseServiceUrl()));
            headers.put("X-Cache-Prefix", Collections.singletonList(endpointConfiguration.getCachePrefix()));
        }
    }
}

@ctoestreich
Copy link
Member

@michmzr Did the out interceptor work for you?

@michmzr
Copy link
Author

michmzr commented Dec 31, 2015

Thanks for help, but interceptor only injected HTTP headers. I need to modify SOAP Request do add xml with soap header

@ctoestreich
Copy link
Member

Still possible via SoapPreProtocolOutInterceptor

http://cxf.apache.org/docs/interceptors.html

@ctoestreich
Copy link
Member

@ctoestreich
Copy link
Member

@michmzr
Copy link
Author

michmzr commented Jan 7, 2016

Thank you for help :) Finally, I found the solution.
I created a Interceptor, which iterate SOAP Header's tags from SOAP request. First, I added annotation @addressing(enabled=true, required=true) to every webservice client's function

My interceptor

public class BirSoapHeaderInterceptor extends AbstractSoapInterceptor
{
    public BirSoapHeaderInterceptor() {
        super(Phase.PRE_PROTOCOL);
    }
    @Override
    public void handleMessage(SoapMessage message) throws Fault
    {
        List list = message.getHeaders()
        //----------------- copy values from old header
        String wsaAction = ""
        String wsaTo = ""
        list.each{tag ->
            System.out.println("${tag.name} ${tag.dataBinding}")
            String tagName = (tag.name as String)
            def objectValue = tag.object?.value
            if(!wsaAction && tagName.contains("Action"))
                wsaAction = objectValue?.value
            if(!wsaTo && tagName.contains("To"))
                wsaTo = objectValue?.value
        }
        list.clear()
        //-----------------wsa:To
        Header headTo = new Header(new QName("", "wsa:To"), wsaTo, new JAXBDataBinding(String.class))
        list.add(headTo)
        //-----------------wsa:Action
        Header headAction = new Header(new QName("", "wsa:Action"), wsaAction, new JAXBDataBinding(String.class))
        list.add(headAction)
        message.put(Header.HEADER_LIST, list)
    }
}

@ctoestreich
Copy link
Member

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants