[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wsas-java-dev
Subject:    Re: [Dev] HTTP Serlvet Transport and HTTP Request Object
From:       Dushan Abeyruwan <dushan () wso2 ! com>
Date:       2013-12-26 13:43:07
Message-ID: CACyyj6f8_A8uA_se3vJHZq9gO-=SnPyCtsHJk2Fv3gvGKuc6vw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi

On Thu, Dec 26, 2013 at 4:20 PM, Aliosha <aliosha79@gmail.com> wrote:

> hi, i need to access the HttpServletRequest as i need to process a rest
> http call structured like the following:
>
> http://localhost:port/myService/[param1,param2,...,paramN]/myIpAddress
>

  Do you have idea how much parameters embedded as given above, if that
static,you can define a RESful API [1] and you can define your url-template
as uri-template="/myService/{parameter1,parameter2,paramter3}/myIpAddress*
     Then you should be able to access those variables in via mediation
flow as ,
         get-property('uri.var.parameter1')
         get-property('uri.var.parameter2')

 But if you don't have any well defined parameter set, above logic will not
work

refer [2]

[1]http://docs.wso2.org/display/ESB480/Getting+Started+with+REST+APIs
[2]http://docs.wso2.org/display/ESB480/Configuring+Specific+Use+Cases

> i want to avoid in my mediator to process the string "
> param1,param2,...,paramN]/myIpAddress"  to obtain my parameters. I prefer
> to invoke a POST request passing them inside Http payload parameters in the
> way i can get them by:
>
> httpRequest.getParameter("param1")
>
> I tried to change the transport receiver inside the axis2.xml using the
> org.wso2.carbon.core.transports.http.HttpTransportListener
> ( I suppose it s not an implementation of the http based on the synapse
> http NIO core... so  the performance will get lower. isn't? )
> in this way i can get the HttpServletRequest object. But i realized that
> this object has Parameters not null only if i append them in the url like a
> query string ( i.e. ?param1=param1&param2=param2....) even if i m sending a
> post request. I m using for testing the chrom advanced Rest client and
> mozilla poster.
> Am i doing anything wrong?
> regards
>  Il 26/dic/2013 08:50 "Dushan Abeyruwan" <dushan@wso2.com> ha scritto:
>
> Hi
>>
>>
>> On Tue, Dec 24, 2013 at 2:57 AM, Aliosha <aliosha79@gmail.com> wrote:
>>
>>> i have developed a custom mediator and i want to try to publish it as a
>>> REST service con my WSO2 ESB 4.7.0.
>>> Once i created the REST API, the ESB publishes it on the 8280 port.
>>> On the client side, the POST REST call needs to specify some http
>>> parameters that i need to recover later in the mediator by this code:
>>>
>>
>>     You should refer  http://docs.wso2.org/display/ESB480/HTTP+Endpoint where
>> you can easily generate request, no need of having custom mediators
>>
>>>
>>>     org.apache.axis2.context.MessageContext axis2MsgContext;
>>> axis2MsgContext =  ((Axis2MessageContext)
>>> synapseMsgContext).getAxis2MessageContext();
>>>  HttpServletRequest obj =
>>> (HttpServletRequest)axis2MsgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
>>>
>>> if (obj != null) {
>>>  System.out.println("Method :"+ obj.getMethod());
>>> System.out.println("Content-type :" +obj.getContentType());
>>>  System.out.println("Content-length :"+obj.getContentLength());
>>> System.out.println("Remote
>>> addtress"+obj.getSession().getLastAccessedTime());
>>>  }
>>>
>>> The object i get is always null.
>>> That's probably because on 8280 ESB uses the NHttp transport.
>>> In what way can i solve this problem?
>>> Have i to activate the HTTP Servlet Transport? How can i do this?
>>>
>>      Can I know why you need to use HTTP Servlet for RESTful application
>> communication ? Do you have any specific requirement to use it? Why default
>> transport shipped with ESB (PTT) not works for you?
>>
>>
>>> What's the difference between HTTP and NHTTP? Does the ESB performance
>>> get lower?
>>>
>>
>>
>>    Obviously, NHTTP far more efficient than Servelet Transport,because
>> NHTTP is non blocking invocation and it uses NIO for communication.. by
>> default we recommend to use NHTTP because its faster and has high
>> performance numbers..
>>
>>> Thanks a lot.
>>> Best Regards.
>>>
>>
>>
>>
>> --
>> Dushan Abeyruwan | Associate Tech Lead
>> Integration Technologies Team
>> PMC Member Apache Synpase
>> WSO2 Inc. http://wso2.com/
>> Blog:http://dushansview.blogspot.com/
>> Mobile:(0094)713942042
>>
>


-- 
Dushan Abeyruwan | Associate Tech Lead
Integration Technologies Team
PMC Member Apache Synpase
WSO2 Inc. http://wso2.com/
Blog:http://dushansview.blogspot.com/
Mobile:(0094)713942042

[Attachment #5 (text/html)]

<div dir="ltr">Hi<div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec \
26, 2013 at 4:20 PM, Aliosha <span dir="ltr">&lt;<a href="mailto:aliosha79@gmail.com" \
target="_blank">aliosha79@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><p>hi, \
i need to access the HttpServletRequest as i need to process a rest http call \
structured like the following:</p>


<p>http://localhost:port/myService/[param1,param2,...,paramN]/myIpAddress</p></blockquote><div><br></div><div> \
Do you have idea how much parameters embedded as given above, if that static,you can \
define a RESful API [1] and you can define your url-template as \
uri-template=&quot;/myService/{parameter1,parameter2,paramter3}/myIpAddress*</div>

<div>     Then you should be able to access those variables in via mediation flow as \
,</div><div>         get-property(&#39;uri.var.parameter1&#39;)</div><div>         \
get-property(&#39;uri.var.parameter2&#39;)</div><div>

<br></div><div> But if you don&#39;t have any well defined parameter set, above logic \
will not work</div><div><br></div><div>refer [2]</div><div><br></div><div>[1]<a \
href="http://docs.wso2.org/display/ESB480/Getting+Started+with+REST+APIs">http://docs.wso2.org/display/ESB480/Getting+Started+with+REST+APIs</a> \
</div>

<div>[2]<a href="http://docs.wso2.org/display/ESB480/Configuring+Specific+Use+Cases">h \
ttp://docs.wso2.org/display/ESB480/Configuring+Specific+Use+Cases</a></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<p>i want to avoid in my mediator to process the string &quot; \
param1,param2,...,paramN]/myIpAddress&quot;  to obtain my parameters. I prefer to \
invoke a POST request passing them inside Http payload parameters in the way i can \
get them by:</p>



<p>httpRequest.getParameter(&quot;param1&quot;)</p>
<p>I tried to change the transport receiver inside the axis2.xml using the<br>
org.wso2.carbon.core.transports.http.HttpTransportListener<br>
( I suppose it s not an implementation of the http based on the synapse http NIO \
core... so  the performance will get lower. isn&#39;t? )<br> in this way i can get \
the HttpServletRequest object. But i realized that this object has Parameters not \
null only if i append them in the url like a query string ( i.e. \
?param1=param1&amp;param2=param2....) even if i m sending a post request. I m using \
for testing the chrom advanced Rest client and mozilla poster.<br>



Am i doing anything wrong?<br>
regards<br>
</p>
<div class="gmail_quote">Il 26/dic/2013 08:50 &quot;Dushan Abeyruwan&quot; &lt;<a \
href="mailto:dushan@wso2.com" target="_blank">dushan@wso2.com</a>&gt; ha \
scritto:<div><div class="h5"><br type="attribution"><blockquote class="gmail_quote" \
style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<div dir="ltr">Hi<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, \
Dec 24, 2013 at 2:57 AM, Aliosha <span dir="ltr">&lt;<a \
href="mailto:aliosha79@gmail.com" target="_blank">aliosha79@gmail.com</a>&gt;</span> \
wrote:<br>





<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div \
dir="ltr"><div>i have developed a custom mediator and i want to try to publish it as \
a REST service con my WSO2 ESB 4.7.0.<br>





</div><div>Once i created the REST API, the ESB publishes it on the 8280 \
port.</div><div>On the client side, the POST REST call needs to specify some http \
parameters that i need to recover later in the mediator by this code:</div>





</div></blockquote><div><br></div><div>    You should refer  <a \
href="http://docs.wso2.org/display/ESB480/HTTP+Endpoint" \
target="_blank">http://docs.wso2.org/display/ESB480/HTTP+Endpoint</a> where you can \
easily generate request, no need of having custom mediators </div>





<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div \
dir="ltr"> <div><br></div><div>    org.apache.axis2.context.MessageContext \
axis2MsgContext;</div><div><span style="white-space:pre-wrap">	</span>axis2MsgContext \
=  ((Axis2MessageContext) synapseMsgContext).getAxis2MessageContext();</div>






<div><span style="white-space:pre-wrap">	</span>HttpServletRequest obj = \
(HttpServletRequest)axis2MsgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);</div><div><br></div><div><span \
style="white-space:pre-wrap">	</span>if (obj != null) {</div>






<div><span style="white-space:pre-wrap">		</span>System.out.println(&quot;Method \
:&quot;+ obj.getMethod());</div><div><span \
style="white-space:pre-wrap">		</span>System.out.println(&quot;Content-type :&quot; \
+obj.getContentType());</div>






<div><span style="white-space:pre-wrap">		</span>System.out.println(&quot;Content-length \
:&quot;+obj.getContentLength());</div><div><span \
style="white-space:pre-wrap">		</span>System.out.println(&quot;Remote \
addtress&quot;+obj.getSession().getLastAccessedTime());  </div>






<div><span style="white-space:pre-wrap">	</span>}</div><div><span \
style="white-space:pre-wrap">	</span> </div><div>The object i get is always null. \
</div><div>That&#39;s probably because on 8280 ESB uses the NHttp transport.</div>






<div>In what way can i solve this problem?</div><div>Have i to activate the HTTP \
Servlet Transport? How can i do this?</div></div></blockquote><div>     Can I know \
why you need to use HTTP Servlet for RESTful application communication ? Do you have \
any specific requirement to use it? Why default transport shipped with ESB (PTT) not \
works for you?</div>




<div>    </div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div \
dir="ltr"><div>What&#39;s the difference between HTTP and NHTTP? Does the ESB \
performance get lower?</div>




</div></blockquote><div>     </div><div><br></div><div>   Obviously, NHTTP far more \
efficient than Servelet Transport,because NHTTP is non blocking invocation and it \
uses NIO for communication.. by default we recommend to use NHTTP because its faster \
and has high performance numbers..</div>





<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div \
dir="ltr"><div> Thanks a lot.</div><div>Best Regards.</div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
dir="ltr"><div><font face="courier new, monospace">Dushan Abeyruwan | <span \
style="color:rgb(153,153,153)">Associate Tech Lead</span></font></div><div><div>





<div><font color="#999999" face="courier new, monospace">Integration Technologies \
Team</font></div></div><div><font color="#999999" face="courier new, monospace">PMC \
Member Apache Synpase</font></div><div><font face="courier new, monospace"><font \
color="#999999">WSO2 Inc. <a href="http://wso2.com/" \
target="_blank">http://wso2.com/</a></font><br>





</font></div><div><font face="courier new, monospace">Blog:<a \
href="http://dushansview.blogspot.com/" \
target="_blank">http://dushansview.blogspot.com/</a></font></div><div><span \
style="background-color:transparent"><font color="#999999" face="courier new, \
monospace">Mobile:(0094)713942042</font></span></div>





</div></div>
</div></div>
</blockquote></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
dir="ltr"><div><font face="courier new, monospace">Dushan Abeyruwan | <span \
style="color:rgb(153,153,153)">Associate Tech Lead</span></font></div><div><div>

<div><font color="#999999" face="courier new, monospace">Integration Technologies \
Team</font></div></div><div><font color="#999999" face="courier new, monospace">PMC \
Member Apache Synpase</font></div><div><font face="courier new, monospace"><font \
color="#999999">WSO2 Inc. <a href="http://wso2.com/" \
target="_blank">http://wso2.com/</a></font><br>

</font></div><div><font face="courier new, monospace">Blog:<a \
href="http://dushansview.blogspot.com/">http://dushansview.blogspot.com/</a></font></div><div><span \
style="background-color:transparent"><font color="#999999" face="courier new, \
monospace">Mobile:(0094)713942042</font></span></div>

</div></div>
</div></div>



_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic