9 Replies Latest reply on Apr 10, 2007 11:03 AM by rmartony

    How Do I See the XML?

    flindet

      Hi,

      I'm new to JBossWS. I'm using JBossWS 1.2.0.SP1, installed into JBoss AS 4.0.5.

      I've created an SEI Document/Wrapped web service (unless I'm confused). I have unit tests that prove that my web service is working. It's a very simple web service based heavily on the "echo" example included with JBossWS.

      It's my understanding from reading the documentation that somehow JBossWS is converting between Java objects and XML, presumably via JAXB.

      JAX-WS simplifies the development model for a web service endpoint a great deal. In short, an endpoint implementation bean is annotated with JAX-WS annotations and deployed to the server. The server automatically generates and publishes the abstract contract (i.e. wsdl+schema) for client consumption. All marshalling/unmarshalling is delegated to JAXB


      I'd like to see the XML that's theoretically being generated and passed along the wire so that I can 1) confirm it matches the schema I expect and 2) better understand how this is all working.

      Ideally, I'd also like to have a unit test that looks at the raw XML because my expected client will not have JAXB, and will probably be in a .NET environment.

      None of the code that I wrote invokes an Unmarshaller. I'm assuming this is magically done for me.

      Can anyone shed some light and help me learn where I'm confused? Thanks for your help.

        • 1. Re: How Do I See the XML?
          oskar.carlstedt

          Hi!

          You can always turn on TRACE debugging on the ws messages. There is an uncommented row in the JBOSS_HOME/server/default/conf/log4j.xml. Now you will see the messages in the JBOSS_HOME/server/default/log/server.log file.

          By default the CONSOLE-appender in log4j.xml has a threshold parameter set to INFO. This makes log4j to reject all messages with lower priority than this value. If you set threshold to TRACE you will get a lot of info, more than you want.

          You can always create a handler (http://jbws.dyndns.org/mediawiki/index.php/JAX-WS_User_Guide#Handler_Framework) to monitor the result of the ws, but it might be tricky. Another way is to create an http filter (http://java.sun.com/products/servlet/Filters.html) that will check your incoming request and outgoing response.

          Best
          Oskar
          [/url]

          • 2. Re: How Do I See the XML?
            oskar.carlstedt
            • 3. Re: How Do I See the XML?
              qpool.char

              There is also a tool called "wsmonitor" that is quickly configured. It receives the incoming request on a certain port, prints it out and forwards it to the service endpoint.

              Therefore you have to change the service endpoint location in your client, perhaps by setting the BindingProperties.

              • 4. Re: How Do I See the XML?
                flindet

                Thanks, guys. This is all great advice. I appreciate it.

                • 5. Re: How Do I See the XML?
                  flindet

                  By the way, oskar, I got the handler working. This is very nice. ;-)

                  • 6. Re: How Do I See the XML?
                    rmartony

                    I created a handler, how can I print out the XML of the incoming request?
                    I have the SOAPMessage, SOAPHeader and SOAPBody.
                    What should I do next?

                    I'm using JBossWS-1.0.4.GA, installed into JBoss AS 4.0.5.GA.

                    Regards,
                    Rafael.

                    • 7. Re: How Do I See the XML?
                      joshlam

                      You can try something like:

                      public boolean handleMessage(SOAPMessageContext ctx)
                      {
                       boolean outbound= ((Boolean)ctx.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();
                       SOAPMessage m = ctx.getMessage();
                       ByteArrayOutputStream bo = new ByteArrayOutputStream();
                       try
                       {
                       if (outbound)
                       {
                      
                       m.writeTo(bo);
                       System.out.println("Outbound: "+bo.toString());
                       }
                       else // inbound
                       {
                      
                       m.writeTo(bo);
                       System.out.println("Inbound: "+bo.toString());
                       }
                       }
                       catch (SOAPException e)
                       {
                       e.printStackTrace();
                       return false;
                       }
                       catch (IOException e)
                       {
                       e.printStackTrace();
                       return false;
                       }
                      
                       return true;
                       }
                      


                      • 8. Re: How Do I See the XML?
                        flindet

                        rmartony, here's what I ended up doing to log my full SOAP message. It's based heavily on the example handlers included with JBossWS.

                        public class ProtocolHandler extends GenericSOAPHandler
                        {
                         /**
                         * The {@link Logger} used for writing logging messages.
                         */
                         private static Logger log = Logger.getLogger(ProtocolHandler.class);
                        
                         /* (non-Javadoc)
                         * @see org.jboss.ws.core.jaxws.handler.GenericSOAPHandler#handleOutbound(javax.xml.ws.handler.MessageContext)
                         */
                         @Override
                         public boolean handleOutbound(final MessageContext msgContext)
                         {
                         if (log.isInfoEnabled())
                         {
                         return logMessage(msgContext);
                         }
                         return true;
                         }
                        
                         /* (non-Javadoc)
                         * @see org.jboss.ws.core.jaxws.handler.GenericSOAPHandler#handleInbound(javax.xml.ws.handler.MessageContext)
                         */
                         @Override
                         public boolean handleInbound(final MessageContext msgContext)
                         {
                         if (log.isInfoEnabled())
                         {
                         return logMessage(msgContext);
                         }
                         return true;
                         }
                        
                         /**
                         * Logs the full SOAP message.
                         *
                         * @param messageContext The message context containing the SOAP message to be handled.
                         * @return True if handler processing should continue, false otherwise.
                         * @throws WebServiceException If the SOAP message is malformed.
                         */
                         private boolean logMessage(final MessageContext messageContext)
                         {
                         try
                         {
                         SOAPMessage soapMessage = ((SOAPMessageContext) messageContext).getMessage();
                         if (soapMessage.getSOAPBody().getChildElements().hasNext())
                         {
                         SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
                         if (soapElement.getChildElements().hasNext())
                         {
                         soapElement = (SOAPElement) soapElement.getChildElements().next();
                        
                         ByteArrayOutputStream xmlStream = new ByteArrayOutputStream();
                         soapMessage.writeTo(xmlStream);
                         log.info(new String(xmlStream.toByteArray()));
                         }
                         }
                        
                         return true;
                         }
                         catch (SOAPException ex)
                         {
                         throw new WebServiceException(ex);
                         }
                         catch (IOException ex)
                         {
                         throw new WebServiceException(ex);
                         }
                         }
                        }
                        


                        • 9. Re: How Do I See the XML?
                          rmartony

                          Hi flindet and joshlam, thank you very much for your help.

                          Regards,
                          Rafael.