Search in sources :

Example 36 with SipURI

use of javax.sip.address.SipURI in project camel by apache.

the class SipConfiguration method createContactHeader.

private void createContactHeader() throws ParseException {
    SipURI contactURI = addressFactory.createSipURI(getFromUser(), getFromHost());
    contactURI.setTransportParam(getTransport());
    contactURI.setPort(Integer.valueOf(getFromPort()).intValue());
    Address contactAddress = addressFactory.createAddress(contactURI);
    // Add the contact address.
    contactAddress.setDisplayName(getFromUser());
    contactHeader = headerFactory.createContactHeader(contactAddress);
}
Also used : Address(javax.sip.address.Address) SipURI(javax.sip.address.SipURI)

Example 37 with SipURI

use of javax.sip.address.SipURI in project Openfire by igniterealtime.

the class SipCommRouter method getNextHops.

/**
     * Return the default address to forward the request to. The list is
     * organized in the following priority.
     * <p/>
     * If the outboung proxy has been specified, then it is used to construct
     * the first element of the list.
     * <p/>
     * If the requestURI refers directly to a host, the host and port
     * information are extracted from it and made the next hop on the list.
     *
     * @param sipRequest is the sip request to route.
     */
public ListIterator<Hop> getNextHops(Request sipRequest) {
    URI requestURI = sipRequest.getRequestURI();
    if (requestURI == null) {
        throw new IllegalArgumentException("Bad message: Null requestURI");
    }
    LinkedList<Hop> hops = new LinkedList<Hop>();
    if (outboundProxy != null) {
        hops.add(outboundProxy);
    }
    ListIterator routes = sipRequest.getHeaders(RouteHeader.NAME);
    if (routes != null && routes.hasNext()) {
        while (routes.hasNext()) {
            RouteHeader route = (RouteHeader) routes.next();
            SipURI uri = (SipURI) route.getAddress().getURI();
            int port = uri.getPort();
            port = (port == -1) ? 5060 : port;
            String host = uri.getHost();
            Log.debug("getNextHops", host);
            String transport = uri.getTransportParam();
            if (transport == null) {
                transport = "udp";
            }
            Hop hop = new SipCommHop(host + ':' + port + '/' + transport);
            hops.add(hop);
        }
    } else if (requestURI instanceof SipURI && ((SipURI) requestURI).getMAddrParam() != null) {
        SipURI sipURI = ((SipURI) requestURI);
        String maddr = sipURI.getMAddrParam();
        String transport = sipURI.getTransportParam();
        if (transport == null) {
            transport = "udp";
        }
        int port = 5060;
        Hop hop = new SipCommHop(maddr, port, transport);
        hops.add(hop);
    } else if (requestURI instanceof SipURI) {
        SipURI sipURI = ((SipURI) requestURI);
        int port = sipURI.getPort();
        if (port == -1) {
            port = 5060;
        }
        String host = sipURI.getHost();
        String transport = sipURI.getTransportParam();
        if (transport == null) {
            transport = "UDP";
        }
        Hop hop = new SipCommHop(host + ":" + port + "/" + transport);
        hops.add(hop);
    } else {
        throw new IllegalArgumentException("Malformed requestURI");
    }
    return (hops.size() == 0) ? null : hops.listIterator();
}
Also used : RouteHeader(javax.sip.header.RouteHeader) Hop(javax.sip.address.Hop) ListIterator(java.util.ListIterator) SipURI(javax.sip.address.SipURI) SipURI(javax.sip.address.SipURI) URI(javax.sip.address.URI) LinkedList(java.util.LinkedList)

Example 38 with SipURI

use of javax.sip.address.SipURI in project Openfire by igniterealtime.

the class SipManager method getContactHeader.

/**
     * Initialises SipManager's contactHeader field in accordance with
     * javax.sip.IP_ADDRESS net.java.mais.sip.DISPLAY_NAME
     * net.java.mais.sip.TRANSPORT net.java.mais.sip.PREFERRED_LOCAL_PORT and
     * returns a reference to it.
     *
     * @param useLocalHostAddress specifies whether the SipURI in the contact header should
     *                            contain the value of javax.sip.IP_ADDRESS (true) or that of
     *                            net.java.mais.sip.PUBLIC_ADDRESS (false).
     * @return a reference to SipManager's contactHeader field.
     * @throws CommunicationsException if a ParseException occurs while initially composing the
     *                                 FromHeader.
     */
