Hi,

Please try applying the attached patch on Synapse
(modules/transports/core/nhttp). It uses the Host header to construct the
full URI. If the header is not present it uses the information available in
the connection object. HTTP spec mandates that all requests contain the Host
header. So most of the time URI will be constructed using the header.

The full URI will be stored in Constants.Configuration.TRANSPORT_IN_URL.

Thanks,
Hiranya

On Sat, Jun 25, 2011 at 10:15 PM, Afkham Azeez <[email protected]> wrote:

>
>
> On Sat, Jun 25, 2011 at 9:47 PM, Afkham Azeez <[email protected]> wrote:
>
>> Hiranya,
>> Can you please coders that. The servlet API provides such information so
>> this is a shortcoming of the nhttp transport.
>>
>
> Oops... this is what happens when you use the phone keyboard :) I meant,
> can you please fix this so that we can use it in the LB?
>
>
>
>> On Jun 25, 2011 9:33 PM, "Hiranya Jayathilaka" <[email protected]> wrote:
>> > The original request uri is not part of the message. So we cannot obtain
>> it from the http message. But at the transport level we can infer it by
>> looking at the socket. Currently nhttp transport doesn't do that. We can add
>> that bit of logic to the transport if needed.
>> >
>> > Sent from my iPhone
>> >
>> > On Jun 25, 2011, at 8:45 AM, Afkham Azeez <[email protected]> wrote:
>> >
>> >>
>> >>
>> >> On Sat, Jun 25, 2011 at 8:24 PM, Hiranya Jayathilaka <[email protected]>
>> wrote:
>> >> This means you rely on the client to always send the Host header. Might
>> not always work.
>> >>
>> >> Is there a way to get the originally requested URL?
>> >>
>> >> Sent from my iPhone
>> >>
>> >> On Jun 24, 2011, at 9:18 PM, Afkham Azeez <[email protected]> wrote:
>> >>
>> >>> The following code works.
>> >>>
>> >>> Map<String, String> headers = (Map<String,
>> String>)((Axis2MessageContext)
>> synCtx).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>> >>>
>> >>> String address = headers.get("Host");
>> >>>
>> >>> On Sat, Jun 25, 2011 at 9:36 AM, Afkham Azeez <[email protected]> wrote:
>> >>>
>> >>>
>> >>> On Sat, Jun 25, 2011 at 4:47 AM, Hiranya Jayathilaka <
>> [email protected]> wrote:
>> >>> I found following on simple HTTP server code:
>> >>>
>> >>> msgContext.setProperty(MessageContext.TRANSPORT_ADDR,
>> >>> conn.getLocalAddress().getHostAddress());
>> >>>
>> >>> This returns null for the NHTTP transport
>> >>>
>> >>> But other transports doesn't seem to be setting this. I didn't find
>> anything relevant in servlet transport code :(
>> >>>
>> >>> Thanks,
>> >>> Hiranya
>> >>>
>> >>> On Sat, Jun 25, 2011 at 3:48 AM, Hiranya Jayathilaka <
>> [email protected]> wrote:
>> >>>
>> >>>
>> >>> On Sat, Jun 25, 2011 at 3:07 AM, Afkham Azeez <[email protected]> wrote:
>> >>> Sorry, this does not work. I had hardcoded the host for testing it, so
>> for subsequent requests that prop was there.
>> >>>
>> >>> It doesn't look like we are keeping track of the full request URI
>> while mediation. The NHTTP transport sets a property named "TransportInURL"
>> (which I think other transports are setting too) on Axis2 message context
>> upon receiving a request. But I'm not sure even that will give the full URL.
>> Here's the implementation from NHTTP transport:
>> >>>
>> >>> msgContext.setProperty(
>> >>> Constants.Configuration.TRANSPORT_IN_URL,
>> request.getRequestLine().getUri());
>> >>>
>> >>> Very often the URI extracted from the request line is a relative URI
>> and so will not contain the hostname part. Worth trying out though.
>> >>>
>> >>> BTW can't we just infer the hostname part since we know the hostname
>> of the server where the code is running?
>> >>>
>> >>> Thanks,
>> >>> Hiranya
>> >>>
>> >>>
>> >>>
>> >>> On Sat, Jun 25, 2011 at 2:57 AM, Afkham Azeez <[email protected]> wrote:
>> >>> I found a way to get this. Hope it is the proper way of handling this.
>> >>>
>> >>>
>> ((Axis2MessageContext)synCtx).getAxis2MessageContext().getConfigurationContext().getProperty("synapse.endpoint.lb.algorithm.sdlbEndpointhost")
>>
>> >>>
>> >>>
>> >>> On Sat, Jun 25, 2011 at 2:39 AM, Afkham Azeez <[email protected]> wrote:
>> >>> Folks,
>> >>> To implement the Service-aware LB, I need to get the requested host
>> name. The MessageContext.getTo() method does not return the hostname part.
>> Is there any other way to get this, perhaps from the transport headers?
>> >>>
>> >>> Thanks
>> >>> Azeez
>> >>>
>> >>> --
>> >>> Afkham Azeez
>> >>> Director of Architecture; WSO2, Inc.; http://wso2.com
>> >>> Member; Apache Software Foundation; http://www.apache.org/
>> >>>
>> >>> email: [email protected] cell: +94 77 3320919
>> >>> blog: http://blog.afkham.org
>> >>> twitter: http://twitter.com/afkham_azeez
>> >>> linked-in: http://lk.linkedin.com/in/afkhamazeez
>> >>>
>> >>> Lean . Enterprise . Middleware
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Afkham Azeez
>> >>> Director of Architecture; WSO2, Inc.; http://wso2.com
>> >>> Member; Apache Software Foundation; http://www.apache.org/
>> >>>
>> >>> email: [email protected] cell: +94 77 3320919
>> >>> blog: http://blog.afkham.org
>> >>> twitter: http://twitter.com/afkham_azeez
>> >>> linked-in: http://lk.linkedin.com/in/afkhamazeez
>> >>>
>> >>> Lean . Enterprise . Middleware
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Afkham Azeez
>> >>> Director of Architecture; WSO2, Inc.; http://wso2.com
>> >>> Member; Apache Software Foundation; http://www.apache.org/
>> >>>
>> >>> email: [email protected] cell: +94 77 3320919
>> >>> blog: http://blog.afkham.org
>> >>> twitter: http://twitter.com/afkham_azeez
>> >>> linked-in: http://lk.linkedin.com/in/afkhamazeez
>> >>>
>> >>> Lean . Enterprise . Middleware
>> >>>
>> >>>
>> >>> _______________________________________________
>> >>> Carbon-dev mailing list
>> >>> [email protected]
>> >>> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Hiranya Jayathilaka
>> >>> Associate Technical Lead;
>> >>> WSO2 Inc.; http://wso2.org
>> >>> E-mail: [email protected]; Mobile: +94 77 633 3491
>> >>> Blog: http://techfeast-hiranya.blogspot.com
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Hiranya Jayathilaka
>> >>> Associate Technical Lead;
>> >>> WSO2 Inc.; http://wso2.org
>> >>> E-mail: [email protected]; Mobile: +94 77 633 3491
>> >>> Blog: http://techfeast-hiranya.blogspot.com
>> >>>
>> >>> _______________________________________________
>> >>> Carbon-dev mailing list
>> >>> [email protected]
>> >>> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Afkham Azeez
>> >>> Director of Architecture; WSO2, Inc.; http://wso2.com
>> >>> Member; Apache Software Foundation; http://www.apache.org/
>> >>>
>> >>> email: [email protected] cell: +94 77 3320919
>> >>> blog: http://blog.afkham.org
>> >>> twitter: http://twitter.com/afkham_azeez
>> >>> linked-in: http://lk.linkedin.com/in/afkhamazeez
>> >>>
>> >>> Lean . Enterprise . Middleware
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Afkham Azeez
>> >>> Director of Architecture; WSO2, Inc.; http://wso2.com
>> >>> Member; Apache Software Foundation; http://www.apache.org/
>> >>>
>> >>> email: [email protected] cell: +94 77 3320919
>> >>> blog: http://blog.afkham.org
>> >>> twitter: http://twitter.com/afkham_azeez
>> >>> linked-in: http://lk.linkedin.com/in/afkhamazeez
>> >>>
>> >>> Lean . Enterprise . Middleware
>> >>>
>> >>> _______________________________________________
>> >>> Carbon-dev mailing list
>> >>> [email protected]
>> >>> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>> >>
>> >> _______________________________________________
>> >> Carbon-dev mailing list
>> >> [email protected]
>> >> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>> >>
>> >>
>> >>
>> >>
>> >> --
>> >> Afkham Azeez
>> >> Director of Architecture; WSO2, Inc.; http://wso2.com
>> >> Member; Apache Software Foundation; http://www.apache.org/
>> >>
>> >> email: [email protected] cell: +94 77 3320919
>> >> blog: http://blog.afkham.org
>> >> twitter: http://twitter.com/afkham_azeez
>> >> linked-in: http://lk.linkedin.com/in/afkhamazeez
>> >>
>> >> Lean . Enterprise . Middleware
>> >>
>> >> _______________________________________________
>> >> Carbon-dev mailing list
>> >> [email protected]
>> >> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>>
>
>
>
> --
> *Afkham Azeez*
> Director of Architecture; WSO2, Inc.; http://wso2.com
> Member; Apache Software Foundation; http://www.apache.org/
> * <http://www.apache.org/>**
> email: **[email protected]* <[email protected]>* cell: +94 77 3320919
> blog: **http://blog.afkham.org* <http://blog.afkham.org>*
> twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
> *
> linked-in: **http://lk.linkedin.com/in/afkhamazeez*
> *
> *
> *Lean . Enterprise . Middleware*
>
>
> _______________________________________________
> Carbon-dev mailing list
> [email protected]
> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>
>


-- 
Hiranya Jayathilaka
Associate Technical Lead;
WSO2 Inc.;  http://wso2.org
E-mail: [email protected];  Mobile: +94 77 633 3491
Blog: http://techfeast-hiranya.blogspot.com
Index: src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
===================================================================
--- src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java	(revision 108296)
+++ src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java	(working copy)
@@ -156,9 +156,27 @@
         // the following statement causes the soap session services to be failing - ruwan        
         // msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
         msgContext.setServerSide(true);
-        msgContext.setProperty(
-            Constants.Configuration.TRANSPORT_IN_URL, request.getRequestLine().getUri());
 
+        String transportInURL = request.getRequestLine().getUri();
+        if (transportInURL.startsWith("/")) {
+            // relative URI
+            Header hostHeader = request.getFirstHeader(HTTP.TARGET_HOST);
+            if (hostHeader != null) {
+                // HTTP spec mandates that Host header is included in all requests
+                // So most of the time we can use the Host header to construct the full URI
+                transportInURL = (isHttps ? "https://"; : "http://";) + hostHeader.getValue() +
+                        request.getRequestLine().getUri();
+            } else {
+                // If the Host header is not available use the information available
+                // in the connection to construct the full URI
+                HttpInetConnection httpConn = (HttpInetConnection) conn;
+                transportInURL = (isHttps ? "https://"; : "http://";) +
+                        NhttpUtil.getHostName(httpConn.getLocalAddress()) + ":" +
+                        httpConn.getLocalPort() + request.getRequestLine().getUri();
+            }
+        }
+        msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL, transportInURL);
+
         // http transport header names are case insensitive 
         Map<String, String> headers = new TreeMap<String, String>(new Comparator<String>() {
             public int compare(String o1, String o2) {
_______________________________________________
Carbon-dev mailing list
[email protected]
http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev

Reply via email to