Search in sources :

Example 1 with ContentTypeHeader

use of javax.sip.header.ContentTypeHeader in project Openfire by igniterealtime.

the class SimpleSession method sendMessage.

/**
     * @see net.sf.kraken.session.TransportSession#sendMessage(org.xmpp.packet.JID, String)
     */
@Override
public void sendMessage(JID jid, String message) {
    Log.debug("SimpleSession(" + jid.getNode() + "):  Starting message sending process.");
    ContentTypeHeader contentTypeHeader;
    try {
        contentTypeHeader = headerFactory.createContentTypeHeader("text", "plain");
    } catch (Exception e) {
        Log.debug("SimpleSession(" + jid.getNode() + ").sendMessage:  Unable to initiate ContentType header.", e);
        return;
    }
    Log.debug("SimpleSession(" + jid.getNode() + "):  Finished adding ContentType header.");
    MessageContent content = new MessageContent(contentTypeHeader, message);
    try {
        Request request = prepareMessageRequest(content, getTransport().convertJIDToID(jid));
        sendRequest(request, ListeningPoint.UDP);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + jid.getNode() + ").sendMessage:  Unable to send message.", e);
    }
//		if (!prepareRequest(RequestType.MESSAGE, ((SimpleTransport) transport).convertJIDToID(jid), null, null, 1L, 70, null, content)) {
//			Log.debug("SimpleSession(" + this.jid.getNode() + ").sendMessage:  Unable to send message!");
//		}
}
Also used : ContentTypeHeader(javax.sip.header.ContentTypeHeader) Request(javax.sip.message.Request) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 2 with ContentTypeHeader

use of javax.sip.header.ContentTypeHeader in project XobotOS by xamarin.

the class MessageChannel method createBadReqRes.

/**
     * Creates a response to a bad request (ie one that causes a ParseException)
     * 
     * @param badReq
     * @return message bytes, null if unable to formulate response
     */
