Java源码示例:javax.sip.address.URI

示例1
/**
 * Retrieves the SIP address.
 * @return the SIP address
 * @throws SipException
 *         if the specified SIP address is not valid
 */
private Address getAddress() throws SipException {
    if (address == null) {
        URI uri;
        try {
            uri = addressFactory.createURI(sipAddress);
        } catch (ParseException e) {
            throw new SipException(e.getMessage(), e);
        }
        if (uri.isSipURI() == false) {
            throw new SipException("Invalid sip uri: " + sipAddress);
        }
        address = addressFactory.createAddress(uri);
    }
    return address;
}
 
示例2
/**
 * Retrieves the contact address.
 * @return the contact address
 * @throws SipException
 *         error creating the contact address
 */
private Address getContactAddress() throws SipException {
    if (contactAddress == null) {
        final Address address = getAddress();
        final URI uri = address.getURI();
        final SipURI sipUri = (SipURI) uri;
        final String user = sipUri.getUser();
        try {
            final String host = stack.getIPAddress();
            final SipURI contactUri = addressFactory.createSipURI(user, host);
            contactUri.setPort(udp.getPort());
            contactUri.setTransportParam("udp");
            contactAddress = addressFactory.createAddress(contactUri);
        } catch (ParseException e) {
            throw new SipException("Could not create contact URI.", e);
        }
    }
    return contactAddress;
}
 
示例3
/**
 * Returns a human readable name representing this peer.
 *
 * @return a String containing a name for that peer.
 */
public String getDisplayName()
{
    String displayName = getPeerAddress().getDisplayName();

    if(displayName == null)
    {
        Contact contact = getContact();

        if (contact != null)
            displayName = contact.getDisplayName();
        else
        {
            URI peerURI = getPeerAddress().getURI();
            if (peerURI instanceof SipURI)
            {
                String userName = ((SipURI) peerURI).getUser();

                if (userName != null && userName.length() > 0)
                    displayName = userName;
            }

            if (displayName == null)
            {
                displayName = peerURI.toString();
            }
        }
    }

    if(displayName.startsWith("sip:"))
        displayName = displayName.substring(4);

    return displayName;
}
 
示例4
public String getRemoteName() {
    Address address;
    if (dialog.getState() != null) {
        address = dialog.getRemoteParty();
    }
    else {
        if (dialog.isServer()) {
            FromHeader fromHeader = (FromHeader)initialRequest
                    .getHeader(FromHeader.NAME);
            address = fromHeader.getAddress();
        }
        else {
            ToHeader toHeader = (ToHeader)initialRequest
                    .getHeader(ToHeader.NAME);
            address = toHeader.getAddress();
        }
    }
    String retVal = null;
    if (address.getDisplayName() != null
            && address.getDisplayName().trim().length() > 0) {
        retVal = address.getDisplayName();
    }
    else {
        URI uri = address.getURI();
        if (uri.isSipURI()) {
            retVal = ((SipURI)uri).getUser();
        }
    }
    return retVal == null ? "" : retVal;
}
 
示例5
/**
 * Returns the <tt>ReplacesHeader</tt> contained, if any, in the
 * <tt>URI</tt> of a specific <tt>Address</tt> after removing it
 * from there.
 *
 * @param address the <tt>Address</tt> which is to have its <tt>URI</tt>
 * examined and modified
 *
 * @return a <tt>Header</tt> which represents the Replaces header contained
 * in the <tt>URI</tt> of the specified <tt>address</tt>; <tt>null</tt> if
 * no such header is present
 *
 * @throws OperationFailedException if we can't parse the replaces header.
 */
private Header stripReplacesHeader( Address address )
    throws OperationFailedException
{
    javax.sip.address.URI uri = address.getURI();
    Header replacesHeader = null;

    if (uri.isSipURI())
    {
        SipURI sipURI = (SipURI) uri;
        String replacesHeaderValue = sipURI.getHeader(ReplacesHeader.NAME);

        if (replacesHeaderValue != null)
        {
            for (Iterator<?> headerNameIter = sipURI.getHeaderNames();
                    headerNameIter.hasNext();)
            {
                if (ReplacesHeader.NAME.equals(headerNameIter.next()))
                {
                    headerNameIter.remove();
                    break;
                }
            }

            try
            {
                replacesHeader = protocolProvider.getHeaderFactory()
                    .createHeader(ReplacesHeader.NAME,
                       URLDecoder.decode(replacesHeaderValue, "UTF-8"));
            }
            catch (Exception ex)
            {
                //ParseException, EncodingNotSupportedException.
                throw new OperationFailedException(
                    "Failed to create ReplacesHeader from "
                        + replacesHeaderValue,
                    OperationFailedException.INTERNAL_ERROR, ex);
            }
        }
    }
    return replacesHeader;
}
 
