Search in sources :

Example 31 with SipURI

use of javax.sip.address.SipURI in project load-balancer by RestComm.

the class ActiveStandbySipTest method testOKRingingLandOnSameNode.

@Test
public void testOKRingingLandOnSameNode() throws Exception {
    EventListener failureEventListener = new EventListener() {

        @Override
        public void uasAfterResponse(int statusCode, AppServer source) {
        }

        @Override
        public void uasAfterRequestReceived(String method, AppServer source) {
        }

        @Override
        public void uacAfterRequestSent(String method, AppServer source) {
        }

        @Override
        public void uacAfterResponse(int statusCode, AppServer source) {
            if (statusCode == 180)
                ringingAppServer = source;
            else
                okAppServer = source;
        }
    };
    for (AppServer as : servers) as.setEventListener(failureEventListener);
    shootist.callerSendsBye = true;
    String fromName = "sender";
    String fromHost = "sip-servlets.com";
    SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
    String toUser = "replaces";
    String toHost = "sip-servlets.com";
    SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
    SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
    ruri.setLrParam();
    SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbint", "127.0.0.1:5065");
    route.setParameter("node_host", "127.0.0.1");
    route.setParameter("node_port", "4060");
    route.setTransportParam(ListeningPoint.UDP);
    route.setLrParam();
    shootist.start();
    servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, route, false, null, null, ruri);
    Thread.sleep(10000);
    assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
    assertSame(ringingAppServer, okAppServer);
    assertNotNull(ringingAppServer);
    assertNotNull(okAppServer);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipURI(javax.sip.address.SipURI) Test(org.junit.Test)

Example 32 with SipURI

use of javax.sip.address.SipURI in project load-balancer by RestComm.

the class EarlyDialogWorstCaseAffinityTest method testOKRingingLandOnDifferentNodes.

@Test
public void testOKRingingLandOnDifferentNodes() throws Exception {
    EventListener failureEventListener = new EventListener() {

        @Override
        public void uasAfterResponse(int statusCode, AppServer source) {
        }

        @Override
        public void uasAfterRequestReceived(String method, AppServer source) {
        // TODO Auto-generated method stub
        }

        @Override
        public void uacAfterRequestSent(String method, AppServer source) {
        // TODO Auto-generated method stub
        }

        @Override
        public void uacAfterResponse(int statusCode, AppServer source) {
            if (statusCode == 180) {
                ringingAppServer = source;
            } else if (statusCode == 200) {
                okAppServer = source;
            }
        }
    };
    for (AppServer as : servers) as.setEventListener(failureEventListener);
    shootist.callerSendsBye = true;
    String fromName = "sender";
    String fromHost = "sip-servlets.com";
    SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
    String toUser = "replaces";
    String toHost = "sip-servlets.com";
    SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
    SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
    ruri.setLrParam();
    SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbint", "127.0.0.1:5065");
    route.setParameter("node_host", "127.0.0.1");
    route.setParameter("node_port", "4060");
    route.setLrParam();
    shootist.start();
    // servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
    servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, route, false, null, null, ruri);
    Thread.sleep(16000);
    assertNotNull(ringingAppServer);
    assertNotNull(okAppServer);
    assertNotSame(ringingAppServer, okAppServer);
    System.out.println(shootist.inviteRequest.toString());
    assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipURI(javax.sip.address.SipURI) Test(org.junit.Test)

Example 33 with SipURI

use of javax.sip.address.SipURI in project load-balancer by RestComm.

the class HeaderConsistentHashBalancerAlgorithm method hashHeader.

