📄 callprocessing.java
字号:
ex);
throw new CommunicationsException(
"Failed to construct a client transaction from the BYE request",
ex);
}
try {
dialog.sendRequest(clientTransaction);
if( console.isDebugEnabled() )
console.debug("sent request: " + bye);
}
catch (SipException ex1) {
throw new CommunicationsException("Failed to send the BYE request");
}
}
finally
{
console.logExit();
}
} //bye
//cancel
private void sayCancel(Dialog dialog) throws CommunicationsException
{
try
{
console.logEntry();
Request request = dialog.getFirstTransaction().getRequest();
if (dialog.isServer()) {
console.error("Cannot cancel a server transaction");
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();
if( console.isDebugEnabled() )
console.debug("sent request: " + cancel);
}
catch (SipException ex) {
console.error("Failed to send the CANCEL request", ex);
throw new CommunicationsException(
"Failed to send the CANCEL request", ex);
}
}
finally
{
console.logExit();
}
} //cancel
//busy here
private void sayBusyHere(Dialog dialog) throws CommunicationsException
{
try
{
console.logEntry();
Request request = dialog.getFirstTransaction().getRequest();
Response busyHere = null;
try {
busyHere = sipManCallback.
messageFactory.createResponse(Response.BUSY_HERE, request);
sipManCallback.attachToTag(busyHere, dialog);
}
catch (ParseException ex) {
console.error("Failed to create the BUSY_HERE response!", ex);
throw new CommunicationsException(
"Failed to create the BUSY_HERE response!", ex);
}
if (!dialog.isServer()) {
console.error("Cannot send BUSY_HERE in a client transaction");
throw new CommunicationsException(
"Cannot send BUSY_HERE in a client transaction");
}
ServerTransaction serverTransaction =
(ServerTransaction) dialog.getFirstTransaction();
try {
serverTransaction.sendResponse(busyHere);
if( console.isDebugEnabled() )
console.debug("sent response: " + busyHere);
}
catch (SipException ex) {
console.error("Failed to send the BUSY_HERE response", ex);
throw new CommunicationsException(
"Failed to send the BUSY_HERE response", ex);
}
}
finally
{
console.logExit();
}
} //busy here
//------------------ say ok
public void sayOK(int callID, String sdpContent) throws
CommunicationsException
{
try
{
console.logEntry();
Call call = callDispatcher.getCall(callID);
if (call == null) {
console.error("Failed to find call with id=" + callID);
throw new CommunicationsException(
"Failed to find call with id=" + callID);
}
Dialog dialog = call.getDialog();
if (dialog == null) {
call.setState(Call.DISCONNECTED);
console.error(
"Failed to extract call's associated dialog! Ending Call!");
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);
console.error(
"Failed to construct an OK response to an INVITE request",
ex);
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);
console.error(
"Failed to create a content type header for the OK request",
ex);
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);
console.error(
"No sdp data was provided for the ok response to an INVITE request!",
ex);
throw new CommunicationsException(
"No sdp data was provided for the ok response to an INVITE request!",
ex);
}
catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
console.error(
"Failed to parse sdp data while creating invite request!", ex);
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);
if( console.isDebugEnabled() )
console.debug("sent response " + ok);
}
catch (SipException ex) {
call.setState(Call.DISCONNECTED);
console.error(
"Failed to send an OK response to an INVITE request",
ex
);
throw new CommunicationsException(
"Failed to send an OK response to an INVITE request",
ex
);
}
}
finally
{
console.logExit();
}
} //answer call
//------------------ Internal Error
public void sayInternalError(int callID) throws CommunicationsException
{
try
{
console.logEntry();
Call call = callDispatcher.getCall(callID);
if (call == null) {
console.error("Failed to find call with id=" + callID);
throw new CommunicationsException(
"Failed to find call with id=" + callID
);
}
Dialog dialog = call.getDialog();
if (dialog == null) {
call.setState(Call.DISCONNECTED);
console.error(
"Failed to extract call's associated dialog! Ending Call!"
);
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);
console.error(
"Failed to extract a transaction"
+" from the call's associated dialog!");
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);
console.error(
"Failed to construct an OK response to an INVITE request",
ex);
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);
if( console.isDebugEnabled() )
console.debug("sent response: " + internalError);
}
catch (SipException ex) {
call.setState(Call.DISCONNECTED);
console.error(
"Failed to send an OK response to an INVITE request",
ex);
throw new CommunicationsException(
"Failed to send an OK response to an INVITE request",
ex
);
}
}
finally
{
console.logExit();
}
} //internal error
public CallDispatcher getCallDispatcher()
{
return callDispatcher;
}
//The following method is currently being implemented and tested
public void processReInvite(ServerTransaction serverTransaction, Request request)
{
try
{
console.logEntry();
console.error("processReInvite is not yet implemented");
}finally
{
console.logExit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -