Search in sources :

Example 1 with MessageExt

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);
    }
}
Also used : RequestEventExt(gov.nist.javax.sip.RequestEventExt) MessageExt(gov.nist.javax.sip.message.MessageExt) RouteHeader(javax.sip.header.RouteHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SIPRequest(gov.nist.javax.sip.message.SIPRequest) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) CacheException(org.jboss.cache.CacheException) SipException(javax.sip.SipException) ListeningPoint(javax.sip.ListeningPoint)

Example 2 with MessageExt

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());
}
Also used : MessageExt(gov.nist.javax.sip.message.MessageExt) ResponseEventExt(gov.nist.javax.sip.ResponseEventExt) ListeningPoint(javax.sip.ListeningPoint)

Example 3 with MessageExt

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();
    }
}
Also used : MessageExt(gov.nist.javax.sip.message.MessageExt) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) CacheException(org.jboss.cache.CacheException) SipException(javax.sip.SipException) ListeningPoint(javax.sip.ListeningPoint)

Example 4 with MessageExt

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);
}
Also used : Response(javax.sip.message.Response) MessageExt(gov.nist.javax.sip.message.MessageExt) ContactHeader(javax.sip.header.ContactHeader) ViaHeader(javax.sip.header.ViaHeader) CallIdHeader(javax.sip.header.CallIdHeader) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) Header(javax.sip.header.Header) CSeqHeader(javax.sip.header.CSeqHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ToHeader(javax.sip.header.ToHeader) RouteHeader(javax.sip.header.RouteHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) EventHeader(javax.sip.header.EventHeader) FromHeader(javax.sip.header.FromHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) ViaHeader(javax.sip.header.ViaHeader) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction) SipException(javax.sip.SipException)

Example 5 with MessageExt

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);
    }
}
Also used : RequestEventExt(gov.nist.javax.sip.RequestEventExt) MessageExt(gov.nist.javax.sip.message.MessageExt) Dialog(javax.sip.Dialog) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SIPRequest(gov.nist.javax.sip.message.SIPRequest) ListeningPoint(javax.sip.ListeningPoint) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) CacheException(org.jboss.cache.CacheException) SipException(javax.sip.SipException)

Aggregations

MessageExt (gov.nist.javax.sip.message.MessageExt)8 ListeningPoint (javax.sip.ListeningPoint)7 ParseException (java.text.ParseException)6 SipException (javax.sip.SipException)6 SIPRequest (gov.nist.javax.sip.message.SIPRequest)5 InvalidArgumentException (javax.sip.InvalidArgumentException)5 Request (javax.sip.message.Request)5 CacheException (org.jboss.cache.CacheException)5 RequestEventExt (gov.nist.javax.sip.RequestEventExt)4 ClientTransaction (javax.sip.ClientTransaction)3 RecordRouteHeader (javax.sip.header.RecordRouteHeader)3 RouteHeader (javax.sip.header.RouteHeader)3 ResponseEventExt (gov.nist.javax.sip.ResponseEventExt)2 Dialog (javax.sip.Dialog)2 SipURI (javax.sip.address.SipURI)2 ServerTransaction (javax.sip.ServerTransaction)1 CSeqHeader (javax.sip.header.CSeqHeader)1 CallIdHeader (javax.sip.header.CallIdHeader)1 ContactHeader (javax.sip.header.ContactHeader)1 ContentLengthHeader (javax.sip.header.ContentLengthHeader)1