You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Luca Manganelli <ma...@itc.it> on 2004/10/19 11:21:27 UTC

Obtaining the client hostname inside *BindingImpl.java

Hi,

I've made a WSDL and then used WSDL2Java with it do create a web service.
My question is: there is a way to know the client hostname of the 
request inside
the *BindingImpl.java source?

Thank you in advance



RE: Obtaining the client hostname inside *BindingImpl.java

Posted by Patrick Herber <pa...@arpage.ch>.
If I correctly understand you are trying to invoke your WebService via a GET
request and not a "usual" "SOAP Client", isn't it?
I gave a look at the code of the org.apache.axis.transport.http.AxisServlet
and there I found that when the Servlet receives a POST request (line 869)
it creates a MessageContext and fills it with lots of properties:

/* Save some HTTP specific info in the bag in case someone needs it */
/********************************************************************/
msgContext.setProperty(Constants.MC_JWS_CLASSDIR, jwsClassDir);
msgContext.setProperty(Constants.MC_HOME_DIR, getHomeDir());
msgContext.setProperty(Constants.MC_RELATIVE_PATH, req.getServletPath());
msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLET, this );
msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, req );
msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE, res );
msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION,
getWebInfPath() );
msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO,
req.getPathInfo() );
msgContext.setProperty(HTTPConstants.HEADER_AUTHORIZATION,
req.getHeader(HTTPConstants.HEADER_AUTHORIZATION));
msgContext.setProperty(Constants.MC_REMOTE_ADDR, req.getRemoteAddr());

However, when it receives a GET request (line 1110) it also creates a
MessageContext but fills it with other properties:

// Place various useful servlet-related objects in
// the MessageContext object being delivered to the
// plugin.

msgContext.setProperty (MessageContext.TRANS_URL, url);
msgContext.setProperty (HTTPConstants.PLUGIN_SERVICE_NAME, serviceName);
msgContext.setProperty (HTTPConstants.PLUGIN_NAME, handlerName);
msgContext.setProperty (HTTPConstants.PLUGIN_IS_DEVELOPMENT, new Boolean
(isDevelopment()));
msgContext.setProperty (HTTPConstants.PLUGIN_ENABLE_LIST, new Boolean
(enableList));
msgContext.setProperty (HTTPConstants.PLUGIN_ENGINE, engine);
msgContext.setProperty (HTTPConstants.PLUGIN_WRITER, writer);
msgContext.setProperty (HTTPConstants.PLUGIN_LOG, log);
msgContext.setProperty (HTTPConstants.PLUGIN_EXCEPTION_LOG, exceptionLog);

... and the request is not part of it.
Honestly I don't understand why different properties are added for these two
different invocations.
You could try to also add the request in the message context:

msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, req );

and see if than work...

Regards,
Patrick
 

> -----Original Message-----
> From: Luca Manganelli [mailto:manganelli@itc.it] 
> Sent: Dienstag, 19. Oktober 2004 14:01
> To: axis-user@ws.apache.org
> Subject: Re: Obtaining the client hostname inside *BindingImpl.java
> 
> Patrick Herber wrote:
> 
> >Nop...
> >I've only found that:
> >
> >"Note that the request will be null if the message came in over a 
> >different transport."
> >
> >See:
> >http://nagoya.apache.org/wiki/apachewiki.cgi?AxisProjectPages
/HttpReque
> >st
> >
> >Good luck and Regards,
> >Patrick
> >  
> >
> But I use SOAP over HTTP (or I think), by typing:
> 
> http://axis-server-host:8080/axis/services/service?method=test
> 
> in my browser.
> And it doesn't work again.
> Why?
> 
> 


Re: Obtaining the client hostname inside *BindingImpl.java

Posted by Luca Manganelli <ma...@itc.it>.
Patrick Herber wrote:

>Nop...
>I've only found that:
>
>"Note that the request will be null if the message came in over a different
>transport."
>
>See:
>http://nagoya.apache.org/wiki/apachewiki.cgi?AxisProjectPages/HttpRequest
>
>Good luck and Regards,
>Patrick
>  
>
But I use SOAP over HTTP (or I think), by typing:

http://axis-server-host:8080/axis/services/service?method=test

in my browser.
And it doesn't work again.
Why?


RE: Obtaining the client hostname inside *BindingImpl.java

Posted by Patrick Herber <pa...@arpage.ch>.
Nop...
I've only found that:

"Note that the request will be null if the message came in over a different
transport."

See:
http://nagoya.apache.org/wiki/apachewiki.cgi?AxisProjectPages/HttpRequest

Good luck and Regards,
Patrick

 

> -----Original Message-----
> From: Luca Manganelli [mailto:manganelli@itc.it] 
> Sent: Dienstag, 19. Oktober 2004 11:47
> To: axis-user@ws.apache.org
> Subject: Re: Obtaining the client hostname inside *BindingImpl.java
> 
> Patrick Herber wrote:
> 
> >Hi,
> >
> >I think you could do something like:
> >
> >MessageContext context = MessageContext.getCurrentContext();
> >HttpServletRequest request = (HttpServletRequest) 
> >context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
> >String clientHost = request.getRemoteAddr();
> >  
> >
> request is null. Any ideas?
> 
> I tried:
> 
>         Iterator i = context.getPropertyNames();
>         while (i.hasNext()) {
>             String v = (String) i.next();
>             System.out.println (v + " = " + msg.getProperty(v));
>         }
> 
> and it returns:
> 
> home.dir = .
> realpath = axis/services/EsempioService
> jws.classDir = jwsClasses
> attachments.directory = C:\Documents and 
> Settings\manganelli\Local Settings\Temp transport.url = 
> http://andromeda:8080/axis/services/EsempioService
> path = axis/services/EsempioService
> 
> 


Re: Obtaining the client hostname inside *BindingImpl.java

Posted by Luca Manganelli <ma...@itc.it>.
Patrick Herber wrote:

>Hi,
>
>I think you could do something like:
>
>MessageContext context = MessageContext.getCurrentContext();
>HttpServletRequest request = (HttpServletRequest)
>context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
>String clientHost = request.getRemoteAddr();
>  
>
request is null. Any ideas?

I tried:

        Iterator i = context.getPropertyNames();
        while (i.hasNext()) {
            String v = (String) i.next();
            System.out.println (v + " = " + msg.getProperty(v));
        }

and it returns:

home.dir = .
realpath = axis/services/EsempioService
jws.classDir = jwsClasses
attachments.directory = C:\Documents and Settings\manganelli\Local 
Settings\Temp
transport.url = http://andromeda:8080/axis/services/EsempioService
path = axis/services/EsempioService


RE: Obtaining the client hostname inside *BindingImpl.java

Posted by Patrick Herber <pa...@arpage.ch>.
Hi,

I think you could do something like:

MessageContext context = MessageContext.getCurrentContext();
HttpServletRequest request = (HttpServletRequest)
context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
String clientHost = request.getRemoteAddr();

Regards,
Patrick

 

> -----Original Message-----
> From: Luca Manganelli [mailto:manganelli@itc.it] 
> Sent: Dienstag, 19. Oktober 2004 11:21
> To: axis-user@ws.apache.org
> Subject: Obtaining the client hostname inside *BindingImpl.java
> 
> Hi,
> 
> I've made a WSDL and then used WSDL2Java with it do create a 
> web service.
> My question is: there is a way to know the client hostname of 
> the request inside the *BindingImpl.java source?
> 
> Thank you in advance
> 
> 
>