Search in sources :

Example 26 with Request

use of javax.sip.message.Request in project camel by apache.

the class SipSubscriptionListener method processRequest.

public void processRequest(RequestEvent requestReceivedEvent) {
    Request request = requestReceivedEvent.getRequest();
    ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
    String viaBranch = ((ViaHeader) (request.getHeaders(ViaHeader.NAME).next())).getParameter("branch");
    LOG.debug("Request: {}", request.getMethod());
    LOG.debug("Server Transaction Id: {}", serverTransactionId);
    LOG.debug("Received From Branch: {}", viaBranch);
    if (request.getMethod().equals(Request.NOTIFY)) {
        processNotify(requestReceivedEvent, serverTransactionId);
    }
}
Also used : ViaHeader(javax.sip.header.ViaHeader) Request(javax.sip.message.Request) ServerTransaction(javax.sip.ServerTransaction)

Example 27 with Request

use of javax.sip.message.Request in project camel by apache.

the class SipConfiguration method createSipRequest.

public Request createSipRequest(long sequenceNumber, String requestMethod, Object body) throws ParseException, InvalidArgumentException {
    //SipConfiguration configuration = sipPublisher.getConfiguration();
    CSeqHeader cSeqHeader = getHeaderFactory().createCSeqHeader(sequenceNumber, requestMethod);
    // Create the request.
    Request request = getMessageFactory().createRequest(getSipUri(), requestMethod, getCallIdHeader(), cSeqHeader, getFromHeader(), getToHeader(), getViaHeaders(), getMaxForwardsHeader());
    if (getEventHeader() != null) {
        request.addHeader(getEventHeader());
    }
    if (getExpiresHeader() != null) {
        request.addHeader(getExpiresHeader());
    }
    if (getContactHeader() != null) {
        request.addHeader(getContactHeader());
    }
    if (getExtensionHeader() != null) {
        request.addHeader(getExtensionHeader());
    }
    request.setContent(body, getContentTypeHeader());
    return request;
}
Also used : CSeqHeader(javax.sip.header.CSeqHeader) Request(javax.sip.message.Request)

Example 28 with Request

use of javax.sip.message.Request in project camel by apache.

the class SipSubscriber method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    Properties properties = configuration.createInitialProperties();
    sipStack = configuration.getSipFactory().createSipStack(properties);
    configuration.parseURI();
    sipSubscriptionListener = new SipSubscriptionListener(this);
    ListeningPoint listeningPoint = sipStack.createListeningPoint(configuration.getFromHost(), Integer.valueOf(configuration.getFromPort()).intValue(), configuration.getTransport());
    configuration.setListeningPoint(listeningPoint);
    provider = sipStack.createSipProvider(configuration.getListeningPoint());
    provider.addSipListener(sipSubscriptionListener);
    if (configuration.getCallIdHeader() == null) {
        configuration.setCallIdHeader(provider.getNewCallId());
    }
    // Create the Subscription request to register with the presence agent and receive notifications.
    configuration.setCallIdHeader(provider.getNewCallId());
    Request request = configuration.createSipRequest(1, Request.SUBSCRIBE, configuration.getEventHeaderName());
    // Create the subscriber transaction from request.
    ClientTransaction subscriberTransactionId = provider.getNewClientTransaction(request);
    // Add an Event header for the subscription.
    request.addHeader(configuration.getEventHeader());
    subscriberDialog = subscriberTransactionId.getDialog();
    // Send the outgoing subscription request.
    subscriberTransactionId.sendRequest();
}
Also used : ClientTransaction(javax.sip.ClientTransaction) SipSubscriptionListener(org.apache.camel.component.sip.listener.SipSubscriptionListener) Request(javax.sip.message.Request) ListeningPoint(javax.sip.ListeningPoint) Properties(java.util.Properties)

Example 29 with Request

use of javax.sip.message.Request in project camel by apache.

the class SipPresenceAgentListener method processRequest.

public void processRequest(RequestEvent requestEvent) {
    Request request = requestEvent.getRequest();
    ServerTransaction serverTransactionId = requestEvent.getServerTransaction();
    LOG.debug("Request: {}", request.getMethod());
    LOG.debug("Server Transaction Id: {}", serverTransactionId);
    if (request.getMethod().equals(Request.SUBSCRIBE)) {
        processSubscribe(requestEvent, serverTransactionId);
    } else if (request.getMethod().equals(Request.PUBLISH)) {
        processPublish(requestEvent, serverTransactionId);
    } else {
        LOG.debug("Received expected request with method: {}. No further processing done", request.getMethod());
    }
}
Also used : Request(javax.sip.message.Request) ServerTransaction(javax.sip.ServerTransaction)

Example 30 with Request

use of javax.sip.message.Request in project camel by apache.

the class SipPresenceAgentListener method processSubscribe.

public void processSubscribe(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
        LOG.debug("SipPresenceAgentListener: Received a Subscribe request, sending OK");
        LOG.debug("SipPresenceAgentListener request: {}", request);
        EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
        if (eventHeader == null) {
            LOG.debug("Cannot find event header.... dropping request.");
            return;
        }
        // Always create a ServerTransaction, best as early as possible in the code
        Response response = null;
        ServerTransaction st = requestEvent.getServerTransaction();
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        // Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
        boolean isInitial = requestEvent.getDialog() == null;
        if (isInitial) {
            String toTag = UUID.randomUUID().toString();
            response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(202, request);
            ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
            // Application is supposed to set.
            toHeader.setTag(toTag);
            this.dialog = st.getDialog();
            // subscribe dialogs do not terminate on bye.
            this.dialog.terminateOnBye(false);
        } else {
            response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(200, request);
        }
        // Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
        response.addHeader(sipPresenceAgent.getConfiguration().getContactHeader());
        // Expires header is mandatory in 2xx responses to SUBSCRIBE
        response.addHeader(sipPresenceAgent.getConfiguration().getExpiresHeader());
        st.sendResponse(response);
        LOG.debug("SipPresenceAgentListener: Sent OK Message");
        LOG.debug("SipPresenceAgentListener response: {}", response);
        sendNotification(eventHeader, isInitial, request.getContent());
    } catch (Throwable e) {
        LOG.error("Exception thrown during Notify processing in the SipPresenceAgentListener.", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) ToHeader(javax.sip.header.ToHeader) EventHeader(javax.sip.header.EventHeader) ServerTransaction(javax.sip.ServerTransaction) SipProvider(javax.sip.SipProvider)

Aggregations

Request (javax.sip.message.Request)38 ParseException (java.text.ParseException)21 SipException (javax.sip.SipException)21 InvalidArgumentException (javax.sip.InvalidArgumentException)13 ClientTransaction (javax.sip.ClientTransaction)9 SipURI (javax.sip.address.SipURI)9 Response (javax.sip.message.Response)9 NotFoundException (org.jivesoftware.util.NotFoundException)7 TooManyListenersException (java.util.TooManyListenersException)6 ServerTransaction (javax.sip.ServerTransaction)6 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)6 Address (javax.sip.address.Address)5 CSeqHeader (javax.sip.header.CSeqHeader)5 ViaHeader (javax.sip.header.ViaHeader)5 SIPRequest (gov.nist.javax.sip.message.SIPRequest)4 FromHeader (javax.sip.header.FromHeader)4 SubscriptionStateHeader (javax.sip.header.SubscriptionStateHeader)4 ToHeader (javax.sip.header.ToHeader)4 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)3 IOException (java.io.IOException)3