Marcos Filho
Marcos Filho

Reputation: 11

How to Get SoapHeader on JaxWS WebService

I have one webservice jax-ws and i need get soap header, i make this:

@Resource
private WebServiceContext context;

MessageContext msContext = context.getMessageContext();
SOAPMessageContext soapMsgContext = (SOAPMessageContext) msContext;
SOAPHeader soapHeader = soapMsgContext.getMessage().getSOAPHeader();
Iterator it=soapHeader.extractAllHeaderElements();

but i have problem to cast MessageContext to SoapMessageContext, and i can't make SoapHandler because i can't send object from handler to webservice because to send i need put de object on Application Scope and i not want that.

Upvotes: 0

Views: 10477

Answers (2)

Gabriel Dinant
Gabriel Dinant

Reputation: 363

Don't know which version of JAX-WS you are using.

But

@WebMethod
public myResource(@WebParam(name = "MyHeader", header = true) String myHeader) {
...
}

Should do the trick.

Upvotes: 2

Paul Vargas
Paul Vargas

Reputation: 42020

What header expect to receive? Since the javax.xml.ws.handler.MessageContext is too a Map<String, Object>, you can print all contents:

import java.util.Map;

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;

@WebService
public class HelloWS {

    @Resource
    private WebServiceContext ctx;

    public String sayHello(String name) {
        Map<String, Object> map = ctx.getMessageContext();
        for (Object obj : map.entrySet()) {
            System.out.println(obj);
        }
        return "Hello, " + name;
    }

}

Upvotes: 0

Related Questions