[SIPForum-discussion] RES: RES: SIP Servlet to HTTP Servlet

Kristine Regis kristine at racequeen.ph
Mon Aug 24 23:37:35 UTC 2009


Giscard, thank you very much for helping me regarding my problem. You 
said that it is good to share my code to you. Here it goes.

            @Override
            protected void doMessage(SipServletRequest request) throws 
ServletException, IOException {
                try{
                    SipServletResponse response = 
request.createResponse(200);
                    response.send();

                    String reply=request.getContent().toString();
                    System.out.print("reply: "+reply);
                }
                catch(Exception err){
                    err.printStackTrace();
                }       
            }

this is the method that is invoked in the instant messaging module. My 
problem here is that I wanted the reply of the other recipient to appear 
on the JSP. In my way, I wanted the reply to be turned over to the Http 
servlet and back to the JSP. Hope you could help me here.

By the way, I received your reply. Thank you very much!

-Kristine

Giscard Fernandes Faria wrote:
> Kristine, I did send this message to you during the morning, I thing you
> didn't receive it...
>
> Here we go again...
>
> ====
>
> Hello Kristine,
>
> Sorry for answer I thoutht you were trying to find a way to pass
> parameter from one to each other (like Just pass some variables), that
> is why I gave you that answer.
>
> Well, if you wanna to invoke a HttpServlet, you have to use dispatchers
>
> 	RequestDispatcher d =
> getServletContext().getRequestDispatcher(<uri>);
> 	d.forward(request, response)
>
> The dispatcher is a engine inside Container that allow us to resend a
> HttpServletRequest/HttpServletResponse to "another servlet". However it
> is most used for authentication and things like that. Personally, I
> cannot see why do things Like that from a SIP Servlet.
> If you pay attention on the source code above, you will see the
> parameters Request/response has HttpServletRequest/HttpServletResponse
> type respectively. However from inside a SIP Servlet you don't have such
> attributes (as you have inside a do request for example), so you will
> have to build them on your own.
>
> If you want to share what you are trying to do, maybe we can try to find
> a better way of performing things, a way that does not require to invoke
> a Http Servlet...:-)
>
> PS1: Using the dispatcher, also is possible to include more than one uri
> to receive the request, just use the "include" method before invoke the
> forward.
>
> PS2: I didn't try do it, however I believe it will work
>
> Hope this can help.
>
> Regards
>
>  
> 	
> Giscard Fernandes Faria-  Software Engineering Department 
> NEC Brasil S.A.
> Phone +55 11 2166-2713 * Mobile + 55 11 8561-0710
> "There are no 'cookbook' methods that can replace intelligence,
> experience, and good taste in design and programming", Bjarne Stroustrup
>  
> giscardf at nec.com.br
>
>  
>  
>  
>  
>  
>  
> -----Mensagem original-----
> De: discussion-bounces at sipforum.org
> [mailto:discussion-bounces at sipforum.org] Em nome de Kristine Regis
> Enviada em: domingo, 23 de agosto de 2009 21:27
> Para: Giscard Fernandes Faria
> Cc: discussion at sipforum.org
> Assunto: Re: [SIPForum-discussion] RES: SIP Servlet to HTTP Servlet
>
> Hello once again!
>
> I am trying what you said but I really wonder how could I call the HTTP 
> servlet from the SIP servlet. I really wonder about it. Hope you could 
> help me with this question. Thank you very much..
>
> -Kristine
>
> Giscard Fernandes Faria wrote:
>   
>> Kristine,
>>
>> The SIP Servlet specification stands that both SIP and HTTP
>>     
> application
>   
>> must be in the same container... at this way I believe you can access
>> them just by using the context (similar way we do in a web app).
>> If both applications are packaged in the same war file, and the
>> deployment
>> Descriptor is OK, this should work.
>>
>> I believe you have everything working fine (because you can pass data
>> from
>> http to sip). Try to create a queue object using collections, put this
>> queue
>> on the ServletContext and exchange data between both http/sip servlet
>> using
>> this queue.
>>
>> Something like this:
>>
>> 	//one servlet create the queue and make it available on the
>> context
>> 	ArrayBlockingQueue queue = new...
>>       ServletContext ctx = getServletContext();
>>       ctx.setAttribute("queue", queue);
>>
>> 	//another servlet get the queue
>>       ArrayBlockingQueue queue =
>> getServletContext().getAttribute("queue");
>>
>>       //after keep reading and writing to the queue
>>       //remember that this queue may block if there is no element to
>> read
>>
>>
>> Below is the text from sip servlet specification (available for free):
>>
>> 7.1 Relationship with HTTP Servlet Applications
>> The directory structure used for SIP servlet applications is very
>> similar to the one defined for HTTP servlets, in particular, the
>> deployment descriptor, class files, libraries etc. of SIP servlet
>> applications exists underneath the WEB-INF/ directory. This allows
>> converged HTTP and SIP servlet applications to be packaged in a single
>> archive file and deployed as a unit without having any part of the SIP
>> application be interpreted as content to be published by the Web
>>     
> server.
>   
>> 7.2 Relationship to ServletContext
>> The servlet container must enforce a one-to-one correspondence between
>>     
> a
>   
>> servlet application and a ServletContext. A ServletContext object
>> provides a servlet with its view of the application. This is true for
>> converged SIP and HTTP applications, also: all servlets within an
>> application see the same ServletContext instance.
>>
>> Hope this can help
>> Regards
>> 	
>> Giscard Fernandes Faria-  Software Engineering Department 
>> NEC Brasil S.A.
>> Phone +55 11 2166-2713 * Mobile + 55 11 8561-0710
>> "There are no 'cookbook' methods that can replace intelligence,
>> experience, and good taste in design and programming", Bjarne
>>     
> Stroustrup
>   
>>  
>> giscardf at nec.com.br
>>
>>  
>>  
>>  
>>  
>>  
>>  
>> -----Mensagem original-----
>> De: discussion-bounces at sipforum.org
>> [mailto:discussion-bounces at sipforum.org] Em nome de Kristine Regis
>> Enviada em: quinta-feira, 20 de agosto de 2009 00:12
>> Para: discussion at sipforum.org
>> Assunto: [SIPForum-discussion] SIP Servlet to HTTP Servlet
>>
>> Hi!
>>
>> I do not know if this is the right forum to handle my question but
>>     
> since
>   
>> my question is also related to SIP, I will take this opportunity to
>>     
> ask 
>   
>> here.
>>
>> I would like to know how can I pass a parameter from SIP servlet to
>>     
> HTTP
>   
>> Servlet. I already know from HTTP servlet going to SIP servlet but I
>>     
> do 
>   
>> not know how the vice versa of it. Please help me with this problem.. 
>> Thank you very much!
>>
>> -Kristine
>> _______________________________________________
>> This is the SIP Forum discussion mailing list
>> TO UNSUBSCRIBE, or edit your delivery options, please visit
>> http://sipforum.org/mailman/listinfo/discussion
>> Post to the list at discussion at sipforum.org
>>
>>   
>>     
>
> _______________________________________________
> This is the SIP Forum discussion mailing list
> TO UNSUBSCRIBE, or edit your delivery options, please visit
> http://sipforum.org/mailman/listinfo/discussion
> Post to the list at discussion at sipforum.org
>
>   




More information about the discussion mailing list