简体   繁体   English

JAIN SIP返回415

[英]JAIN SIP returns 415

I'm trying to use JAIN SIP to initiate a call. 我正在尝试使用JAIN SIP发起呼叫。 When trying to execute the code I get a response with code 415 - Unsupported Media Type. 尝试执行代码时,我收到代码415-不支持的媒体类型的响应。

I'm calling from my ip address (using port 5061) to a different sip address. 我正在从我的IP地址(使用端口5061)呼叫另一个SIP地址。

Am I missing headers? 我是否缺少标题? Or have wrong ones? 还是有错的?

This is the constructor that sets up the sip stack and sip provider: 这是设置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);
    }

This is the function that uses the factories to create the request and sends it: 这是使用工厂创建请求并发送请求的函数:

    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);
    }

(I also have the Implementation to the SipListener functions) (我也有SipListener函数的实现)

You are missing the SDP which negotiates the media settings. 您缺少协商媒体设置的SDP。 The 415 error means the remote side needs you to give it a valid SDP and will not work without it. 415错误表示远程端需要您提供有效的SDP,否则将无法正常工作。 Take a look at this example how to provide fake media settings if you don't have an RTP stack ready https://github.com/usnistgov/jsip/blob/master/src/examples/simplecallsetup/Shootist.java#L348 看一下这个示例,如果您尚未准备好RTP堆栈,如何提供伪造的媒体设置https://github.com/usnistgov/jsip/blob/master/src/examples/simplecallsetup/Shootist.java#L348

If you need the audio/media to work you ultimately want to use some kind of media stack that will give you proper valid SDP. 如果您需要音频/媒体来工作,则最终希望使用某种可以为您提供适当有效SDP的媒体堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM