use of org.jivesoftware.openfire.sip.tester.comm.CommunicationsException in project Openfire by igniterealtime.
the class SipManager method main.
public static void main(String[] args) {
SIPConfig.setRegistrarAddress("apollo");
SIPConfig.setAuthenticationRealm("apollo");
SIPConfig.setDefaultDomain("apollo");
InetAddress address = null;
try {
address = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
SipManager sipManager = new SipManager(address);
try {
sipManager.start();
} catch (CommunicationsException e) {
e.printStackTrace();
}
try {
sipManager.startRegisterProcess("7512", "7512", "7512");
} catch (CommunicationsException e) {
e.printStackTrace();
}
try {
sipManager.unregister();
} catch (CommunicationsException e) {
e.printStackTrace();
}
}
use of org.jivesoftware.openfire.sip.tester.comm.CommunicationsException in project Openfire by igniterealtime.
the class SipManager method sendNotImplemented.
/**
* Sends a NOT_IMPLEMENTED response through the specified transaction.
*
* @param serverTransaction the transaction to send the response through.
* @param request the request that is being answered.
*/
void sendNotImplemented(ServerTransaction serverTransaction, Request request) {
Response notImplemented;
try {
notImplemented = messageFactory.createResponse(Response.NOT_IMPLEMENTED, request);
attachToTag(notImplemented, serverTransaction.getDialog());
} catch (ParseException ex) {
fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
return;
}
try {
serverTransaction.sendResponse(notImplemented);
} catch (SipException ex) {
fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
}
}
use of org.jivesoftware.openfire.sip.tester.comm.CommunicationsException in project Openfire by igniterealtime.
the class SipManager method getLocalViaHeaders.
/**
* Initializes (if null) and returns an ArrayList with a single ViaHeader
* containing localhost's address. This ArrayList may be used when sending
* requests.
*
* @return ViaHeader-s list to be used when sending requests.
* @throws CommunicationsException if a ParseException is to occur while initializing the array
* list.
*/
public ArrayList<ViaHeader> getLocalViaHeaders() throws CommunicationsException {
if (viaHeaders != null) {
return viaHeaders;
}
ListeningPoint lp = sipProvider.getListeningPoint();
viaHeaders = new ArrayList<ViaHeader>();
try {
ViaHeader viaHeader = headerFactory.createViaHeader(SIPConfig.getIPAddress(), lp.getPort(), lp.getTransport(), null);
viaHeader.setParameter("rport", null);
viaHeaders.add(viaHeader);
return viaHeaders;
} catch (ParseException ex) {
throw new CommunicationsException("A ParseException occurred while creating Via Headers!");
} catch (InvalidArgumentException ex) {
throw new CommunicationsException("Unable to create a via header for port " + lp.getPort(), ex);
}
}
use of org.jivesoftware.openfire.sip.tester.comm.CommunicationsException in project Openfire by igniterealtime.
the class SipManager method getContactHeader.
/**
* Initialises SipManager's contactHeader field in accordance with
* javax.sip.IP_ADDRESS net.java.mais.sip.DISPLAY_NAME
* net.java.mais.sip.TRANSPORT net.java.mais.sip.PREFERRED_LOCAL_PORT and
* returns a reference to it.
*
* @param useLocalHostAddress specifies whether the SipURI in the contact header should
* contain the value of javax.sip.IP_ADDRESS (true) or that of
* net.java.mais.sip.PUBLIC_ADDRESS (false).
* @return a reference to SipManager's contactHeader field.
* @throws CommunicationsException if a ParseException occurs while initially composing the
* FromHeader.
*/
public ContactHeader getContactHeader(boolean useLocalHostAddress) throws CommunicationsException {
if (contactHeader != null) {
return contactHeader;
}
try {
SipURI contactURI;
if (useLocalHostAddress) {
contactURI = addressFactory.createSipURI(null, UserCredentials.getUserDisplay() + "@" + publicIpAddress.getAddress().getHostAddress());
} else {
contactURI = (SipURI) addressFactory.createURI(currentlyUsedURI);
}
contactURI.setPort(publicIpAddress.getPort());
Address contactAddress = addressFactory.createAddress(contactURI);
if (displayName != null && displayName.trim().length() > 0) {
contactAddress.setDisplayName(displayName);
}
contactHeader = headerFactory.createContactHeader(contactAddress);
} catch (ParseException ex) {
throw new CommunicationsException("A ParseException occurred while creating From Header!", ex);
}
return contactHeader;
}
use of org.jivesoftware.openfire.sip.tester.comm.CommunicationsException in project Openfire by igniterealtime.
the class SipManager method startRegisterProcess.
public void startRegisterProcess(String userName, String authUserName, String password) throws CommunicationsException {
try {
checkIfStarted();
// Obtain initial credentials
String realm = SIPConfig.getAuthenticationRealm();
realm = realm == null ? "" : realm;
// put the returned user name in the properties file
// so that it appears as a default one next time user is prompted
// for pass
SIPConfig.setUserName(userName);
SIPConfig.setAuthUserName(authUserName);
UserCredentials initialCredentials = new UserCredentials();
initialCredentials.setUserName(userName);
initialCredentials.setAuthUserName(authUserName);
initialCredentials.setPassword(password.toCharArray());
register(initialCredentials.getUserName() + "@" + realm);
// at this point a simple register request has been sent and the
// global
// from header in SipManager has been set to a valid value by the
// RegisterProcesing
// class. Use it to extract the valid user name that needs to be
// cached by
// the security manager together with the user provided password.
initialCredentials.setUserName(((SipURI) getFromHeader().getAddress().getURI()).getUser());
// JOptionPane.showMessageDialog(null,( (SipURI)
// getFromHeader().getAddress().getURI()).getUser());
cacheCredentials(realm, initialCredentials);
} catch (Exception ee) {
Log.error("startRegisterProcess", ee);
}
}
Aggregations