logger.debug("msg num=" + messageNumber);
    public void pipeMsgEvent(PipeMsgEvent event) {        final int WAIT_TIMEOUT = 10*1000;        Message msg;        try {            msg = event.getMessage();            if (msg == null) {                logger.error("received null message");                return;            }        } catch (Exception e) {            e.printStackTrace();            return;        }        // Get message        String newMessage = msg.getString(DATA_TAG);        if (newMessage == null) {            logger.debug("data tag in message was empty or missing");            return;        }        logger.debug("Received message: " + newMessage);        // verify message, then extract query and input pipe        org.w3c.dom.Document msgDoc = null;        try {            msgDoc = db.parse(new InputSource(new StringReader(newMessage)));        }        catch (Exception e) {            logger.warn("Could not parse message: " + e);            return;        }        SignatureManagerResponse response = null;        try {            response = signatureManager.verifyDocument(msgDoc);            logger.info("verified message, from service space " + response.getSigner().getName());        }        catch (SignatureManagerException e) {            logger.warn("Could not verify signature: " + e);            // for now we continue anyway            logger.warn("continuing anyway!");        }        if (response != null) {            msgDoc = response.getDocument();        }        // extract message number - we have to send the response back with this same number        String messageNumber = null;        {            NodeList list = msgDoc.getElementsByTagName(MSGNUM_TAG);            if (list == null || list.getLength() == 0) {                logger.error("did not find message number in document");                return;            }            Node envelopeNode = list.item(0);            Text msgNumText = (Text) envelopeNode.getFirstChild();            messageNumber = msgNumText.getNodeValue();            logger.debug("msg num=" + messageNumber);        }        // prepare the document that is going to hold the response        // we need this here because when we process the response (below),        // we need to pass the element where the responses should go        org.w3c.dom.Document responseDoc = db.newDocument();        Element responseElement = responseDoc.createElement(RESPONSE_TAG);        // extract query element - this is what we'll process to send the response        // (for example, the UDDI query would be here)        {            NodeList list = msgDoc.getElementsByTagName(QUERY_TAG);            if (list == null || list.getLength() == 0) {                logger.error("did not find query element in document");                return;            }            processQuery(list.item(0), responseElement, response.getSigner());        }        OutputPipe clientPipe = null;        {            // extract inputpipe element            logger.debug("extracting pipe element");            NodeList list = msgDoc.getElementsByTagName(PIPE_TAG);            if (list == null || list.getLength() == 0) {                logger.error("did not find pipe element in document");                return;            }            // Unfortunately JXTA makes it very hard to create PipeAdvertisements from existing XML...            // the only way is to give it the actual XML for the pipe, which means we need to extract it            // and feed it in a very inefficient way            Node pipeAdNode = list.item(0);            try {                ByteArrayOutputStream out = new ByteArrayOutputStream();                out.write(new String("<?xml version=\"1.0\"?><!DOCTYPE jxta:PipeAdvertisement>").getBytes());                XMLUtils.outputDOM(pipeAdNode, out);                logger.debug("creating pipeadvertisement from " + out.toString());                PipeAdvertisement clientPipeAd = (PipeAdvertisement)                        AdvertisementFactory.newAdvertisement(                                xmlMimeMediaType, new ByteArrayInputStream(out.toByteArray()));                clientPipe = pipeService.createOutputPipe(clientPipeAd, WAIT_TIMEOUT);            } catch (Exception e) {                logger.error("Could not create client pipe");                return;            }        }        // finally, send the response to the client        Message outmsg = pipeService.createMessage();        Element dataElement = responseDoc.createElement(Server.DATA_TAG);        Element msgNumElement = responseDoc.createElement(Server.MSGNUM_TAG);        Text msgNumText = responseDoc.createTextNode(String.valueOf(messageNumber));        msgNumElement.appendChild(msgNumText);        dataElement.appendChild(msgNumElement);        dataElement.appendChild(responseElement);        responseDoc.appendChild(dataElement);        // sign everything        try {            responseDoc = signatureManager.signDocument(responseDoc);        } catch (SignatureManagerException e) {            logger.error("could not sign message: " + e);            return;        }        // import into JXTA message        ByteArrayOutputStream out = new ByteArrayOutputStream();        XMLUtils.outputDOM(responseDoc, out);        logger.debug("sending msg: \n" + out.toString());        MessageElement element = msg.newMessageElement(Server.DATA_TAG, xmlMimeMediaType, out.toByteArray());        outmsg.addElement(element);        try {            clientPipe.send(outmsg);            logger.debug("sent message");        } catch (IOException e) {            logger.error("could not send message: " + e);            return;        }    }