title: How to get payload object from SOAP Logical Handler
body: <p>I am learning how to create Logical Handlers in JAX-WS SOAP web services. Here I am trying to get the payload data and want to print that for testing. But I am getting issues.</p>
  
  <p>Here is my <code>LogincalHandler</code> code</p>
  
  <pre><code>public class HelloMessengerLogicalHandler implements LogicalHandler&lt;LogicalMessageContext&gt; {
  
      public void close(MessageContext ctx) {
      }
  
      public boolean handleFault(LogicalMessageContext ctx) {
          return false;
      }
  
      public boolean handleMessage(LogicalMessageContext ctx) {
          Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
          if(outbound) {
              LogicalMessage message = ctx.getMessage();
              //Source payload = message.getPayload();
              JAXBContext jaxbContext;
              try {
                  jaxbContext = JAXBContext.newInstance(Person.class);
                  Object jaxbPayload = message.getPayload(jaxbContext);
                  System.out.println(jaxbPayload);
              } catch (JAXBException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
          }
  
          return true;
      }
  }
  </code></pre>
  
  <p>Here is my webservice code:</p>
  
  <pre><code>@WebService
  @HandlerChain(file = "handler-chain.xml")
  public class HelloMessenger {
      public Person getPerson(String name) {
          return new Person(name);
      }
  }
  </code></pre>
  
  <p>This is my <code>Person</code> class:</p>
  
  <pre><code>public class Person {
  
      // Default Constructor &amp; Getters, Setters
      private String name;
  
      public Person(String name) {
          this.name = name;
      }
      @Override
      public String toString() {
          return "Person [name=" + name + "]";
      }
  }
  </code></pre>
  
  <p>When I publish my code and access the webservice I am getting below exception:</p>
  
  <pre><code>javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
   - with linked exception:
  [com.sun.istack.internal.SAXParseException2; unexpected element (uri:"http://simple/", local:"getPersonResponse"). Expected elements are (none)]
      at com.sun.xml.internal.ws.handler.LogicalMessageImpl.getPayload(LogicalMessageImpl.java:121)
      at simple.HelloMessengerLogicalHandler.handleMessage(HelloMessengerLogicalHandler.java:31)
      at simple.HelloMessengerLogicalHandler.handleMessage(HelloMessengerLogicalHandler.java:1)
      at com.sun.xml.internal.ws.handler.HandlerProcessor.callHandleMessageReverse(HandlerProcessor.java:326)
      at com.sun.xml.internal.ws.handler.HandlerProcessor.callHandlersResponse(HandlerProcessor.java:197)
      at com.sun.xml.internal.ws.handler.ServerLogicalHandlerTube.callHandlersOnResponse(ServerLogicalHandlerTube.java:158)
      at com.sun.xml.internal.ws.handler.HandlerTube.processResponse(HandlerTube.java:149)
      at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:636)
      at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
      at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
      at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
      at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:299)
      at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:593)
      at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
      at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:95)
      at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:80)
      at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
      at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
      at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
      at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:677)
      at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
      at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:649)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I am a newbie, my understanding is the payload object is Person, so it should display the person object in logs, but I am seeing this error.</p>
  
  <p>Please explain what does this error indicates &amp; how to get the payload data in logical handler?</p>