/**
  * Creates a SIP response message.
  *
  * @param req the request message
  * @param code the response code
  * @param reason the response reason
  * @param contact the contact address
  * @param local_tag the local tag in the 'To' header
  * @param body the message body
  */
 public static Message createResponse(
     Message req,
     int code,
     String reason,
     String local_tag,
     NameAddress contact,
     String content_type,
     String body) {
   Message resp = new Message();
   resp.setStatusLine(new StatusLine(code, reason));
   resp.setVias(req.getVias());
   if (code >= 180 && code < 300 && req.hasRecordRouteHeader())
     resp.setRecordRoutes(req.getRecordRoutes());
   ToHeader toh = req.getToHeader();
   if (local_tag != null) toh.setParameter("tag", local_tag);
   resp.setToHeader(toh);
   resp.setFromHeader(req.getFromHeader());
   resp.setCallIdHeader(req.getCallIdHeader());
   resp.setCSeqHeader(req.getCSeqHeader());
   if (contact != null) resp.setContactHeader(new ContactHeader(contact));
   // add Server header field
   if (SipStack.server_info != null) resp.setServerHeader(new ServerHeader(SipStack.server_info));
   // if (body!=null) resp.setBody(body); else resp.setBody("");
   if (content_type == null) resp.setBody(body);
   else resp.setBody(content_type, body);
   // System.out.println("DEBUG: MessageFactory:
   // response:\n"+resp.toString());
   return resp;
 }
Beispiel #2
0
  @Override
  public String receive(Boolean transactional)
      throws IOException, InterruptedException, ClassNotFoundException {
    ClientRequestHandler crh = new ClientRequestHandler("localhost", 1313, true);
    Marshaller marshaller = new Marshaller();
    RequestPacket requestPacket = new RequestPacket();
    ReplyPacket marshalledReplyPacket = new ReplyPacket();
    byte[] unmarshalledReplyPacket = new byte[1024];
    Message message = new Message();

    // configure message
    message.setHeader(new MessageHeader(this.queueName, transactional));
    message.setBody(new MessageBody("messageBody"));

    // configure packet
    RequestPacketBody packetBody = new RequestPacketBody();
    ArrayList<Object> parameters = new ArrayList<Object>(0);
    packetBody.setParameters(parameters);
    packetBody.setMessage(message);
    requestPacket.setPacketHeader(new RequestPacketHeader("receive"));
    requestPacket.setPacketBody(packetBody);

    // send request
    crh.send(marshaller.marshall((Object) requestPacket));

    // receive reply
    unmarshalledReplyPacket = crh.receive();
    marshalledReplyPacket = (ReplyPacket) marshaller.unmarshall(unmarshalledReplyPacket);

    return marshalledReplyPacket.getReply(); // TODO
  }
Beispiel #3
0
  @Override
  public void send(String m, Boolean transactional) throws IOException, InterruptedException {
    // configure
    ClientRequestHandler crh = new ClientRequestHandler("localhost", 1313, false);
    Marshaller marshaller = new Marshaller();
    RequestPacket packet = new RequestPacket();
    Message message = new Message();

    // configure message
    message.setHeader(new MessageHeader(this.queueName, transactional));
    message.setBody(new MessageBody(m));

    // configure packet
    RequestPacketBody packetBody = new RequestPacketBody();
    ArrayList<Object> parameters = new ArrayList<Object>(0);

    packetBody.setParameters(parameters);
    packetBody.setMessage(message);
    packet.setPacketHeader(new RequestPacketHeader("send"));
    packet.setPacketBody(packetBody);

    // send request
    crh.send(marshaller.marshall((Object) packet));

    return;
  }
 /**
  * Creates a SIP request message.
  *
  * @param method method name
  * @param request_uri request-uri
  * @param to ToHeader NameAddress
  * @param from FromHeader NameAddress
  * @param contact Contact NameAddress (if null, no ContactHeader is added)
  * @param host_addr Via address
  * @param host_port Via port number
  * @param call_id Call-ID value
  * @param cseq CSeq value
  * @param local_tag tag in FromHeader
  * @param remote_tag tag in ToHeader (if null, no tag is added)
  * @param branch branch value (if null, a random value is picked)
  * @param body body (if null, no body is added)
  * @param qvalue Q value (if ICSI is null, no Q value is added)
  * @param icsi ICSI (if null, no ICSI is added)
  */
 public static Message createRequest(
     String method,
     SipURL request_uri,
     NameAddress to,
     NameAddress from,
     NameAddress contact,
     String proto,
     String via_addr,
     int host_port,
     boolean rport,
     String call_id,
     long cseq,
     String local_tag,
     String remote_tag,
     String branch,
     String body,
     String qvalue,
     String icsi) { // modified by mandrajg
   Message req = new Message();
   // mandatory headers first (To, From, Via, Max-Forwards, Call-ID, CSeq):
   req.setRequestLine(new RequestLine(method, request_uri));
   ViaHeader via = new ViaHeader(proto, via_addr, host_port);
   if (rport) via.setRport();
   if (branch == null) branch = SipProvider.pickBranch();
   via.setBranch(branch);
   req.addViaHeader(via);
   req.setMaxForwardsHeader(new MaxForwardsHeader(70));
   if (remote_tag == null) req.setToHeader(new ToHeader(to));
   else req.setToHeader(new ToHeader(to, remote_tag));
   req.setFromHeader(new FromHeader(from, local_tag));
   req.setCallIdHeader(new CallIdHeader(call_id));
   req.setCSeqHeader(new CSeqHeader(cseq, method));
   // optional headers:
   // start modification by mandrajg
   if (contact != null) {
     if (((method == "REGISTER") || (method == "INVITE")) && (icsi != null)) {
       MultipleHeader contacts = new MultipleHeader(SipHeaders.Contact);
       contacts.addBottom(new ContactHeader(contact, qvalue, icsi));
       req.setContacts(contacts);
     } else {
       MultipleHeader contacts = new MultipleHeader(SipHeaders.Contact);
       contacts.addBottom(new ContactHeader(contact));
       req.setContacts(contacts);
     }
     // System.out.println("DEBUG: Contact: "+contact.toString());
   }
   if ((method == "INVITE") && (icsi != null)) {
     req.setAcceptContactHeader(new AcceptContactHeader(icsi));
   }
   // end modifications by mandrajg
   req.setExpiresHeader(new ExpiresHeader(String.valueOf(SipStack.default_expires)));
   // add User-Agent header field
   if (SipStack.ua_info != null) req.setUserAgentHeader(new UserAgentHeader(SipStack.ua_info));
   // if (body!=null) req.setBody(body); else req.setBody("");
   req.setBody(body);
   // System.out.println("DEBUG: MessageFactory: request:\n"+req);
   return req;
 }
 /**
  * Responds with <i>code</i> and <i>reason</i>. This method can be called when the InviteDialog is
  * in D_INVITED, D_ReINVITED states
  */
 public void respond(
     int code, String reason, int expires, String contact, String content_type, String body) {
   printLog("inside respond(" + code + "," + reason + ")", LogLevel.MEDIUM);
   NameAddress contact_url = null;
   if (contact != null) contact_url = new NameAddress(contact);
   Message resp =
       MessageFactory.createResponse(
           subscribe_req, code, SipResponses.reasonOf(code), contact_url);
   if (expires >= 0) resp.setExpiresHeader(new ExpiresHeader(expires));
   if (body != null) resp.setBody(content_type, body);
   respond(resp);
 }
  public void sendFeedback(View view) {

    if (MainMenu.dbAvailable) {
      Message message = new Message();

      message.setSender(MainMenu.user.name());
      message.setRecipient("ryan"); // TODO: set this up to message all the admins
      message.setSubject("USER FEEDBACK");
      message.setBody(feedbackBox.getText().toString());

      messageHandler.Send(MainMenu.dbHandle, message);
    } else {
      MainMenu.noDatabaseConnection(this);
    }
  }
