Package com.ericsson.ssa.container.sim

Source Code of com.ericsson.ssa.container.sim.TargettedRequestHandler

/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) Ericsson AB, 2004-2008. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License").  You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Parameterable Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code.  If applicable, add the following below the License
* Parameterable, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license."  If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above.  However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.ericsson.ssa.container.sim;

import com.ericsson.ssa.sip.SessionTarget;
import com.ericsson.ssa.sip.SipApplicationSessionImpl;
import com.ericsson.ssa.sip.SipApplicationSessionUtil;
import com.ericsson.ssa.sip.SipServletRequestImpl;
import com.ericsson.ssa.sip.SipSessionBase;
import com.ericsson.ssa.sip.SipSessionImplBase;
import com.ericsson.ssa.sip.SipSessionManagerRegistry;
import com.ericsson.ssa.sip.URIImpl;
import com.ericsson.ssa.sip.UriUtil;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.sip.ar.SipApplicationRouterInfo;
import javax.servlet.sip.ar.SipTargetedRequestInfo;
import javax.servlet.sip.ar.SipTargetedRequestType;
import javax.servlet.sip.Address;

import org.jvnet.glassfish.comms.util.LogUtil;

/**
* This class handles Targetted requests for ApplicationDispatcher
* or ApplicationRouter handling. This includes URI encoded session
* and Join/Replace handling.
*
* @author binod
*/
class TargettedRequestHandler {
    private static final Logger m_logger = LogUtil.SIP_LOGGER.getLogger();

    /**
     * Section 15.11.5 of JSR 289.                       
     *
     * Basically, first Join/Replace header is considered for targetting. If it
     * is not there, look for encoded sas.
     */
    static SipTargetedRequestInfo get (SipServletRequestImpl request) {
        try {           
            SipApplicationSessionImpl sas = null;
            String appName = null;
            SipTargetedRequestInfo stri = null;
           
            SessionTarget st = request.getSessionTarget();
           
            if (st != null) {
                return st.getTargetedRequestInfo();
            }
           
           
            // XXX it is a pity that we do the SAS loading twice.
            // once here to check for a targeted request and once in the Factory
            // when we actually create the ss/sas for the request
            // maybe we can refactor a bit, so that if we have a targeted
            // request we already set the SAS that we found on the request somehow...
            String uriEncodedSasId = null;
            Address routeAddr = request.getInitialPoppedRoute();
            if (routeAddr != null) {
                uriEncodedSasId = UriUtil.getAndDecodeParameter(
                        routeAddr.getURI(), URIImpl.SASID_PARAM);
            }
            if (uriEncodedSasId == null)
                uriEncodedSasId = UriUtil.getAndDecodeParameter(request.getRequestURI(), URIImpl.SASID_PARAM);
            if (uriEncodedSasId != null) {
                appName = SipApplicationSessionUtil.getApplicationName(uriEncodedSasId);
                if (appName != null) {
                    sas = SipSessionManagerRegistry.getInstance().get(appName).findSipApplicationSession(uriEncodedSasId);
                    if (sas != null && sas.isValid()) {
                        if (m_logger.isLoggable(Level.FINEST)) {
                                    m_logger.log(Level.FINEST, "targeted request for app {0} with encodedURI: {1}", new Object[] {appName, uriEncodedSasId});
                                }
                        return new SipTargetedRequestInfo(SipTargetedRequestType.ENCODED_URI, appName);
                    }
                }
            }
    
        } catch (UnsupportedEncodingException e1) {
            m_logger.log(Level.WARNING, "com.ericsson.ssa.config.SipFactoryFacade.uri_encoded_sas_corrupt", e1);
        } catch (Exception ex) {
            m_logger.log(Level.WARNING, "com.ericsson.ssa.config.SipFactoryFacade.uri_encoded_sas_corrupt", ex);
        }
       
        return null;
    }

    /**
     * Returns the sas of the targetted/original request of the Join/Replace.
     *
     * @param request
     * @param info
     * @return
     */
    static SipApplicationSessionImpl
    getApplicationSession(SipServletRequestImpl request,
    SipApplicationRouterInfo info) {
        SessionTarget st = request.getSessionTarget();
        if (st != null && (request.getSessionImpl() == null)) {
            SipApplicationSessionImpl sas = st.getApplicationSessionImpl();
            if (sas != null && sas.isValid()) {
                String app = info.getNextApplicationName();
                if (app != null && app.equals(sas.getApplicationName())) {
                    return sas;
                }
            }
        }
       
        return null;
    }

    /**
     * Link the session with corresponding session that was originally targetted
     * for a Join or Replace header. The session id is saved and the session is
     * looked up each time.
     *
     * @param request
     * @param s
     */
    static void linkCorrespondingSession
    (SipServletRequestImpl request, SipSessionBase s) {
        SessionTarget st = request.getSessionTarget();
        if (st != null) {
            ((SipSessionImplBase)s).setLinkedCorrespondingSipSessionId
            (st.getSessionImpl().getId(), st.getHeader());
        }
    }
}
TOP

Related Classes of com.ericsson.ssa.container.sim.TargettedRequestHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.