/** * * @param req * @throws IOException */ private void notImplemented(SipServletRequest req) throws IOException { SipServletResponse resp = req.createResponse(501, "Request not implemented"); resp.send(); } }
if (response.getSession() == null || !response.getSession().isValid()) { if (logger.isDebugEnabled()) { logger.debug("Response session is either null or invalidated"); if (response.getStatus() > 200) response.getSession().setAttribute(B2BUA_LAST_FINAL_RESPONSE, response); if (response.getStatus() == 487 || (response.getStatus() == 200 && response.getMethod().equalsIgnoreCase("CANCEL"))) { if (logger.isDebugEnabled()) { logger.debug("response to CANCEL not forwarding"); if (response.getStatus() == 200 && response.getMethod().equalsIgnoreCase("BYE")) { if (logger.isDebugEnabled()) { logger.debug("response to BYE not forwarding"); if (response.getSession() != null && (!response.getSession().getState().equals(SipSession.State.TERMINATED))) { response.getSession().setAttribute(B2BUA_LAST_RESPONSE, response); SipServletResponse clonedResponse = linkedRequest.createResponse(response.getStatus()); SipURI originalURI = null; try { if(clonedResponse.getAddressHeader("Contact") != null && response.getAddressHeader("Contact") != null && response.getAddressHeader("Contact").getURI() != null) { originalURI = (SipURI) response.getAddressHeader("Contact").getURI(); if (originalURI != null && originalURI.getUser() != null && !originalURI.getUser().isEmpty()) { ((SipURI) clonedResponse.getAddressHeader("Contact").getURI()).setUser(originalURI.getUser());
public synchronized void established(final SipServletResponse successResponse) throws CallException, IOException { final List<State> possibleStates = new ArrayList<State>(); possibleStates.add(QUEUED); possibleStates.add(RINGING); assertState(possibleStates); byte[] answer = successResponse.getRawContent(); try { if(answer != null) { answer = patchMedia(successResponse.getInitialRemoteAddr(), successResponse.getRawContent()); final ConnectionDescriptor remoteDescriptor = new ConnectionDescriptor(new String(answer)); userAgentConnection.modify(remoteDescriptor); } else { terminate(); setState(FAILED); fireStatusChanged(); throw new CallException("The remote client did not send an SDP answer with their 200 OK response."); } } catch(final SdpException exception) { terminate(); setState(FAILED); fireStatusChanged(); throw new CallException(exception); } final SipServletRequest ack = successResponse.createAck(); ack.send(); }
static void authenticate(final SipServletRequest request, String realm) throws IOException { final SipServletResponse response = request.createResponse(SC_PROXY_AUTHENTICATION_REQUIRED); final String nonce = nonce(); String algorithm = RestcommConfiguration.getInstance().getMain().getClientAlgorithm(); String qop = RestcommConfiguration.getInstance().getMain().getClientQOP(); final String header = header(nonce, realm, "Digest", algorithm, qop); response.addHeader("Proxy-Authenticate", header); response.send(); }
@Override public synchronized void answer() throws CallException { assertState(RINGING); try { // Establish the media path way. relayOutboundConnection = session.createConnection(relayEndpoint); relayOutboundConnection.addObserver(this); relayOutboundConnection.connect(ConnectionMode.SendRecv); block(6, RINGING); // Send the response back to the caller. final byte[] answer = patchMedia(server.getExternalAddress(), userAgentConnection.getLocalDescriptor().toString().getBytes()); final SipServletResponse ok = initialInvite.createResponse(SipServletResponse.SC_OK); ok.setContent(answer, "application/sdp"); ok.send(); } catch(final Exception exception) { fail(SipServletResponse.SC_SERVER_INTERNAL_ERROR); fireStatusChanged(); logger.error(exception); throw new CallException(exception); } }
/** * @param response the finalResponse to set */ public void setResponse(SipServletResponseImpl response) { if(response.getStatus() >= 200 && (lastFinalResponse == null || lastFinalResponse.getStatus() < response.getStatus())) { if(logger.isDebugEnabled()) { logger.debug("last final response " + response + " set on " + this); } this.lastFinalResponse = response; } // we keep the last informational response for noPrackReceived only if(containsRel100(response.getMessage()) && (response.getStatus() > 100 && response.getStatus() < 200) && (lastInformationalResponse == null || lastInformationalResponse.getStatus() < response.getStatus())) { if(logger.isDebugEnabled()) { logger.debug("last informational response " + lastInformationalResponse + " set on " + this); } this.lastInformationalResponse = response; } }
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException { if(request != null) { ((SipServletRequest)request).getSession().setHandler(handler.getName()); } else { ((SipServletResponse)response).getSession().setHandler(handler.getName()); } Servlet servlet = handler.allocate(); servlet.service(request, response); handler.deallocate(servlet); }
private void updateReadyToInvalidate(Transaction transaction) { // Section 6.2.4.1.2 Invalidate When Ready Mechanism : // "The container determines the SipSession to be in the ready-to-invalidate state under any of the following conditions: // 3. A SipSession acting as a UAC transitions from the EARLY state back to // the INITIAL state on account of receiving a non-2xx final response (6.2.1 Relationship to SIP Dialogs, point 4) // and has not initiated any new requests (does not have any pending transactions)." if(logger.isDebugEnabled()) { if(ongoingTransactions != null) { logger.debug("ongoingTransactions " + ongoingTransactions.isEmpty() + " for sipsession " + key); } else { logger.debug("ongoingTransactions " + null + " for sipsession " + key); } } if(!readyToInvalidate && (ongoingTransactions == null || ongoingTransactions.isEmpty()) && transaction instanceof ClientTransaction && getProxy() == null && state != null && state.equals(State.INITIAL) && // Fix for Issue 1734 sessionCreatingTransactionRequest != null && sessionCreatingTransactionRequest.getLastFinalResponse() != null && sessionCreatingTransactionRequest.getLastFinalResponse().getStatus() >= 300) { setReadyToInvalidate(true); } }
/** * * @param req * @throws IOException */ private void notHandled(SipServletRequest req) throws IOException { SipServletResponse resp = req.createResponse(500, "Request not handled by app"); resp.send(); }
if(response.getStatus() > Response.TRYING) { servlet.service(null, response);
private void fail(int code) { final SipServletResponse fail = initialInvite.createResponse(code); try { fail.send(); } catch(final IOException exception) { logger.error(exception); } cleanup(); setState(FAILED); }
/** * Invoked to handle incoming responses. This method dispatched responses to one of the * , * , * . Servlets will not usually need to override this method. */ protected void doResponse(javax.servlet.sip.SipServletResponse resp) throws javax.servlet.ServletException, java.io.IOException{ int status = resp.getStatus(); if (status < 200) { doProvisionalResponse(resp); } else { if (status < 300) { doSuccessResponse(resp); } else if (status < 400) { doRedirectResponse(resp); } else { doErrorResponse(resp); } } }
public synchronized void bye(final SipServletRequest request) throws IOException { final List<State> possibleStates = new ArrayList<State>(); possibleStates.add(QUEUED); possibleStates.add(RINGING); possibleStates.add(IN_PROGRESS); assertState(possibleStates); final SipServletResponse ok = request.createResponse(SipServletResponse.SC_OK); try { ok.send(); } finally { cleanup(); setState(COMPLETED); dateEnded = DateTime.now(); fireStatusChanged(); } }
public boolean allResponsesHaveArrived() { for(final MobicentsProxyBranch pbi: this.proxyBranches.values()) { final SipServletResponse response = pbi.getResponse(); // The unstarted branches still haven't got a chance to get response // Issue http://code.google.com/p/mobicents/issues/detail?id=2461 adding !isCancelled if(!pbi.isStarted() && !pbi.isCanceled()) { return false; } if(pbi.isStarted() && !pbi.isTimedOut() // Issue http://code.google.com/p/mobicents/issues/detail?id=2461 adding !isCancelled // Issue https://code.google.com/p/sipservlets/issues/detail?id=283 fixing !isCancelled for parallel branches, // we should wait for best reponse from all branches && (!parallel && !pbi.isCanceled() || parallel) ) { if(response == null || // if there is no response yet response.getStatus() < Response.OK) { // or if the response if not final return false; // then we should wait more } } } return true; }
public synchronized void cancel(final SipServletRequest request) throws IOException { final List<State> possibleStates = new ArrayList<State>(); possibleStates.add(QUEUED); possibleStates.add(RINGING); possibleStates.add(TRYING); assertState(possibleStates); final SipServletResponse ok = request.createResponse(SipServletResponse.SC_OK); try { ok.send(); } finally { cleanup(); setState(CANCELLED); fireStatusChanged(); } }
if(lastFinalResponse != null && lastFinalResponse.getStatus() >= 300) { callServlet = false; if(logger.isDebugEnabled()) {
@Override public synchronized void reject() { assertState(RINGING); final SipServletResponse busy = initialInvite.createResponse(SipServletResponse.SC_BUSY_HERE); try { busy.send(); } catch(final IOException exception) { cleanup(); setState(FAILED); fireStatusChanged(); logger.error(exception); } }
(sessionCreatingTransactionRequest.getLastFinalResponse().getStatus() != 401 && sessionCreatingTransactionRequest.getLastFinalResponse().getStatus() != 407 && sessionCreatingTransactionRequest.getLastFinalResponse().getStatus() != SipServletResponse.SC_SESSION_INTERVAL_TOO_SMALL)) { throw new IllegalStateException("cannot create a subsequent request " + method + " because the dialog " + sessionCreatingDialog + " for session " + key + " is in TERMINATED state"); sessionCreatingTransactionRequest.getLastFinalResponse().getStatus() >= 400 && sessionCreatingTransactionRequest.getLastFinalResponse().getStatus() < 500) { if(logger.isDebugEnabled()) { logger.debug("Treating as Initial Request");
response.send(); } catch (IOException e) { logger.error("Can not send error response", e);
@Override public JsonElement serialize(CallInfo callInfo, Type typeOfSrc, JsonSerializationContext context) { final JsonObject object = new JsonObject(); writeSid(callInfo.sid(), object); writeState(callInfo.state().name(), object); if (callInfo.type() != null) writeType(callInfo.type().name(), object); writeDirection(callInfo.direction(), object); writeDateCreated(callInfo.dateCreated(), object); writeForwardedFrom(callInfo.forwardedFrom(), object); writeCallerName(callInfo.fromName(), object); writeFrom(callInfo.from(), object); writeTo(callInfo.to(), object); if (callInfo.invite() != null) { writeInviteUri(callInfo.invite().getRequestURI(), object); } if (callInfo.lastResponse() != null) writeLastResponseUri(callInfo.lastResponse().getStatus(), object); return object; }