user994165
user994165

Reputation: 9512

Extracting whole SOAP message with JAX-WS

I have an EJB stateless bean web service and would like to get access to the whole SOAP message, not just the SOAP Body as I'm currently getting in the parameter. I want to submit the message to a different component. I'm using Spring configuration but not Spring-WS. I followed this tutorial:

http://java.dzone.com/articles/creating-soap-message-handlers

as is and didn't make any changes for now. It just logs the SOAP message. handleMessage() isn't getting called.

@Stateless
@WebService(portName = "XRequest_PortType", serviceName = "XRequestService", endpointInterface = "XRequestPortType")
@Addressing(enabled = true)
@HandlerChain(file = "LogMessage_handler.xml")
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class XRequest_PortTypeWS implements
        XRequestPortType {
...}

The LogMessage_handler.xml is slightly different from the tutorial but I tried it both ways:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains 
     xmlns:javaee="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <javaee:handler-chain>
    <javaee:handler>
      <javaee:handler-class>com.test.ws.LogMessageHandle</javaee:handler-class>
    </javaee:handler>
  </javaee:handler-chain>
</javaee:handler-chains>

LogMessageHandler:

package com.test.ws;

import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

/**
 * 
 * @author meerasubbarao
 */
public class LogMessageHandler implements SOAPHandler<SOAPMessageContext> {

    public boolean handleMessage(SOAPMessageContext messageContext) {
        log(messageContext);
        return true;

    }

    public Set<QName> getHeaders() {
        return Collections.EMPTY_SET;
    }

    public boolean handleFault(SOAPMessageContext messageContext) {
        return true;
    }

    public void close(MessageContext context) {
    }

    private void log(SOAPMessageContext messageContext) {
        SOAPMessage msg = messageContext.getMessage(); // Line 1
        try {
            msg.writeTo(System.out); // Line 3
        } catch (SOAPException ex) {
            Logger.getLogger(LogMessageHandler.class.getName()).log(
                    Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(LogMessageHandler.class.getName()).log(
                    Level.SEVERE, null, ex);
        }
    }

}

Is this even the best way to get the whole SOAP message? I would still need to to call a Spring bean from XRequest_PortTypeWS to send the SOAP message.

Upvotes: 1

Views: 14066

Answers (2)

user994165
user994165

Reputation: 9512

I did use a SOAP Handler and was able to get the full SOAP Message. The details are in this other post.

Sending Object from SOAP Handler to Web Service

Upvotes: 0

Denys
Denys

Reputation: 31

I've checked the article in http://java.dzone.com/articles/creating-soap-message-handlers and I noticed that you don't set up handler name in LogMessage_handler.xml and one more important thing is to locate LogMessage_handler.xml in the same package where is web service bean. Also please add @Remote annotation to webservice bean.

Upvotes: 1

Related Questions