Get Url of endpoint using on a handler (JAX-WS)
Asked Answered
S

3

6

I am implementing many JAX-WS web services with a common Handler class to validate the correct structure of incoming SOAP messages.

Is there some way to obtain the URL to which is directed the current message so i could get the schema from this url automatically and get the message validated?

Spitz answered 27/12, 2013 at 10:50 Comment(1)
make different methods and put first element as method name so that you can direct varisous soap messageSorn
S
1

Found!!!

public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {

public boolean handleMessage(SOAPMessageContext smc) {
    System.out.println("URL of Endpoint" +smc.get(JAXWSProperties.HTTP_REQUEST_URL));
 }
}
Spitz answered 27/12, 2013 at 11:23 Comment(1)
com.sun.xml.ws.developer for JAXWSProperties seems not to be available in Java 7. Any alternatives?Sharanshard
A
9

In my application smc.get(JAXWSProperties.HTTP_REQUEST_URL) returns null. I've fount another way, I hope this helps:

public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {

    public boolean handleMessage(SOAPMessageContext smc) {
        String endpointAddress = (String) smc.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
        log.debug("endpointAddress " +endpointAddress);
    }
}
Adamo answered 20/1, 2014 at 17:16 Comment(1)
Yes, you are right. I found that to be filled when the handled message was the response from the server. In this case, the HTTP method used is not GET, but POST, so the HTTP_REQUEST_URL is empty. So summarizing, if you need to get the Url as a server on an incoming message should use HTTP_REQUEST_URL while if you are doing it like a client ENDPOINT_ADDRESS_PROPERTY. At least in tomcat 7!!!Spitz
S
1

Found!!!

public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {

public boolean handleMessage(SOAPMessageContext smc) {
    System.out.println("URL of Endpoint" +smc.get(JAXWSProperties.HTTP_REQUEST_URL));
 }
}
Spitz answered 27/12, 2013 at 11:23 Comment(1)
com.sun.xml.ws.developer for JAXWSProperties seems not to be available in Java 7. Any alternatives?Sharanshard
I
0

Neither JAXWSProperties.HTTP_REQUEST_URL nor BindingProvider.ENDPOINT_ADDRESS_PROPERTY worked for me.

This is how i got url in an outbound message on WildFly 10 (Java 7):

public boolean handleMessage(SOAPMessageContext context) {
    String url = (String) context.get(MessageContext.PATH_INFO);
    ...
}
Ianiana answered 9/8, 2018 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.