/** * Creates a new SUBSCRIBE request in the form of a <tt>ClientTransaction</tt> with the parameters * of a specific <tt>Subscription</tt>. * * @param subscription the <tt>Subscription</tt> to be described in a SUBSCRIBE request * @param expires the subscription duration of the SUBSCRIBE request to be created * @return a new <tt>ClientTransaction</tt> initialized with a new SUBSCRIBE request which matches * the parameters of the specified <tt>Subscription</tt> * @throws OperationFailedException if the request could not be generated */ private ClientTransaction createSubscription(Subscription subscription, int expires) throws OperationFailedException { Address toAddress = subscription.getAddress(); HeaderFactory headerFactory = protocolProvider.getHeaderFactory(); // Call ID CallIdHeader callIdHeader = protocolProvider.getDefaultJainSipProvider().getNewCallId(); // CSeq CSeqHeader cSeqHeader; try { cSeqHeader = headerFactory.createCSeqHeader(1l, Request.SUBSCRIBE); } catch (InvalidArgumentException ex) { // Shouldn't happen logger.error("An unexpected error occurred while" + "constructing the CSeqHeader", ex); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the CSeqHeader", OperationFailedException.INTERNAL_ERROR, ex); } catch (ParseException ex) { // shouldn't happen logger.error("An unexpected error occurred while" + "constructing the CSeqHeader", ex); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the CSeqHeader", OperationFailedException.INTERNAL_ERROR, ex); } // FromHeader and ToHeader String localTag = SipMessageFactory.generateLocalTag(); FromHeader fromHeader; ToHeader toHeader; try { // FromHeader fromHeader = headerFactory.createFromHeader(protocolProvider.getOurSipAddress(toAddress), localTag); // ToHeader toHeader = headerFactory.createToHeader(toAddress, null); } catch (ParseException ex) { // these two should never happen. logger.error( "An unexpected error occurred while" + "constructing the FromHeader or ToHeader", ex); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the FromHeader or ToHeader", OperationFailedException.INTERNAL_ERROR, ex); } // ViaHeaders ArrayList<ViaHeader> viaHeaders = protocolProvider.getLocalViaHeaders(toAddress); // MaxForwards MaxForwardsHeader maxForwards = protocolProvider.getMaxForwardsHeader(); Request req; try { req = protocolProvider .getMessageFactory() .createRequest( toHeader.getAddress().getURI(), Request.SUBSCRIBE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards); } catch (ParseException ex) { // shouldn't happen logger.error("Failed to create message Request!", ex); throw new OperationFailedException( "Failed to create message Request!", OperationFailedException.INTERNAL_ERROR, ex); } populateSubscribeRequest(req, subscription, expires); // Transaction ClientTransaction subscribeTransaction; try { subscribeTransaction = protocolProvider.getDefaultJainSipProvider().getNewClientTransaction(req); } catch (TransactionUnavailableException ex) { logger.error( "Failed to create subscribe transaction.\n" + "This is most probably a network connection error.", ex); throw new OperationFailedException( "Failed to create the subscription transaction", OperationFailedException.NETWORK_FAILURE); } return subscribeTransaction; }