Package org.restlet.ext.sip

Examples of org.restlet.ext.sip.SipRequest


    @Override
    protected void addGeneralHeaders(Series<Parameter> headers) {
        if (getMessage().getRequest() instanceof SipRequest) {
            // Put the VIA header at the top most level.
            SipRequest sipRequest = (SipRequest) getMessage().getRequest();

            if (!sipRequest.getSipRecipientsInfo().isEmpty()) {
                for (SipRecipientInfo recipient : sipRequest
                        .getSipRecipientsInfo()) {
                    // Generate one VIA header per recipient
                    headers.add(HeaderConstants.HEADER_VIA,
                            SipRecipientInfoWriter.write(recipient));
                }
View Full Code Here


        super.addGeneralHeaders(headers);
    }

    @Override
    protected void addRequestHeaders(Series<Parameter> headers) {
        SipRequest sipRequest = null;

        if (getMessage().getRequest() instanceof SipRequest) {
            sipRequest = (SipRequest) getMessage().getRequest();

            if (sipRequest.getCallId() != null) {
                headers.add(SipConstants.HEADER_CALL_ID, sipRequest.getCallId());
            }

            if (sipRequest.getCommandSequence() != null) {
                headers.add(SipConstants.HEADER_CALL_SEQ,
                        sipRequest.getCommandSequence());
            }

            if (sipRequest.getFrom() != null) {
                headers.add(HeaderConstants.HEADER_FROM,
                        AddressWriter.write(sipRequest.getFrom()));
            }

            if (sipRequest.getTo() != null) {
                headers.add(SipConstants.HEADER_TO,
                        AddressWriter.write(sipRequest.getTo()));
            }

            if (sipRequest.getAlertInfo() != null) {
                headers.add(SipConstants.HEADER_ALERT_INFO,
                        AddressWriter.write(sipRequest.getAlertInfo()));
            }

            if (!sipRequest.getAllowedEventTypes().isEmpty()) {
                headers.add(SipConstants.HEADER_ALLOW_EVENTS, EventTypeWriter
                        .write(sipRequest.getAllowedEventTypes()));
            }

            if (!sipRequest.getCallerInfo().isEmpty()) {
                headers.add(SipConstants.HEADER_CALL_INFO,
                        AddressWriter.write(sipRequest.getCallerInfo()));
            }

            if (!sipRequest.getContacts().isEmpty()) {
                headers.add(SipConstants.HEADER_CONTACT,
                        ContactInfoWriter.write(sipRequest.getContacts()));
            }

            if (sipRequest.getEvent() != null) {
                headers.add(SipConstants.HEADER_EVENT,
                        EventWriter.write(sipRequest.getEvent()));
            }

            if (sipRequest.getMimeVersion() != null) {
                headers.add(SipConstants.HEADER_MIME_VERSION,
                        sipRequest.getMimeVersion());
            }

            if (sipRequest.getOrganization() != null) {
                headers.add(SipConstants.HEADER_ORGANIZATION,
                        sipRequest.getOrganization());
            }

            if (!sipRequest.getRecordedRoutes().isEmpty()) {
                headers.add(SipConstants.HEADER_RECORD_ROUTE,
                        AddressWriter.write(sipRequest.getRecordedRoutes()));
            }

            if (sipRequest.getReplyTo() != null) {
                headers.add(SipConstants.HEADER_REPLY_TO,
                        AddressWriter.write(sipRequest.getReplyTo()));
            }

            if (!sipRequest.getSupported().isEmpty()) {
                headers.add(SipConstants.HEADER_SUPPORTED,
                        OptionTagWriter.write(sipRequest.getSupported()));
            }

            if (!sipRequest.getInReplyTo().isEmpty()) {
                StringBuilder sb = new StringBuilder(sipRequest.getInReplyTo()
                        .get(0));

                for (int i = 1; i < sipRequest.getInReplyTo().size(); i++) {
                    sb.append(",").append(sipRequest.getInReplyTo().get(i));
                }

                headers.add(SipConstants.HEADER_IN_REPLY_TO, sb.toString());
            }

            if (sipRequest.getPriority() != null) {
                headers.add(SipConstants.HEADER_PRIORITY, sipRequest
                        .getPriority().getValue());
            }

            if (!sipRequest.getProxyRequires().isEmpty()) {
                headers.add(SipConstants.HEADER_PROXY_REQUIRE,
                        OptionTagWriter.write(sipRequest.getProxyRequires()));
            }

            if (sipRequest.getReferTo() != null) {
                headers.add(SipConstants.HEADER_REFER_TO,
                        AddressWriter.write(sipRequest.getReferTo()));
            }

            if (!sipRequest.getRequires().isEmpty()) {
                headers.add(SipConstants.HEADER_REQUIRE,
                        OptionTagWriter.write(sipRequest.getProxyRequires()));
            }

            if (!sipRequest.getRoutes().isEmpty()) {
                headers.add(SipConstants.HEADER_ROUTE,
                        AddressWriter.write(sipRequest.getRoutes()));
            }

            if (sipRequest.getSipIfMatch() != null) {
                headers.add(HeaderConstants.HEADER_IF_MATCH,
                        TagWriter.write(sipRequest.getSipIfMatch()));
            }

            if (sipRequest.getSubject() != null) {
                headers.add(SipConstants.HEADER_SUBJECT,
                        sipRequest.getSubject());
            }

            if (sipRequest.getSubscriptionState() != null) {
                headers.add(SipConstants.HEADER_SUBSCRIPTION_STATE,
                        SubscriptionWriter.write(sipRequest
                                .getSubscriptionState()));
            }
        }

        super.addRequestHeaders(headers);
View Full Code Here

    @Override
    protected void handle(Response response) {
        if ((getMessage() == null) && (response != null)) {
            // Update the map of SIP transactions
            SipResponse sipResponse = (SipResponse) response;
            SipRequest request = (SipRequest) sipResponse.getRequest();
            String tid = request.getTransaction();
            getHelper().getRequests().put(tid, request);
            request.updateLastActivity();

            if (getLogger().isLoggable(Level.FINER)) {
                getLogger().log(Level.FINER,
                        "Handling outbound request: " + request);
            }
View Full Code Here

    }

    @Override
    protected void onReceived(Response message) {
        if (message != null) {
            SipRequest request = (SipRequest) getHelper().getRequest(message);

            if (request != null) {
                request.updateLastActivity();
                message.setRequest(request);
            } else {
                getLogger()
                        .fine("Unable to find the transaction associated to a given response");
            }
View Full Code Here

        super(connection, bufferSize);
    }

    @Override
    protected void addResponseHeaders(Series<Parameter> headers) {
        SipRequest sipRequest = (SipRequest) getMessage().getRequest();
        SipResponse sipResponse = (SipResponse) getMessage();

        if (!sipResponse.getSipRecipientsInfo().isEmpty()) {
            for (SipRecipientInfo recipient : sipResponse
                    .getSipRecipientsInfo()) {
                // Generate one Via header per recipient
                headers.add(HeaderConstants.HEADER_VIA,
                        SipRecipientInfoWriter.write(recipient));
            }
        }

        if (sipRequest.getCallId() != null) {
            headers.add(SipConstants.HEADER_CALL_ID, sipRequest.getCallId());
        }

        if (sipRequest.getCommandSequence() != null) {
            headers.add(SipConstants.HEADER_CALL_SEQ,
                    sipRequest.getCommandSequence());
        }

        if (sipRequest.getFrom() != null) {
            headers.add(HeaderConstants.HEADER_FROM,
                    AddressWriter.write(sipRequest.getFrom()));
        }

        if (sipRequest.getTo() != null) {
            headers.add(SipConstants.HEADER_TO,
                    AddressWriter.write(sipRequest.getTo()));
        }

        if (sipResponse.getAlertInfo() != null) {
            headers.add(SipConstants.HEADER_ALERT_INFO,
                    AddressWriter.write(sipResponse.getAlertInfo()));
View Full Code Here

    }

    @Override
    protected boolean control() {
        boolean result = super.control();
        SipRequest request;

        // Control the transactions for timeouts
        for (Iterator<SipRequest> iter = getRequests().values().iterator(); iter
                .hasNext();) {
            request = iter.next();

            if (request.hasTimedOut()) {
                Level level;

                if (request.isHandled() || !request.isExpectingResponse()) {
                    level = Level.FINE;
                } else {
                    level = Level.INFO;

                    // Send an error response to the client
                    SipResponse response = new SipResponse(request);
                    response.setStatus(
                            SipStatus.CLIENT_ERROR_REQUEST_TIMEOUT,
                            "The SIP client connector has timeout due to lack of activity on this transaction: "
                                    + request.getTransaction());
                    handleInbound(response, false);
                }

                // Remove the transaction from the map
                getLogger().log(
                        level,
                        "This SIP transaction has timed out: "
                                + request.getTransaction());
                iter.remove();
            }
        }

        return result;
View Full Code Here

    }

    @Override
    protected void unblock(Response response) {
        if (response.getRequest() != null) {
            SipRequest request = (SipRequest) response.getRequest();
            request.setHandled(true);
            CountDownLatch latch = (CountDownLatch) response.getRequest()
                    .getAttributes().get(CONNECTOR_LATCH);

            if (latch == null) {
                getLogger().warning("Final response ignored: " + response);
View Full Code Here

TOP

Related Classes of org.restlet.ext.sip.SipRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.