use of javax.sip.header.CSeqHeader in project load-balancer by RestComm.
the class Shootist method processResponse.
public void processResponse(ResponseEvent responseReceivedEvent) {
System.out.println("Got a response");
Response response = (Response) responseReceivedEvent.getResponse();
ClientTransaction tid = responseReceivedEvent.getClientTransaction();
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
System.out.println("Response received : Status Code = " + response.getStatusCode() + " " + cseq);
if (tid == null) {
// RFC3261: MUST respond to every 2xx
if (ackRequest != null && dialog != null) {
System.out.println("re-sending ACK");
try {
dialog.sendAck(ackRequest);
} catch (SipException se) {
se.printStackTrace();
fail("Unxpected exception ");
}
}
return;
}
// If the caller is supposed to send the bye
if (callerSendsBye && !byeTaskRunning) {
byeTaskRunning = true;
new Timer().schedule(new ByeTask(dialog), 4000);
}
System.out.println("transaction state is " + tid.getState());
System.out.println("Dialog = " + tid.getDialog());
System.out.println("Dialog State is " + tid.getDialog().getState());
TestCase.assertSame("Checking dialog identity", tid.getDialog(), this.dialog);
try {
if (response.getStatusCode() == Response.OK) {
if (cseq.getMethod().equals(Request.INVITE)) {
System.out.println("Dialog after 200 OK " + dialog);
System.out.println("Dialog State after 200 OK " + dialog.getState());
Request ackRequest = dialog.createAck(cseq.getSeqNumber());
System.out.println("Sending ACK");
dialog.sendAck(ackRequest);
} else if (cseq.getMethod().equals(Request.CANCEL)) {
if (dialog.getState() == DialogState.CONFIRMED) {
// oops cancel went in too late. Need to hang up the
// dialog.
System.out.println("Sending BYE -- cancel went in too late !!");
Request byeRequest = dialog.createRequest(Request.BYE);
ClientTransaction ct = sipProvider.getNewClientTransaction(byeRequest);
dialog.sendRequest(ct);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of javax.sip.header.CSeqHeader in project load-balancer by RestComm.
the class TestSipListener method sendSipRequest.
public Request sendSipRequest(String method, URI fromURI, URI toURI, String messageContent, SipURI route, boolean useToURIasRequestUri, String[] headerNames, String[] headerContents, boolean setHeader) throws SipException, ParseException, InvalidArgumentException {
this.useToURIasRequestUri = useToURIasRequestUri;
// create >From Header
Address fromNameAddress = protocolObjects.addressFactory.createAddress(fromURI);
FromHeader fromHeader = protocolObjects.headerFactory.createFromHeader(fromNameAddress, Integer.toString(new Random().nextInt(10000000)));
// create To Header
Address toNameAddress = protocolObjects.addressFactory.createAddress(toURI);
ToHeader toHeader = protocolObjects.headerFactory.createToHeader(toNameAddress, null);
if (toURI instanceof SipURI) {
SipURI toSipUri = (SipURI) toURI;
// create Request URI
this.requestURI = protocolObjects.addressFactory.createSipURI(toSipUri.getUser(), peerHostPort);
((SipURI) this.requestURI).setPort(peerPort);
if (setTransport) {
((SipURI) this.requestURI).setTransportParam(listeningPoint.getTransport());
}
}
if (useToURIasRequestUri || toURI instanceof TelURL) {
this.requestURI = toURI;
}
// Create ViaHeaders
List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = null;
if (!isIpv6)
viaHeader = protocolObjects.headerFactory.createViaHeader("127.0.0.1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
else
viaHeader = protocolObjects.headerFactory.createViaHeader("::1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
// add via headers
viaHeaders.add(viaHeader);
// Create ContentTypeHeader
// ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory
// .createContentTypeHeader("application", "sdp");
// Create a new CallId header
CallIdHeader callIdHeader = sipProvider.getNewCallId();
// Create a new Cseq header
CSeqHeader cSeqHeader = protocolObjects.headerFactory.createCSeqHeader(1L, method);
// Create a new MaxForwardsHeader
MaxForwardsHeader maxForwards = protocolObjects.headerFactory.createMaxForwardsHeader(70);
// Create the request.
Request request = protocolObjects.messageFactory.createRequest(requestURI, method, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
// Create contact headers
String host = null;
if (!isIpv6)
host = "127.0.0.1";
else
host = "::1";
URI contactUrl = null;
if (fromURI instanceof SipURI) {
contactUrl = protocolObjects.addressFactory.createSipURI(((SipURI) fromURI).getUser(), host);
/**
* either use tcp or udp
*/
((SipURI) contactUrl).setPort(listeningPoint.getPort());
if (setTransport) {
((SipURI) contactUrl).setTransportParam(listeningPoint.getTransport());
((SipURI) contactUrl).setLrParam();
}
} else {
contactUrl = fromURI;
}
// Create the contact name address.
Address contactAddress = protocolObjects.addressFactory.createAddress(contactUrl);
// Add the contact address.
// contactAddress.setDisplayName(fromName);
contactHeader = protocolObjects.headerFactory.createContactHeader(contactAddress);
request.addHeader(contactHeader);
SipURI uri = null;
if (!isIpv6)
uri = protocolObjects.addressFactory.createSipURI(null, "127.0.0.1");
else
uri = protocolObjects.addressFactory.createSipURI(null, "::1");
uri.setLrParam();
uri.setTransportParam(protocolObjects.transport);
uri.setPort(this.peerPort);
if (route != null) {
Address address = protocolObjects.addressFactory.createAddress(route);
RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
request.addHeader(routeHeader);
} else if (useDefaultRoute) {
Address address = protocolObjects.addressFactory.createAddress(uri);
RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
request.addHeader(routeHeader);
}
// set the message content
if (messageContent != null) {
ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(messageContent.length());
ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(TEXT_CONTENT_TYPE, PLAIN_UTF8_CONTENT_SUBTYPE);
byte[] contents = messageContent.getBytes();
request.setContent(contents, contentTypeHeader);
request.setContentLength(contentLengthHeader);
}
if (headerNames != null) {
for (int q = 0; q < headerNames.length; q++) {
Header h = protocolObjects.headerFactory.createHeader(headerNames[q], headerContents[q]);
if (setHeader) {
request.setHeader(h);
} else {
request.addHeader(h);
}
}
}
addSpecificHeaders(method, request);
// Create the client transaction.
inviteClientTid = sipProvider.getNewClientTransaction(request);
// send the request out.
inviteClientTid.sendRequest();
logger.info("client tx = " + inviteClientTid);
if (!Request.MESSAGE.equalsIgnoreCase(method)) {
dialog = inviteClientTid.getDialog();
}
if (Request.INVITE.equalsIgnoreCase(method)) {
inviteRequest = request;
}
this.dialogCount++;
return inviteRequest;
}
use of javax.sip.header.CSeqHeader in project camel by apache.
the class SipConfiguration method createSipRequest.
public Request createSipRequest(long sequenceNumber, String requestMethod, Object body) throws ParseException, InvalidArgumentException {
//SipConfiguration configuration = sipPublisher.getConfiguration();
CSeqHeader cSeqHeader = getHeaderFactory().createCSeqHeader(sequenceNumber, requestMethod);
// Create the request.
Request request = getMessageFactory().createRequest(getSipUri(), requestMethod, getCallIdHeader(), cSeqHeader, getFromHeader(), getToHeader(), getViaHeaders(), getMaxForwardsHeader());
if (getEventHeader() != null) {
request.addHeader(getEventHeader());
}
if (getExpiresHeader() != null) {
request.addHeader(getExpiresHeader());
}
if (getContactHeader() != null) {
request.addHeader(getContactHeader());
}
if (getExtensionHeader() != null) {
request.addHeader(getExtensionHeader());
}
request.setContent(body, getContentTypeHeader());
return request;
}
use of javax.sip.header.CSeqHeader in project Openfire by igniterealtime.
the class SimpleListener method processResponse.
public void processResponse(ResponseEvent responseEvent) {
if (responseEvent.getClientTransaction() != null) {
Log.debug("SimpleListener for " + myUsername + ": Getting client transaction...");
ClientTransaction clientTransaction = responseEvent.getClientTransaction();
Dialog clientDialog = clientTransaction.getDialog();
getSession().printDialog(clientDialog);
}
Log.debug("SimpleListener for " + myUsername + ": Received a response event: " + responseEvent.getResponse().toString());
// String fromAddr = "";
String toAddr = "";
Response response = responseEvent.getResponse();
// }
if (response.getHeader(ToHeader.NAME) != null) {
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
URI toUri = toHeader.getAddress().getURI();
if (toUri instanceof SipUri)
toAddr = ((SipUri) toUri).getUser() + "@" + ((SipUri) toUri).getHost();
else
toAddr = toUri.toString();
}
if (response.getHeader(CSeqHeader.NAME) != null) {
String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
if (method.equals(Request.REGISTER)) {
if (response.getStatusCode() / 100 == 2) {
int expires = 0;
if (response.getHeader(ContactHeader.NAME) != null) {
expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
} else if (response.getHeader(ExpiresHeader.NAME) != null) {
expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
}
if (expires > 0) {
Log.debug("SimpleListener(" + myUsername + ").processResponse: " + getSession().getRegistration().getUsername() + " log in successful!");
getSession().sipUserLoggedIn();
} else {
if (getSession().getLoginStatus().equals(TransportLoginStatus.LOGGING_OUT)) {
Log.debug("SimpleListener(" + myUsername + ").processResponse: " + getSession().getRegistration().getUsername() + " log out successful!");
getSession().sipUserLoggedOut();
getSession().removeStack();
}
}
}
}
if (method.equals(Request.SUBSCRIBE)) {
if (response.getStatusCode() / 100 == 2) {
Log.debug("SimpleListener for " + myUsername + ": Handling SUBSCRIBE acknowledgement!!");
int expires = 0;
if (response.getHeader(ContactHeader.NAME) != null) {
expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
}
if (response.getHeader(ExpiresHeader.NAME) != null) {
expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
}
if (expires > 0) {
// Confirm subscription of roster item
getSession().contactSubscribed(toAddr);
} else {
// Confirm unsubscription of roster item
getSession().contactUnsubscribed(toAddr);
}
Log.debug("SimpleListener for " + myUsername + ": Handled SUBSCRIBE acknowledgement!!");
}
}
}
}
use of javax.sip.header.CSeqHeader in project XobotOS by xamarin.
the class SipHelper method sendInviteAck.
/**
* @param event the INVITE ACK request event
*/
public void sendInviteAck(ResponseEvent event, Dialog dialog) throws SipException {
Response response = event.getResponse();
long cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getSeqNumber();
Request ack = dialog.createAck(cseq);
if (DEBUG)
Log.d(TAG, "send ACK: " + ack);
dialog.sendAck(ack);
}
Aggregations