示例6
/**
 * Calls the same method in the internal wrapped factory
 * and returns a <tt>Request</tt> marked with its service.
 *
 * @param requestURI the new URI object of the requestURI value of this
 * <tt>Message</tt>.
 * @param method the new string of the method value of this
 * <tt>Message</tt>.
 * @param callId the new CallIdHeader object of the callId value of this
 * <tt>Message</tt>.
 * @param cSeq the new CSeqHeader object of the cSeq value of this
 * <tt>Message</tt>.
 * @param from the new FromHeader object of the from value of this
 * <tt>Message</tt>.
 * @param to the new ToHeader object of the to value of this
 * <tt>Message</tt>.
 * @param via the new List object of the ViaHeaders of this
 * <tt>Message</tt>.
 * @param maxForwards the Max-Forwards header for the new <tt>Request</tt>.
 * @param contentType the new ContentTypeHeader object of the content type
 * value of this <tt>Message</tt>.
 * @param content the new Object of the body content value of this Message.
 *
 * @return a <tt>Request</tt> marked with its service
 *
 * @throws ParseException which signals that an error has been reached
 * unexpectedly while parsing the method or the body.
 */
public Request createRequest(URI requestURI, String method, CallIdHeader
        callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via,
            MaxForwardsHeader maxForwards, ContentTypeHeader contentType,
            Object content)
    throws ParseException
{
    Request request = this.wrappedFactory.createRequest(requestURI, method,
            callId, cSeq, from, to, via, maxForwards, contentType, content);
    return (Request)attachScSpecifics(request);
}
 
示例7
/**
 * Calls the same method in the internal wrapped factory
 * and returns a <tt>Request</tt> marked with its service.
 *
 * @param requestURI the new URI object of the requestURI value of this
 * <tt>Message</tt>.
 * @param method the new string of the method value of this
 * <tt>Message</tt>.
 * @param callId the new CallIdHeader object of the callId value of this
 * <tt>Message</tt>.
 * @param cSeq the new CSeqHeader object of the cSeq value of this
 * <tt>Message</tt>.
 * @param from the new FromHeader object of the from value of this
 * <tt>Message</tt>.
 * @param to the new ToHeader object of the to value of this
 * <tt>Message</tt>.
 * @param via the new List object of the ViaHeaders of this
 * <tt>Message</tt>.
 * @param maxForwards the Max-Forwards header for the new <tt>Request</tt>.
 * @param contentType the new ContentTypeHeader object of the content type
 * value of this <tt>Message</tt>.
 * @param content the new Object of the body content value of this Message.
 *
 * @return a <tt>Request</tt> marked with its service
 *
 * @throws ParseException which signals that an error has been reached
 * unexpectedly while parsing the method or the body.
 */
public Request createRequest(URI requestURI, String method, CallIdHeader
        callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via,
            MaxForwardsHeader maxForwards, ContentTypeHeader contentType,
            byte[] content)
    throws ParseException
{
    Request request = this.wrappedFactory.createRequest(requestURI, method,
            callId, cSeq, from, to, via, maxForwards, contentType, content);
    return (Request)attachScSpecifics(request);
}
 
示例8
/**
 * Calls the same method in the internal wrapped factory
 * and returns a <tt>Request</tt> marked with its service.
 *
 * @param requestURI the new URI object of the requestURI value of this
 * <tt>Message</tt>.
 * @param method the new string of the method value of this
 * <tt>Message</tt>.
 * @param callId the new CallIdHeader object of the callId value of this
 * <tt>Message</tt>.
 * @param cSeq the new CSeqHeader object of the cSeq value of this
 * <tt>Message</tt>.
 * @param from the new FromHeader object of the from value of this
 * <tt>Message</tt>.
 * @param to the new ToHeader object of the to value of this
 * <tt>Message</tt>.
 * @param via the new List object of the ViaHeaders of this
 * <tt>Message</tt>.
 * @param maxForwards the Max-Forwards header for the new <tt>Request</tt>.
 *
 * @return a <tt>Request</tt> marked with its service
 *
 * @throws ParseException which signals that an error has been reached
 * unexpectedly while parsing the method or the body.
 */
public Request createRequest(URI requestURI, String method, CallIdHeader
        callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via,
            MaxForwardsHeader maxForwards)
    throws ParseException
{
    Request request = this.wrappedFactory.createRequest(requestURI, method,
            callId, cSeq, from, to, via, maxForwards);
    return (Request)attachScSpecifics(request);
}