[JIRA] Commented: (METRO-24) Cannot call web services which return non-XML responses

  • From: "nhinds (JIRA)" <jira-no-reply@...>
  • To: issues@...
  • Subject: [JIRA] Commented: (METRO-24) Cannot call web services which return non-XML responses
  • Date: Tue, 1 Apr 2014 04:40:49 +0000 (UTC)
  • Auto-submitted: auto-generated


    [ 
https://java.net/jira/browse/METRO-24?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=374092#action_374092
 ] 

nhinds commented on METRO-24:
-----------------------------

Here is a testcase which passes when run with Metro 1.5/1.6.2/2.0/2.1/2.2 and 
fails when run with metro 2.2.1/2.2.1-1/2.3:

{code}
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.Service.Mode;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.http.HTTPBinding;

import org.junit.Test;

import com.sun.xml.ws.api.SOAPVersion;
import com.sun.xml.ws.api.message.Message;
import com.sun.xml.ws.api.message.Messages;
import com.sun.xml.ws.api.message.Packet;
import com.sun.xml.ws.encoding.xml.XMLMessage;
import com.sun.xml.ws.encoding.xml.XMLMessage.MessageDataSource;

public class NonXmlDispatchIssueTest {
        @Test
        public void callNonXmlResourceViaJavaxXmlAPI() throws IOException {
                final List<String> failures = new ArrayList<String>();

                final Service service = Service.create(new QName("dummy", 
"value"));
                final QName portName = new QName("dummy", "port");
                service.addPort(portName, HTTPBinding.HTTP_BINDING, 
"http://google.com";);
                final Dispatch<Source> dispatch = 
service.createDispatch(portName, Source.class, Mode.MESSAGE);
                
dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, "GET");

                final Source response = dispatch.invoke(null);

                if (response instanceof StreamSource) {
                        final StreamSource streamSource = (StreamSource) 
response;
                        final int firstRead = streamSource.getReader() != 
null ? streamSource.getReader().read() : streamSource.getInputStream().read();
                        if (firstRead == -1) {
                                failures.add("Calling a non-XML URL should 
return some data");
                        }
                } else {
                        failures.add("Source should be a StreamSource");
                }

                assertTrue("Failures: " + failures, failures.isEmpty());
        }

        @Test
        public void callNonXmlResourceViaComSunXmlAPI() throws IOException {
                final List<String> failures = new ArrayList<String>();

                final Service service = Service.create(new QName("dummy", 
"value"));
                final QName portName = new QName("dummy", "port");
                service.addPort(portName, HTTPBinding.HTTP_BINDING, 
"http://google.com";);
                final Dispatch<Message> dispatch = 
service.createDispatch(portName, Message.class, Mode.MESSAGE);
                
dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, "GET");

                final Message response = 
dispatch.invoke(Messages.createEmpty(SOAPVersion.SOAP_11));

                if (!(response instanceof MessageDataSource)) {
                        failures.add("Message should implement 
MessageDataSource or XMLMessage.getDataSource will not work");
                }

                final DataSource dataSource = 
XMLMessage.getDataSource(response, null);
                if (dataSource.getInputStream().read() == -1) {
                        failures.add("Calling a non-XML URL should return 
some data");
                }

                assertTrue("Failures: " + failures, failures.isEmpty());
        }

        @Test
        public void getDataSourceFromMessageWrapper() {
                final DataSource inputDataSource = new FileDataSource("");
                final Packet packet = new Packet(new 
XMLMessage.UnknownContent(inputDataSource));
                final DataSource outputDataSource = 
XMLMessage.getDataSource(packet.getMessage(), null);
                assertSame("Should be able to retrieve the original 
DataSource", inputDataSource, outputDataSource);
        }
}

{code}

> Cannot call web services which return non-XML responses
> -------------------------------------------------------
>
>                 Key: METRO-24
>                 URL: https://java.net/jira/browse/METRO-24
>             Project: metro
>          Issue Type: Bug
>    Affects Versions: 2.2.1, 2.2.1-1, 2.3
>            Reporter: nhinds
>            Assignee: Martin Grebac
>
> Web services which return non-XML data no longer return any data when 
> called via the metro web service library. This worked in metro 1.5, 1.6.2, 
> 2.0, 2.1 and 2.2, but does not work against 2.2.1, 2.2.1-1 or 2.3.
> This appears to be because {{Packet.getMessage()}} now returns a 
> {{MessageWrapper}} object, instead of the real {{Message}} object. This in 
> turn means that {{XMLMessage.getDataSource()}} can't see that 
> {{UnknownContent}} objects implement {{MessageDataSource}}, and ends up 
> calling {{UnknownContent.writePayloadTo(XMLStreamWriter)}} (which does 
> nothing) instead of {{UnknownContent.getDataSource()}}.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://java.net/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


[JIRA] Created: (METRO-24) Cannot call web services which return non-XML responses

nhinds (JIRA) 04/01/2014

[JIRA] Commented: (METRO-24) Cannot call web services which return non-XML responses

nhinds (JIRA) 04/01/2014
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20150626.29986a4)
 
 
Close
loading
Please Confirm
Close