use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class InviteTransactionFailover method testASactingAsUAC.
@Test
public void testASactingAsUAC() 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;
// source.sendCleanShutdownToBalancers();
} 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);
assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
assertNotSame(ringingAppServer, okAppServer);
assertNotNull(ringingAppServer);
assertNotNull(okAppServer);
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class NoInternalAddressTest method testASactingAsUAC.
@Test
public void testASactingAsUAC() 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;
// source.sendCleanShutdownToBalancers();
source.stop();
} 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("lbaddress_noInternalPort", "127.0.0.1:5060");
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);
assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
assertNotSame(ringingAppServer, okAppServer);
assertNotNull(ringingAppServer);
assertNotNull(okAppServer);
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class Shootist method sendInitial.
public void sendInitial(String fromUser, String fromHost, String method, RouteHeader route, String[] headerNames, String[] headerContents) {
try {
if (!started)
start();
String fromName = fromUser;
String fromSipAddress = fromHost;
String fromDisplayName = "The Master Blaster";
String toSipAddress = "there.com";
String toUser = "LittleGuy";
String toDisplayName = "The Little Blister";
// create >From Header
SipURI fromAddress = addressFactory.createSipURI(fromName, fromSipAddress);
Address fromNameAddress = addressFactory.createAddress(fromAddress);
fromNameAddress.setDisplayName(fromDisplayName);
FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, "12345");
// create To Header
SipURI toAddress = addressFactory.createSipURI(toUser, toSipAddress);
Address toNameAddress = addressFactory.createAddress(toAddress);
toNameAddress.setDisplayName(toDisplayName);
ToHeader toHeader = headerFactory.createToHeader(toNameAddress, null);
// create Request URI
SipURI requestURI = addressFactory.createSipURI(toUser, peerHostPort);
// Create ViaHeaders
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
String ipAddress = null;
if (fromUser.equals("KostyaNosach"))
ipAddress = "127.0.0.2";
else
ipAddress = listeningPoint.getIPAddress();
ViaHeader viaHeader = headerFactory.createViaHeader(ipAddress, sipProvider.getListeningPoint(transport).getPort(), transport, null);
// add via headers
viaHeaders.add(viaHeader);
// Create ContentTypeHeader
ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "sdp");
// Create a new CallId header
CallIdHeader callIdHeader = sipProvider.getNewCallId();
// Create a new Cseq header
CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L, method);
// Create a new MaxForwardsHeader
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);
// Create the request.
Request request = messageFactory.createRequest(requestURI, method, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
// Create contact headers
String host = localIPAddress;
SipURI contactUrl = addressFactory.createSipURI(fromName, host);
contactUrl.setPort(listeningPoint.getPort());
contactUrl.setLrParam();
// Create the contact name address.
SipURI contactURI = addressFactory.createSipURI(fromName, host);
contactURI.setPort(sipProvider.getListeningPoint(transport).getPort());
Address contactAddress = addressFactory.createAddress(contactURI);
// Add the contact address.
contactAddress.setDisplayName(fromName);
contactHeader = headerFactory.createContactHeader(contactAddress);
request.addHeader(contactHeader);
// to the outgoing SIP request.
// Add the extension header.
Header extensionHeader = headerFactory.createHeader("My-Header", "my header value");
request.addHeader(extensionHeader);
if (headerNames != null) {
for (int q = 0; q < headerNames.length; q++) {
Header h = headerFactory.createHeader(headerNames[q], headerContents[q]);
// if(setHeader) {
request.setHeader(h);
// } else {
// request.addHeader(h);
// }
}
}
if (route != null)
request.addHeader(route);
String sdpData = "v=0\r\n" + "o=4855 13760799956958020 13760799956958020" + " IN IP4 129.6.55.78\r\n" + "s=mysession session\r\n" + "p=+46 8 52018010\r\n" + "c=IN IP4 129.6.55.78\r\n" + "t=0 0\r\n" + "m=audio 6022 RTP/AVP 0 4 18\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n" + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
byte[] contents = sdpData.getBytes();
request.setContent(contents, contentTypeHeader);
// You can add as many extension headers as you
// want.
extensionHeader = headerFactory.createHeader("My-Other-Header", "my new header value ");
request.addHeader(extensionHeader);
Header callInfoHeader = headerFactory.createHeader("Call-Info", "<http://www.antd.nist.gov>");
request.addHeader(callInfoHeader);
// Create the client transaction.
inviteTid = sipProvider.getNewClientTransaction(request);
// send the request out.
inviteTid.sendRequest();
dialog = inviteTid.getDialog();
} catch (Exception ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
fail("Unxpected exception ");
}
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class WssWorstCaseAffinityTest 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:5066");
route.setParameter("node_host", "127.0.0.1");
route.setParameter("node_port", "4060");
route.setTransportParam(ListeningPointExt.WSS);
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);
assertTrue(shootist.inviteRequest.getHeader(RecordRouteHeader.NAME).toString().contains("node_host"));
assertNotNull(ringingAppServer);
assertNotNull(okAppServer);
assertNotSame(ringingAppServer, okAppServer);
}
use of javax.sip.address.SipURI in project load-balancer by RestComm.
the class TestSipListener method sendSipRequest.
public Request sendSipRequest(String method, URI fromURI, URI toURI, String messageContent, SipURI route, boolean useToURIasRequestUri, String[] headerNames, String[] headerContents, boolean setHeader) throws SipException, ParseException, InvalidArgumentException {
this.useToURIasRequestUri = useToURIasRequestUri;
// create >From Header
Address fromNameAddress = protocolObjects.addressFactory.createAddress(fromURI);
FromHeader fromHeader = protocolObjects.headerFactory.createFromHeader(fromNameAddress, Integer.toString(new Random().nextInt(10000000)));
// create To Header
Address toNameAddress = protocolObjects.addressFactory.createAddress(toURI);
ToHeader toHeader = protocolObjects.headerFactory.createToHeader(toNameAddress, null);
if (toURI instanceof SipURI) {
SipURI toSipUri = (SipURI) toURI;
// create Request URI
this.requestURI = protocolObjects.addressFactory.createSipURI(toSipUri.getUser(), peerHostPort);
((SipURI) this.requestURI).setPort(peerPort);
if (setTransport) {
((SipURI) this.requestURI).setTransportParam(listeningPoint.getTransport());
}
}
if (useToURIasRequestUri || toURI instanceof TelURL) {
this.requestURI = toURI;
}
// Create ViaHeaders
List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = null;
if (!isIpv6)
viaHeader = protocolObjects.headerFactory.createViaHeader("127.0.0.1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
else
viaHeader = protocolObjects.headerFactory.createViaHeader("::1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
// add via headers
viaHeaders.add(viaHeader);
// Create ContentTypeHeader
// ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory
// .createContentTypeHeader("application", "sdp");
// Create a new CallId header
CallIdHeader callIdHeader = sipProvider.getNewCallId();
// Create a new Cseq header
CSeqHeader cSeqHeader = protocolObjects.headerFactory.createCSeqHeader(1L, method);
// Create a new MaxForwardsHeader
MaxForwardsHeader maxForwards = protocolObjects.headerFactory.createMaxForwardsHeader(70);
// Create the request.
Request request = protocolObjects.messageFactory.createRequest(requestURI, method, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
// Create contact headers
String host = null;
if (!isIpv6)
host = "127.0.0.1";
else
host = "::1";
URI contactUrl = null;
if (fromURI instanceof SipURI) {
contactUrl = protocolObjects.addressFactory.createSipURI(((SipURI) fromURI).getUser(), host);
/**
* either use tcp or udp
*/
((SipURI) contactUrl).setPort(listeningPoint.getPort());
if (setTransport) {
((SipURI) contactUrl).setTransportParam(listeningPoint.getTransport());
((SipURI) contactUrl).setLrParam();
}
} else {
contactUrl = fromURI;
}
// Create the contact name address.
Address contactAddress = protocolObjects.addressFactory.createAddress(contactUrl);
// Add the contact address.
// contactAddress.setDisplayName(fromName);
contactHeader = protocolObjects.headerFactory.createContactHeader(contactAddress);
request.addHeader(contactHeader);
SipURI uri = null;
if (!isIpv6)
uri = protocolObjects.addressFactory.createSipURI(null, "127.0.0.1");
else
uri = protocolObjects.addressFactory.createSipURI(null, "::1");
uri.setLrParam();
uri.setTransportParam(protocolObjects.transport);
uri.setPort(this.peerPort);
if (route != null) {
Address address = protocolObjects.addressFactory.createAddress(route);
RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
request.addHeader(routeHeader);
} else if (useDefaultRoute) {
Address address = protocolObjects.addressFactory.createAddress(uri);
RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
request.addHeader(routeHeader);
}
// set the message content
if (messageContent != null) {
ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(messageContent.length());
ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(TEXT_CONTENT_TYPE, PLAIN_UTF8_CONTENT_SUBTYPE);
byte[] contents = messageContent.getBytes();
request.setContent(contents, contentTypeHeader);
request.setContentLength(contentLengthHeader);
}
if (headerNames != null) {
for (int q = 0; q < headerNames.length; q++) {
Header h = protocolObjects.headerFactory.createHeader(headerNames[q], headerContents[q]);
if (setHeader) {
request.setHeader(h);
} else {
request.addHeader(h);
}
}
}
addSpecificHeaders(method, request);
// Create the client transaction.
inviteClientTid = sipProvider.getNewClientTransaction(request);
// send the request out.
inviteClientTid.sendRequest();
logger.info("client tx = " + inviteClientTid);
if (!Request.MESSAGE.equalsIgnoreCase(method)) {
dialog = inviteClientTid.getDialog();
}
if (Request.INVITE.equalsIgnoreCase(method)) {
inviteRequest = request;
}
this.dialogCount++;
return inviteRequest;
}
Aggregations