use of javax.sip.InvalidArgumentException in project Openfire by igniterealtime.
the class SipTPCCallAgent method initiateCall.
/*
* Begin Third-Party Call Control.
*/
public void initiateCall() throws IOException {
try {
try {
busyTreatment = new TreatmentManager("busy.au", 0);
} catch (IOException e) {
Logger.println("Invalid busy treatment: " + e.getMessage());
}
Logger.writeFile("Call " + cp + ": Begin SIP third party call");
setState(CallState.INVITED);
InetSocketAddress isa = callHandler.getReceiveAddress();
if (isa == null) {
throw new IOException("can't get receiver socket!");
}
// send INVITE to the CallParticipant
clientTransaction = sipUtil.sendInvite(cp, isa);
if (clientTransaction == null) {
Logger.error("Error placing call: " + cp);
setState(CallState.ENDED, "Reason='Error placing call'");
throw new IOException("Error placing call: " + cp);
}
CallIdHeader callIdHeader = (CallIdHeader) clientTransaction.getRequest().getHeader(CallIdHeader.NAME);
sipCallId = callIdHeader.getCallId();
sipServerCallback = SipServer.getSipServerCallback();
sipServerCallback.addSipListener(sipCallId, this);
} catch (java.text.ParseException e) {
Logger.println("Call " + cp + " Error placing call " + cp + ": " + e.getMessage());
setState(CallState.ENDED, "Reason='Error placing call " + cp + " " + e.getMessage() + "'");
throw new IOException("Error placing call " + cp + " " + e.getMessage());
} catch (InvalidArgumentException e) {
Logger.println("Call " + cp + " Error placing call " + cp + ": " + e.getMessage());
setState(CallState.ENDED, "Reason='Error placing call " + cp + " " + e.getMessage() + "'");
throw new IOException("Error placing call " + cp + " " + e.getMessage());
} catch (SipException e) {
Logger.println("Call " + cp + " Error placing call " + cp + ": " + e.getMessage());
setState(CallState.ENDED, "Reason='Error placing call " + cp + " " + e.getMessage() + "'");
throw new IOException("Error placing call " + cp + " " + e.getMessage());
}
}
use of javax.sip.InvalidArgumentException in project Openfire by igniterealtime.
the class SimpleSession method sendNotify.
public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
Request notifyRequest = prepareNotifyRequest(dialog);
try {
User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
String presenceContent;
SimplePresence simplePresence = new SimplePresence();
simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
simplePresence.setDmNote(myPresence.getStatus());
if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
else {
simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
if (myPresence.getShow() != null) {
switch(myPresence.getShow()) {
case away:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
case dnd:
simplePresence.setRpid(SimplePresence.Rpid.BUSY);
break;
case xa:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
default:
break;
}
}
}
presenceContent = simplePresence.toXML();
ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
notifyRequest.setContent(presenceContent, contentTypeHeader);
} catch (Exception e) {
Log.debug("Unable to include presence details in the packet.", e);
}
sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
use of javax.sip.InvalidArgumentException in project Openfire by igniterealtime.
the class SimpleSession method prepareMessageRequest.
private Request prepareMessageRequest(MessageContent content, String destination) throws InvalidArgumentException, ParseException {
String destUsername = destination;
String destHost = sipHost;
if (destination.indexOf("@") == 0 || destination.indexOf("@") == destination.length() - 1) {
throw new InvalidArgumentException("The address provided is invalid!");
} else if (destination.indexOf("@") > 0) {
destUsername = destination.substring(0, destination.indexOf("@"));
destHost = destination.substring(destination.indexOf("@") + 1);
}
SipURI destUri = addressFactory.createSipURI(destUsername, destHost);
Request messageRequest = prepareRequest(RequestType.MESSAGE, destUri, null, destUri, sessionId, seqNum++);
messageRequest.setContent(content.content, content.contentTypeHeader);
return messageRequest;
}
use of javax.sip.InvalidArgumentException in project XobotOS by xamarin.
the class SIPDialog method createRequest.
/**
* The method that actually does the work of creating a request.
*
* @param method
* @param response
* @return
* @throws SipException
*/
private Request createRequest(String method, SIPResponse sipResponse) throws SipException {
if (method == null || sipResponse == null)
throw new NullPointerException("null argument");
if (method.equals(Request.CANCEL))
throw new SipException("Dialog.createRequest(): Invalid request");
if (this.getState() == null || (this.getState().getValue() == TERMINATED_STATE && !method.equalsIgnoreCase(Request.BYE)) || (this.isServer() && this.getState().getValue() == EARLY_STATE && method.equalsIgnoreCase(Request.BYE)))
throw new SipException("Dialog " + getDialogId() + " not yet established or terminated " + this.getState());
SipUri sipUri = null;
if (this.getRemoteTarget() != null)
sipUri = (SipUri) this.getRemoteTarget().getURI().clone();
else {
sipUri = (SipUri) this.getRemoteParty().getURI().clone();
sipUri.clearUriParms();
}
CSeq cseq = new CSeq();
try {
cseq.setMethod(method);
cseq.setSeqNumber(this.getLocalSeqNumber());
} catch (Exception ex) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("Unexpected error");
InternalErrorHandler.handleException(ex);
}
/*
* Add a via header for the outbound request based on the transport of the message
* processor.
*/
ListeningPointImpl lp = (ListeningPointImpl) this.sipProvider.getListeningPoint(sipResponse.getTopmostVia().getTransport());
if (lp == null) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
throw new SipException("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
}
Via via = lp.getViaHeader();
From from = new From();
from.setAddress(this.localParty);
To to = new To();
to.setAddress(this.remoteParty);
SIPRequest sipRequest = sipResponse.createRequest(sipUri, via, cseq, from, to);
if (SIPRequest.isTargetRefresh(method)) {
ContactHeader contactHeader = ((ListeningPointImpl) this.sipProvider.getListeningPoint(lp.getTransport())).createContactHeader();
((SipURI) contactHeader.getAddress().getURI()).setSecure(this.isSecure());
sipRequest.setHeader(contactHeader);
}
try {
/*
* Guess of local sequence number - this is being re-set when the request is actually
* dispatched
*/
cseq = (CSeq) sipRequest.getCSeq();
cseq.setSeqNumber(this.localSequenceNumber + 1);
} catch (InvalidArgumentException ex) {
InternalErrorHandler.handleException(ex);
}
if (method.equals(Request.SUBSCRIBE)) {
if (eventHeader != null)
sipRequest.addHeader(eventHeader);
}
try {
if (this.getLocalTag() != null) {
from.setTag(this.getLocalTag());
} else {
from.removeTag();
}
if (this.getRemoteTag() != null) {
to.setTag(this.getRemoteTag());
} else {
to.removeTag();
}
} catch (ParseException ex) {
InternalErrorHandler.handleException(ex);
}
// get the route list from the dialog.
this.updateRequest(sipRequest);
return sipRequest;
}
use of javax.sip.InvalidArgumentException in project XobotOS by xamarin.
the class SIPDialog method createReliableProvisionalResponse.
/*
* (non-Javadoc)
*
* @see javax.sip.Dialog#createReliableProvisionalResponse(int)
*/
public Response createReliableProvisionalResponse(int statusCode) throws InvalidArgumentException, SipException {
if (!(firstTransactionIsServerTransaction)) {
throw new SipException("Not a Server Dialog!");
}
/*
* A UAS MUST NOT attempt to send a 100 (Trying) response reliably. Only provisional
* responses numbered 101 to 199 may be sent reliably. If the request did not include
* either a Supported or Require header field indicating this feature, the UAS MUST NOT
* send the provisional response reliably.
*/
if (statusCode <= 100 || statusCode > 199)
throw new InvalidArgumentException("Bad status code ");
SIPRequest request = this.originalRequest;
if (!request.getMethod().equals(Request.INVITE))
throw new SipException("Bad method");
ListIterator<SIPHeader> list = request.getHeaders(SupportedHeader.NAME);
if (list == null || !optionPresent(list, "100rel")) {
list = request.getHeaders(RequireHeader.NAME);
if (list == null || !optionPresent(list, "100rel")) {
throw new SipException("No Supported/Require 100rel header in the request");
}
}
SIPResponse response = request.createResponse(statusCode);
/*
* The provisional response to be sent reliably is constructed by the UAS core according
* to the procedures of Section 8.2.6 of RFC 3261. In addition, it MUST contain a Require
* header field containing the option tag 100rel, and MUST include an RSeq header field.
* The value of the header field for the first reliable provisional response in a
* transaction MUST be between 1 and 2**31 - 1. It is RECOMMENDED that it be chosen
* uniformly in this range. The RSeq numbering space is within a single transaction. This
* means that provisional responses for different requests MAY use the same values for the
* RSeq number.
*/
Require require = new Require();
try {
require.setOptionTag("100rel");
} catch (Exception ex) {
InternalErrorHandler.handleException(ex);
}
response.addHeader(require);
RSeq rseq = new RSeq();
/*
* set an arbitrary sequence number. This is actually set when the response is sent out
*/
rseq.setSeqNumber(1L);
/*
* Copy the record route headers from the request to the response ( Issue 160 ). Note that
* other 1xx headers do not get their Record Route headers copied over but reliable
* provisional responses do. See RFC 3262 Table 2.
*/
RecordRouteList rrl = request.getRecordRouteHeaders();
if (rrl != null) {
RecordRouteList rrlclone = (RecordRouteList) rrl.clone();
response.setHeader(rrlclone);
}
return response;
}
Aggregations