Java源码示例:javax.sip.message.Request
示例1
@Test
public void testPresenceAgentBasedPubSub() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(createRouteBuilder());
MockEndpoint mockNeverland = camelctx.getEndpoint("mock:neverland", MockEndpoint.class);
mockNeverland.expectedMessageCount(0);
MockEndpoint mockNotification = camelctx.getEndpoint("mock:notification", MockEndpoint.class);
mockNotification.expectedMinimumMessageCount(1);
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
template.sendBodyAndHeader(
"sip://[email protected]:" + port1 + "?stackName=client&eventHeaderName=evtHdrName&eventId=evtid&fromUser=user2&fromHost=localhost&fromPort=" + port3,
"EVENT_A",
"REQUEST_METHOD", Request.PUBLISH);
mockNeverland.assertIsSatisfied();
mockNotification.assertIsSatisfied();
} finally {
camelctx.close();
}
}
示例2
public void processTimeout(TimeoutEvent transactionTimeOutEvent) {
Transaction transaction;
if (transactionTimeOutEvent.isServerTransaction()) {
transaction = transactionTimeOutEvent.getServerTransaction();
} else {
transaction = transactionTimeOutEvent.getClientTransaction();
}
Request request = transaction.getRequest();
if (request.getMethod().equals(Request.REGISTER)) {
registerProcessing.processTimeout(transaction, request);
} else if (request.getMethod().equals(Request.INVITE)) {
callProcessing.processTimeout(transaction, request);
} else {
// Just show an error for now
}
}
示例3
void processAck(ServerTransaction serverTransaction, Request ackRequest) {
if (!serverTransaction.getDialog().getFirstTransaction()
.getRequest().getMethod().equals(Request.INVITE)) {
return;
}
// find the call
Call call = callDispatcher.findCall(serverTransaction.getDialog());
if (call == null) {
// this is most probably the ack for a killed call - don't
// signal it
// sipManCallback.fireUnknownMessageReceived(ackRequest);
return;
}
ContentLengthHeader cl = ackRequest.getContentLength();
if (cl != null && cl.getContentLength() > 0) {
call.setRemoteSdpDescription(new String(ackRequest
.getRawContent()));
}
// change status
call.setState(Call.CONNECTED);
}
示例4
private void sayCancel(Dialog dialog) throws CommunicationsException {
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);
}
}
示例5
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);
}
示例6
/**
* Creates a list of media descriptions. For now, this simply copies
* the received description.
* TODO
* @return list of media descriptions
* @throws SdpException
* error parsing the media descriptions from the request
*/
@SuppressWarnings("unchecked")
private Vector<MediaDescription> createMediaDescriptions(
final Request request) throws SdpException {
byte[] content = request.getRawContent();
if (content == null) {
return null;
}
final String sdp = new String(content);
final SdpFactory factory = SdpFactory.getInstance();
final SessionDescription description =
factory.createSessionDescription(sdp);
return description.getMediaDescriptions(false);
}
示例7
/**
* Processes a BYE request.
* @param request the received request
* @param transaction the transaction of the request
* @throws ParseException
* error parsing the status code
* @throws SipException
* error sending the message
* @throws InvalidArgumentException
* if the creation of the response is invalid
*/
public void processBye(final Request request,
final ServerTransaction transaction)
throws ParseException, SipException, InvalidArgumentException {
final Response response =
messageFactory.createResponse(Response.OK, request);
transaction.sendResponse(response);
dialog = null;
inviteTransaction = null;
for (UserAgentListener listener : listeners) {
listener.sessionDropped(session);
}
session = null;
}
示例8
public static String dumpSIPMsgHdr(Message message)
{
String msgdsc="";
try{
if(message==null) return "";
Header fromUri = message.getHeader("From");
Header toUri = message.getHeader("To");
if(message instanceof Request)
{
msgdsc ="SIP Request";
return " method of "+msgdsc+ ": "+ ((Request)message).getMethod() + " RequestURI:"
+((Request)message).getRequestURI()
+" fromUri:"+fromUri+ " toUri:"+toUri;
}
else if (message instanceof Response)
{
msgdsc ="SIP Response";
return " method of "+msgdsc+ ": statusCode: "+ ((Response)message).getStatusCode()
+" fromUri:"+fromUri+ " toUri:"+toUri;
}
else msgdsc ="unknow SIP message";
}catch(Exception ex)
{
ExLog.exception(LOGGER, ex);
}
return msgdsc;
}
示例9
private void forwardRequest(Request request, boolean subsequent) {
try {
VNXLog.info("creating cloned Request for proxybranch " + request);
final SipServletRequestImpl clonedRequest = (SipServletRequestImpl) proxy
.getSipFactoryImpl().getMobicentsSipServletMessageFactory()
.createSipServletRequest(request, null, null, null, false);
if (subsequent) {
clonedRequest.setRoutingState(RoutingState.SUBSEQUENT);
}
// Initialize the sip session for the new request if initial
final MobicentsSipSession originalSipSession = originalRequest
.getSipSession();
clonedRequest.setCurrentApplicationName(originalRequest
.getCurrentApplicationName());
if (clonedRequest.getCurrentApplicationName() == null && subsequent) {
clonedRequest.setCurrentApplicationName(originalSipSession
.getSipApplicationSession().getApplicationName());
}
clonedRequest.setSipSession(originalSipSession);
final MobicentsSipSession newSession = (MobicentsSipSession) clonedRequest
.getSipSession();
try {
newSession.setHandler(originalSipSession.getHandler());
} catch (ServletException e) {
VNXLog.error(
"could not set the session handler while forwarding the request",
e);
throw new RuntimeException(
"could not set the session handler while forwarding the request",
e);
}
clonedRequest.send();
} catch (Exception ex) {
VNXLog.error(ex);
}
}
示例10
/**
* Returns whether loop detected
* @param request Request
* @return true if request is looped, false otherwise
*/
private boolean checkLoopDetection(Request request)
{
/**
* 4. Optional Loop Detection check
*
* An element MAY check for forwarding loops before forwarding a
* request. If the request contains a Via header field with a sent-
* by value that equals a value placed into previous requests by the
* proxy, the request has been forwarded by this element before. The
* request has either looped or is legitimately spiraling through the
* element. To determine if the request has looped, the element MAY
* perform the branch parameter calculation described in Step 8 of
* Section 16.6 on this message and compare it to the parameter
* received in that Via header field. If the parameters match, the
* request has looped. If they differ, the request is spiraling, and
* processing continues. If a loop is detected, the element MAY
* return a 482 (Loop Detected) response.
*/
// ListIterator viaList = request.getHeaders(ViaHeader.NAME);
// if (viaList != null && viaList.hasNext())
// {
// ViaHeader viaHeader = (ViaHeader) viaList.next();
//
// ListeningPoint[] lps = sipProvider.getListeningPoints();
//
// String viaHost = viaHeader.getHost();
// int viaPort = viaHeader.getPort();
//
// if ( (viaHost.equals(lps[0].getIPAddress()) || viaHost.equalsIgnoreCase(getHostname(sipProvider)) ) && viaPort == lps[0].getPort())
// {
// /**
// * @todo We have to check the branch-ids...
// */
// return true;
// }
// }
return false;
}
示例11
/**
* Fired when a message is received
*
* @param evt MessageEvent
*/
public void messageReceived(MessageEvent evt) {
if (evt.getSource() instanceof Request) {
Request request = (Request)evt.getSource();
if (request.getMethod().equals(Request.NOTIFY)) {
VoiceMail vm = new VoiceMail(evt);
dialControl.setVoiceMailLabel(vm.getUnread());
dialControl.setVoiceMailDescription("You have " + vm.getUnread() + " new voice mails.");
}
}
}
示例12
Call createCall(Dialog dialog, Request initialRequest) {
Call call = null;
if (dialog.getDialogId() != null) {
call = findCall(dialog);
}
if (call == null) {
call = new Call();
}
call.setDialog(dialog);
call.setInitialRequest(initialRequest);
// call.setState(Call.DIALING);
calls.put(Integer.valueOf(call.getID()), call);
call.addStateChangeListener(this);
return call;
}
示例13
void fireMessageReceived(Request message) {
try {
MessageEvent evt = new MessageEvent( message );
for ( int i = listeners.size() - 1; i >= 0; i-- )
{
( (CommunicationsListener) listeners.get( i ) )
.messageReceived( evt );
}
} catch ( Exception e ) {
Log.error("fireMessageReceived", e);
}
}
示例14
public String getMessageName() {
if (source instanceof Request) {
return (source == null) ? "" : ((Request)source).getMethod();
}
else {
return (source == null) ? "" : ((Response)source).getStatusCode()
+ " " + ((Response)source).getReasonPhrase();
}
}
示例15
public String getBody() {
Request request = (Request)getSource();
Object content = request.getContent();
String text = null;
if (content instanceof String) {
text = (String)content;
}
else if (content instanceof byte[]) {
text = new String((byte[])content);
}
return text == null ? "" : text;
}
示例16
public String getFromAddress() {
Request request = (Request)getSource();
String fromAddress = "<unknown>";
try {
FromHeader fromHeader = (FromHeader)request
.getHeader(FromHeader.NAME);
fromAddress = fromHeader.getAddress().getURI().toString();
}
catch (NullPointerException exc) {
// Noone wants to know about ou null pointer exception
}
return fromAddress;
}
示例17
public String getFromName() {
Request request = (Request)getSource();
String fromName = null;
try {
FromHeader fromHeader = (FromHeader)request
.getHeader(FromHeader.NAME);
fromName = fromHeader.getAddress().getDisplayName();
}
catch (NullPointerException exc) {
// Noone wants to know about ou null pointer exception
}
return fromName == null ? "<unknown>" : fromName;
}
示例18
void processTimeout(Transaction transaction, Request request) {
System.err.println("TIME ERROR");
isRegistered = true;
FromHeader fromHeader = ((FromHeader) request.getHeader(FromHeader.NAME));
Address address = fromHeader.getAddress();
sipManCallback.fireRegistrationFailed("Unable to register with " + address.toString(), RegistrationEvent.Type.TimeOut);
}
示例19
void processInviteOK(ClientTransaction clientTransaction, Response ok) {
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
if (call == null) {
sipManCallback.fireUnknownMessageReceived(ok);
return;
}
// Send ACK
try {
// Need to use dialog generated ACKs so that the remote UA core
// sees them - Fixed by M.Ranganathan
Request ackRequest = clientTransaction.getDialog()
.createAck(((CSeqHeader)ok.getHeader(CSeqHeader.NAME)).getSeqNumber());
clientTransaction.getDialog().sendAck(ackRequest);
}
catch (SipException ex) {
ex.printStackTrace();
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to acknowledge call!", ex));
return;
} catch (InvalidArgumentException e) {
e.printStackTrace();
call.setState(Call.DISCONNECTED);
sipManCallback.fireCommunicationsError(new CommunicationsException(
"Failed to create ack!", e));
return;
}
call.setRemoteSdpDescription(new String(ok.getRawContent()));
// change status
if (!call.getState().equals(Call.CONNECTED)) {
call.setState(Call.CONNECTED);
}
}
示例20
void processTimeout(Transaction transaction, Request request) {
Call call = callDispatcher.findCall(transaction.getDialog());
if (call == null) {
return;
}
sipManCallback.fireCommunicationsError(new CommunicationsException(
"The remote party has not replied!"
+ "The call will be disconnected"));
// change status
call.setState(Call.DISCONNECTED);
}
示例21
void processNotFound(ClientTransaction clientTransaction, Response response) {
if (!clientTransaction.getDialog().getFirstTransaction()
.getRequest().getMethod().equals(Request.INVITE)) {
// Not for us
return;
}
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
if (call != null)
call.setState(Call.DISCONNECTED);
sipManCallback.fireCallRejectedRemotely(
"Number NOT found at the server.", response, call);
}
示例22
void processNotImplemented(ClientTransaction clientTransaction,
Response response) {
if (!clientTransaction.getDialog().getFirstTransaction()
.getRequest().getMethod().equals(Request.INVITE)) {
// Not for us
return;
}
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
call.setState(Call.DISCONNECTED);
sipManCallback.fireCallRejectedRemotely(
"Server cannot dial this number.", response, call);
}
示例23
/**
* Handles an incoming INVITE.
* @param request the received request
* @throws ParseException
* error parsing the status code
* @throws SipException
* error sending the message
* @throws InvalidArgumentException
* if the creation of the response is invalid
* @throws SdpException
*/
public void processInvite(final Request request)
throws ParseException, SipException, InvalidArgumentException, SdpException {
final Response ringingResponse =
messageFactory.createResponse(Response.RINGING, request);
final ToHeader ringingToHeader =
(ToHeader) ringingResponse.getHeader(ToHeader.NAME);
ringingToHeader.setTag("4321");
final ContactHeader contactHeader =
headerFactory.createContactHeader();
final Address ca = getContactAddress();
contactHeader.setAddress(ca);
ringingResponse.addHeader(contactHeader);
final ServerTransaction transaction =
provider.getNewServerTransaction(request);
dialog = transaction.getDialog();
if (dialog != null) {
LOGGER.info("Dialog: " + dialog);
LOGGER.info("Dialog state: " + dialog.getState());
}
transaction.sendResponse(ringingResponse);
final FromHeader fromHeader =
(FromHeader) request.getHeader(FromHeader.NAME);
final Address fromAddress = fromHeader.getAddress();
LOGGER.info("sent 'RINGING' to '" + fromAddress + "'");
final Response okResponse =
messageFactory.createResponse(Response.OK, request);
final ToHeader okToHeader =
(ToHeader) okResponse.getHeader(ToHeader.NAME);
okToHeader.setTag("4321");
okResponse.addHeader(contactHeader);
ContentTypeHeader contentTypeHeader =
headerFactory.createContentTypeHeader("application", "sdp");
String sdp;
try {
final Vector<MediaDescription> mediaDescriptions
= createMediaDescriptions(request);
final SessionDescription description =
createSessionDescription(InetAddress.getLocalHost(), null,
mediaDescriptions);
sdp = description.toString();
} catch (UnknownHostException e) {
throw new SdpException(e.getMessage(), e);
}
okResponse.setContent(sdp, contentTypeHeader);
transaction.sendResponse(okResponse);
LOGGER.info("sent 'OK' to '" + fromAddress + "'");
inviteTransaction = transaction;
// Create a new session
session = new SipSession();
for (UserAgentListener listener : listeners) {
listener.sessionCreated(session);
}
}
示例24
/**
* After the branch is initialized, this method proxies the initial request to the
* specified destination. Subsequent requests are proxied through proxySubsequentRequest
*/
public void cloneRequest()
{
try {
VNXLog.info("cloneRequest targetURI:" + targetURI);
SipURI recordRoute = null;
SipURI recordRouteURI = null;
recordRouteURI = proxy.getRecordRouteURI();
// If the proxy is not adding record-route header, set it to null
// and it
// will be ignored in the Proxying
if (proxy.getRecordRoute()) {
if (recordRouteURI == null) {
recordRouteURI = proxy.getSipFactoryImpl().createSipURI(
"proxy", "localhost");
}
recordRoute = recordRouteURI;
}
Request clonedInit = (Request) originalRequest.getMessage().clone();
((MessageExt) clonedInit).setApplicationData(null);
outgoingRequest = (SipServletRequestImpl) proxy
.getSipFactoryImpl()
.getMobicentsSipServletMessageFactory()
.createSipServletRequest(clonedInit,
originalRequest.getSipSession(), null, null, false);
//
ProxyBranchImpl branch = new ProxyBranchImpl(targetURI,
(ProxyImpl) (originalRequest.getProxy()));
branch.setRecordRoute(true);
branch.setRecurse(true);
//
Request cloned = ProxyUtils.createProxiedRequest(outgoingRequest,
branch, targetURI, proxy.getOutboundInterface(),
recordRoute, proxy.getPathURI());
// Shadowman
VNXLog.info("remove content");
cloned.removeContent();
// tells the application dispatcher to stop routing the original
// request
// since it has been proxied
originalRequest.setRoutingState(RoutingState.PROXIED);
forwardRequest(cloned, false);
} catch (Exception ex) {
VNXLog.error(ex);
}
}
示例25
public MessageEvent(Request source) {
super(source);
}
示例26
/**
* @return Returns the registerRequest.
*/
private Request getRegisterRequest() {
return registerRequest;
}
示例27
void processRefer(ServerTransaction serverTransaction, Request request) {
System.out.println("REFER ANSWER");
}
示例28
/**
* Verifies whether there are any user credentials registered for the call
* that "request" belongs to and appends corresponding authorization headers
* if that is the case.
*
* @param request the request that needs to be attached credentials.
*/
public void appendCredentialsIfNecessary(Request request) {
// TODO IMPLEMENT
}
示例29
/**
* Set Initial request of this call
*
* @param initialRequest The initialRequest to set.
*/
void setInitialRequest(Request initialRequest) {
this.initialRequest = initialRequest;
this.lastRequest = initialRequest;
}
示例30
/**
* Get Initial request of this call
*
* @return Returns the initialRequest.
*/
public Request getInitialRequest() {
return this.initialRequest;
}