Package javax.servlet.sip.ar

Examples of javax.servlet.sip.ar.SipApplicationRouterInfo


public class RouterInfoUtilTest
{
  @Test
  public void testDecode() throws Exception
  {
    testRouterInfo(new SipApplicationRouterInfo("kaleo",
        SipApplicationRoutingRegion.NEUTRAL_REGION,
        "sip:alice@cipango.voip",
        new String[] { "sip:as1.cipango.voip", "sip:as2.cipango.voip" },
        SipRouteModifier.ROUTE,
        "1"));
View Full Code Here


  }

  @Test
  public void testDecodeNull() throws Exception
  {
    testRouterInfo(new SipApplicationRouterInfo("kaleo",
        null, null, null, null, null));
  }
View Full Code Here

  }

  @Test
  public void testStrangeAppName() throws Exception
  {
    testRouterInfo(new SipApplicationRouterInfo(":@1=>!;",
        null, null, null, null, null));
  }
View Full Code Here

  }

  @Test
  public void testCustomRegion() throws Exception
  {
    testRouterInfo(new SipApplicationRouterInfo("kaleo",
        new CustomRegion("custom", SipApplicationRoutingRegionType.NEUTRAL),
        "sip:alice@cipango.voip",
        new String[] { "sip:as1.cipango.voip", "sip:as2.cipango.voip" },
        SipRouteModifier.ROUTE,
        "1"));
View Full Code Here

    public void customizeRequest(SipRequest request) throws IOException
    {
      if (!request.isInitial())
        return;
     
      SipApplicationRouterInfo routerInfo = _applicationRouter.getNextApplication(
          request,
          request.getRegion(),
          request.getRoutingDirective(),
          null,
          request.getStateInfo());
     
      if (routerInfo != null && routerInfo.getNextApplicationName() != null)
      {
        SipConnector connector = _connectorManager.getDefaultConnector();
        SipURI route = new SipURIImpl(null, connector.getHost(), connector.getPort());
        RouterInfoUtil.encode(route, routerInfo);
        route.setLrParam(true);
View Full Code Here

    String sRouteModifier = uri.getParameter(ROUTE_MODIFIER);
    SipRouteModifier routeModifier = null;
    if (sRouteModifier != null)
      routeModifier = SipRouteModifier.valueOf(sRouteModifier);
   
    return new SipApplicationRouterInfo(
        appName,
        (SipApplicationRoutingRegion) getSerializable(uri, ROUTING_REGION),
        uri.getParameter(SUBSCRIBER_URI),
        (String[]) getSerializable(uri, ROUTES),
        routeModifier,
View Full Code Here

      SipApplicationRoutingRegion region, SipApplicationRoutingDirective directive,
      SipTargetedRequestInfo requestedInfo, Serializable info)
  {
    if (request.getRemoteAddr() == null)
      return null;
    return new SipApplicationRouterInfo(SipClient.class.getName(),
        SipApplicationRoutingRegion.NEUTRAL_REGION,
        request.getFrom().getURI().toString(),
        null,
        SipRouteModifier.NO_ROUTE,
        1);
View Full Code Here

     
      if (isInitial(request))
          {
        request.setInitial(true);
       
        SipApplicationRouterInfo routerInfo = null;
        SipAppContext appContext = null;
       
        try
        {
          if (route != null)
          {
            SipURI uri = (SipURI) route.getURI();
            if (RouterInfoUtil.ROUTER_INFO.equals(uri.getUser()))
            {
              routerInfo = RouterInfoUtil.decode(uri);
              route = popLocalRoute(request);
            }
            if (route != null)
              request.setPoppedRoute(route);
          }
         
          if (routerInfo == null)
          {
            routerInfo = ((Server) getServer()).getApplicationRouter().getNextApplication(
              request, null, SipApplicationRoutingDirective.NEW, null, null);
          }
        }
        catch (Throwable t)
        {
          if (!request.isAck())
          {
            SipResponse response = new SipResponse(
                request,
                SipServletResponse.SC_SERVER_INTERNAL_ERROR,
                "Application router error: " + t.getMessage());
            ExceptionUtil.fillStackTrace(response, t);
            getConnectorManager().sendResponse(response);
          }
          return;
        }
       
        if (routerInfo != null && routerInfo.getNextApplicationName() != null)
        {
          boolean handle = handlingRoute(request, routerInfo);
          if (handle)
            return;
         
          request.setStateInfo(routerInfo.getStateInfo());
          request.setRegion(routerInfo.getRoutingRegion());
         
          String s = routerInfo.getSubscriberURI();
          if (s != null)
          {
            try
            {
              request.setSubscriberURI(URIFactory.parseURI(s));
            }
            catch (ServletParseException e)
            {
              Log.debug(e);
            }
          }
         
          String applicationName = routerInfo.getNextApplicationName();
          appContext = (SipAppContext) getContext(applicationName);
                   
          Method method = appContext == null ? null : appContext.getSipApplicationKeyMethod();
          if (method != null)
          {
View Full Code Here

    if (_routerInfoMap == null || _routerInfoMap.isEmpty())
    {
      if (stateInfo != null || _applicationNames.isEmpty() || directive != SipApplicationRoutingDirective.NEW)
        return null;
     
      return new SipApplicationRouterInfo(_applicationNames.first(),
          SipApplicationRoutingRegion.NEUTRAL_REGION,
          initialRequest.getFrom().getURI().toString(),
          null,
          SipRouteModifier.NO_ROUTE,
          1);
    }
   
    String method = initialRequest.getMethod();
    RouterInfo[] infos = _routerInfoMap.get(method.toUpperCase());

    if (infos == null)
      return null;
   
    int index = 0;
    if (stateInfo != null)
      index = (Integer) stateInfo;

    if (index >= 0 && index < infos.length)
    {
      RouterInfo info = infos[index];
     
      String identity = info.getIdentity();
      if (identity.startsWith("DAR:"))
      {
        try
        {
          identity = initialRequest.getAddressHeader(identity.substring("DAR:".length())).getURI().toString();
        }
        catch (Exception e)
        {
          Log.debug("Failed to parse router info identity: " + info.getIdentity(), e);
        }
      }
     
      return new SipApplicationRouterInfo(info.getName(), info.getRegion(), identity, null,
          SipRouteModifier.NO_ROUTE, index + 1);
    }

    return null;
  }
View Full Code Here

          if (targetedRequestInfo != null && targetedRequestInfo.getApplicationName() != null) {
              if (theirLog.isLoggable(Level.FINEST)) {
                  theirLog.log(Level.FINEST, LOGPREFIX + "targeted_request_type",
                          new Object[] {targetedRequestInfo.getType().name(), targetedRequestInfo.getApplicationName()});
              }
              return new SipApplicationRouterInfo(targetedRequestInfo.getApplicationName(), region, initialRequest.getRequestURI().toString(), EMPTY_STRING_ARRAY, SipRouteModifier.NO_ROUTE, targetedRequestInfo.getApplicationName());
          }

   
    Integer order = new Integer(0);
    // Upon first invocation, stateInfo will not yet be set.
    if (stateInfo != null){
      // only Integer stateInfo supported
      try {
        order = new Integer(stateInfo.toString());
      }
      catch (NumberFormatException e){
        theirLog.log(Level.SEVERE, LOGPREFIX + "wrongstateinfo");
        return null;
      }
    }
   
    // lookup request method in cache 
    String method = initialRequest.getMethod();
    theirLog.log(Level.INFO, LOGPREFIX + "infolookup", new Object[] { method, order });
   
    // lookup routing info in cache for this method
    RouterInfoBean infoBean = null;
    HashMap<Integer, RouterInfoBean> infoMap = itsRouterInfoMap.get(method);
   
    if (infoMap == null){
      theirLog.log(Level.INFO, LOGPREFIX + "noinfofound", method);
      return null; // TODO is this allowed?
    } else {
      // stateinfo contains the Integer we last put in. Increase the
      // Integer by one, lookup the next routing info in cache.
      order++;
      infoBean = infoMap.get(order);
      if (infoBean == null){
        theirLog.log(Level.INFO, LOGPREFIX + "noinfofoundforthisorder", new Object[] { method, order });
        return null; // TODO is this allowed? 
       
        // TODO return appname=null
       
      }
      theirLog.log(Level.INFO, LOGPREFIX + "infofound");
    }

    // Determine subscriber URI
    String subId = infoBean.getSubscriberId();
    String subUri = null;
    if (subId.startsWith("DAR:")) {
      // subscriber URI is to be retrieved from request
      String header = subId.substring(4).trim();
      // (IndexOutOfBounds exception was checked at config-time)
      try {
        subUri = initialRequest.getAddressHeader(header).getURI().toString();
      } catch (ServletParseException e){
        theirLog.log(Level.SEVERE, LOGPREFIX + "invalidsubscriberuri", header);
        theirLog.log(Level.SEVERE, LOGPREFIX + e.getMessage(), e);
      }
    }
   
    // Determine route info
    String[] routes = new String[] {infoBean.getRouteUri()};
    SipRouteModifier modifier =
      SipRouteModifier.valueOf(infoBean.getRouteModifier());
   
    // Determine routing region
    String regionOutStr = infoBean.getRegion();
    SipApplicationRoutingRegionType regionOutType =
      SipApplicationRoutingRegionType.valueOf(regionOutStr);
    SipApplicationRoutingRegion regionOut =
      new SipApplicationRoutingRegion(regionOutStr, regionOutType);
   
    SipApplicationRouterInfo info =
      new SipApplicationRouterInfo(
        infoBean.getApplicationName(),
        regionOut,
        subUri,
        routes,
        modifier,
View Full Code Here

TOP

Related Classes of javax.servlet.sip.ar.SipApplicationRouterInfo

Copyright © 2018 www.massapicom. 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.