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!");
// }
}
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();
}
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);
}
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);
}
}
Aggregations