JAIN SIP返回415

时间:2017-10-25 06:43:31

标签: java jain-sip

我尝试使用JAIN SIP发起呼叫。 在尝试执行代码时,我得到代码415 - 不支持的媒体类型的响应。

我从我的IP地址(使用端口5061)呼叫到另一个SIP地址。

我错过了标题吗?或者有错误的?

这是设置sip堆栈和sip提供程序的构造函数:

public SipLayer(String username, String ip, int port) throws PeerUnavailableException,
            TransportNotSupportedException, InvalidArgumentException, ObjectInUseException, TooManyListenersException {
        sipFactory = SipFactory.getInstance();
        sipFactory.setPathName("gov.nist");
        Properties properties = new Properties();
        properties.setProperty("javax.sip.STACK_NAME", "SipInitiator");
        properties.setProperty("javax.sip.IP_ADDRESS", ip);

        sipStack = sipFactory.createSipStack(properties);
        headerFactory = sipFactory.createHeaderFactory();
        addressFactory = sipFactory.createAddressFactory();
        messageFactory = sipFactory.createMessageFactory();

        ListeningPoint udp = sipStack.createListeningPoint(ip, port, "udp");
        sipProvider = sipStack.createSipProvider(udp);
        sipProvider.addSipListener(this);
    }

这是使用工厂创建请求并发送它的函数:

    public void sendMessage(String to) throws ParseException, InvalidArgumentException, SipException {

        SipURI from = addressFactory.createSipURI(getUsername(), getHost() + ":" + getPort());
        Address fromNameAddress = addressFactory.createAddress(from);
        fromNameAddress.setDisplayName(getUsername());
        FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, "sipinitiator");

        String username = to.substring(to.indexOf(":") + 1, to.indexOf("@"));
        String address = to.substring(to.indexOf("@") + 1);

        SipURI toAddress = addressFactory.createSipURI(username, address);
        Address toNameAddress = addressFactory.createAddress(toAddress);
        toNameAddress.setDisplayName(username);
        ToHeader toHeader = headerFactory.createToHeader(toNameAddress, null);

        SipURI requestURI = addressFactory.createSipURI(username, address);
        requestURI.setTransportParam("udp");

        ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
        ViaHeader viaHeader = headerFactory.createViaHeader(getHost(), getPort(), "udp", "branch1");
        viaHeaders.add(viaHeader);

        CallIdHeader callIdHeader = sipProvider.getNewCallId();

        CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L, Request.MESSAGE);

        MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);

        Request request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader,
                fromHeader, toHeader, viaHeaders, maxForwards);

        SipURI contactURI = addressFactory.createSipURI(getUsername(), getHost());
        contactURI.setPort(getPort());
        Address contactAddress = addressFactory.createAddress(contactURI);
        contactAddress.setDisplayName(getUsername());
        ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
        request.addHeader(contactHeader);

        sipProvider.sendRequest(request);
    }

(我还有SipListener函数的实现)

1 个答案:

答案 0 :(得分:0)

您缺少协商媒体设置的SDP。 415错误意味着远程端需要您为其提供有效的SDP,没有它就无法工作。如果您没有准备好RTP堆栈,请查看此示例如何提供虚假媒体设置https://github.com/usnistgov/jsip/blob/master/src/examples/simplecallsetup/Shootist.java#L348

如果你需要音频/媒体工作,你最终想要使用某种媒体堆栈来为你提供适当的有效SDP。