Author: sergeyb
Date: 2010-10-04 13:58:22 -0400 (Mon, 04 Oct 2010)
New Revision: 13058
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/saaj/SOAPConnectionImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/cxf/WEB-INF/wsdl/SaajService.wsdl
Log:
[JBWS-3084] Implementing SOAPConnection.get
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/saaj/SOAPConnectionImpl.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/saaj/SOAPConnectionImpl.java 2010-10-04
17:01:43 UTC (rev 13057)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/saaj/SOAPConnectionImpl.java 2010-10-04
17:58:22 UTC (rev 13058)
@@ -58,13 +58,10 @@
{
private boolean closed = false;
- @SuppressWarnings("unchecked")
@Override
public SOAPMessage call(SOAPMessage msgOut, Object addressObject) throws
SOAPException
{
- if (closed) {
- throw new SOAPException("Cannot send messages using a previously closed
connection!");
- }
+ checkClosed();
String address = getAddress(addressObject);
ConduitInitiator ci = getConduitInitiator(address);
@@ -84,7 +81,7 @@
Map<String, List<String>> outHeaders = new HashMap<String,
List<String>>();
- for (Iterator it = msgOut.getMimeHeaders().getAllHeaders(); it.hasNext();)
+ for (Iterator<?> it = msgOut.getMimeHeaders().getAllHeaders();
it.hasNext();)
{
MimeHeader mimeHeader = (MimeHeader)it.next();
if ("Content-Type".equals(mimeHeader.getName()))
@@ -116,27 +113,7 @@
OutputStream outs = outMessage.getContent(OutputStream.class);
msgOut.writeTo(outs);
- c.setMessageObserver(new MessageObserver() {
- public void onMessage(Message inMessage)
- {
- LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
- try
- {
- IOUtils.copy(inMessage.getContent(InputStream.class), bout);
- inMessage.getExchange().put(InputStream.class,
bout.createInputStream());
-
- Map<String, List<String>> inHeaders =
- (Map<String,
List<String>>)inMessage.get(Message.PROTOCOL_HEADERS);
-
- inMessage.getExchange().put(Message.PROTOCOL_HEADERS, inHeaders);
- c.close(inMessage);
- }
- catch (IOException e)
- {
- //ignore
- }
- }
- });
+ c.setMessageObserver(createMessageObserver(c));
c.close(outMessage);
}
@@ -146,52 +123,44 @@
}
// read SOAPMessage
+ return readSoapMessage(exch);
+ }
+
+ @Override
+ public SOAPMessage get(Object addressObject) throws SOAPException
+ {
+ checkClosed();
+
+ String address = getAddress(addressObject);
+ ConduitInitiator ci = getConduitInitiator(address);
+
+
+ // create a new Message and Exchange
+ EndpointInfo info = new EndpointInfo();
+ info.setAddress(address);
+ Message outMessage = new MessageImpl();
+ Exchange exch = new ExchangeImpl();
+ outMessage.setExchange(exch);
+
+ // sent GET request
try
{
- InputStream ins = exch.get(InputStream.class);
- Map<String, List<String>> inHeaders =
- (Map<String, List<String>>)exch.get(Message.PROTOCOL_HEADERS);
+ final Conduit c = ci.getConduit(info);
- MimeHeaders mimeHeaders = new MimeHeaders();
- if (inHeaders != null)
- {
- for (Map.Entry<String, List<String>> entry :
inHeaders.entrySet())
- {
- if (entry.getValue() != null)
- {
- for (String value : entry.getValue())
- {
- mimeHeaders.addHeader(entry.getKey(), value);
- }
- }
- }
- }
+ outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
+ c.prepare(outMessage);
- //if inputstream is empty, no need to build
- if (ins.markSupported())
- {
- ins.mark(1);
- final int bytesRead = ins.read(new byte[1]);
- ins.reset();
- if (bytesRead == -1)
- {
- return null;
- }
- }
- else if (ins.available() == 0)
- {
- return null;
- }
-
- MessageFactory msgFac =
MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
- return msgFac.createMessage(mimeHeaders, ins);
+ c.setMessageObserver(createMessageObserver(c));
+
+ c.close(outMessage);
}
catch (Exception ex)
- {
- throw new SOAPException("SOAPMessage can not be read", ex);
- }
-
-
+ {
+ throw new SOAPException("GET request can not be sent", ex);
+ }
+
+ // read SOAPMessage
+ return readSoapMessage(exch);
}
@Override
@@ -214,27 +183,119 @@
+ " is not supported");
}
- private ConduitInitiator getConduitInitiator(String address) throws SOAPException {
-
- ConduitInitiator ci = null;
- try {
- Bus bus = BusFactory.getThreadDefaultBus(true);
- ConduitInitiatorManager mgr =
bus.getExtension(ConduitInitiatorManager.class);
+ private ConduitInitiator getConduitInitiator(String address) throws SOAPException
+ {
+ ConduitInitiator ci = null;
+ try
+ {
+ Bus bus = BusFactory.getThreadDefaultBus(true);
+ ConduitInitiatorManager mgr = bus.getExtension(ConduitInitiatorManager.class);
- if (address.startsWith("http")) {
- ci =
mgr.getConduitInitiator("http://cxf.apache.org/transports/http");
- }
- if (ci == null) {
- ci = mgr.getConduitInitiatorForUri(address);
- }
+ if (address.startsWith("http"))
+ {
+ ci =
mgr.getConduitInitiator("http://cxf.apache.org/transports/http");
+ }
+ if (ci == null)
+ {
+ ci = mgr.getConduitInitiatorForUri(address);
+ }
- } catch (Exception ex) {
- throw new SOAPException("No ConduitInitiator is available for " +
address, ex);
- }
+ }
+ catch (Exception ex)
+ {
+ throw new SOAPException("No ConduitInitiator is available for " +
address, ex);
+ }
- if (ci == null) {
- throw new SOAPException("No ConduitInitiator is available for " +
address);
- }
- return ci;
+ if (ci == null)
+ {
+ throw new SOAPException("No ConduitInitiator is available for " +
address);
+ }
+ return ci;
}
+
+ @SuppressWarnings("unchecked")
+ private MessageObserver createMessageObserver(final Conduit c)
+ {
+ return new MessageObserver()
+ {
+ public void onMessage(Message inMessage)
+ {
+ LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
+ try
+ {
+ IOUtils.copy(inMessage.getContent(InputStream.class), bout);
+ inMessage.getExchange().put(InputStream.class,
bout.createInputStream());
+
+ Map<String, List<String>> inHeaders =
+ (Map<String,
List<String>>)inMessage.get(Message.PROTOCOL_HEADERS);
+
+ inMessage.getExchange().put(Message.PROTOCOL_HEADERS, inHeaders);
+ c.close(inMessage);
+ }
+ catch (IOException e)
+ {
+ //ignore
+ }
+ }
+ };
+ }
+
+ @SuppressWarnings("unchecked")
+ private SOAPMessage readSoapMessage(Exchange exch) throws SOAPException
+ {
+ // read SOAPMessage
+ try
+ {
+ InputStream ins = exch.get(InputStream.class);
+
+ Map<String, List<String>> inHeaders =
+ (Map<String, List<String>>)exch.get(Message.PROTOCOL_HEADERS);
+
+ MimeHeaders mimeHeaders = new MimeHeaders();
+ if (inHeaders != null)
+ {
+ for (Map.Entry<String, List<String>> entry :
inHeaders.entrySet())
+ {
+ if (entry.getValue() != null)
+ {
+ for (String value : entry.getValue())
+ {
+ mimeHeaders.addHeader(entry.getKey(), value);
+ }
+ }
+ }
+ }
+
+ //if inputstream is empty, no need to build
+ if (ins.markSupported())
+ {
+ ins.mark(1);
+ final int bytesRead = ins.read(new byte[1]);
+ ins.reset();
+ if (bytesRead == -1)
+ {
+ return null;
+ }
+ }
+ else if (ins.available() == 0)
+ {
+ return null;
+ }
+
+ MessageFactory msgFac =
MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
+ return msgFac.createMessage(mimeHeaders, ins);
+ }
+ catch (Exception ex)
+ {
+ throw new SOAPException("SOAPMessage can not be read", ex);
+ }
+ }
+
+ private void checkClosed() throws SOAPException
+ {
+ if (closed) {
+ throw new SOAPException("Cannot send messages using a previously closed
connection!");
+ }
+ }
+
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java 2010-10-04
17:01:43 UTC (rev 13057)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java 2010-10-04
17:58:22 UTC (rev 13058)
@@ -46,23 +46,39 @@
*/
public class SOAPConnectionTestCase extends JBossWSTest
{
- private final String serviceURL = "http://" + getServerHost() +
":8080/saaj-soap-connection/SaajService";
-
public static Test suite()
{
return new JBossWSTestSetup(SOAPConnectionTestCase.class,
"saaj-soap-connection.war");
}
- public void testSoapConnectionWithoutChunkedEncoding() throws Exception
+ public void testSoapConnectionPostWithoutChunkedEncoding() throws Exception
{
doTestSoapConnection(true);
}
- public void testSoapConnectionWithChunkedEncoding() throws Exception
+ public void testSoapConnectionPostWithChunkedEncoding() throws Exception
{
- doTestSoapConnection(false);
+ doTestSoapConnection(false);
}
+ // TODO: ignore until CXF 2.3 update to AbstractHttpDestination makes it into JBoss
repos
+ public void ignoreTestSoapConnectionGet() throws Exception
+ {
+ final String serviceURL = "http://" + getServerHost() +
":8080/saaj-soap-connection/greetMe";
+ SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
+
+ SOAPConnection con = conFac.createConnection();
+ URL endpoint = new URL(serviceURL);
+ SOAPMessage response = con.get(endpoint);
+ QName greetMeResp = new
QName("http://www.jboss.org/jbossws/saaj",
"greetMeResponse");
+
+ Iterator<?> sayHiRespIterator =
response.getSOAPBody().getChildElements(greetMeResp);
+ SOAPElement soapElement = (SOAPElement)sayHiRespIterator.next();
+ assertNotNull(soapElement);
+
+ assertEquals(1, response.countAttachments());
+ }
+
private void doTestSoapConnection(boolean disableChunking) throws Exception
{
SOAPFactory soapFac = SOAPFactory.newInstance();
@@ -94,6 +110,9 @@
msg.saveChanges();
SOAPConnection con = conFac.createConnection();
+
+ final String serviceURL = "http://" + getServerHost() +
":8080/saaj-soap-connection";
+
URL endpoint = new URL(serviceURL);
SOAPMessage response = con.call(msg, endpoint);
QName sayHiResp = new
QName("http://www.jboss.org/jbossws/saaj",
"sayHelloResponse");
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java 2010-10-04
17:01:43 UTC (rev 13057)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java 2010-10-04
17:58:22 UTC (rev 13058)
@@ -32,4 +32,7 @@
{
@WebMethod
String sayHello();
+
+ @WebMethod
+ String greetMe();
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java 2010-10-04
17:01:43 UTC (rev 13057)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java 2010-10-04
17:58:22 UTC (rev 13058)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.saaj;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
@@ -113,4 +114,28 @@
return "Hello World!";
}
+ public String greetMe()
+ {
+ try
+ {
+ Map<String, DataHandler> outDataHandlers = CastUtils.cast(
+ (Map<?,
?>)context.getMessageContext().get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));
+
+ final char[] content = new char[16 * 1024];
+ Arrays.fill(content, 'A');
+
+ DataHandler handler = new DataHandler(
+ new InputStreamDataSource(new ByteArrayInputStream(new
String(content).getBytes()),
+ "text/plain", "1"));
+ outDataHandlers.put("1", handler);
+
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+
+ return "Greetings";
+ }
+
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/cxf/WEB-INF/wsdl/SaajService.wsdl
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/cxf/WEB-INF/wsdl/SaajService.wsdl 2010-10-04
17:01:43 UTC (rev 13057)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/cxf/WEB-INF/wsdl/SaajService.wsdl 2010-10-04
17:58:22 UTC (rev 13058)
@@ -12,6 +12,18 @@
<xsd:element minOccurs="0" name="return"
type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
+
+<xsd:element name="greetMe" type="tns:greetMe"/>
+<xsd:complexType name="greetMe">
+<xsd:sequence/>
+</xsd:complexType>
+<xsd:element name="greetMeResponse"
type="tns:greetMeResponse"/>
+<xsd:complexType name="greetMeResponse">
+<xsd:sequence>
+<xsd:element minOccurs="0" name="return"
type="xsd:string"/>
+</xsd:sequence>
+</xsd:complexType>
+
</xsd:schema>
</wsdl:types>
<wsdl:message name="sayHelloResponse">
@@ -22,6 +34,16 @@
<wsdl:part name="parameters" element="tns:sayHello">
</wsdl:part>
</wsdl:message>
+
+ <wsdl:message name="greetMeResponse">
+ <wsdl:part name="parameters"
element="tns:greetMeResponse">
+ </wsdl:part>
+ </wsdl:message>
+ <wsdl:message name="greetMe">
+ <wsdl:part name="parameters" element="tns:greetMe">
+ </wsdl:part>
+ </wsdl:message>
+
<wsdl:portType name="ServiceIface">
<wsdl:operation name="sayHello">
<wsdl:input name="sayHello" message="tns:sayHello">
@@ -29,9 +51,17 @@
<wsdl:output name="sayHelloResponse"
message="tns:sayHelloResponse">
</wsdl:output>
</wsdl:operation>
+
+ <wsdl:operation name="greetMe">
+ <wsdl:input name="greetMe" message="tns:greetMe">
+ </wsdl:input>
+ <wsdl:output name="greetMeResponse"
message="tns:greetMeResponse">
+ </wsdl:output>
+ </wsdl:operation>
+
</wsdl:portType>
<wsdl:binding name="SaajServiceSoapBinding"
type="tns:ServiceIface">
- <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/wsdl/http/"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
@@ -41,6 +71,15 @@
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
+ <wsdl:operation name="greetMe">
+ <soap:operation soapAction="" style="document"/>
+ <wsdl:input name="greetMe">
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="greetMeResponse">
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
</wsdl:binding>
<wsdl:service name="SaajService">
<wsdl:port name="SaajServicePort"
binding="tns:SaajServiceSoapBinding">