protected Integer hashHeader(Message message, Boolean isIpV6) {
    String headerValue = null;
    if (sipHeaderAffinityKey.equals("From")) {
        headerValue = ((SipURI) ((FromHeader) message.getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
    } else if (sipHeaderAffinityKey.equals("To")) {
        headerValue = ((SipURI) ((ToHeader) message.getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
    } else {
        headerValue = ((SIPHeader) message.getHeader(sipHeaderAffinityKey)).getValue();
    }
    if (nodesArray(isIpV6).length == 0) {
        throw new RuntimeException("No Application Servers registered. All servers are dead.");
    }
    int nodeIndex = hashAffinityKeyword(headerValue, isIpV6);
    if (isAlive((Node) nodesArray(isIpV6)[nodeIndex])) {
        return nodeIndex;
    } else {
        return -1;
    }
}
Also used : SIPHeader(gov.nist.javax.sip.header.SIPHeader) ToHeader(javax.sip.header.ToHeader) SipURI(javax.sip.address.SipURI) ListeningPoint(javax.sip.ListeningPoint)

Example 34 with SipURI

use of javax.sip.address.SipURI in project camel by apache.

the class SipPresenceAgentListener method sendNotification.

private void sendNotification(EventHeader eventHeader, boolean isInitial, Object body) throws SipException, ParseException {
    /*
         * NOTIFY requests MUST contain a "Subscription-State" header with a
         * value of "active", "pending", or "terminated". The "active" value
         * indicates that the subscription has been accepted and has been
         * authorized (in most cases; see section 5.2.). The "pending" value
         * indicates that the subscription has been received, but that
         * policy information is insufficient to accept or deny the
         * subscription at this time. The "terminated" value indicates that
         * the subscription is not active.
         */
    Request notifyRequest = dialog.createRequest("NOTIFY");
    // Mark the contact header, to check that the remote contact is updated
    ((SipURI) sipPresenceAgent.getConfiguration().getContactHeader().getAddress().getURI()).setParameter(sipPresenceAgent.getConfiguration().getFromUser(), sipPresenceAgent.getConfiguration().getFromHost());
    SubscriptionStateHeader sstate;
    if (isInitial) {
        // Initial state is pending, second time we assume terminated (Expires==0)
        sstate = sipPresenceAgent.getConfiguration().getHeaderFactory().createSubscriptionStateHeader(isInitial ? SubscriptionStateHeader.PENDING : SubscriptionStateHeader.TERMINATED);
        // Need a reason for terminated
        if (sstate.getState().equalsIgnoreCase("terminated")) {
            sstate.setReasonCode("deactivated");
        }
    } else {
        sstate = sipPresenceAgent.getConfiguration().getHeaderFactory().createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
    }
    notifyRequest.addHeader(sstate);
    notifyRequest.setHeader(eventHeader);
    notifyRequest.setHeader(sipPresenceAgent.getConfiguration().getContactHeader());
    notifyRequest.setContent(body, sipPresenceAgent.getConfiguration().getContentTypeHeader());
    LOG.debug("Sending the following NOTIFY request to Subscriber: {}", notifyRequest);
    ClientTransaction clientTransactionId = sipPresenceAgent.getProvider().getNewClientTransaction(notifyRequest);
    dialog.sendRequest(clientTransactionId);
}
Also used : SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI)

Example 35 with SipURI

use of javax.sip.address.SipURI in project camel by apache.

the class SipConfiguration method createToHeader.

private void createToHeader() throws ParseException {
    SipURI toAddress = getAddressFactory().createSipURI(getToUser(), getToHost());
    toAddress.setPort(getToPort());
    Address toNameAddress = addressFactory.createAddress(toAddress);
    toNameAddress.setDisplayName(getToUser());
    setToHeader(headerFactory.createToHeader(toNameAddress, getToUser() + "_Header"));
}
Also used : Address(javax.sip.address.Address) SipURI(javax.sip.address.SipURI)

Aggregations

SipURI (javax.sip.address.SipURI)70 ParseException (java.text.ParseException)27 Request (javax.sip.message.Request)24 Address (javax.sip.address.Address)22 InvalidArgumentException (javax.sip.InvalidArgumentException)20 ViaHeader (javax.sip.header.ViaHeader)20 SipException (javax.sip.SipException)19 ToHeader (javax.sip.header.ToHeader)18 ContactHeader (javax.sip.header.ContactHeader)17 FromHeader (javax.sip.header.FromHeader)17 Test (org.junit.Test)17 RouteHeader (javax.sip.header.RouteHeader)16 AppServer (org.mobicents.tools.sip.balancer.AppServer)16 EventListener (org.mobicents.tools.sip.balancer.EventListener)16 CSeqHeader (javax.sip.header.CSeqHeader)13 CallIdHeader (javax.sip.header.CallIdHeader)13 Header (javax.sip.header.Header)13 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)13 RecordRouteHeader (javax.sip.header.RecordRouteHeader)13 URI (javax.sip.address.URI)11