Open glassfishrobot opened 10 years ago
Reported by nhinds
nhinds said: 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:
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);
}
}
Was assigned to snajper
This issue was imported from java.net JIRA METRO-24
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().
Affected Versions
[2.2.1, 2.2.1-1, 2.3]