logger.debug("Trying to bind to pipe for service space id " + endpoint.getServiceSpaceId() + "...");
logger.debug("Trying to bind to pipe for " + endpoint.getServiceSpace() + "...");
    public void sendQuery(ClientQuery query) {        final int BIND_TIMEOUT = 15000;     // how long we try to connect to the endpoint for before timing out        logger.info("sending query...");        for (Enumeration endpoints = knownPipeAds.elements(); endpoints.hasMoreElements();) {            try {                ServiceSpaceEndpoint endpoint = (ServiceSpaceEndpoint) endpoints.nextElement();                PipeAdvertisement pipeAd = (PipeAdvertisement) endpoint.getPipeAdvertisement();                // create the output pipe endpoint to connect                // to the server, try 3 times to bind the pipe endpoint to                // the listening endpoint pipe of the service                OutputPipe endpointPipe = null;                for (int i = 0; i < 3; i++) {                    logger.debug("Trying to bind to pipe for service space id " + endpoint.getServiceSpaceId() + "...");                    try {                        endpointPipe = pipeService.createOutputPipe(pipeAd, BIND_TIMEOUT);                        break;                    } catch (java.io.IOException e) {                        // will try again;                    }                }                if (endpointPipe == null) {                    logger.warn("Could not resolve pipe endpoint - removing");                    // this pipe advertisement seems outdated - remove it from the "known pipes" and the database                    knownPipeAds.remove(pipeAd.getID());                    clientDAO.removePipeAdvertisement(pipeAd);                    continue;                }                // create the pipe message                Message msg = pipeService.createMessage();                org.w3c.dom.Document doc = db.newDocument();                Element dataElement = doc.createElement(DATA_TAG);                // first we uniquely identify this message, and store it in the queries hashtable                // with a reference to its ClientQuery                Long messageNumber = new Long(random.nextLong());                QueryMessage queryMessage = new QueryMessage(query,endpoint.getServiceSpaceId());                queries.put(messageNumber, queryMessage);                Element msgNumElement = doc.createElement(MSGNUM_TAG);                Text msgNumText = doc.createTextNode(String.valueOf(messageNumber));                msgNumElement.appendChild(msgNumText);                dataElement.appendChild(msgNumElement);                // then we add the given query to our query element                Element queryElement = doc.createElement(QUERY_TAG);                // we need to import the queryelement because we are putting it into a different DOM document                Node queryNode = doc.importNode(query.getQueryElement(),true);                queryElement.appendChild(queryNode);                dataElement.appendChild(queryElement);                Node ad = doc.importNode(inputPipeXMLAd, true);                dataElement.appendChild(ad);                doc.appendChild(dataElement);                doc = signatureManager.signDocument(doc);                ByteArrayOutputStream out = new ByteArrayOutputStream();                XMLUtils.outputDOM(doc, out);                logger.debug("sending msg: \n" + out.toString());                MessageElement element = msg.newMessageElement(DATA_TAG, xmlMimeMediaType, out.toByteArray());                msg.addElement(element);                // send the message                endpointPipe.send(msg);                logger.info("message sent to service space");            } catch (Exception e) {                logger.error("Problem sending message: " + e);                continue;            }        }    }