📄 callprocessing.java.svn-base
字号:
}
}
catch (SipException ex) {
throw new CommunicationsException(
"Failed to create bye request!", ex);
}
ClientTransaction clientTransaction = null;
try {
clientTransaction = sipManCallback.sipProvider
.getNewClientTransaction(info);
}
catch (TransactionUnavailableException ex) {
throw new CommunicationsException(
"Failed to construct a client transaction from the INFO request",
ex);
}
try {
dialog.sendRequest(clientTransaction);
}
catch (SipException ex1) {
throw new CommunicationsException(
"Failed to send the INFO request");
}
} // send message
// Bye
private void sayBye(Dialog dialog) throws CommunicationsException {
Request bye = null;
bye = dialog.getFirstTransaction().getRequest();
try {
bye = dialog.createRequest(Request.BYE);
} catch (SipException e) {
Log.error("bye", e);
}
long cseq = ((CSeq) (bye.getHeader(CSeq.NAME)))
.getSequenceNumber() + 1;
bye.removeHeader(CSeq.NAME);
try {
bye.addHeader(sipManCallback.headerFactory.createCSeqHeader(cseq, Request.BYE));
}
catch (Exception e) {
Log.error("bye", e);
}
bye.removeHeader(ViaHeader.NAME);
for (ViaHeader via : sipManCallback.getLocalViaHeaders())
bye.addHeader(via);
ContactHeader contactHeader = sipManCallback.getContactHeader();
bye.addHeader(contactHeader);
AllowHeader allow = null;
try {
allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
bye.addHeader(allow);
} catch (ParseException e) {
Log.error(e);
}
// Transaction
ClientTransaction inviteTransaction;
try {
inviteTransaction = sipManCallback.sipProvider.getNewClientTransaction(bye);
dialog.sendRequest(inviteTransaction);
}
catch (SipException ee) {
Log.error("bye", ee);
}
return;
} // bye
// cancel
private void sayCancel(Dialog dialog) throws CommunicationsException {
Request request = dialog.getFirstTransaction().getRequest();
if (dialog.isServer()) {
throw new CommunicationsException(
"Cannot cancel a server transaction");
}
ClientTransaction clientTransaction = (ClientTransaction) dialog
.getFirstTransaction();
try {
Request cancel = clientTransaction.createCancel();
ClientTransaction cancelTransaction = sipManCallback.sipProvider
.getNewClientTransaction(cancel);
cancelTransaction.sendRequest();
}
catch (SipException ex) {
throw new CommunicationsException(
"Failed to send the CANCEL request", ex);
}
} // cancel
// busy here
private void sayBusyHere(Dialog dialog) throws CommunicationsException {
Request request = dialog.getFirstTransaction().getRequest();
Response busyHere = null;
try {
busyHere = sipManCallback.messageFactory.createResponse(
Response.BUSY_HERE, request);
sipManCallback.attachToTag(busyHere, dialog);
}
catch (ParseException ex) {
throw new CommunicationsException(
"Failed to create the BUSY_HERE response!", ex);
}
if (!dialog.isServer()) {
throw new CommunicationsException(
"Cannot send BUSY_HERE in a client transaction");
}
ServerTransaction serverTransaction = (ServerTransaction) dialog
.getFirstTransaction();
try {
serverTransaction.sendResponse(busyHere);
}
catch (SipException ex) {
throw new CommunicationsException(
"Failed to send the BUSY_HERE response", ex);
} catch (InvalidArgumentException e) {
throw new CommunicationsException(
"Failed to send the BUSY_HERE response", e);
}
} // busy here
// ------------------ say ok
public void sayOK(int callID, String sdpContent)
throws CommunicationsException {
Call call = callDispatcher.getCall(callID);
if (call == null) {
throw new CommunicationsException(
"Failed to find call with id=" + callID);
}
if (!call.isIncoming()) return;
Dialog dialog = call.getDialog();
if (dialog == null) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to extract call's associated dialog! Ending Call!");
}
Transaction transaction = dialog.getFirstTransaction();
if (transaction == null || !dialog.isServer()) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to extract a ServerTransaction "
+ "from the call's associated dialog!");
}
ServerTransaction serverTransaction = (ServerTransaction) transaction;
Response ok = null;
try {
ok = sipManCallback.messageFactory.createResponse(Response.OK,
dialog.getFirstTransaction().getRequest());
sipManCallback.attachToTag(ok, dialog);
}
catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to construct an OK response to an INVITE request",
ex);
}
// Content
ContentTypeHeader contentTypeHeader = null;
try {
// content type should be application/sdp (not applications)
// reported by Oleg Shevchenko (Miratech)
contentTypeHeader = sipManCallback.headerFactory
.createContentTypeHeader("application", "sdp");
}
catch (ParseException ex) {
// Shouldn't happen
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to create a content type header for the OK request",
ex);
}
try {
ok.setContent(sdpContent, contentTypeHeader);
}
catch (NullPointerException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"No sdp data was provided for the ok response to an INVITE request!",
ex);
}
catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to parse sdp data while creating invite request!",
ex);
}
// TODO This is here provisionally as my remote user agent that I am
// using for
// testing is not doing it. It is not correct from the protocol
// point of view
// and should probably be removed
if (((ToHeader) ok.getHeader(ToHeader.NAME)).getTag() == null) {
try {
((ToHeader) ok.getHeader(ToHeader.NAME)).setTag(Integer
.toString(dialog.hashCode()));
}
catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException("Unable to set to tag",
ex);
}
}
ContactHeader contactHeader = sipManCallback.getContactHeader();
ok.addHeader(contactHeader);
try {
serverTransaction.sendResponse(ok);
}
catch (SipException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to send an OK response to an INVITE request",
ex);
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a NOT_FOUND response to an INVITE request!",
e));
}
} // answer call
// ------------------ Internal Error
void sayInternalError(int callID) throws CommunicationsException {
Call call = callDispatcher.getCall(callID);
if (call == null) {
throw new CommunicationsException(
"Failed to find call with id=" + callID);
}
Dialog dialog = call.getDialog();
if (dialog == null) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to extract call's associated dialog! Ending Call!");
}
Transaction transaction = dialog.getFirstTransaction();
if (transaction == null || !dialog.isServer()) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to extract a transaction from the call's associated dialog!");
}
ServerTransaction serverTransaction = (ServerTransaction) transaction;
Response internalError = null;
try {
internalError = sipManCallback.messageFactory.createResponse(
Response.SERVER_INTERNAL_ERROR, dialog
.getFirstTransaction().getRequest());
sipManCallback.attachToTag(internalError, dialog);
}
catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to construct an OK response to an INVITE request",
ex);
}
ContactHeader contactHeader = sipManCallback.getContactHeader();
internalError.addHeader(contactHeader);
try {
serverTransaction.sendResponse(internalError);
}
catch (SipException ex) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to send an OK response to an INVITE request",
ex);
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
throw new CommunicationsException(
"Failed to send an OK response to an INVITE request",
e);
}
} // internal error
/**
* @return Returns the callDispatcher.
* @uml.property name="callDispatcher"
*/
CallDispatcher getCallDispatcher() {
return callDispatcher;
}
// The following method is currently being implemented and tested
protected void processReInvite(ServerTransaction serverTransaction,
Request invite) {
sipManCallback.setBusy(false);
Log.debug("REINVITE DETECTED");
Call call = callDispatcher.findCall(serverTransaction.getDialog());
if (call == null) {
call = callDispatcher.createCall(serverTransaction.getDialog(),
invite);
}
call.setRemoteSdpDescription(new String(invite.getRawContent()));
Log.debug("CALL CONNECT EVENT");
try {
sayOK(call.getID(), call.getLocalSdpDescription().toString());
} catch (CommunicationsException e) {
Log.error("Re-Invite", e);
}
call.setState(Call.MOVING_REMOTELY);
call.setState(Call.CONNECTED);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -