2 Replies Latest reply on Jun 12, 2011 7:24 PM by nafees sharif

    Debug web services request/response

    miragpl Newbie

      Hi everyone,


      Is there any way to turn on traces that would show request/response of webservice call?

      If so please please write also the the place where the log should be enabled.

       

      Thanks in advance

        • 1. Re: Debug web services request/response
          Miklós Kasza Newbie

          Hi,

           

          are you looking for this: JBossWS - Log4j? Btw. as of AS 4.x and 5.x, you can find jboss-log4j.xml in

           

               <jboss-dir>/server/<config-dir>/conf

          directory. As of AS 6, the file

           

               <jboss-dir>/server/<config-dir>/deploy/jboss-logging.xml

          can be used similarly.

           

          I hope it helped.

          • 2. Re: Debug web services request/response
            nafees sharif Newbie

            Hello MK,

             

            We used a handler chain to log our outgoing and incoming messages. This is a three step process, which is as follows:

             

            1- Annotate the Service class with the handler configuration file.

                 Example: @HandlerChain (file="handlers.xml")

             

            2- Define the handlers.xml file as follows (this file needs to be on classpath):

                 Example: see below

                 <handler-chains xmlns="http://java.sun.com/xml/ns/javaee"> 

                    <handler-chain> 

                       <handler> 

                          <handler-class>com.whatever.LoggingHandler</handler-class> 

                       </handler> 

                    </handler-chain> 

                 </handler-chains> 

             

            3- Create LoggingHandler java file

                 Example: see attached!

             

                public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {

             

                    public Set<QName> getHeaders() {

                        return null;

                    }

             

                    public void close(MessageContext context) {

                    }

             

                    public boolean handleFault(SOAPMessageContext context) {

                        logToSystemOut(context);

                        return true;

                    }

             

                    public boolean handleMessage(SOAPMessageContext context) {

                        logToSystemOut(context);

                        return true;

                    }

             

                    private void logToSystemOut(SOAPMessageContext smc) {

                        Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

                        try {

                            smc.getMessage().getSOAPBody();

                        } catch (SOAPException e1) {

                            e1.printStackTrace();

                        }

                        SOAPMessage message = smc.getMessage();

                        String header = "";

                        if (outboundProperty.booleanValue()) {

                            header = "Outgoing Message: ";

                        } else {

                            header = "Incoming Message: ";

                        }

                        try {

                            ByteArrayOutputStream baos = new ByteArrayOutputStream();

                            message.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);

                            message.writeTo(baos);

                            System.out.println(header + baos.toString());

                        } catch (Exception e) {

                            e.printStackTrace();

                        }

                    }

                }

             

             

            HTH!

             

            --Nafees