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);
}
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"));
}
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;
}
}
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);
}
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"));
}
Aggregations