use of javax.sip.ListeningPoint in project XobotOS by xamarin.
the class SipHelper method createViaHeaders.
private List<ViaHeader> createViaHeaders() throws ParseException, SipException {
List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(1);
ListeningPoint lp = getListeningPoint();
ViaHeader viaHeader = mHeaderFactory.createViaHeader(lp.getIPAddress(), lp.getPort(), lp.getTransport(), null);
viaHeader.setRPort();
viaHeaders.add(viaHeader);
return viaHeaders;
}
use of javax.sip.ListeningPoint in project XobotOS by xamarin.
the class SipProviderImpl method sendResponse.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
*/
public void sendResponse(Response response) throws SipException {
if (!sipStack.isAlive())
throw new SipException("Stack is stopped");
SIPResponse sipResponse = (SIPResponse) response;
Via via = sipResponse.getTopmostVia();
if (via == null)
throw new SipException("No via header in response!");
SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage) response, true);
if (st != null && st.getState() != TransactionState.TERMINATED && this.isAutomaticDialogSupportEnabled()) {
throw new SipException("Transaction exists -- cannot send response statelessly");
}
String transport = via.getTransport();
// check to see if Via has "received paramaeter". If so
// set the host to the via parameter. Else set it to the
// Via host.
String host = via.getReceived();
if (host == null)
host = via.getHost();
// Symmetric nat support
int port = via.getRPort();
if (port == -1) {
port = via.getPort();
if (port == -1) {
if (transport.equalsIgnoreCase("TLS"))
port = 5061;
else
port = 5060;
}
}
// for correct management of IPv6 addresses.
if (host.indexOf(":") > 0)
if (host.indexOf("[") < 0)
host = "[" + host + "]";
Hop hop = sipStack.getAddressResolver().resolveAddress(new HopImpl(host, port, transport));
try {
ListeningPointImpl listeningPoint = (ListeningPointImpl) this.getListeningPoint(transport);
if (listeningPoint == null)
throw new SipException("whoopsa daisy! no listening point found for transport " + transport);
MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getListeningPoint(hop.getTransport()).getIPAddress(), listeningPoint.port, hop);
messageChannel.sendMessage(sipResponse);
} catch (IOException ex) {
throw new SipException(ex.getMessage());
}
}
use of javax.sip.ListeningPoint in project XobotOS by xamarin.
the class SipStackImpl method createListeningPoint.
/*
* (non-Javadoc)
*
* @see javax.sip.SipStack#createListeningPoint(java.lang.String, int,
* java.lang.String)
*/
public synchronized ListeningPoint createListeningPoint(String address, int port, String transport) throws TransportNotSupportedException, InvalidArgumentException {
if (isLoggingEnabled())
getStackLogger().logDebug("createListeningPoint : address = " + address + " port = " + port + " transport = " + transport);
if (address == null)
throw new NullPointerException("Address for listening point is null!");
if (transport == null)
throw new NullPointerException("null transport");
if (port <= 0)
throw new InvalidArgumentException("bad port");
if (!transport.equalsIgnoreCase("UDP") && !transport.equalsIgnoreCase("TLS") && !transport.equalsIgnoreCase("TCP") && !transport.equalsIgnoreCase("SCTP"))
throw new TransportNotSupportedException("bad transport " + transport);
/** Reusing an old stack instance */
if (!this.isAlive()) {
this.toExit = false;
this.reInitialize();
}
String key = ListeningPointImpl.makeKey(address, port, transport);
ListeningPointImpl lip = (ListeningPointImpl) listeningPoints.get(key);
if (lip != null) {
return lip;
} else {
try {
InetAddress inetAddr = InetAddress.getByName(address);
MessageProcessor messageProcessor = this.createMessageProcessor(inetAddr, port, transport);
if (this.isLoggingEnabled()) {
this.getStackLogger().logDebug("Created Message Processor: " + address + " port = " + port + " transport = " + transport);
}
lip = new ListeningPointImpl(this, port, transport);
lip.messageProcessor = messageProcessor;
messageProcessor.setListeningPoint(lip);
this.listeningPoints.put(key, lip);
// start processing messages.
messageProcessor.start();
return (ListeningPoint) lip;
} catch (java.io.IOException ex) {
if (isLoggingEnabled())
getStackLogger().logError("Invalid argument address = " + address + " port = " + port + " transport = " + transport);
throw new InvalidArgumentException(ex.getMessage(), ex);
}
}
}
use of javax.sip.ListeningPoint in project camel by apache.
the class SipPublisher method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
Properties properties = configuration.createInitialProperties();
setSipStack(configuration.getSipFactory().createSipStack(properties));
configuration.parseURI();
if (sipPublishListener == null) {
sipPublishListener = new SipPublishListener(this);
}
configuration.setListeningPoint(sipStack.createListeningPoint(configuration.getFromHost(), Integer.valueOf(configuration.getFromPort()).intValue(), configuration.getTransport()));
boolean found = false;
if (provider != null) {
for (ListeningPoint listeningPoint : provider.getListeningPoints()) {
if (listeningPoint.getIPAddress().equalsIgnoreCase(configuration.getListeningPoint().getIPAddress()) && (listeningPoint.getPort() == configuration.getListeningPoint().getPort())) {
found = true;
}
}
}
if (!found) {
provider = getSipStack().createSipProvider(configuration.getListeningPoint());
provider.addSipListener(sipPublishListener);
configuration.setCallIdHeader(provider.getNewCallId());
}
}
use of javax.sip.ListeningPoint in project camel by apache.
the class SipSubscriber method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
Properties properties = configuration.createInitialProperties();
sipStack = configuration.getSipFactory().createSipStack(properties);
configuration.parseURI();
sipSubscriptionListener = new SipSubscriptionListener(this);
ListeningPoint listeningPoint = sipStack.createListeningPoint(configuration.getFromHost(), Integer.valueOf(configuration.getFromPort()).intValue(), configuration.getTransport());
configuration.setListeningPoint(listeningPoint);
provider = sipStack.createSipProvider(configuration.getListeningPoint());
provider.addSipListener(sipSubscriptionListener);
if (configuration.getCallIdHeader() == null) {
configuration.setCallIdHeader(provider.getNewCallId());
}
// Create the Subscription request to register with the presence agent and receive notifications.
configuration.setCallIdHeader(provider.getNewCallId());
Request request = configuration.createSipRequest(1, Request.SUBSCRIBE, configuration.getEventHeaderName());
// Create the subscriber transaction from request.
ClientTransaction subscriberTransactionId = provider.getNewClientTransaction(request);
// Add an Event header for the subscription.
request.addHeader(configuration.getEventHeader());
subscriberDialog = subscriberTransactionId.getDialog();
// Send the outgoing subscription request.
subscriberTransactionId.sendRequest();
}
Aggregations