// if we are calling to vmail this means we want to check our mail
// box
// sameUser = true
boolean sameUser = sameUser(event);
URI uri;
if (sameUser) {
// The user is the caller
FromHeader fromHeader = (FromHeader) request
.getHeader(FromHeader.NAME);
uri = fromHeader.getAddress().getURI();
} else {
// The user is the callee - we are calling someone else
ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
uri = toHeader.getAddress().getURI();
}
// In the Profile Table the port is not used
((SipURI) uri).removePort();
// Responding to the user
// To know whether the user has the Voice mail service enabled
boolean isSubscriber = isSubscriber(uri.toString());
if (isSubscriber) {
// Voice Mail service enabled
String fileRoute = null;
// Looking for the audio file to transmit
Context initCtx = new InitialContext();
Context myEnv = (Context) initCtx.lookup("java:comp/env");
// check if the user is calling their own number to check voice
// mail
if (sameUser) {
}
// or someone else is calling the user to leave a voice message
else {
ToHeader toHeader = (ToHeader) request
.getHeader(ToHeader.NAME);
String fileName = ((SipURI) toHeader.getAddress().getURI())
.getUser()
+ WAV_EXT;
// Setting File Route where recording the voice message
String route = (String) myEnv.lookup("filesRoute");
fileRoute = route + fileName;
}
// SDP Description from the request
String sdp = new String(request.getRawContent());
// Creating Media Session
MsSession mediaSession = msProvider.createSession();
// Setting Media Session
this.setMediaSession(mediaSession);
MsConnection msConnection = mediaSession
.createNetworkConnection(ENDPOINT_NAME);
// Attaching session AC
ActivityContextInterface msAci = null;
try {
msAci = msActivityFactory
.getActivityContextInterface(msConnection);
msAci.attach(this.getSbbLocalObject());
} catch (Exception ex) {
log.error("Internal server error", ex);
getMessageFactory().createResponse(
Response.SERVER_INTERNAL_ERROR, request);
return;
}
// Attaching to SIP Dialog activity
Dialog dial = getSipFactoryProvider().getSipProvider()
.getNewDialog((Transaction) st);
ActivityContextInterface dialogAci = sipACIF
.getActivityContextInterface(dial);
// attach this SBB object to the Dialog activity to receive
// subsequent events on this Dialog
dialogAci.attach(this.getSbbLocalObject());
// Notify caller that we're TRYING to reach voice mail. Just a
// formality, we know we can go further than TRYING at this
// point
response = getMessageFactory().createResponse(Response.TRYING,
request);
st.sendResponse(response);
// RINGING. Another formality of the SIP protocol.
response = getMessageFactory().createResponse(Response.RINGING,
request);
st.sendResponse(response);
log.info("Creating RTP connection [" + ENDPOINT_NAME + "]");
msConnection.modify("$", sdp);
}
// Voice Mail service disabled
else {
response = getMessageFactory().createResponse(
Response.TEMPORARILY_UNAVAILABLE, request);
log.info("########## NO VOICE MAIL AVAILABLE FOR USER: "
+ uri.toString());
st.sendResponse(response);
}
} catch (TransactionRequiredLocalException e) {
log.error(e.getMessage(), e);