// Process Request received public void processRequest(jain.protocol.ip.sip.SipEvent requestReceivedEvent) { Request request = (Request) requestReceivedEvent.getMessage(); long serverTransactionId = requestReceivedEvent.getTransactionId(); System.out.println( "\n\nRequest received with server transaction id " + serverTransactionId + ":\n" + request); try { // If request is not an ACK then try to send an OK Response if ((!Request.ACK.equals(request.getMethod())) && (!Request.REGISTER.equals(request.getMethod()))) { String body = request.getBodyAsString(); getSipProvider().sendResponse(serverTransactionId, Response.OK, body, "application", "sdp"); } } catch (TransactionDoesNotExistException e) { e.printStackTrace(); System.out.println(e.getMessage()); System.exit(-1); } catch (SipParseException e) { e.printStackTrace(); System.out.println(e.getMessage()); System.exit(-1); } catch (SipException e) { e.printStackTrace(); System.out.println(e.getMessage()); System.exit(-1); } System.out.println("Completed processing request!"); }
/** * handles a BYE request * * @param request the request * @param transId the transaction Id * @throws TransactionDoesNotExistException when the transaction record does not exist. */ private void handleBye(Request request, ServerTransaction st) { try { CallIdHeader callIdHeader = (CallIdHeader) request.getHeader("Call-Id"); String sipCallId = callIdHeader.getCallId(); if (sipCallId.equals(this.sipCallId)) { receivedBye = true; try { Logger.writeFile("Call " + cp + " has hung up."); // sipUtil.sendOK(clientTransaction, st, cp); sipUtil.sendOK(request, st); } catch (Exception e) { /* * We sometimes get a null ServerTransaction */ } cancelRequest("hung up"); sipServerCallback.removeSipListener(sipCallId); } else { /* * this should not happen since the message has been * delegated to this sip agent. */ throw new TransactionDoesNotExistException( cp + "BYE request received did not " + "match either party: " + request); } } catch (TransactionDoesNotExistException e) { Logger.error("Call " + cp + " Transaction not found " + e.getMessage()); } catch (SipException e) { Logger.exception("Call " + cp + " SIP Stack error", e); cancelRequest("handleBye: SIP Stack error " + e.getMessage()); } catch (Exception e) { Logger.exception("Call " + cp + " Unknown error ", e); cancelRequest("handleBye: SIP Stack error " + e.getMessage()); } }