Search in sources :

Example 1 with ContentLengthHeader

use of javax.sip.header.ContentLengthHeader in project load-balancer by RestComm.

the class TestSipListener method sendInDialogSipRequest.

/**
 * @param transport TODO
 * @param messageToSend
 * @throws SipException
 * @throws InvalidArgumentException
 * @throws ParseException
 */
public void sendInDialogSipRequest(String method, String content, String contentType, String subContentType, List<Header> headers, String transport) throws SipException, InvalidArgumentException, ParseException {
    Request message = dialog.createRequest(method);
    if (transport != null) {
        ((SipURI) message.getRequestURI()).setTransportParam(transport);
    }
    if (content != null) {
        ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(content.length());
        ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(contentType, subContentType);
        message.setContentLength(contentLengthHeader);
        message.setContent(content, contentTypeHeader);
    }
    if (headers != null) {
        for (Header header : headers) {
            message.addHeader(header);
        }
    }
    addSpecificHeaders(method, message);
    message.removeHeader(ViaHeader.NAME);
    ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(message);
    if (method.equals("INVITE")) {
        inviteClientTid = clientTransaction;
    }
    dialog.sendRequest(clientTransaction);
}
Also used : ReasonHeader(javax.sip.header.ReasonHeader) RequireHeader(javax.sip.header.RequireHeader) SIPETagHeader(javax.sip.header.SIPETagHeader) ContactHeader(javax.sip.header.ContactHeader) ReferToHeader(javax.sip.header.ReferToHeader) ViaHeader(javax.sip.header.ViaHeader) SIPIfMatchHeader(javax.sip.header.SIPIfMatchHeader) AuthorizationHeader(javax.sip.header.AuthorizationHeader) CallIdHeader(javax.sip.header.CallIdHeader) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ExtensionHeader(javax.sip.header.ExtensionHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) Header(javax.sip.header.Header) ReplacesHeader(gov.nist.javax.sip.header.extensions.ReplacesHeader) CSeqHeader(javax.sip.header.CSeqHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) JoinHeader(gov.nist.javax.sip.header.extensions.JoinHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ToHeader(javax.sip.header.ToHeader) RouteHeader(javax.sip.header.RouteHeader) ProxyAuthorizationHeader(javax.sip.header.ProxyAuthorizationHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) EventHeader(javax.sip.header.EventHeader) FromHeader(javax.sip.header.FromHeader) ProxyAuthenticateHeader(javax.sip.header.ProxyAuthenticateHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) ContentLengthHeader(javax.sip.header.ContentLengthHeader) SipURI(javax.sip.address.SipURI)

Example 2 with ContentLengthHeader

use of javax.sip.header.ContentLengthHeader in project load-balancer by RestComm.

the class TestSipListener method sendMessageInDialog.

/**
 * @param messageToSend
 * @throws SipException
 * @throws InvalidArgumentException
 * @throws ParseException
 */
public void sendMessageInDialog(String messageToSend) throws SipException, InvalidArgumentException, ParseException {
    Request message = dialog.createRequest(Request.MESSAGE);
    ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(messageToSend.length());
    ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(TEXT_CONTENT_TYPE, PLAIN_UTF8_CONTENT_SUBTYPE);
    message.setContentLength(contentLengthHeader);
    message.setContent(messageToSend, contentTypeHeader);
    ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(message);
    dialog.sendRequest(clientTransaction);
}
Also used : ContentTypeHeader(javax.sip.header.ContentTypeHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) ContentLengthHeader(javax.sip.header.ContentLengthHeader)

Example 3 with ContentLengthHeader

use of javax.sip.header.ContentLengthHeader in project load-balancer by RestComm.

the class TestSipListener method sendSipRequest.

public Request sendSipRequest(String method, URI fromURI, URI toURI, String messageContent, SipURI route, boolean useToURIasRequestUri, String[] headerNames, String[] headerContents, boolean setHeader) throws SipException, ParseException, InvalidArgumentException {
    this.useToURIasRequestUri = useToURIasRequestUri;
    // create >From Header
    Address fromNameAddress = protocolObjects.addressFactory.createAddress(fromURI);
    FromHeader fromHeader = protocolObjects.headerFactory.createFromHeader(fromNameAddress, Integer.toString(new Random().nextInt(10000000)));
    // create To Header
    Address toNameAddress = protocolObjects.addressFactory.createAddress(toURI);
    ToHeader toHeader = protocolObjects.headerFactory.createToHeader(toNameAddress, null);
    if (toURI instanceof SipURI) {
        SipURI toSipUri = (SipURI) toURI;
        // create Request URI
        this.requestURI = protocolObjects.addressFactory.createSipURI(toSipUri.getUser(), peerHostPort);
        ((SipURI) this.requestURI).setPort(peerPort);
        if (setTransport) {
            ((SipURI) this.requestURI).setTransportParam(listeningPoint.getTransport());
        }
    }
    if (useToURIasRequestUri || toURI instanceof TelURL) {
        this.requestURI = toURI;
    }
    // Create ViaHeaders
    List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
    ViaHeader viaHeader = null;
    if (!isIpv6)
        viaHeader = protocolObjects.headerFactory.createViaHeader("127.0.0.1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
    else
        viaHeader = protocolObjects.headerFactory.createViaHeader("::1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
    // add via headers
    viaHeaders.add(viaHeader);
    // Create ContentTypeHeader
    // ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory
    // .createContentTypeHeader("application", "sdp");
    // Create a new CallId header
    CallIdHeader callIdHeader = sipProvider.getNewCallId();
    // Create a new Cseq header
    CSeqHeader cSeqHeader = protocolObjects.headerFactory.createCSeqHeader(1L, method);
    // Create a new MaxForwardsHeader
    MaxForwardsHeader maxForwards = protocolObjects.headerFactory.createMaxForwardsHeader(70);
    // Create the request.
    Request request = protocolObjects.messageFactory.createRequest(requestURI, method, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
    // Create contact headers
    String host = null;
    if (!isIpv6)
        host = "127.0.0.1";
    else
        host = "::1";
    URI contactUrl = null;
    if (fromURI instanceof SipURI) {
        contactUrl = protocolObjects.addressFactory.createSipURI(((SipURI) fromURI).getUser(), host);
        /**
         * either use tcp or udp
         */
        ((SipURI) contactUrl).setPort(listeningPoint.getPort());
        if (setTransport) {
            ((SipURI) contactUrl).setTransportParam(listeningPoint.getTransport());
            ((SipURI) contactUrl).setLrParam();
        }
    } else {
        contactUrl = fromURI;
    }
    // Create the contact name address.
    Address contactAddress = protocolObjects.addressFactory.createAddress(contactUrl);
    // Add the contact address.
    // contactAddress.setDisplayName(fromName);
    contactHeader = protocolObjects.headerFactory.createContactHeader(contactAddress);
    request.addHeader(contactHeader);
    SipURI uri = null;
    if (!isIpv6)
        uri = protocolObjects.addressFactory.createSipURI(null, "127.0.0.1");
    else
        uri = protocolObjects.addressFactory.createSipURI(null, "::1");
    uri.setLrParam();
    uri.setTransportParam(protocolObjects.transport);
    uri.setPort(this.peerPort);
    if (route != null) {
        Address address = protocolObjects.addressFactory.createAddress(route);
        RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
        request.addHeader(routeHeader);
    } else if (useDefaultRoute) {
        Address address = protocolObjects.addressFactory.createAddress(uri);
        RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
        request.addHeader(routeHeader);
    }
    // set the message content
    if (messageContent != null) {
        ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(messageContent.length());
        ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(TEXT_CONTENT_TYPE, PLAIN_UTF8_CONTENT_SUBTYPE);
        byte[] contents = messageContent.getBytes();
        request.setContent(contents, contentTypeHeader);
        request.setContentLength(contentLengthHeader);
    }
    if (headerNames != null) {
        for (int q = 0; q < headerNames.length; q++) {
            Header h = protocolObjects.headerFactory.createHeader(headerNames[q], headerContents[q]);
            if (setHeader) {
                request.setHeader(h);
            } else {
                request.addHeader(h);
            }
        }
    }
    addSpecificHeaders(method, request);
    // Create the client transaction.
    inviteClientTid = sipProvider.getNewClientTransaction(request);
    // send the request out.
    inviteClientTid.sendRequest();
    logger.info("client tx = " + inviteClientTid);
    if (!Request.MESSAGE.equalsIgnoreCase(method)) {
        dialog = inviteClientTid.getDialog();
    }
    if (Request.INVITE.equalsIgnoreCase(method)) {
        inviteRequest = request;
    }
    this.dialogCount++;
    return inviteRequest;
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) RouteHeader(javax.sip.header.RouteHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) ContentLengthHeader(javax.sip.header.ContentLengthHeader) SipURI(javax.sip.address.SipURI) TelURL(javax.sip.address.TelURL) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI) ListeningPoint(javax.sip.ListeningPoint) CSeqHeader(javax.sip.header.CSeqHeader) Random(java.util.Random) ReasonHeader(javax.sip.header.ReasonHeader) RequireHeader(javax.sip.header.RequireHeader) SIPETagHeader(javax.sip.header.SIPETagHeader) ContactHeader(javax.sip.header.ContactHeader) ReferToHeader(javax.sip.header.ReferToHeader) ViaHeader(javax.sip.header.ViaHeader) SIPIfMatchHeader(javax.sip.header.SIPIfMatchHeader) AuthorizationHeader(javax.sip.header.AuthorizationHeader) CallIdHeader(javax.sip.header.CallIdHeader) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ExtensionHeader(javax.sip.header.ExtensionHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) Header(javax.sip.header.Header) ReplacesHeader(gov.nist.javax.sip.header.extensions.ReplacesHeader) CSeqHeader(javax.sip.header.CSeqHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) JoinHeader(gov.nist.javax.sip.header.extensions.JoinHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ToHeader(javax.sip.header.ToHeader) RouteHeader(javax.sip.header.RouteHeader) ProxyAuthorizationHeader(javax.sip.header.ProxyAuthorizationHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) EventHeader(javax.sip.header.EventHeader) FromHeader(javax.sip.header.FromHeader) ProxyAuthenticateHeader(javax.sip.header.ProxyAuthenticateHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) ViaHeader(javax.sip.header.ViaHeader) ReferToHeader(javax.sip.header.ReferToHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader)

Example 4 with ContentLengthHeader

use of javax.sip.header.ContentLengthHeader in project load-balancer by RestComm.

the class TestSipListener method sendMessageNoDialog.

/**
 * @param messageToSend
 * @throws SipException
 * @throws InvalidArgumentException
 * @throws ParseException
 */
public void sendMessageNoDialog(String messageToSend) throws SipException, InvalidArgumentException, ParseException {
    Request message = dialog.createRequest(Request.MESSAGE);
    ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(messageToSend.length());
    ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(TEXT_CONTENT_TYPE, PLAIN_UTF8_CONTENT_SUBTYPE);
    message.setContentLength(contentLengthHeader);
    message.setContent(messageToSend, contentTypeHeader);
    ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(message);
    dialog.sendRequest(clientTransaction);
}
Also used : ContentTypeHeader(javax.sip.header.ContentTypeHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) ContentLengthHeader(javax.sip.header.ContentLengthHeader)

Example 5 with ContentLengthHeader

use of javax.sip.header.ContentLengthHeader in project load-balancer by RestComm.

the class TestSipListener method addSpecificHeaders.

private void addSpecificHeaders(String method, Request request) throws ParseException, InvalidArgumentException {
    if (Request.SUBSCRIBE.equals(method) || Request.PUBLISH.equals(method)) {
        // Create an event header for the subscription.
        EventHeader eventHeader = protocolObjects.headerFactory.createEventHeader(publishEvent);
        request.addHeader(eventHeader);
        ExpiresHeader expires = protocolObjects.headerFactory.createExpiresHeader(200);
        request.addHeader(expires);
    }
    if (Request.PUBLISH.equals(method)) {
        if (sipETag != null) {
            SIPIfMatchHeader sipIfMatchHeader = protocolObjects.headerFactory.createSIPIfMatchHeader(sipETag);
            request.addHeader(sipIfMatchHeader);
        }
        if (publishContentMessage != null) {
            ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(publishContentMessage.length());
            ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(APPLICATION_CONTENT_TYPE, PIDF_XML_SUBTYPE);
            request.setContentLength(contentLengthHeader);
            request.setContent(publishContentMessage, contentTypeHeader);
        }
    }
    if (Request.REFER.equals(method)) {
        ReferToHeader referToHeader = (ReferToHeader) protocolObjects.headerFactory.createHeader(ReferToHeader.NAME, "sip:refer-to@nist.gov");
        request.addHeader(referToHeader);
    }
}
Also used : ContentTypeHeader(javax.sip.header.ContentTypeHeader) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ReferToHeader(javax.sip.header.ReferToHeader) EventHeader(javax.sip.header.EventHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) SIPIfMatchHeader(javax.sip.header.SIPIfMatchHeader)

Aggregations

ContentLengthHeader (javax.sip.header.ContentLengthHeader)5 ContentTypeHeader (javax.sip.header.ContentTypeHeader)5 Request (javax.sip.message.Request)4 ClientTransaction (javax.sip.ClientTransaction)3 EventHeader (javax.sip.header.EventHeader)3 ExpiresHeader (javax.sip.header.ExpiresHeader)3 ReferToHeader (javax.sip.header.ReferToHeader)3 SIPIfMatchHeader (javax.sip.header.SIPIfMatchHeader)3 JoinHeader (gov.nist.javax.sip.header.extensions.JoinHeader)2 ReplacesHeader (gov.nist.javax.sip.header.extensions.ReplacesHeader)2 SipURI (javax.sip.address.SipURI)2 AuthorizationHeader (javax.sip.header.AuthorizationHeader)2 CSeqHeader (javax.sip.header.CSeqHeader)2 CallIdHeader (javax.sip.header.CallIdHeader)2 ContactHeader (javax.sip.header.ContactHeader)2 ExtensionHeader (javax.sip.header.ExtensionHeader)2 FromHeader (javax.sip.header.FromHeader)2 Header (javax.sip.header.Header)2 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)2 ProxyAuthenticateHeader (javax.sip.header.ProxyAuthenticateHeader)2