javax.sip.SipFactory Java Examples

The following examples show how to use javax.sip.SipFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MsgSip.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * decode the message from binary data
 */
@Override
public void decode(byte[] data) throws Exception {
    MessageFactory messageFactory = SipFactory.getInstance().createMessageFactory();
    String text = new String(data);
    if (text.startsWith("SIP/")) {
        sipMessage = (SIPResponse) messageFactory.createResponse(text);
    } else {
        sipMessage = (SIPMessage) messageFactory.createRequest(text);
    }
}
 
Example #2
Source File: MsgSip.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parse the message from XML element
 */
@Override
public void parseFromXml(ParseFromXmlContext context, Element root, Runner runner) throws Exception {
    Debug.debug = true;
    Debug.parserDebug = true;
    super.parseFromXml(context, root, runner);
    String text = root.getText().trim().replace("\r\n", "\n").replace("\n", "\r\n");
    MessageFactory messageFactory = SipFactory.getInstance().createMessageFactory();

    GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.CORE, "before replace\n", text);
    text = text.replaceAll("(Content-Length[ ]*:[ ]*)[xX]", "$1 1");

    // if there is a content we might need to add CRLF at the end for the parser
    if (text.contains("\r\n\r\n")) {
        // if the stack option is activated
        if (((StackSipCommon) stack).addCRLFContent == 1) {
            text += "\r\n";
        }
    } // if there is no content, add CRLF at the end (the parser needs it)
    else {
        text += "\r\n";
    }

    GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.CORE, "before parsing\n", text);
    if (text.startsWith("SIP/")) {
        sipMessage = (SIPResponse) messageFactory.createResponse(text);
    } else {
        sipMessage = (SIPMessage) messageFactory.createRequest(text);
    }

    sipMessage.getUnrecognizedHeaders().forEachRemaining(s -> GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.CORE, "Unrecognised header : ", s));
}