You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/05/07 13:47:26 UTC
svn commit: r772620 - in /cxf/trunk:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/
rt/frontend/jaxrs/src/main/ja...
Author: sergeyb
Date: Thu May 7 11:47:25 2009
New Revision: 772620
URL: http://svn.apache.org/viewvc?rev=772620&view=rev
Log:
JAXRS: updating JAXB provider to use STAX readers/writers if available
Added:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamReader.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java (with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java Thu May 7 11:47:25 2009
@@ -36,6 +36,9 @@
public interface MessageContext {
Object get(Object key);
+ Object getContextualProperty(Object key);
+ <T> T getContent(Class<T> format);
+
void put(Object key, Object value);
UriInfo getUriInfo();
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java Thu May 7 11:47:25 2009
@@ -59,6 +59,14 @@
}
return m.get(key);
}
+
+ public <T> T getContent(Class<T> format) {
+ return m.getContent(format);
+ }
+
+ public Object getContextualProperty(Object key) {
+ return m.getContextualProperty(key.toString());
+ }
public <T> T getContext(Class<T> contextClass) {
return getContext(contextClass, contextClass);
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java Thu May 7 11:47:25 2009
@@ -89,4 +89,12 @@
return get() != null ? get().getResolver(resolverClass, resolveClazz) : null;
}
+ public <T> T getContent(Class<T> format) {
+ return get() != null ? get().getContent(format) : null;
+ }
+
+ public Object getContextualProperty(Object key) {
+ return get() != null ? get().getContextualProperty(key) : null;
+ }
+
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java Thu May 7 11:47:25 2009
@@ -241,11 +241,9 @@
enabled = InjectionUtils.invokeBooleanGetter(w, "getEnableBuffering");
}
if (enabled) {
- boolean streamingOn =
- "org.apache.cxf.jaxrs.provider.JAXBElementProvider".equals(w.getClass().getName())
- && InjectionUtils.invokeBooleanGetter(w, "getEnableStreaming");
+ boolean streamingOn = InjectionUtils.invokeBooleanGetter(w, "getEnableStreaming");
if (streamingOn) {
- m.put(XMLStreamWriter.class.getName(), new CachingXmlEventWriter());
+ m.setContent(XMLStreamWriter.class, new CachingXmlEventWriter());
} else {
m.setContent(OutputStream.class, new CachedOutputStream());
}
@@ -257,7 +255,7 @@
if (!enabled) {
return;
}
- XMLStreamWriter writer = (XMLStreamWriter)m.get(XMLStreamWriter.class.getName());
+ XMLStreamWriter writer = m.getContent(XMLStreamWriter.class);
if (writer instanceof CachingXmlEventWriter) {
CachingXmlEventWriter cache = (CachingXmlEventWriter)writer;
if (cache.getEvents().size() != 0) {
@@ -266,7 +264,7 @@
StaxUtils.writeEvent(event, origWriter);
}
}
- m.put(XMLStreamWriter.class.getName(), null);
+ m.setContent(XMLStreamWriter.class, null);
return;
}
OutputStream os = m.getContent(OutputStream.class);
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java Thu May 7 11:47:25 2009
@@ -24,6 +24,7 @@
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -39,6 +40,8 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.ValidationEventHandler;
+import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.stream.StreamSource;
@@ -51,14 +54,26 @@
@Provider
public class JAXBElementProvider extends AbstractJAXBProvider {
+ private static final List<String> MARSHALLER_PROPERTIES =
+ Arrays.asList(new String[] {Marshaller.JAXB_ENCODING,
+ Marshaller.JAXB_FORMATTED_OUTPUT,
+ Marshaller.JAXB_FRAGMENT,
+ Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION,
+ Marshaller.JAXB_SCHEMA_LOCATION});
+
private Map<String, Object> mProperties = new HashMap<String, Object>();
private boolean enableStreaming;
+ private ValidationEventHandler eventHandler;
@Context
public void setMessageContext(MessageContext mc) {
super.setContext(mc);
}
+ public void setValidationHandler(ValidationEventHandler handler) {
+ eventHandler = handler;
+ }
+
public void setEnableStreaming(boolean enableStream) {
enableStreaming = enableStream;
}
@@ -101,7 +116,9 @@
try {
Class<?> theType = getActualType(type, genericType, anns);
Unmarshaller unmarshaller = createUnmarshaller(theType, genericType);
-
+ if (eventHandler != null) {
+ unmarshaller.setEventHandler(eventHandler);
+ }
Object response = null;
if (JAXBElement.class.isAssignableFrom(type)) {
response = unmarshaller.unmarshal(new StreamSource(is), theType);
@@ -124,8 +141,25 @@
protected Object doUnmarshal(Unmarshaller unmarshaller, InputStream is, MediaType mt)
throws JAXBException {
+ MessageContext mc = getContext();
+ if (mc != null) {
+ XMLStreamReader reader = getContext().getContent(XMLStreamReader.class);
+ if (reader != null) {
+ return unmarshalFromReader(unmarshaller, reader, mt);
+ }
+ }
+ return unmarshalFromInputStream(unmarshaller, is, mt);
+ }
+
+ protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is, MediaType mt)
+ throws JAXBException {
return unmarshaller.unmarshal(is);
}
+
+ protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader, MediaType mt)
+ throws JAXBException {
+ return unmarshaller.unmarshal(reader);
+ }
public void writeTo(Object obj, Class<?> cls, Type genericType, Annotation[] anns,
MediaType m, MultivaluedMap<String, Object> headers, OutputStream os)
@@ -155,20 +189,38 @@
for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
ms.setProperty(entry.getKey(), entry.getValue());
}
- if (enableStreaming) {
- XMLStreamWriter writer =
- (XMLStreamWriter)getContext().get(XMLStreamWriter.class.getName());
- if (writer == null) {
+
+ XMLStreamWriter writer = null;
+ MessageContext mc = getContext();
+ if (mc != null) {
+ writer = mc.getContent(XMLStreamWriter.class);
+ if (writer == null && enableStreaming) {
writer = StaxUtils.createXMLStreamWriter(os);
}
- ms.marshal(obj, writer);
+ // check Marshaller properties here as well which might've been set earlier on,
+ // they'll overwrite statically configured ones
+ for (String key : MARSHALLER_PROPERTIES) {
+ Object value = mc.get(key);
+ if (value != null) {
+ ms.setProperty(key, value);
+ }
+ }
+
+ }
+ if (writer != null) {
+ marshalToWriter(ms, obj, writer, mt);
} else {
- doMarshal(ms, obj, os, mt);
+ marshalToOutputStream(ms, obj, os, mt);
}
}
- protected void doMarshal(Marshaller ms, Object obj, OutputStream os, MediaType mt)
+ protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, MediaType mt)
throws Exception {
ms.marshal(obj, os);
}
+
+ protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer, MediaType mt)
+ throws Exception {
+ ms.marshal(obj, writer);
+ }
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java Thu May 7 11:47:25 2009
@@ -27,7 +27,6 @@
import java.io.Reader;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -103,11 +102,15 @@
}
protected boolean inTemplatesAvailable(MediaType mt) {
- return inTemplates != null || inMediaTemplates.containsKey(mt.getType() + "/" + mt.getSubtype());
+ return inTemplates != null
+ || inMediaTemplates != null && inMediaTemplates.containsKey(mt.getType() + "/"
+ + mt.getSubtype());
}
protected boolean outTemplatesAvailable(MediaType mt) {
- return outTemplates != null || outMediaTemplates.containsKey(mt.getType() + "/" + mt.getSubtype());
+ return outTemplates != null
+ || outMediaTemplates != null && outMediaTemplates.containsKey(mt.getType()
+ + "/" + mt.getSubtype());
}
protected Templates getInTemplates(MediaType mt) {
@@ -121,7 +124,7 @@
}
@Override
- protected Object doUnmarshal(Unmarshaller unmarshaller, InputStream is, MediaType mt)
+ protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is, MediaType mt)
throws JAXBException {
try {
XMLFilter filter = factory.newXMLFilter(
@@ -138,7 +141,7 @@
}
@Override
- protected void doMarshal(Marshaller ms, Object obj, OutputStream os, MediaType mt)
+ protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, MediaType mt)
throws Exception {
TransformerHandler th = factory.newTransformerHandler(
createTemplates(getOutTemplates(mt), outParamsMap, outProperties));
@@ -199,22 +202,16 @@
this.outProperties = outProps;
}
- public void setInClassname(String className) {
- if (inClassesToHandle == null) {
- inClassesToHandle = new ArrayList<String>();
- }
- inClassesToHandle.add(className);
+ public void setInClassNames(List<String> classNames) {
+ inClassesToHandle = classNames;
}
public boolean inClassCanBeHandled(String className) {
return inClassesToHandle == null || inClassesToHandle.contains(className);
}
- public void setOutClassname(String className) {
- if (outClassesToHandle == null) {
- outClassesToHandle = new ArrayList<String>();
- }
- outClassesToHandle.add(className);
+ public void setOutClassNames(List<String> classNames) {
+ outClassesToHandle = classNames;
}
public boolean outClassCanBeHandled(String className) {
Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamReader.java?rev=772620&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamReader.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamReader.java Thu May 7 11:47:25 2009
@@ -0,0 +1,44 @@
+/**
+ * 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.jaxrs;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
+
+public class CustomXmlStreamReader extends DepthXMLStreamReader {
+ public CustomXmlStreamReader(XMLStreamReader reader) {
+ super(reader);
+ }
+
+ @Override
+ public String getNamespaceURI() {
+ return "http://www.example.org/books";
+ }
+
+ @Override
+ public String getNamespaceURI(int index) {
+ return getNamespaceURI();
+ }
+
+ @Override
+ public String getNamespaceURI(String prefix) {
+ return getNamespaceURI();
+ }
+}
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamReader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java?rev=772620&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java Thu May 7 11:47:25 2009
@@ -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.jaxrs;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
+
+public class CustomXmlStreamWriter extends DelegatingXMLStreamWriter {
+
+ public CustomXmlStreamWriter(XMLStreamWriter writer) {
+ super(writer);
+ }
+
+ @Override
+ public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
+
+ super.writeStartElement("b", local, "");
+ if ("Book".equals(local)) {
+ super.writeNamespace("b", "http://www.w3.org/1999/xhtml");
+ }
+ }
+
+}
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Thu May 7 11:47:25 2009
@@ -48,7 +48,7 @@
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
- launchServer(BookServerSpring.class));
+ launchServer(BookServerSpring.class, true));
}
@Test
@@ -201,6 +201,20 @@
assertEquals("CXF in Action - 2", b.getName());
}
+ @Test
+ public void testGetBookReaderWriter() throws Exception {
+ String endpointAddress =
+ "http://localhost:9080/the/thebooks5/bookstore/books/convert";
+ WebClient wc = WebClient.create(endpointAddress);
+ wc.type("application/xml").accept("application/xml");
+ Book2 b = new Book2();
+ b.setId(777L);
+ b.setName("CXF - 777");
+ Book2 b2 = wc.post(b, Book2.class);
+ assertNotSame(b, b2);
+ assertEquals(777, b2.getId());
+ assertEquals("CXF - 777", b2.getName());
+ }
@Test
public void testGetBookXSLTHtml() throws Exception {
Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java?rev=772620&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java Thu May 7 11:47:25 2009
@@ -0,0 +1,43 @@
+/**
+ * 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.jaxrs;
+
+import java.io.InputStream;
+
+import javax.ws.rs.core.Response;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.jaxrs.ext.RequestHandler;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public class XmlStreamReaderProvider implements RequestHandler {
+
+ public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
+ String method = m.get(Message.HTTP_REQUEST_METHOD).toString();
+ if ("POST".equals(method)) {
+ XMLStreamReader reader =
+ StaxUtils.createXMLStreamReader(m.getContent(InputStream.class));
+ m.setContent(XMLStreamReader.class, new CustomXmlStreamReader(reader));
+ }
+ return null;
+ }
+
+}
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java?rev=772620&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java Thu May 7 11:47:25 2009
@@ -0,0 +1,43 @@
+/**
+ * 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.jaxrs;
+
+import java.io.OutputStream;
+
+import javax.ws.rs.core.Response;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.jaxrs.ext.ResponseHandler;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public class XmlStreamWriterProvider implements ResponseHandler {
+
+ public Response handleResponse(Message m, OperationResourceInfo ori, Response response) {
+ String method = ori.getHttpMethod();
+ if ("POST".equals(method)) {
+ XMLStreamWriter writer =
+ StaxUtils.createXMLStreamWriter(m.getContent(OutputStream.class));
+ m.setContent(XMLStreamWriter.class, new CustomXmlStreamWriter(writer));
+ }
+ return null;
+ }
+
+}
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=772620&r1=772619&r2=772620&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml Thu May 7 11:47:25 2009
@@ -98,13 +98,19 @@
<jaxrs:providers>
<ref bean="xsltProvider"/>
+ <bean class="org.apache.cxf.systest.jaxrs.XmlStreamReaderProvider"/>
+ <bean class="org.apache.cxf.systest.jaxrs.XmlStreamWriterProvider"/>
</jaxrs:providers>
</jaxrs:server>
<util:map id="outTemplates">
<entry key="application/xhtml+xml" value="classpath:/org/apache/cxf/systest/jaxrs/resources/template.xsl"/>
<entry key="application/xml" value="classpath:/org/apache/cxf/systest/jaxrs/resources/template2.xsl"/>
- </util:map>
+ </util:map>
+
+ <util:list id="outClassNames">
+ <value>org.apache.cxf.systest.jaxrs.Book</value>
+ </util:list>
<bean id="xsltProvider" class="org.apache.cxf.jaxrs.provider.XSLTJaxbProvider">
<property name="resolver" ref="uriResolver"/>
@@ -112,6 +118,7 @@
<property name="outTemplate" value="classpath:/org/apache/cxf/systest/jaxrs/resources/template.xsl"/>
-->
<property name="outMediaTemplates" ref="outTemplates"/>
+ <property name="outClassNames" ref="outClassNames"/>
</bean>
<bean id="uriResolver" class="org.apache.cxf.systest.jaxrs.URIResolverImpl"/>