Package org.restlet.ext.sip

Examples of org.restlet.ext.sip.SipResponse


    @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)) {
View Full Code Here


    }

    @Override
    protected void copyResponseTransportHeaders(Series<Parameter> headers,
            Response response) {
        SipResponse sr = (SipResponse) response;

        // Set the "alertInfo" header
        String header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_ALERT_INFO);

        if (header != null) {
            try {
                sr.setAlertInfo(new AddressReader(header).readValue());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set "allowedEventTypes" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_ALLOW_EVENTS);

        if (header != null) {
            try {
                sr.getAllowedEventTypes().addAll(
                        new EventTypeReader(header).readValues());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "callerInfo" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_CALL_INFO);

        if (header != null) {
            try {
                sr.getCalleeInfo().addAll(
                        new AddressReader(header).readValues());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "callId" property
        String callIdHeader = (getHeaders() == null) ? null : getHeaders()
                .getFirstValue(SipConstants.HEADER_CALL_ID);
        if (callIdHeader != null) {
            sr.setCallId(callIdHeader);
        }

        // Set the "commandSeq" property
        String commandSeqHeader = (getHeaders() == null) ? null : getHeaders()
                .getFirstValue(SipConstants.HEADER_CALL_SEQ);
        if (commandSeqHeader != null) {
            sr.setCommandSequence(commandSeqHeader);
        }

        // Set the "contacts" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_CONTACT);

        if (header != null) {
            try {
                sr.getContacts().addAll(
                        new ContactInfoReader(header).readValues());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "errorInfo" header
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_ERROR_INFO);

        if (header != null) {
            try {
                sr.setErrorInfo(new AddressReader(header).readValue());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "event" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_EVENT);

        if (header != null) {
            try {
                sr.setEvent(new EventReader(header).readValue());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "from" property
        String fromHeader = (getHeaders() == null) ? null : getHeaders()
                .getFirstValue(HeaderConstants.HEADER_FROM);
        if (fromHeader != null) {
            try {
                sr.setFrom(new AddressReader(fromHeader).readValue());
            } catch (IOException e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "minExpires" property
        header = (getHeaders() == null) ? null : getHeaders().getFirstValue(
                SipConstants.HEADER_MIN_EXPIRES);
        sr.setMinExpires(header);

        // Set the "mime-version" property
        header = (getHeaders() == null) ? null : getHeaders().getFirstValue(
                SipConstants.HEADER_MIME_VERSION);
        sr.setMimeVersion(header);

        // Set the "mime-version" property
        header = (getHeaders() == null) ? null : getHeaders().getFirstValue(
                SipConstants.HEADER_MIME_VERSION);
        sr.setMimeVersion(header);

        // Set the "organization" property
        header = (getHeaders() == null) ? null : getHeaders().getFirstValue(
                SipConstants.HEADER_MIME_VERSION);
        sr.setOrganization(header);

        // Set the "recordedRoute" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_RECORD_ROUTE);

        if (header != null) {
            try {
                sr.getRecordedRoutes().addAll(
                        new AddressReader(header).readValues());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "replyTo" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_REPLY_TO);

        if (header != null) {
            try {
                sr.setReplyTo(new AddressReader(header).readValue());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "sipRecipientsInfo" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                HeaderConstants.HEADER_VIA);

        if (header != null) {
            try {
                sr.getSipRecipientsInfo().addAll(
                        new SipRecipientInfoReader(header).readValues());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "sipRetryAfter" property
        header = (getHeaders() == null) ? null : getHeaders().getFirstValue(
                SipConstants.HEADER_RETRY_AFTER);
        if (header != null) {
            try {
                sr.setSipRetryAfter(new AvailabilityReader(header).readValue());
            } catch (IOException e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "sipTag" property
        header = (getHeaders() == null) ? null : getHeaders().getFirstValue(
                SipConstants.HEADER_SIP_ETAG);
        if (header != null) {
            sr.setSipTag(Tag.parse(header));
        }

        // Set the "supported" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_SUPPORTED);

        if (header != null) {
            try {
                sr.getSupported().addAll(
                        new OptionTagReader(header).readValues());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "to" property
        header = (getHeaders() == null) ? null : getHeaders().getFirstValue(
                SipConstants.HEADER_TO);
        if (header != null) {
            try {
                sr.setTo(new AddressReader(header).readValue());
            } catch (IOException e) {
                getLogger().info(e.getMessage());
            }
        }

        // Set the "unsupported" property
        header = (getHeaders() == null) ? null : getHeaders().getValues(
                SipConstants.HEADER_UNSUPPORTED);

        if (header != null) {
            try {
                sr.getUnsupported().addAll(
                        new OptionTagReader(header).readValues());
            } catch (Exception e) {
                getLogger().info(e.getMessage());
            }
        }

        for (Parameter headerParam : headers) {
            if (headerParam.getName().equalsIgnoreCase(
                    HeaderConstants.HEADER_VIA)) {
                SipRecipientInfoReader.addValues(headerParam,
                        sr.getSipRecipientsInfo());
            }
        }

        // Don't let the parent code handle the VIA header
        // according to HTTP syntax.
View Full Code Here

        super.copyResponseTransportHeaders(headers, response);
    }

    @Override
    protected Response createResponse(Status status) {
        return new SipResponse(null);
    }
View Full Code Here

    public void start() {
        trace();

        // Indicate successful reception
        SipResponse provisionalResponse = new SipResponse(getRequest());
        provisionalResponse.setStatus(SipStatus.INFO_TRYING);
        provisionalResponse.commit();

        sleep();

        // Indicate that the user phone is ringing
        provisionalResponse = new SipResponse(getRequest());
        provisionalResponse.setStatus(SipStatus.INFO_RINGING);
        provisionalResponse.commit();

        sleep();

        // Indicate that the session is progressing
        provisionalResponse = new SipResponse(getRequest());
        provisionalResponse.setStatus(SipStatus.INFO_SESSION_PROGRESS);
        provisionalResponse.commit();

        sleep();
        if (getTo() != null) {
            getTo().getParameters().add("tag",
                    "restlet" + TAG.incrementAndGet());
        }

        // Send a first final response
        provisionalResponse = new SipResponse(getRequest());
        provisionalResponse.setStatus(SipStatus.SUCCESS_OK);
        provisionalResponse.commit();

        sleep();

        // Set the final response
        setStatus(SipStatus.SUCCESS_OK);
View Full Code Here

    }

    @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()));
        }

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

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

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

        if (sipResponse.getErrorInfo() != null) {
            headers.add(SipConstants.HEADER_ERROR_INFO,
                    AddressWriter.write(sipResponse.getErrorInfo()));
        }

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

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

        if (sipResponse.getMinExpires() != null) {
            headers.add(SipConstants.HEADER_MIN_EXPIRES,
                    sipResponse.getMinExpires());
        }

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

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

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

        if (sipResponse.getRetryAfter() != null) {
            headers.add(SipConstants.HEADER_RETRY_AFTER,
                    DateWriter.write(sipResponse.getRetryAfter()));
        }

        if (sipResponse.getSipTag() != null) {
            headers.add(SipConstants.HEADER_SIP_ETAG, sipResponse.getSipTag()
                    .format());
        }

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

        if (!sipResponse.getUnsupported().isEmpty()) {
            headers.add(SipConstants.HEADER_UNSUPPORTED,
                    OptionTagWriter.write(sipResponse.getUnsupported()));
        }

        super.addResponseHeaders(headers);
    }
View Full Code Here

        super(connection, bufferSize);
    }

    @Override
    protected Response createResponse(Request request) {
        return new SipResponse(request);
    }
View Full Code Here

                    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);
                }
View Full Code Here

        if (response != null) {
            result = response.getRequest();

            if (result == null) {
                SipResponse sipResponse = (SipResponse) response;

                // Lookup the parent request that initiated the SIP transaction
                String tid = sipResponse.getTransactionId();
                result = getRequests().get(tid);
            }
        }

        return result;
View Full Code Here

TOP

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

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.