protected final String createBadReqRes(String badReq, ParseException pe) {
    StringBuffer buf = new StringBuffer(512);
    buf.append("SIP/2.0 400 Bad Request (" + pe.getLocalizedMessage() + ')');
    // We need the following headers: all Vias, CSeq, Call-ID, From, To
    if (!copyViaHeaders(badReq, buf))
        return null;
    if (!copyHeader(CSeqHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(CallIdHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(FromHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(ToHeader.NAME, badReq, buf))
        return null;
    // Should add a to-tag if not already present...
    int toStart = buf.indexOf(ToHeader.NAME);
    if (toStart != -1 && buf.indexOf("tag", toStart) == -1) {
        buf.append(";tag=badreq");
    }
    // Let's add a Server header too..
    ServerHeader s = MessageFactoryImpl.getDefaultServerHeader();
    if (s != null) {
        buf.append("\r\n" + s.toString());
    }
    int clength = badReq.length();
    if (!(this instanceof UDPMessageChannel) || clength + buf.length() + ContentTypeHeader.NAME.length() + ": message/sipfrag\r\n".length() + ContentLengthHeader.NAME.length() < 1300) {
        /*
             * Check to see we are within one UDP packet.
             */
        ContentTypeHeader cth = new ContentType("message", "sipfrag");
        buf.append("\r\n" + cth.toString());
        ContentLength clengthHeader = new ContentLength(clength);
        buf.append("\r\n" + clengthHeader.toString());
        buf.append("\r\n\r\n" + badReq);
    } else {
        ContentLength clengthHeader = new ContentLength(0);
        buf.append("\r\n" + clengthHeader.toString());
    }
    return buf.toString();
}
Also used : ContentType(gov.nist.javax.sip.header.ContentType) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ServerHeader(javax.sip.header.ServerHeader) ContentLength(gov.nist.javax.sip.header.ContentLength)

Example 3 with ContentTypeHeader

use of javax.sip.header.ContentTypeHeader in project Openfire by igniterealtime.

the class SimpleSession method sendNotify.

public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
    Request notifyRequest = prepareNotifyRequest(dialog);
    try {
        User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
        Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
        String presenceContent;
        SimplePresence simplePresence = new SimplePresence();
        simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
        simplePresence.setDmNote(myPresence.getStatus());
        if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
        else {
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
            if (myPresence.getShow() != null) {
                switch(myPresence.getShow()) {
                    case away:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    case dnd:
                        simplePresence.setRpid(SimplePresence.Rpid.BUSY);
                        break;
                    case xa:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    default:
                        break;
                }
            }
        }
        presenceContent = simplePresence.toXML();
        ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
        notifyRequest.setContent(presenceContent, contentTypeHeader);
    } catch (Exception e) {
        Log.debug("Unable to include presence details in the packet.", e);
    }
    sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
Also used : User(org.jivesoftware.openfire.user.User) ContentTypeHeader(javax.sip.header.ContentTypeHeader) Request(javax.sip.message.Request) Presence(org.xmpp.packet.Presence) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 4 with ContentTypeHeader

use of javax.sip.header.ContentTypeHeader in project XobotOS by xamarin.

the class MultipartMimeContentImpl method createContentList.

/**
     * unpack a multipart mime packet and return a list of content packets.
     * 
     * @return -- an iterator of Content blocks.
     * 
     */
public void createContentList(String body) throws ParseException {
    try {
        HeaderFactoryExt headerFactory = new HeaderFactoryImpl();
        String delimiter = this.getContentTypeHeader().getParameter(BOUNDARY);
        if (delimiter == null) {
            this.contentList = new LinkedList<Content>();
            ContentImpl content = new ContentImpl(body, delimiter);
            content.setContentTypeHeader(this.getContentTypeHeader());
            this.contentList.add(content);
            return;
        }
        String[] fragments = body.split("--" + delimiter + "\r\n");
        for (String nextPart : fragments) {
            if (nextPart == null) {
                return;
            }
            StringBuffer strbuf = new StringBuffer(nextPart);
            while (strbuf.length() > 0 && (strbuf.charAt(0) == '\r' || strbuf.charAt(0) == '\n')) strbuf.deleteCharAt(0);
            if (strbuf.length() == 0)
                continue;
            nextPart = strbuf.toString();
            int position = nextPart.indexOf("\r\n\r\n");
            int off = 4;
            if (position == -1) {
                position = nextPart.indexOf("\n");
                off = 2;
            }
            if (position == -1)
                throw new ParseException("no content type header found in " + nextPart, 0);
            String rest = nextPart.substring(position + off);
            if (rest == null)
                throw new ParseException("No content [" + nextPart + "]", 0);
            // logger.debug("rest = [[" + rest + "]]");
            String headers = nextPart.substring(0, position);
            ContentImpl content = new ContentImpl(rest, boundary);
            String[] headerArray = headers.split("\r\n");
            for (String hdr : headerArray) {
                Header header = headerFactory.createHeader(hdr);
                if (header instanceof ContentTypeHeader) {
                    content.setContentTypeHeader((ContentTypeHeader) header);
                } else if (header instanceof ContentDispositionHeader) {
                    content.setContentDispositionHeader((ContentDispositionHeader) header);
                } else {
                    throw new ParseException("Unexpected header type " + header.getName(), 0);
                }
                contentList.add(content);
            }
        }
    } catch (StringIndexOutOfBoundsException ex) {
        throw new ParseException("Invalid Multipart mime format", 0);
    }
}
Also used : ContentTypeHeader(javax.sip.header.ContentTypeHeader) HeaderFactoryExt(gov.nist.javax.sip.header.HeaderFactoryExt) ContentDispositionHeader(javax.sip.header.ContentDispositionHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) Header(javax.sip.header.Header) HeaderFactoryImpl(gov.nist.javax.sip.header.HeaderFactoryImpl) ContentDispositionHeader(javax.sip.header.ContentDispositionHeader) ParseException(java.text.ParseException)

Aggregations

ContentTypeHeader (javax.sip.header.ContentTypeHeader)4 ParseException (java.text.ParseException)3 TooManyListenersException (java.util.TooManyListenersException)2 InvalidArgumentException (javax.sip.InvalidArgumentException)2 SipException (javax.sip.SipException)2 Request (javax.sip.message.Request)2 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2 NotFoundException (org.jivesoftware.util.NotFoundException)2 ContentLength (gov.nist.javax.sip.header.ContentLength)1 ContentType (gov.nist.javax.sip.header.ContentType)1 HeaderFactoryExt (gov.nist.javax.sip.header.HeaderFactoryExt)1 HeaderFactoryImpl (gov.nist.javax.sip.header.HeaderFactoryImpl)1 ContentDispositionHeader (javax.sip.header.ContentDispositionHeader)1 Header (javax.sip.header.Header)1 ServerHeader (javax.sip.header.ServerHeader)1 User (org.jivesoftware.openfire.user.User)1 Presence (org.xmpp.packet.Presence)1