use of gov.nist.javax.sip.message.MessageExt in project jain-sip.ha by RestComm.
the class SimpleStatefulProxy method processBye.
public void processBye(RequestEvent requestEvent) {
try {
serverTransaction = requestEvent.getServerTransaction();
if (serverTransaction == null) {
try {
serverTransaction = sipProvider.getNewServerTransaction(requestEvent.getRequest());
} catch (Exception e) {
((SipStackImpl) sipStack).getStackLogger().logError("unexpected exception", e);
return;
}
}
int remotePort = ((RequestEventExt) requestEvent).getRemotePort();
if (ListeningPoint.TCP.equalsIgnoreCase(transport)) {
remotePort = ((MessageExt) requestEvent.getRequest()).getTopmostViaHeader().getPort();
}
((ClusteredSipStack) sipStack).getStackLogger().logDebug("remotePort = " + remotePort);
final Request request = (Request) requestEvent.getRequest().clone();
((SipURI) request.getRequestURI()).setPort(5070);
request.removeLast(RouteHeader.NAME);
RouteHeader routeHeader = (RouteHeader) request.getHeader(RouteHeader.NAME);
if (routeHeader != null && (((SipURI) routeHeader.getAddress().getURI()).getPort() == 5080 || ((SipURI) routeHeader.getAddress().getURI()).getPort() == 5081)) {
request.removeFirst(RouteHeader.NAME);
}
request.addHeader(headerFactory.createViaHeader(ipAddress, myPort, transport, null));
final ClientTransaction ct = sipProvider.getNewClientTransaction(request);
ct.sendRequest();
} catch (Exception e) {
((SipStackImpl) sipStack).getStackLogger().logError("unexpected exception", e);
}
}
use of gov.nist.javax.sip.message.MessageExt in project jain-sip.ha by RestComm.
the class SimpleStatefulProxy method processInvite200.
/**
* @param responseEvent
* @throws SipException
* @throws InvalidArgumentException
*/
private void processInvite200(ResponseEvent responseEvent, CSeqHeader cseq) throws InvalidArgumentException, SipException {
// lets ack it ourselves to avoid UAS retransmissions due to
// forwarding of this response and further UAC Ack
// note that the app does not handles UAC ACKs
// String outgoingDialogId = responseEvent.getDialog().getDialogId();
int remotePort = ((ResponseEventExt) responseEvent).getRemotePort();
if (ListeningPoint.TCP.equalsIgnoreCase(transport)) {
remotePort = ((MessageExt) responseEvent.getResponse()).getTopmostViaHeader().getPort();
}
((ClusteredSipStack) sipStack).getStackLogger().logDebug("remotePort = " + remotePort);
// if(remotePort == 5065 || remotePort == 5081) {
// storeOutgoingDialogId(outgoingDialogId);
// }
// if(myPort == 5080 && getOutgoingDialogId() == null) {
// storeOutgoingDialogId(outgoingDialogId);
// }
forwardResponse(responseEvent.getResponse());
}
use of gov.nist.javax.sip.message.MessageExt in project jain-sip.ha by RestComm.
the class SimpleStatefulProxy method processInvite.
public void processInvite(RequestEvent requestEvent) {
// System.out.println("Got invite: "+requestEvent.getRequest());
try {
serverTransaction = requestEvent.getServerTransaction();
if (serverTransaction == null) {
try {
serverTransaction = sipProvider.getNewServerTransaction(requestEvent.getRequest());
} catch (Exception e) {
((SipStackImpl) sipStack).getStackLogger().logError("unexpected exception", e);
return;
}
}
storeServerTransactionId(serverTransaction.getBranchId());
serverTransaction.sendResponse(messageFactory.createResponse(100, requestEvent.getRequest()));
int peerPort = 5070;
if (((MessageExt) requestEvent.getRequest()).getToHeader().getTag() != null) {
peerPort = 5050;
((MessageExt) requestEvent.getRequest()).removeLast(RouteHeader.NAME);
}
forwardInvite(peerPort);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of gov.nist.javax.sip.message.MessageExt in project jain-sip.ha by RestComm.
the class SimpleB2BUAHandler method forwardResponse.
/**
* @param responseEvent
* @throws InvalidArgumentException
*/
@SuppressWarnings("unchecked")
private void forwardResponse(Response receivedResponse) throws SipException, InvalidArgumentException {
if (receivedResponse.getStatusCode() == 202) {
return;
}
System.out.println("Forwarding " + receivedResponse);
final ServerTransaction origServerTransaction = this.getServerTransaction();
Response forgedResponse = null;
try {
forgedResponse = messageFactory.createResponse(receivedResponse.getStatusCode(), origServerTransaction.getRequest());
} catch (ParseException e) {
throw new SipException("Failed to forge message", e);
}
// if ((getIncomingDialog() == null || getIncomingDialog().getState() == DialogState.EARLY) && localTag != null && getIncomingDialog() != null && getIncomingDialog().isServer()) {
// // no tag set in the response, since the dialog creating transaction didn't had it
// try {
// ((ToHeader)forgedResponse.getHeader(ToHeader.NAME)).setTag(localTag);
// } catch (ParseException e) {
// throw new SipException("Failed to set local tag", e);
// }
// }
// copy headers
ListIterator<String> lit = receivedResponse.getHeaderNames();
String headerName = null;
ListIterator<Header> headersIterator = null;
while (lit.hasNext()) {
headerName = lit.next();
if (SimpleB2BUAHandler.getHeadersToOmmitOnResponseCopy().contains(headerName)) {
continue;
} else {
forgedResponse.removeHeader(headerName);
headersIterator = receivedResponse.getHeaders(headerName);
while (headersIterator.hasNext()) {
forgedResponse.addLast((Header) headersIterator.next().clone());
}
}
}
// Copy content
final byte[] rawOriginal = receivedResponse.getRawContent();
if (rawOriginal != null && rawOriginal.length != 0) {
final byte[] copy = new byte[rawOriginal.length];
System.arraycopy(rawOriginal, 0, copy, 0, copy.length);
try {
forgedResponse.setContent(copy, (ContentTypeHeader) forgedResponse.getHeader(ContentTypeHeader.NAME));
} catch (ParseException e) {
throw new SipException("Failed to copy content.", e);
}
}
// set contact if the received response had it
if (receivedResponse.getHeader(ContactHeader.NAME) != null) {
final String transport = ((ViaHeader) forgedResponse.getHeader(ViaHeader.NAME)).getTransport();
forgedResponse.setHeader(((ListeningPointImpl) sipProvider.getListeningPoint(transport)).createContactHeader());
}
// set the to tag mandatory so that the dialog gets replicated
if (((MessageExt) forgedResponse).getToHeader().getTag() == null) {
try {
((MessageExt) forgedResponse).getToHeader().setTag("696");
} catch (ParseException e) {
e.printStackTrace();
}
}
origServerTransaction.sendResponse(forgedResponse);
}
use of gov.nist.javax.sip.message.MessageExt in project jain-sip.ha by RestComm.
the class SimpleB2BUAHandler method processAck.
public void processAck(RequestEvent requestEvent) {
int remotePort = ((RequestEventExt) requestEvent).getRemotePort();
if (ListeningPoint.TCP.equalsIgnoreCase(transport)) {
remotePort = ((MessageExt) requestEvent.getRequest()).getTopmostViaHeader().getPort();
}
((ClusteredSipStack) sipStack).getStackLogger().logDebug("remotePort = " + remotePort);
try {
if (!sendAckOn2xx) {
Dialog dialog = null;
if (remotePort == 5070) {
dialog = getIncomingDialog();
}
if (remotePort == 5050 || remotePort == 5060 || remotePort == 5065) {
storeIncomingDialogId(requestEvent.getDialog().getDialogId());
dialog = getOutgoingDialog();
}
final Request ack = dialog.createAck(((MessageExt) requestEvent.getRequest()).getCSeqHeader().getSeqNumber());
dialog.sendAck(ack);
} else {
if (myPort == 5080 && getIncomingDialogId() == null) {
storeIncomingDialogId(requestEvent.getDialog().getDialogId());
}
if (remotePort == 5050 || remotePort == 5060 || remotePort == 5065) {
storeIncomingDialogId(requestEvent.getDialog().getDialogId());
}
}
if (createInviteOnAck) {
createInviteOnAck = false;
Request request = getIncomingDialog().createRequest("INVITE");
final ClientTransaction ct = sipProvider.getNewClientTransaction(request);
getIncomingDialog().sendRequest(ct);
}
} catch (Exception e) {
((SipStackImpl) sipStack).getStackLogger().logError("unexpected exception", e);
}
}
Aggregations