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)