0

I'm trying to use JAIN SIP to initiate a call. When trying to execute the code I get a response with code 415 - Unsupported Media Type.

I'm calling from my ip address (using port 5061) to a different sip address.

Am I missing headers? Or have wrong ones?

This is the constructor that sets up the sip stack and sip provider:

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)

tal weissler
  • 177
  • 1
  • 9

1 Answers1

0

You are missing the SDP which negotiates the media settings. The 415 error means the remote side needs you to give it a valid SDP and will not work without it. 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

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.

Vladimir Ralev
  • 1,371
  • 9
  • 18
  • I've added a fake SDP as shown in the example you've mentioned (changed the ip to my ip), but am still getting 415. Any idea why? – tal weissler Oct 25 '17 at 12:19
  • Make sure you include the contentTypeHeader as shown in the example. Otherwise that's unusual. If it keeps giving the error, you need to examine your remote party's debug logs to see why they send the error, may be it only accepts certain rare formats. You may also capture known compatible SDP if you have a device that works, simply copy and paste that SDP. – Vladimir Ralev Oct 25 '17 at 12:54
  • Added contentTypeHeader and now it works. thank you! – tal weissler Oct 26 '17 at 11:44