Beispiel #7
0
  /**
   * Pushes a message onto the queue.
   *
   * @param msg The body of the message to push.
   * @param timeout The message's timeout in seconds.
   * @param delay The message's delay in seconds.
   * @param expiresIn The message's expiration offset in seconds.
   * @return The new message's ID
   * @throws HTTPException If the IronMQ service returns a status other than 200 OK.
   * @throws IOException If there is an error accessing the IronMQ server.
   */
  public String push(String msg, long timeout, long delay, long expiresIn) throws IOException {
    Message message = new Message();
    message.setBody(msg);
    message.setTimeout(timeout);
    message.setDelay(delay);
    message.setExpiresIn(expiresIn);

    Messages msgs = new Messages(message);
    Gson gson = new Gson();
    String body = gson.toJson(msgs);

    Reader reader = client.post("queues/" + name + "/messages", body);
    Ids ids = gson.fromJson(reader, Ids.class);
    reader.close();
    return ids.getId(0);
  }
Beispiel #8
0
 /**
  * Responds with <i>code</i> and <i>reason</i>. This method can be called when the InviteDialog is
  * in D_INVITED, D_ReINVITED states
  */
 public void respond(int code, String reason, String contact, String sdp) {
   printLog("inside respond(" + code + "," + reason + ")", LogLevel.MEDIUM);
   if (statusIs(D_INVITED) || statusIs(D_ReINVITED)) {
     NameAddress contact_address = null;
     if (contact != null) contact_address = new NameAddress(contact);
     Message resp = MessageFactory.createResponse(invite_req, code, reason, contact_address);
     resp.setBody(sdp);
     respond(resp);
   } else
     printWarning(
         "Dialog isn't in \"invited\" state: cannot respond ("
             + code
             + "/"
             + getStatus()
             + "/"
             + getDialogID()
             + ")",
         LogLevel.MEDIUM);
 }
Beispiel #9
0
  public Packet doAction(Packet packet) throws PacketRejectedException {
    SessionManager sessionManager = SessionManager.getInstance();
    ClientSession clientSession = sessionManager.getSession(packet.getFrom());
    Packet rejectPacket;
    String pfFrom = JiveGlobals.getProperty("pf.From", "packetfilter");

    if (packet instanceof Message) {
      Message in = (Message) packet.createCopy();
      if (clientSession != null && in.getBody() != null) {

        in.setFrom(new JID(pfFrom));
        String rejectMessage =
            JiveGlobals.getProperty(
                "pf.rejectMessage", "Your message was rejected by the packet filter");
        in.setBody(rejectMessage);
        in.setType(Message.Type.error);
        in.setTo(packet.getFrom());
        String rejectSubject = JiveGlobals.getProperty("pf.rejectSubject", "Rejected");
        in.setSubject(rejectSubject);
        clientSession.process(in);
      }

    } else if (packet instanceof Presence) {
      rejectPacket = new Presence();
      rejectPacket.setTo(packet.getFrom());
      rejectPacket.setError(PacketError.Condition.forbidden);

    } else if (packet instanceof IQ) {
      rejectPacket = new IQ();
      rejectPacket.setTo(packet.getFrom());
      rejectPacket.setError(PacketError.Condition.forbidden);
    }
    if (doLog()) {
      Log.info("Rejecting packet from " + packet.getFrom() + " to " + packet.getTo());
    }
    throw new PacketRejectedException();
  }