use of javax.sip.message.Request in project camel by apache.
the class SipSubscriptionListener method processRequest.
public void processRequest(RequestEvent requestReceivedEvent) {
Request request = requestReceivedEvent.getRequest();
ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
String viaBranch = ((ViaHeader) (request.getHeaders(ViaHeader.NAME).next())).getParameter("branch");
LOG.debug("Request: {}", request.getMethod());
LOG.debug("Server Transaction Id: {}", serverTransactionId);
LOG.debug("Received From Branch: {}", viaBranch);
if (request.getMethod().equals(Request.NOTIFY)) {
processNotify(requestReceivedEvent, serverTransactionId);
}
}
use of javax.sip.message.Request 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.message.Request in project camel by apache.
the class SipSubscriber method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
Properties properties = configuration.createInitialProperties();
sipStack = configuration.getSipFactory().createSipStack(properties);
configuration.parseURI();
sipSubscriptionListener = new SipSubscriptionListener(this);
ListeningPoint listeningPoint = sipStack.createListeningPoint(configuration.getFromHost(), Integer.valueOf(configuration.getFromPort()).intValue(), configuration.getTransport());
configuration.setListeningPoint(listeningPoint);
provider = sipStack.createSipProvider(configuration.getListeningPoint());
provider.addSipListener(sipSubscriptionListener);
if (configuration.getCallIdHeader() == null) {
configuration.setCallIdHeader(provider.getNewCallId());
}
// Create the Subscription request to register with the presence agent and receive notifications.
configuration.setCallIdHeader(provider.getNewCallId());
Request request = configuration.createSipRequest(1, Request.SUBSCRIBE, configuration.getEventHeaderName());
// Create the subscriber transaction from request.
ClientTransaction subscriberTransactionId = provider.getNewClientTransaction(request);
// Add an Event header for the subscription.
request.addHeader(configuration.getEventHeader());
subscriberDialog = subscriberTransactionId.getDialog();
// Send the outgoing subscription request.
subscriberTransactionId.sendRequest();
}
use of javax.sip.message.Request in project camel by apache.
the class SipPresenceAgentListener method processRequest.
public void processRequest(RequestEvent requestEvent) {
Request request = requestEvent.getRequest();
ServerTransaction serverTransactionId = requestEvent.getServerTransaction();
LOG.debug("Request: {}", request.getMethod());
LOG.debug("Server Transaction Id: {}", serverTransactionId);
if (request.getMethod().equals(Request.SUBSCRIBE)) {
processSubscribe(requestEvent, serverTransactionId);
} else if (request.getMethod().equals(Request.PUBLISH)) {
processPublish(requestEvent, serverTransactionId);
} else {
LOG.debug("Received expected request with method: {}. No further processing done", request.getMethod());
}
}
use of javax.sip.message.Request in project camel by apache.
the class SipPresenceAgentListener method processSubscribe.
public void processSubscribe(RequestEvent requestEvent, ServerTransaction serverTransaction) {
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
try {
LOG.debug("SipPresenceAgentListener: Received a Subscribe request, sending OK");
LOG.debug("SipPresenceAgentListener request: {}", request);
EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
if (eventHeader == null) {
LOG.debug("Cannot find event header.... dropping request.");
return;
}
// Always create a ServerTransaction, best as early as possible in the code
Response response = null;
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
// Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
boolean isInitial = requestEvent.getDialog() == null;
if (isInitial) {
String toTag = UUID.randomUUID().toString();
response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(202, request);
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
// Application is supposed to set.
toHeader.setTag(toTag);
this.dialog = st.getDialog();
// subscribe dialogs do not terminate on bye.
this.dialog.terminateOnBye(false);
} else {
response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(200, request);
}
// Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
response.addHeader(sipPresenceAgent.getConfiguration().getContactHeader());
// Expires header is mandatory in 2xx responses to SUBSCRIBE
response.addHeader(sipPresenceAgent.getConfiguration().getExpiresHeader());
st.sendResponse(response);
LOG.debug("SipPresenceAgentListener: Sent OK Message");
LOG.debug("SipPresenceAgentListener response: {}", response);
sendNotification(eventHeader, isInitial, request.getContent());
} catch (Throwable e) {
LOG.error("Exception thrown during Notify processing in the SipPresenceAgentListener.", e);
}
}
Aggregations