Пример #1
0
  /**
   * @see
   *     org.apache.james.jspf.executor.DNSAsynchLookupService#getRecordsAsynch(org.apache.james.jspf.core.DNSRequest,
   *     int, org.apache.james.jspf.executor.IResponseQueue)
   */
  public void getRecordsAsynch(DNSRequest request, int id, IResponseQueue responsePool) {

    Message message;
    try {
      message = makeQuery(request, id);
      LookupAsynch la =
          new LookupAsynch(message.getQuestion().getName(), message.getQuestion().getType());
      la.runAsynch(
          new Runnable() {

            private IResponseQueue responsePool;
            private Integer id;
            private LookupAsynch lookup;

            public void run() {
              responsePool.insertResponse(
                  new IResponse() {

                    public Exception getException() {
                      if (lookup.getResult() == LookupAsynch.TRY_AGAIN) {
                        return new TimeoutException(lookup.getErrorString());
                      } else {
                        return null;
                      }
                    }

                    public Object getId() {
                      return id;
                    }

                    public List<String> getValue() {
                      return (DNSServiceXBillImpl.convertRecordsToList(lookup.getAnswers()));
                    }
                  });
            }

            public Runnable setResponsePool(
                LookupAsynch la, IResponseQueue responsePool, Integer integer) {
              this.lookup = la;
              this.responsePool = responsePool;
              this.id = integer;
              return this;
            }
          }.setResponsePool(la, responsePool, new Integer(id)));
      // this.resolver.sendAsync(message, new Integer(id), new ResponseQueueAdaptor(responsePool));
    } catch (TextParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #2
0
 private DomainResource getDomainResource(String domainString) {
   try {
     logger.info("Fetching domain: " + domainString);
     Domain domain = factory.getDomain(domainString);
     Name domainName = Utils.stringToName(domainString);
     DomainResource dr = DomainResource.fromDomain(domain, domainName);
     return dr;
   } catch (ForeignDomainException e) {
     logger.error("Iterator returned foreign domain: " + domainString);
     throw new RuntimeException(e);
   } catch (TextParseException e) {
     logger.error("Invalid domain name: " + e.getMessage());
     throw new RuntimeException(e);
   }
 }
Пример #3
0
  private void sendQuery() {
    Header queryHeader = new Header();

    // If we set the RA (Recursion Available) flag and our message ID to 0
    // then the packet matches the real mDNS query packet as displayed in Wireshark
    queryHeader.setFlag(org.xbill.DNS.Flags.RA);
    queryHeader.setID(0);

    Record question = null;
    try {
      // We need to create our "Question" DNS query that is a pointer record to
      // the mDNS Query "Name"
      question = Record.newRecord(new Name(NvmDNS.MDNS_QUERY), Type.PTR, DClass.IN);
    } catch (TextParseException e) {
      Log.e("NvmDNS Query", e.getMessage());
      return;
    }

    // We combine our header and our question into a single message
    Message query = new Message();
    query.setHeader(queryHeader);
    query.addRecord(question, Section.QUESTION);

    // Convert the message into Network Byte Order
    byte[] wireQuery = query.toWire();
    Log.i("NvmDNS Query", query.toString());

    // Convert our byte array into a Packet
    DatagramPacket transmitPacket = new DatagramPacket(wireQuery, wireQuery.length);
    transmitPacket.setAddress(NvmDNS.MDNS_MULTICAST_ADDRESS);
    transmitPacket.setPort(NvmDNS.MDNS_PORT);

    // And (attempt) to send the packet
    try {
      Log.d("NvmDNS Query", "Blocking on this.nvstream_socket.send(transmitPacket)");
      this.socket.send(transmitPacket);
      Log.d("NvmDNS Query", "Passed this.nvstream_socket.send(transmitPacket)");
    } catch (IOException e) {
      Log.e("NvmDNS Query", "There was an error sending the DNS query.");
      Log.e("NvmDNS Query", e.getMessage());
    }
  }