views:

18

answers:

0

Hello, I'm trying to return binary data with MTOM as ant attachment, but actually data is inlined as base64 encoded data and then duplicated as attachment. Why? Here is my web service:

@WebService
@MTOM(threshold=0, enabled=true)
public class BinaryService {
    private static final String SERVICE_ENDPOINT = "http://localhost:8998/test";
    @WebMethod
    public DataHandler  getData()
    {
        try {
            System.out.println("Try to return data....");
            return new DataHandler(new URL("file:///java/apache-ant-1.8.0/docs/images/JDJEditorsChoiceAward.jpg"));
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            throw new RuntimeException(e);
        }
    }

And here is how I instantiate client and call the service:

public static void main(String[] args)
    {
        Endpoint.publish(SERVICE_ENDPOINT, new BinaryService());
        System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
        System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");

        xxx.BinaryService port = new BinaryService_Service().getBinaryServicePort(new MTOMFeature(true));
        SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding();
        binding.setMTOMEnabled(true);

        Map<String, Object> ctxt = ((BindingProvider)port ).getRequestContext();
        ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, SERVICE_ENDPOINT);

        List handlerList = binding.getHandlerChain(); 
        if (handlerList == null) { 
                System.out.println("HandlerList is null"); 
                   handlerList = new ArrayList(); 
        } 
        System.out.println("Handlers: " + handlerList);
        LoggingHandler loggingHandler = new LoggingHandler(); 
        handlerList.add(loggingHandler); 
        binding.setHandlerChain(handlerList);   

        byte[] data = port.getData();

code of LoggingHandler:

@Override
    public boolean handleMessage(SOAPMessageContext context) {

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

    PrintStream out = System.out;
    if (outboundProperty.booleanValue()) {
        out .println("\nOutbound message:");
    } else {
        out.println("\nInbound message:");
    }

    SOAPMessage message = context.getMessage();
    try {
        //System.out.println("CONTENT DESC: " + message.getContentDescription());
        message.writeTo(out);
        out.println("");   
    } catch (Exception e) {
        out.println("Exception in handler: " + e);
    }
        return true;
    }

finally, response from the server:

Outbound message:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;S:Body&gt;&lt;ns2:getData xmlns:ns2="http://test.ba.lt/"/&gt;&lt;/S:Body&gt;&lt;/S:Envelope&gt;

Inbound message:

------=_Part_0_15572807.1280997662593
Content-Type: text/xml; charset=utf-8
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;S:Header/&gt;&lt;S:Body&gt;&lt;ns2:getDataResponse xmlns:ns2="http://test.ba.lt/"&gt;&lt;return&gt;/9j/4AAQSkZJRgABAgEASABIAAD/7RZaUGhvdG9zaG9wIDMuMAA4klNA+
**<base64 data cut out>**
a+3dpYCSqnze46gqKXHUkSxaV0XBYxzvu8z7/ut1u1zBFFNLp7IwwRQiLGoUOztTSo4sTXz6SySGVy5ABPp1/9k=</return></ns2:getDataResponse></S:Body></S:Envelope>
------=_Part_0_15572807.1280997662593
Content-Type: image/jpeg
Content-ID: <[email protected]>
˙Ų˙ą
**<binary data cut out>**
~ńĶ×nŻŻ?ŽŁ¬†v«kķŻ?€’Ŗ|ŽćØ*)qŌ‘,ZWEĮcļ»Ģūžėu»\ĮSK§²0Į",j;;SJˇ,M|śK$†W.@śu˙Ł
------=_Part_0_15572807.1280997662593--

@MTOM annotation seems to haven effect, because I can see ant attachment, but attachment is not referenced from within Soap response message body. Am I missing something in the code? I'm using JAX-WS RI 2.1