Package javax.sip.message

Examples of javax.sip.message.Request


    private boolean loopDetectedSeen;

    public void processRequest(RequestEvent requestEvent) {
        try {
            Request request = requestEvent.getRequest();
            SipProvider sipProvider = (SipProvider) requestEvent.getSource();
            this.inviteServerTxProvider = sipProvider;
            if (request.getMethod().equals(Request.INVITE)) {

                ListeningPoint lp = sipProvider.getListeningPoint(protocolObjects.transport);
                String host = lp.getIPAddress();
                int port = lp.getPort();

                ServerTransaction st = null;
                if (requestEvent.getServerTransaction() == null) {
                    st = sipProvider.getNewServerTransaction(request);

                    Request newRequest = (Request) request.clone();
                    SipURI sipUri = protocolObjects.addressFactory.createSipURI("UA1",
                            "127.0.0.1");
                    sipUri.setPort(5080);
                    sipUri.setLrParam();
                    Address address = protocolObjects.addressFactory.createAddress("client1",
                            sipUri);
                    RouteHeader rheader = protocolObjects.headerFactory
                            .createRouteHeader(address);

                    newRequest.addFirst(rheader);
                    ViaHeader viaHeader = protocolObjects.headerFactory.createViaHeader(host,
                            port, protocolObjects.transport, null);
                    newRequest.addFirst(viaHeader);
                    ClientTransaction ct1 = sipProvider.getNewClientTransaction(newRequest);
                    sipUri = protocolObjects.addressFactory.createSipURI("proxy", "127.0.0.1");
                    address = protocolObjects.addressFactory.createAddress("proxy", sipUri);
                    sipUri.setPort(5080);
                    sipUri.setLrParam();
                    RecordRouteHeader recordRoute = protocolObjects.headerFactory
                            .createRecordRouteHeader(address);
                    newRequest.addHeader(recordRoute);
                    ct1.setApplicationData(st);
                    this.clientTxTable.add(ct1);

                    newRequest = (Request) request.clone();
                    sipUri = protocolObjects.addressFactory.createSipURI("UA2", "127.0.0.1");
                    sipUri.setLrParam();
                    sipUri.setPort(5080);
                    address = protocolObjects.addressFactory.createAddress("client2", sipUri);
                    rheader = protocolObjects.headerFactory.createRouteHeader(address);
                    newRequest.addFirst(rheader);
                    viaHeader = protocolObjects.headerFactory.createViaHeader(host, port,
                            protocolObjects.transport, null);
                    newRequest.addFirst(viaHeader);
                    sipUri = protocolObjects.addressFactory.createSipURI("proxy", "127.0.0.1");
                    sipUri.setPort(5080);
                    sipUri.setLrParam();
                    sipUri.setTransportParam(protocolObjects.transport);
                    address = protocolObjects.addressFactory.createAddress("proxy", sipUri);

                    recordRoute = protocolObjects.headerFactory.createRecordRouteHeader(address);

                    newRequest.addHeader(recordRoute);
                    ClientTransaction ct2 = sipProvider.getNewClientTransaction(newRequest);
                    ct2.setApplicationData(st);
                    this.clientTxTable.add(ct2);

                    // Send the requests out to the two listening points of the
                    // client.

                    ct2.sendRequest();
                    ct1.sendRequest();
                }

            } else {
                // Remove the topmost route header
                // The route header will make sure it gets to the right place.
                logger.info("proxy: Got a request " + request.getMethod());
                Request newRequest = (Request) request.clone();
                newRequest.removeFirst(RouteHeader.NAME);
                sipProvider.sendRequest(newRequest);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
View Full Code Here


        protected int notifyCount = 0;

   

        public void processRequest(RequestEvent requestEvent) {
            Request request = requestEvent.getRequest();
            ServerTransaction serverTransactionId = requestEvent.getServerTransaction();

            logger.info("\n\nRequest " + request.getMethod() + " received at "
                    + sipStack.getStackName() + " with server transaction id "
                    + serverTransactionId + " and dialog id " + requestEvent.getDialog());

            if (request.getMethod().equals(Request.SUBSCRIBE)) {
                processSubscribe(requestEvent, serverTransactionId);
            }

        }
View Full Code Here

         * Process the invite request.
         */
        public void processSubscribe(RequestEvent requestEvent,
                ServerTransaction serverTransaction) {
            SipProvider sipProvider = (SipProvider) requestEvent.getSource();
            Request request = requestEvent.getRequest();
            try {
                logger.info("notifier: got an Subscribe sending OK");
                logger.info("notifier:  " + request);
                logger.info("notifier : dialog = " + requestEvent.getDialog());
                EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
                if (eventHeader == null) {
                    logger.info("Cannot find event header.... dropping request.");
                    return;
                }

                // Always create a ServerTransaction, best as early as possible in the code
                Response response = null;
                ServerTransaction st = requestEvent.getServerTransaction();
                if (st == null) {
                    st = sipProvider.getNewServerTransaction(request);
                }

                // Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
                boolean isInitial = requestEvent.getDialog() == null;
                if (isInitial) {
                    // JvB: need random tags to test forking
                    String toTag = Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE));
                    response = messageFactory.createResponse(202, request);
                    ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);

                    // Sanity check: to header should not ahve a tag. Else the dialog
                    // should have matched
                    if (toHeader.getTag() != null) {
                        System.err
                                .println("####ERROR: To-tag!=null but no dialog match! My dialog="
                                        + dialog.getState());
                    }
                    toHeader.setTag(toTag); // Application is supposed to set.

                    this.dialog = st.getDialog();
                    // subscribe dialogs do not terminate on bye.
                    this.dialog.terminateOnBye(false);
                    if (dialog != null) {
                        logger.info("Dialog " + dialog);
                        logger.info("Dialog state " + dialog.getState());
                    }
                } else {
                    response = messageFactory.createResponse(200, request);
                }

                // Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
                Address address = addressFactory.createAddress("Notifier <sip:127.0.0.1>");
                ((SipURI) address.getURI()).setPort(udpProvider.getListeningPoint("udp")
                        .getPort());
                ContactHeader contactHeader = headerFactory.createContactHeader(address);
                response.addHeader(contactHeader);

                // Expires header is mandatory in 2xx responses to SUBSCRIBE
                ExpiresHeader expires = (ExpiresHeader) request.getHeader(ExpiresHeader.NAME);
                if (expires == null) {
                    expires = headerFactory.createExpiresHeader(30); // rather short
                }
                response.addHeader(expires);

                /*
                 * NOTIFY requests MUST contain a "Subscription-State" header with a value of
                 * "active", "pending", or "terminated". The "active" value indicates that the
                 * subscription has been accepted and has been authorized (in most cases; see
                 * section 5.2.). The "pending" value indicates that the subscription has been
                 * received, but that policy information is insufficient to accept or deny the
                 * subscription at this time. The "terminated" value indicates that the
                 * subscription is not active.
                 */

                Address fromAddress = ((ToHeader) response.getHeader(ToHeader.NAME)).getAddress();
                String fromTag = ((ToHeader) response.getHeader(ToHeader.NAME)).getTag();
                FromHeader fromHeader = headerFactory.createFromHeader(fromAddress, fromTag);
               
                Address toAddress = ((FromHeader) response.getHeader(FromHeader.NAME)).getAddress();
                String toTag = ((FromHeader) response.getHeader(FromHeader.NAME)).getTag();
                ToHeader toHeader = headerFactory.createToHeader(toAddress, toTag);
               
               
               
                CallIdHeader callId = (CallIdHeader) response.getHeader(CallIdHeader.NAME);

                ContactHeader requestContact = (ContactHeader) request
                        .getHeader(ContactHeader.NAME);
                SipURI notifyRuri = (SipURI) requestContact.getAddress().getURI();
                CSeqHeader cSeq = headerFactory.createCSeqHeader(1L, Request.NOTIFY);
                String ipAddress = sipProvider.getListeningPoint("udp").getIPAddress();
                int port = sipProvider.getListeningPoint("udp").getPort();
                ViaHeader viaHeader = headerFactory.createViaHeader(ipAddress, port, "udp", null);
                LinkedList llist = new LinkedList<ViaHeader>();
                llist.add(viaHeader);

                MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);
                Request notifyRequest = messageFactory.createRequest(notifyRuri, Request.NOTIFY,
                        callId, cSeq, fromHeader, toHeader, llist, maxForwards);
                notifyRequest.addHeader(contactHeader);

                // Mark the contact header, to check that the remote contact is updated
                ((SipURI) contactHeader.getAddress().getURI()).setParameter("id", "not");

                // Initial state is pending, second time we assume terminated (Expires==0)
                SubscriptionStateHeader sstate = headerFactory
                        .createSubscriptionStateHeader(isInitial ? SubscriptionStateHeader.PENDING
                                : SubscriptionStateHeader.TERMINATED);

                // Need a reason for terminated
                if (sstate.getState().equalsIgnoreCase("terminated")) {
                    sstate.setReasonCode("deactivated");
                }

                notifyRequest.addHeader(sstate);
                notifyRequest.setHeader(eventHeader);
                notifyRequest.setHeader(contactHeader);
                // notifyRequest.setHeader(routeHeader);
                ClientTransaction ct = udpProvider.getNewClientTransaction(notifyRequest);

                /*
                 * We deliberately send the NOTIFY first before the 202 is sent.
View Full Code Here

  public Shootme(ProtocolObjects protocolObjects) {
    this.protocolObjects = protocolObjects;
  }

  public void processRequest(RequestEvent requestEvent) {
    Request request = requestEvent.getRequest();
    ServerTransaction serverTransactionId = requestEvent
        .getServerTransaction();

    logger.info("\n\nRequest " + request.getMethod() + " received at "
        + protocolObjects.sipStack.getStackName()
        + " with server transaction id " + serverTransactionId);

    if (request.getMethod().equals(Request.INVITE)) {
      processInvite(requestEvent, serverTransactionId);
    } else if (request.getMethod().equals(Request.ACK)) {
      processAck(requestEvent, serverTransactionId);
    } else if (request.getMethod().equals(Request.BYE)) {
      processBye(requestEvent, serverTransactionId);
    }

  }
View Full Code Here

   * Process the invite request.
   */
  public void processInvite(RequestEvent requestEvent,
      ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    logger.info("Got an INVITE  " + request);
    try {

      // JvB: first time, challenge with 401 response (without proper
      // headers)
      if (!challenged) {
        challenged = true;
        ChallengeTest.assertNull(requestEvent.getServerTransaction());

        Response challenge = protocolObjects.messageFactory
            .createResponse(401, request);
        ToHeader toHeader = (ToHeader) challenge
            .getHeader(ToHeader.NAME);
        toHeader.setTag("challenge");
        sipProvider.sendResponse(challenge); // dont create ST
        return;
      }

      logger.info("shootme: got an Invite sending OK");
      // logger.info("shootme: " + request);
      Response response = protocolObjects.messageFactory.createResponse(
          180, request);
      ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
      toHeader.setTag("4321");
      Address address = protocolObjects.addressFactory
          .createAddress("Shootme <sip:" + myAddress + ":" + myPort
              + ">");
      ContactHeader contactHeader = protocolObjects.headerFactory
          .createContactHeader(address);
      response.addHeader(contactHeader);
      ServerTransaction st = requestEvent.getServerTransaction();

      if (st == null) {
        st = sipProvider.getNewServerTransaction(request);
        logger.info("Server transaction created!" + request);

        logger.info("Dialog = " + st.getDialog());
        if (st.getDialog().getApplicationData() == null) {
          st.getDialog().setApplicationData(new ApplicationData());
        }
      } else {
        // If Server transaction is not null, then
        // this is a re-invite.
        logger.info("This is a RE INVITE ");
        ChallengeTest.assertSame("Dialog mismatch ", st.getDialog(),
            this.dialog);
      }

      // Thread.sleep(5000);
      logger.info("got a server tranasaction " + st);
      byte[] content = request.getRawContent();
      if (content != null) {
        logger.info(" content = " + new String(content));
        ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory
            .createContentTypeHeader("application", "sdp");
        logger.info("response = " + response);
View Full Code Here

   */
  public void processBye(RequestEvent requestEvent,
      ServerTransaction serverTransactionId) {

    // SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      // JvB: first time, challenge with 401 response (without proper
      // headers)
      if (!challengedBye) {
        challengedBye = true;
View Full Code Here

        ChallengeTest.assertNotNull(
            "INVITE 200 response should match a transaction", tid);
        Dialog dialog = tid.getDialog();
        CSeqHeader cseq = (CSeqHeader) response
            .getHeader(CSeqHeader.NAME);
        Request request = dialog.createAck(cseq.getSeqNumber());
        dialog.sendAck(request);
      }
      if (tid != null) {
        Dialog dialog = tid.getDialog();
        logger.info("Dalog State = " + dialog.getState());
View Full Code Here

   
    protocolObjects.logLevel = 32// JvB
  }

  public void processRequest(RequestEvent requestReceivedEvent) {
    Request request = requestReceivedEvent.getRequest();
    ServerTransaction serverTransactionId = requestReceivedEvent
        .getServerTransaction();

    logger.info("\n\nRequest " + request.getMethod() + " received at "
        + protocolObjects.sipStack.getStackName()
        + " with server transaction id " + serverTransactionId);

    // We are the UAC so the only request we get is the BYE.
    if (request.getMethod().equals(Request.BYE))
      processBye(request, serverTransactionId);
    else
      TestHarness.fail("Unexpected request ! : " + request);

  }
View Full Code Here

      if (response.getStatusCode() == Response.OK) {
        if (cseq.getMethod().equals(Request.INVITE)) {
          TestHarness.assertEquals( DialogState.CONFIRMED, dialog.getState() );
                 
         
          Request ackRequest = dialog.createAck(cseq
                            .getSeqNumber());
                   
                    TestHarness.assertNotNull( ackRequest.getHeader( MaxForwardsHeader.NAME ) );
   
          // Proxy will fork. I will accept the second dialog
          // but not the first.
          this.forkedDialogs.add(dialog);
          dialog.sendAck(ackRequest);
          if ( forkedDialogs.size() == 2 ) {
            logger.info("Sending ACK");
           
            TestHarness.assertTrue(
                "Dialog state should be CONFIRMED", dialog
                    .getState() == DialogState.CONFIRMED);
            this.ackedDialog = dialog;
           
            // TestHarness.assertNotNull( "JvB: Need CT to find original dialog", tid );

          } else {
           
            // Kill the first dialog by sending a bye.
            SipProvider sipProvider = (SipProvider) responseReceivedEvent
                .getSource();
            Request byeRequest = dialog.createRequest(Request.BYE);
            ClientTransaction ct = sipProvider
                .getNewClientTransaction(byeRequest);
            dialog.sendRequest(ct);         
          }
         
View Full Code Here

      // Create a new MaxForwardsHeader
      MaxForwardsHeader maxForwards = protocolObjects.headerFactory
          .createMaxForwardsHeader(70);

      // Create the request.
      Request request = protocolObjects.messageFactory.createRequest(
          requestURI, Request.INVITE, callIdHeader, cSeqHeader,
          fromHeader, toHeader, viaHeaders, maxForwards);
      // Create contact headers

      SipURI contactUrl = protocolObjects.addressFactory.createSipURI(
          fromName, host);
      contactUrl.setPort(listeningPoint.getPort());

      // Create the contact name address.
      SipURI contactURI = protocolObjects.addressFactory.createSipURI(
          fromName, host);
      contactURI.setPort(sipProvider.getListeningPoint(
          protocolObjects.transport).getPort());
      contactURI.setTransportParam(protocolObjects.transport);

      Address contactAddress = protocolObjects.addressFactory
          .createAddress(contactURI);

      // Add the contact address.
      contactAddress.setDisplayName(fromName);

      contactHeader = protocolObjects.headerFactory
          .createContactHeader(contactAddress);
      request.addHeader(contactHeader);

      // Dont use the Outbound Proxy. Use Lr instead.
      request.setHeader(routeHeader);

      // Add the extension header.
      Header extensionHeader = protocolObjects.headerFactory
          .createHeader("My-Header", "my header value");
      request.addHeader(extensionHeader);

      String sdpData = "v=0\r\n"
          + "o=4855 13760799956958020 13760799956958020"
          + " IN IP4  129.6.55.78\r\n" + "s=mysession session\r\n"
          + "p=+46 8 52018010\r\n" + "c=IN IP4  129.6.55.78\r\n"
          + "t=0 0\r\n" + "m=audio 6022 RTP/AVP 0 4 18\r\n"
          + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n"
          + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
      byte[] contents = sdpData.getBytes();

      request.setContent(contents, contentTypeHeader);

      extensionHeader = protocolObjects.headerFactory.createHeader(
          "My-Other-Header", "my new header value ");
      request.addHeader(extensionHeader);

      Header callInfoHeader = protocolObjects.headerFactory.createHeader(
          "Call-Info", "<http://www.antd.nist.gov>");
      request.addHeader(callInfoHeader);

      // Create the client transaction.
      inviteTid = sipProvider.getNewClientTransaction(request);
      Dialog dialog = inviteTid.getDialog();
View Full Code Here

TOP

Related Classes of javax.sip.message.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.