public ContactHeader getContactHeader(boolean useLocalHostAddress) throws CommunicationsException {
    if (contactHeader != null) {
        return contactHeader;
    }
    try {
        SipURI contactURI;
        if (useLocalHostAddress) {
            contactURI = addressFactory.createSipURI(null, UserCredentials.getUserDisplay() + "@" + publicIpAddress.getAddress().getHostAddress());
        } else {
            contactURI = (SipURI) addressFactory.createURI(currentlyUsedURI);
        }
        contactURI.setPort(publicIpAddress.getPort());
        Address contactAddress = addressFactory.createAddress(contactURI);
        if (displayName != null && displayName.trim().length() > 0) {
            contactAddress.setDisplayName(displayName);
        }
        contactHeader = headerFactory.createContactHeader(contactAddress);
    } catch (ParseException ex) {
        throw new CommunicationsException("A ParseException occurred while creating From Header!", ex);
    }
    return contactHeader;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) ParseException(java.text.ParseException) SipURI(javax.sip.address.SipURI) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 39 with SipURI

use of javax.sip.address.SipURI in project Openfire by igniterealtime.

the class SimpleSession method prepareNotifyRequest.

private Request prepareNotifyRequest(Dialog dialog) throws ParseException {
    if (dialog == null) {
        return null;
    }
    printDialog(dialog);
    String fromTag = dialog.getRemoteTag();
    Address fromAddress = dialog.getRemoteParty();
    SipURI destUri = (SipURI) fromAddress.getURI();
    dialog.incrementLocalSequenceNumber();
    long seqNum = dialog.getLocalSeqNumber();
    String callId = dialog.getCallId().getCallId();
    SipURI fromReqUri = null;
    Log.debug("Getting request URI from dialog");
    Address fromReqAddr = dialog.getRemoteTarget();
    if (fromReqAddr != null && fromReqAddr.getURI() != null && fromReqAddr.getURI() instanceof SipURI)
        fromReqUri = (SipURI) fromReqAddr.getURI();
    if (fromReqUri == null) {
        Log.debug("Getting request URI from destination URI");
        fromReqUri = destUri;
    }
    // Instantiate request packet
    Request notifyRequest = prepareRequest(RequestType.NOTIFY, destUri, fromTag, fromReqUri, callId, seqNum);
    //		Request notifyRequest = dialog.createRequest(Request.NOTIFY);
    ((FromHeader) notifyRequest.getHeader(FromHeader.NAME)).setTag(dialog.getLocalTag());
    // Set "subscription state" header
    SubscriptionStateHeader subscriptionStateHeader = headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE.toLowerCase());
    //		if (expires > 0) subscriptionStateHeader.setExpires(expires);
    notifyRequest.setHeader(subscriptionStateHeader);
    // Set "event" header
    notifyRequest.setHeader(headerFactory.createEventHeader("presence"));
    return notifyRequest;
}
Also used : InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI)

Example 40 with SipURI

use of javax.sip.address.SipURI in project Openfire by igniterealtime.

the class SimpleSession method prepareMessageRequest.

private Request prepareMessageRequest(MessageContent content, String destination) throws InvalidArgumentException, ParseException {
    String destUsername = destination;
    String destHost = sipHost;
    if (destination.indexOf("@") == 0 || destination.indexOf("@") == destination.length() - 1) {
        throw new InvalidArgumentException("The address provided is invalid!");
    } else if (destination.indexOf("@") > 0) {
        destUsername = destination.substring(0, destination.indexOf("@"));
        destHost = destination.substring(destination.indexOf("@") + 1);
    }
    SipURI destUri = addressFactory.createSipURI(destUsername, destHost);
    Request messageRequest = prepareRequest(RequestType.MESSAGE, destUri, null, destUri, sessionId, seqNum++);
    messageRequest.setContent(content.content, content.contentTypeHeader);
    return messageRequest;
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI)

Aggregations

SipURI (javax.sip.address.SipURI)70 ParseException (java.text.ParseException)27 Request (javax.sip.message.Request)24 Address (javax.sip.address.Address)22 InvalidArgumentException (javax.sip.InvalidArgumentException)20 ViaHeader (javax.sip.header.ViaHeader)20 SipException (javax.sip.SipException)19 ToHeader (javax.sip.header.ToHeader)18 ContactHeader (javax.sip.header.ContactHeader)17 FromHeader (javax.sip.header.FromHeader)17 Test (org.junit.Test)17 RouteHeader (javax.sip.header.RouteHeader)16 AppServer (org.mobicents.tools.sip.balancer.AppServer)16 EventListener (org.mobicents.tools.sip.balancer.EventListener)16 CSeqHeader (javax.sip.header.CSeqHeader)13 CallIdHeader (javax.sip.header.CallIdHeader)13 Header (javax.sip.header.Header)13 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)13 RecordRouteHeader (javax.sip.header.RecordRouteHeader)13 URI (javax.sip.address.URI)11