use of javax.sip.SipProvider in project load-balancer by RestComm.
the class SIPBalancerForwarder method processRequest.
/*
* (non-Javadoc)
* @see javax.sip.SipListener#processRequest(javax.sip.RequestEvent)
*/
public void processRequest(RequestEvent requestEvent) {
// This will be invoked only by external endpoint
BalancerAppContent content = (BalancerAppContent) requestEvent.getSource();
boolean isIpv6 = content.isIpv6();
final SipProvider sipProvider = content.getProvider();
final Request request = requestEvent.getRequest();
final String requestMethod = request.getMethod();
if (logger.isDebugEnabled()) {
logger.debug("got request:\n" + request);
}
if ((requestMethod.equals(Request.OPTIONS) || requestMethod.equals(Request.INFO)) && request.getHeader("Mobicents-Heartbeat") != null && sipProvider == balancerRunner.balancerContext.internalSipProvider) {
byte[] bytes = (byte[]) request.getContent();
Properties prop = new Properties();
try {
prop.load(new ByteArrayInputStream(bytes, 0, bytes.length));
Node node = new Node(prop.getProperty("hostname"), prop.getProperty("ip"));
for (String id : prop.stringPropertyNames()) {
node.getProperties().put(id, prop.getProperty(id));
}
ArrayList<Node> list = new ArrayList<Node>();
list.add(node);
this.register.handlePingInRegister(list);
Response response = balancerRunner.balancerContext.messageFactory.createResponse(Response.OK, request);
sipProvider.sendResponse(response);
return;
} catch (Exception e) {
logger.error("Failure parsing heartbeat properties from this request " + request, e);
}
}
// Issue 10: https://telestax.atlassian.net/browse/LB-10
if (request.getContent() != null || (requestMethod.equals(Request.REGISTER) && sipProvider != balancerRunner.balancerContext.internalSipProvider)) {
SIPMessage message = (SIPMessage) request;
String initialRemoteAddr = message.getPeerPacketSourceAddress().getHostAddress();
String initialRemotePort = String.valueOf(message.getPeerPacketSourcePort());
Header remoteAddrHeader = null;
Header remotePortHeader = null;
try {
remoteAddrHeader = SipFactory.getInstance().createHeaderFactory().createHeader("X-Sip-Balancer-InitialRemoteAddr", initialRemoteAddr);
remotePortHeader = SipFactory.getInstance().createHeaderFactory().createHeader("X-Sip-Balancer-InitialRemotePort", initialRemotePort);
} catch (PeerUnavailableException e) {
logger.error("Unexpected exception while creating custom headers for REGISTER message ", e);
} catch (ParseException e) {
logger.error("Unexpected exception while creating custom headers for REGISTER message ", e);
}
if (remoteAddrHeader != null)
request.addHeader(remoteAddrHeader);
if (remotePortHeader != null)
request.addHeader(remotePortHeader);
}
try {
updateStats(request);
forwardRequest(sipProvider, request, isIpv6);
} catch (Throwable throwable) {
logger.error("Unexpected exception while forwarding the request " + request, throwable);
if (!Request.ACK.equalsIgnoreCase(requestMethod)) {
try {
Response response = balancerRunner.balancerContext.messageFactory.createResponse(Response.SERVER_INTERNAL_ERROR, request);
sipProvider.sendResponse(response);
} catch (Exception e) {
logger.error("Unexpected exception while trying to send the error response for this " + request, e);
}
}
}
}
use of javax.sip.SipProvider in project load-balancer by RestComm.
the class ProtocolObjects method destroy.
public synchronized void destroy() {
HashSet<SipProvider> hashSet = new HashSet<SipProvider>();
for (SipProvider sipProvider : hashSet) {
hashSet.add(sipProvider);
}
for (SipProvider sipProvider : hashSet) {
for (int j = 0; j < 5; j++) {
try {
sipStack.deleteSipProvider(sipProvider);
} catch (ObjectInUseException ex) {
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
}
}
sipStack.stop();
}
use of javax.sip.SipProvider in project load-balancer by RestComm.
the class TestSipListener method processPublish.
private void processPublish(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
try {
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
logger.info("shootist: got a publish . ServerTxId = " + serverTransactionId);
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
inviteServerTid = st;
Dialog dialog = st.getDialog();
this.dialogCount++;
this.dialog = dialog;
logger.info("Shootme: dialog = " + dialog);
if (request.getRawContent() != null) {
this.lastMessageContent = new String(request.getRawContent());
allMessagesContent.add(new String(lastMessageContent));
}
SIPIfMatchHeader sipIfMatchHeader = (SIPIfMatchHeader) request.getHeader(SIPIfMatchHeader.NAME);
boolean sipIfMatchFound = true;
if (sipIfMatchHeader != null && sipIfMatchHeader.getETag() != null && !sipIfMatchHeader.getETag().equals(sipETag)) {
sipIfMatchFound = false;
}
if (sipIfMatchFound) {
Response response = protocolObjects.messageFactory.createResponse(200, request);
sipETag = Integer.toString(new Random().nextInt(10000000));
SIPETagHeader sipTagHeader = protocolObjects.headerFactory.createSIPETagHeader(sipETag);
response.addHeader(sipTagHeader);
response.addHeader(request.getHeader(ExpiresHeader.NAME));
st.sendResponse(response);
logger.info("shootist: Sending OK.");
} else {
Response response = protocolObjects.messageFactory.createResponse(500, request);
serverTransactionId.sendResponse(response);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of javax.sip.SipProvider in project load-balancer by RestComm.
the class ProtocolObjects method destroy.
public synchronized void destroy() {
HashSet<SipProvider> hashSet = new HashSet<SipProvider>();
for (SipProvider sipProvider : hashSet) {
hashSet.add(sipProvider);
}
for (SipProvider sipProvider : hashSet) {
for (int j = 0; j < 5; j++) {
try {
sipStack.deleteSipProvider(sipProvider);
} catch (ObjectInUseException ex) {
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
}
}
sipStack.stop();
}
use of javax.sip.SipProvider in project jain-sip.ha by RestComm.
the class B2BUAEarlyDialogRecoveryOn1xxTest method stopSipStack.
public static void stopSipStack(SipStack sipStack, SipListener listener) {
Iterator<SipProvider> sipProviderIterator = sipStack.getSipProviders();
try {
while (sipProviderIterator.hasNext()) {
SipProvider sipProvider = sipProviderIterator.next();
ListeningPoint[] listeningPoints = sipProvider.getListeningPoints();
for (ListeningPoint listeningPoint : listeningPoints) {
sipProvider.removeListeningPoint(listeningPoint);
sipStack.deleteListeningPoint(listeningPoint);
listeningPoints = sipProvider.getListeningPoints();
}
sipProvider.removeSipListener(listener);
sipStack.deleteSipProvider(sipProvider);
sipProviderIterator = sipStack.getSipProviders();
}
} catch (Exception e) {
throw new IllegalStateException("Cant remove the listening points or sip providers", e);
}
sipStack.stop();
sipStack = null;
}
Aggregations