test.tck.msgflow.callflows.router.Shootme Maven / Gradle / Ivy
/*
* Conditions Of Use
*
* This software was developed by employees of the National Institute of
* Standards and Technology (NIST), and others.
* This software is has been contributed to the public domain.
* As a result, a formal license is not needed to use the software.
*
* This software is provided "AS IS."
* NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY. NIST does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
*
*/
package test.tck.msgflow.callflows.router;
import javax.sip.*;
import javax.sip.address.*;
import javax.sip.header.*;
import javax.sip.message.*;
import org.apache.log4j.Logger;
import test.tck.TestHarness;
import test.tck.msgflow.callflows.ProtocolObjects;
import java.util.*;
/**
* This class is a UAC template.
*
* @author M. Ranganathan
*/
public class Shootme implements SipListener {
private static SipProvider sipProvider;
private static AddressFactory addressFactory;
private static MessageFactory messageFactory;
private static HeaderFactory headerFactory;
private static SipStack sipStack;
private static final String myAddress = "127.0.0.1";
protected ServerTransaction inviteTid;
private Dialog dialog;
private String toTag;
private String transport;
private boolean inviteReceived;
public static final int myPort = 5080;
private static Logger logger = Logger.getLogger("test.tck");
public Shootme(ProtocolObjects protObjects) {
addressFactory = protObjects.addressFactory;
messageFactory = protObjects.messageFactory;
headerFactory = protObjects.headerFactory;
sipStack = protObjects.sipStack;
transport = protObjects.transport;
}
public void processRequest(RequestEvent requestEvent) {
Request request = requestEvent.getRequest();
ServerTransaction serverTransactionId = requestEvent
.getServerTransaction();
logger.info("\n\nRequest " + request.getMethod()
+ " received at " + sipStack.getStackName()
+ " with server transaction id " + serverTransactionId);
if (request.getMethod().equals(Request.INVITE)) {
processInvite(requestEvent, serverTransactionId);
} else if (request.getMethod().equals(Request.ACK)) {
processAck(requestEvent, serverTransactionId);
} else if (request.getMethod().equals(Request.BYE)) {
processBye(requestEvent, serverTransactionId);
}
}
public void processResponse(ResponseEvent responseEvent) {
}
/**
* Process the ACK request. Send the bye and complete the call flow.
*/
public void processAck(RequestEvent requestEvent,
ServerTransaction serverTransaction) {
try {
logger.info("shootme: got an ACK! Sending a BYE");
logger.info("Dialog State = " + dialog.getState());
Dialog dialog = serverTransaction.getDialog();
AbstractRouterTestCase.assertTrue("Dialog mismatch", dialog == this.dialog);
SipProvider provider = (SipProvider) requestEvent.getSource();
AbstractRouterTestCase.assertTrue("Provider mismatch", sipProvider == provider);
Request byeRequest = dialog.createRequest(Request.BYE);
ClientTransaction ct = provider.getNewClientTransaction(byeRequest);
dialog.sendRequest(ct);
} catch (Exception ex) {
TestHarness.fail(ex.getMessage());
}
}
/**
* Process the invite request.
*/
public void processInvite(RequestEvent requestEvent,
ServerTransaction serverTransaction) {
inviteReceived = true;
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
try {
logger.info("shootme: got an Invite sending Trying");
// logger.info("shootme: " + request);
Response response = messageFactory.createResponse(Response.TRYING,
request);
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
dialog = st.getDialog();
st.sendResponse(response);
// reliable provisional response.
Response okResponse = messageFactory.createResponse(Response.OK, request);
ToHeader toHeader = (ToHeader) okResponse.getHeader(ToHeader.NAME);
this.toTag = "4321";
toHeader.setTag(toTag); // Application is supposed to set.
this.inviteTid = st;
Address address = addressFactory.createAddress("Shootme ");
ContactHeader contactHeader = headerFactory
.createContactHeader(address);
okResponse.addHeader(contactHeader);
logger.info("sending response.");
st.sendResponse(okResponse);
// new Timer().schedule(new MyTimerTask(this), 100);
} catch (Exception ex) {
TestHarness.fail(ex.getMessage());
}
}
/**
* Process the bye request.
*/
public void processBye(RequestEvent requestEvent,
ServerTransaction serverTransactionId) {
Request request = requestEvent.getRequest();
try {
logger.info("shootme: got a bye sending OK.");
Response response = messageFactory.createResponse(200, request);
serverTransactionId.sendResponse(response);
logger.info("Dialog State is "
+ serverTransactionId.getDialog().getState());
} catch (Exception ex) {
TestHarness.fail(ex.getMessage());
System.exit(0);
}
}
public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
Transaction transaction;
if (timeoutEvent.isServerTransaction()) {
transaction = timeoutEvent.getServerTransaction();
} else {
transaction = timeoutEvent.getClientTransaction();
}
logger.info("state = " + transaction.getState());
logger.info("dialog = " + transaction.getDialog());
logger.info("dialogState = "
+ transaction.getDialog().getState());
logger.info("Transaction Time out");
}
public SipProvider createProvider() throws Exception {
ListeningPoint lp = sipStack.createListeningPoint("127.0.0.1",
myPort, transport);
sipProvider = sipStack.createSipProvider(lp);
logger.info(transport + " SIP provider " + sipProvider);
return sipProvider;
}
public void processIOException(IOExceptionEvent exceptionEvent) {
logger.info("IOException");
}
public void processTransactionTerminated(
TransactionTerminatedEvent transactionTerminatedEvent) {
logger.info("Transaction terminated event recieved");
}
public void processDialogTerminated(
DialogTerminatedEvent dialogTerminatedEvent) {
logger.info("Dialog terminated event recieved");
}
public void checkState() {
TestHarness.assertTrue( inviteReceived);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy