[Users] WeSIP b2bua problem

Ginés Gómez gines at voztele.com
Mon Mar 5 17:46:27 CET 2007


Hi ,


>
> I'm not fully understand what you means in your pseudo-code
> It's not clear to me how to identified the correct call-leg where to
> send the BYE message.
> The problem is that if the BYE come from the called the legs al
> terminated correctly, but if come from the caller the BYE request  
> that i
> create is not correct, the call-id is of the request recived.
>

I understand. I'll try to explain myself clearer. Let's go back to  
your original code. This is extracted from the doInvite method. Here  
you save both call legs in the application session
.....

//Save reference to SipSessions in the SipApplication
sas.setAttribute("upstreamLeg",upstreamLeg);
sas.setAttribute("downstreamLeg",downstreamLeg);
.....

what I suggest is that you do the following (after saving in  
ApplicationSession)

upstreamLeg.setAttribute("COUNTERPART_LEG",downstreamLeg);
downstreamLeg.setAttribute("COUNTERPART_LEG",upstreamLeg);

this way, at any time, you can always get a reference to the  
counterpart dialog doing

req.getSession().getAttribute("COUNTERPART_LEG");

then, when receiving the BYE

>> protected void doBye(SipServletRequest req) throws
>> ServletException,IOException{
>>
>>     //Answer positively
>>     request.createResponse(200,"Have a nice day").send();
>>
>>     //Mark my dialog as finished
>>     request.getSession().setAttribute("FINISHED","OK");
>>
>>     //Get the other leg and finish it in case it is not finished
>>
>>     //Note how useful is to have in both SipSessions (that is, both
>> legs) an attribute which refers the
>>     //other leg involved in the B2BUA transaction.
>>     SipSession counterPartLeg= (SipSession)
>> request.getSession.getAttribute("COUNTERPART_LEG");	
>>     if (counterPartLeg.getAttribute("FINISHED")==null){
>> 	counterPartLeg.createRequest("BYE").send();
>>     }
>> }

as you'll see what I do is sending BYE to the 'other' leg. I don't  
care wether I'm processing upstream or downstream because the  
COUNTERPART_LEG attribute in the SipSession will always return a  
reference to the counterpart SipSession. Since the processing (answer  
OK, send BYE the other leg) is simetrical regardless the BYE was  
received from the upstream or the downstream the method will work

:-)

Regards

Gines




>    protected void doBye(SipServletRequest req) throws  
> ServletException,
> IOException {
>         req.createResponse(200,"OK").send();
>         SipSession downstreamLeg =
> (SipSession)req.getSession().getApplicationSession().getAttribute 
> ("downstreamLeg");
>         SipServletRequest byeRequest =
> downstreamLeg.createRequest("BYE");
>         byeRequest.send();
>    }
>
> this works only when the BYE come from called.
>
> maybe i can get the Id of session of the current request arrived in
> doBye with getId() and do a check for the other id in the upstreamLeg
> and downstreamLeg then if equals to any of this, generate the BYE
> request in the other call-leg.
>
> pseudo code:
>
> String sessionId (SipSession)req.getSession().getId();
> SipSession upSession =
> (SipSession)req.getSession().getApplicationSession().getAttribute 
> ("upstreamLeg");
> SipSession downSession =
> (SipSession)req.getSession().getApplicationSession().getAttribute 
> ("downstreamLeg");
>
> if (sessionId == upSession.getId())
> {
>    // create and send BYE request in the upstreamLeg
>    ....
> } else {
>    // create and send BYE request in the downstreamLeg
>    ....
> };
>
>
> regards,
>
> :tele
>
>
> On Mon, 2007-03-05 at 15:27 +0100, Ginés Gómez wrote:
>> Anyway.... when doing B2BUA you tipically don't need to wait for
>> 200OK to generate BYE response. You can simply send a 200OK to any
>> incoming BYE request (since there is no SDP involved in the BYE
>> handshake) then finish the other leg.  The idea would be doing
>> something like this (not 100% real code, some pseudocode here)
>>
>>
>> protected void doBye(SipServletRequest req) throws
>> ServletException,IOException{
>>
>>     //Answer positively
>>     request.createResponse(200,"Have a nice day").send();
>>
>>     //Mark my dialog as finished
>>     request.getSession().setAttribute("FINISHED","OK");
>>
>>     //Get the other leg and finish it in case it is not finished
>>
>>     //Note how useful is to have in both SipSessions (that is, both
>> legs) an attribute which refers the
>>     //other leg involved in the B2BUA transaction.
>>     SipSession counterPartLeg= (SipSession)
>> request.getSession.getAttribute("COUNTERPART_LEG");	
>>     if (counterPartLeg.getAttribute("FINISHED")==null){
>> 	counterPartLeg.createRequest("BYE").send();
>>     }
>> }
>>
>> Regards
>>
>> Gines
>>
>> El 05/03/2007, a las 14:36, tele escribió:
>>
>>> Hi Gines!
>>>
>>> It's almost clear to me how to do, this what i have done and it  
>>> works.
>>>
>>> now i need last clarification how forward the 200 OK from BYE
>>> request, i
>>> cannot get it working.
>>> for forwarding the 200 ok from the BYE in the doBye request i save
>>> downstreamLeg.setAttribute("byereq", req) and then in the  
>>> doResponse i
>>> get the bye request and create the response from it,
>>> something like this but i'm wrong.
>>>
>>> if (resp.getStatus() == 200 && resp.getMethod().equalsIgnoreCase
>>> ("BYE"))
>>> {
>>>                         SipServletRequest upstreamRequest =
>>> (SipServletRequest)upstreamLeg.getAttribute("byereq");
>>>                         SipServletResponse upstreamResponse =
>>> upstreamRequest.createResponse(resp.getStatus(),resp.getReasonPhrase
>>> ());
>>>                         //Copy the content from the downstream
>>> response
>>> to the upstream response
>>>                         if (resp.getContentType() != null) {
>>>
>>> upstreamResponse.setContent(resp.getRawContent(),
>>> resp.getContentType());
>>>                         }
>>>                         upstreamResponse.send();
>>> }
>>>
>>>
>>>
>>> this is what i have done for working ACK.
>>>
>>>
>>>   protected void doAck(SipServletRequest req) throws  
>>> ServletException,
>>> IOException {
>>>         //Retrieve the upstream request to respond it
>>>         SipSession downstreamLeg =
>>> (SipSession)req.getSession().getApplicationSession().getAttribute
>>> ("downstreamLeg");
>>>         SipServletResponse downstreamResponse = (SipServletResponse)
>>> downstreamLeg.getAttribute("200ok");
>>>         SipServletRequest ackRequest =  
>>> downstreamResponse.createAck();
>>>         //Copy the content from the downstream response to the
>>> upstream
>>> response
>>>         if (req.getContentType() != null) {
>>>                 ackRequest.setContent(req.getRawContent(),
>>> req.getContentType());
>>>         }
>>>         ackRequest.send();
>>>    }
>>>
>>>    protected void doBye(SipServletRequest req) throws
>>> ServletException,
>>> IOException {
>>>         SipSession downstreamLeg =
>>> (SipSession)req.getSession().getApplicationSession().getAttribute
>>> ("downstreamLeg");
>>>         SipServletRequest byeRequest =
>>> downstreamLeg.createRequest("BYE");
>>>         // Copy the content from the downstream response to the
>>> upstream
>>> response
>>>         if (req.getContentType() != null) {
>>>                 byeRequest.setContent(req.getRawContent(),
>>> req.getContentType());
>>>         }
>>>         byeRequest.send();
>>>    }
>>>
>>>    protected void doResponse(SipServletResponse resp) throws
>>> ServletException, IOException {
>>>
>>>                 if (resp.getStatus() == 200 &&
>>> resp.getMethod().equalsIgnoreCase("INVITE")) {
>>>                         SipSession downstreamLeg = (SipSession)
>>> resp.getSession().getApplicationSession().getAttribute
>>> ("downstreamLeg");
>>>                         downstreamLeg.setAttribute("200ok",resp);
>>>                 }
>>>
>>>                 //Retrieve the upstream request to respond it
>>>                 SipSession upstreamLeg =
>>> (SipSession)resp.getSession().getApplicationSession().getAttribute
>>> ("upstreamLeg");
>>>
>>> }
>>>
>>> 	
>>>
>>>
>>> On Mon, 2007-03-05 at 00:29 +0100, Ginés Gómez wrote:
>>>> The problem is that you didn't implement the doACK method.  
>>>> Implement
>>>> it following a similar technique as the one used in doResponse.  
>>>> Save
>>>> the 200OK response in the downstream session so you can retrieve it
>>>> when the ACK arrives from the upstream then generate ACK using
>>>> response.createACK() and copy the content using getContentType/
>>>> setContentType geContent/setContent if required
>>>>
>>>>
>>>> Hope it helps
>>>>
>>>> Gines
>>>>
>>>>> Attached there is a .zip with all the log, trace and  
>>>>> configuration.
>>>>>
>>>>> thanks for the support,
>>>>>
>>>>> :tele
>>>>> <wesip_test.zip>
>>>>> _______________________________________________
>>>>> Users mailing list
>>>>> Users at openser.org
>>>>> http://openser.org/cgi-bin/mailman/listinfo/users
>>>>
>>>
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openser.org
>>> http://openser.org/cgi-bin/mailman/listinfo/users
>>>
>>
>
>
> _______________________________________________
> Users mailing list
> Users at openser.org
> http://openser.org/cgi-bin/mailman/listinfo/users
>





More information about the Users mailing list