Author: ffang
Date: Wed Jun 20 21:12:00 2007
New Revision: 549357
URL: http://svn.apache.org/viewvc?view=rev&rev=549357
Log:
[CXF-741] cannot invoke on endpoint implemented using Provider<DataSource>
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
(with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
(with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/Server.java
(with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
(with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/WebProvider.java
(with props)
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/WebServiceProviderConfiguration.java
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java?view=diff&rev=549357&r1=549356&r2=549357
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataWriter.java
Wed Jun 20 21:12:00 2007
@@ -18,9 +18,11 @@
*/
package org.apache.cxf.databinding.source;
+import java.io.IOException;
import java.util.Collection;
import java.util.logging.Logger;
+import javax.activation.DataSource;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
@@ -45,16 +47,24 @@
public void write(Object obj, XMLStreamWriter writer) {
try {
- Source s = (Source) obj;
- if (s instanceof DOMSource
- && ((DOMSource) s).getNode() == null) {
- return;
- }
+ XMLStreamReader reader = null;
+ if (obj instanceof DataSource) {
+ DataSource ds = (DataSource)obj;
+ reader = StaxUtils.createXMLStreamReader(ds.getInputStream());
+ } else {
+ Source s = (Source) obj;
+ if (s instanceof DOMSource
+ && ((DOMSource) s).getNode() == null) {
+ return;
+ }
- XMLStreamReader reader = StaxUtils.createXMLStreamReader(s);
+ reader = StaxUtils.createXMLStreamReader(s);
+ }
StaxUtils.copy(reader, writer);
reader.close();
} catch (XMLStreamException e) {
+ throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
+ } catch (IOException e) {
throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
}
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/WebServiceProviderConfiguration.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/WebServiceProviderConfiguration.java?view=diff&rev=549357&r1=549356&r2=549357
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/WebServiceProviderConfiguration.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/WebServiceProviderConfiguration.java
Wed Jun 20 21:12:00 2007
@@ -21,6 +21,7 @@
import java.lang.reflect.Method;
+import javax.activation.DataSource;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
@@ -36,7 +37,8 @@
return method.getName().equals("invoke")
&& method.getParameterTypes().length == 1
&& (Source.class.isAssignableFrom(method.getParameterTypes()[0])
- ||
SOAPMessage.class.isAssignableFrom(method.getParameterTypes()[0]));
+ ||
SOAPMessage.class.isAssignableFrom(method.getParameterTypes()[0])
+ ||
DataSource.class.isAssignableFrom(method.getParameterTypes()[0]));
}
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java?view=auto&rev=549357
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
Wed Jun 20 21:12:00 2007
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.provider.datasource;
+
+import java.util.logging.Logger;
+
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.http.HTTPBinding;
+
+public abstract class AbstractProvider<T> implements WebProvider {
+ static final Logger LOG =
Logger.getLogger(AbstractProvider.class.getName());
+ protected WebServiceContext wsContext;
+
+ public T invoke(T req) {
+
+ MessageContext mc = wsContext.getMessageContext();
+ String method = (String)mc.get(MessageContext.HTTP_REQUEST_METHOD);
+ LOG.info("method: " + method);
+
+ T ret = null;
+ if ("GET".equalsIgnoreCase(method)) {
+ ret = get(req);
+ }
+ return ret;
+ }
+
+ protected abstract T get(T req);
+
+ public WebServiceContext getWebServiceContext() {
+ return wsContext;
+ }
+
+ public void publish(String url) {
+ Endpoint ep = Endpoint.create(HTTPBinding.HTTP_BINDING, this);
+ ep.publish(url);
+ }
+
+ public void setWebServiceContext(WebServiceContext wsc) {
+ wsContext = wsc;
+ }
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/AbstractProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java?view=auto&rev=549357
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
Wed Jun 20 21:12:00 2007
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.provider.datasource;
+
+import java.io.ByteArrayOutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DataSourceProviderTest extends Assert {
+
+ static final Logger LOG =
Logger.getLogger(DataSourceProviderTest.class.getName());
+ private static final String TEST_URI = "http://localhost:9000/test/foo";
+
+ @Before
+ public void launchServer() {
+ TestProvider tp = new TestProvider();
+ tp.publish(TEST_URI);
+ }
+
+
+ @Test
+ public void invokeOnServer() throws Exception {
+ URL url = new URL("http://localhost:9000/test/foo");
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ printSource(new StreamSource(conn.getInputStream()));
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ URL url = new URL("http://localhost:9000/test/foo");
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ String header = conn.getHeaderField("WWW-Authenticate");
+ LOG.info("header: " + header);
+ printSource(new StreamSource(conn.getInputStream()));
+ }
+
+ private static void printSource(Source source) {
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ StreamResult sr = new StreamResult(bos);
+ Transformer trans =
TransformerFactory.newInstance().newTransformer();
+ Properties oprops = new Properties();
+ oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ trans.setOutputProperties(oprops);
+ trans.transform(source, sr);
+ assertEquals(bos.toString(),
"<doc><response>Hello</response></doc>");
+ bos.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/Server.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/Server.java?view=auto&rev=549357
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/Server.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/Server.java
Wed Jun 20 21:12:00 2007
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.provider.datasource;
+
+
+public class Server {
+
+ public void publish() {
+
+ TestProvider servant = new TestProvider();
+ servant.publish("http://localhost:9000/test/foo");
+ }
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("server starting");
+
+ Server srv = new Server();
+ srv.publish();
+
+ Thread.sleep(60 * 60 * 1000);
+ System.out.println("Server exiting");
+ System.exit(0);
+ }
+}
\ No newline at end of file
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/Server.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/Server.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java?view=auto&rev=549357
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
Wed Jun 20 21:12:00 2007
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.provider.datasource;
+
+
+import javax.activation.DataSource;
+import javax.mail.util.ByteArrayDataSource;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.Provider;
+import javax.xml.ws.Service;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceProvider;
+
+
[EMAIL PROTECTED](serviceName = "ModelProvider")
[EMAIL PROTECTED](value = Service.Mode.PAYLOAD)
[EMAIL PROTECTED](value = "http://cxf.apache.org/bindings/xformat")
+public class TestProvider extends AbstractProvider<DataSource> implements
Provider<DataSource> {
+
+ @javax.annotation.Resource
+ public void setWebServiceContext(WebServiceContext wsc) {
+ super.setWebServiceContext(wsc);
+ }
+
+ @Override
+ public DataSource invoke(DataSource req) {
+ return super.invoke(req);
+ }
+
+ @Override
+ protected DataSource get(DataSource req) {
+ String msg = "<doc><response>Hello</response></doc>";
+ return new ByteArrayDataSource(msg.getBytes(),
"application/octet-stream");
+ }
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/WebProvider.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/WebProvider.java?view=auto&rev=549357
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/WebProvider.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/WebProvider.java
Wed Jun 20 21:12:00 2007
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.provider.datasource;
+
+import javax.xml.ws.WebServiceContext;
+
+public interface WebProvider {
+ WebServiceContext getWebServiceContext();
+
+ void publish(String url);
+
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/WebProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/WebProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date