cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1386718 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: impl/ provider/
Date Mon, 17 Sep 2012 16:56:25 GMT
Author: sergeyb
Date: Mon Sep 17 16:56:24 2012
New Revision: 1386718

URL: http://svn.apache.org/viewvc?rev=1386718&view=rev
Log:
[CXF-4455] Prototyping the support for reader/writer interceptors

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractPropertiesImpl.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractRequestContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java?rev=1386718&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
Mon Sep 17 16:56:24 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.jaxrs.impl;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.message.Message;
+
+public class AbstractInterceptorContextImpl extends AbstractPropertiesImpl {
+
+    private Class<?> cls;
+    private Type type;
+    private Annotation[] anns;
+    private MediaType mt;
+    public AbstractInterceptorContextImpl(Class<?> cls,
+                                        Type type,
+                                        Annotation[] anns,
+                                        MediaType mt,
+                                        Message message) {
+        super(message);
+        this.cls = cls;
+        this.type = type;
+        this.mt = mt;
+        this.anns = anns;
+    }
+    
+    public Class<?> getType() {
+        return cls;
+    }
+    
+    public Annotation[] getAnnotations() {
+        return anns;
+    }
+
+    public Type getGenericType() {
+        return type;
+    }
+
+    public MediaType getMediaType() {
+        return mt;
+    }
+
+    public void setAnnotations(Annotation[] annotations) {
+        anns = annotations;
+
+    }
+
+    public void setGenericType(Type genType) {
+        type = genType;
+    }
+
+    public void setMediaType(MediaType mtype) {
+        mt = mtype;
+    }
+
+    public void setType(Class<?> ctype) {
+        cls = ctype;
+    }
+
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractPropertiesImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractPropertiesImpl.java?rev=1386718&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractPropertiesImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractPropertiesImpl.java
Mon Sep 17 16:56:24 2012
@@ -0,0 +1,79 @@
+/**
+ * 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.jaxrs.impl;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.message.Message;
+
+public abstract class AbstractPropertiesImpl {
+
+    private static final String PROPERTY_KEY = "jaxrs.filter.properties";
+    
+    protected Message m;
+    private Map<String, Object> props;
+    public AbstractPropertiesImpl(Message message) {
+        this.m = message;
+        this.props = CastUtils.cast((Map<?, ?>)message.get(PROPERTY_KEY));
+    }
+    
+    
+    public Object getProperty(String name) {
+        return props == null ? null : props.get(name);
+    }
+
+    public Enumeration<String> getPropertyNames() {
+        final Iterator<String> it = props.keySet().iterator();
+        return new Enumeration<String>() {
+
+            @Override
+            public boolean hasMoreElements() {
+                return it.hasNext();
+            }
+
+            @Override
+            public String nextElement() {
+                return it.next();
+            }
+            
+        };
+    }
+
+
+    public void removeProperty(String name) {
+        if (props != null) {
+            props.remove(name);    
+        }
+    }
+
+
+    public void setProperty(String name, Object value) {
+        if (props == null) {
+            props = new HashMap<String, Object>();
+            m.put(PROPERTY_KEY, props);
+        }    
+        props.put(name, value);    
+        
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractPropertiesImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractPropertiesImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractRequestContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractRequestContextImpl.java?rev=1386718&r1=1386717&r2=1386718&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractRequestContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractRequestContextImpl.java
Mon Sep 17 16:56:24 2012
@@ -19,9 +19,6 @@
 package org.apache.cxf.jaxrs.impl;
 
 import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -31,20 +28,14 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
 
-public abstract class AbstractRequestContextImpl {
+public abstract class AbstractRequestContextImpl extends AbstractPropertiesImpl {
 
-    private static final String PROPERTY_KEY = "jaxrs.filter.properties";
-    
     protected HttpHeaders h;
-    protected Message m;
-    private Map<String, Object> props;
     private boolean responseContext;
     public AbstractRequestContextImpl(Message message, boolean responseContext) {
-        this.m = message;
-        this.props = CastUtils.cast((Map<?, ?>)message.get(PROPERTY_KEY));
+        super(message);
         this.h = new HttpHeadersImpl(message);
         this.responseContext = responseContext;
     }
@@ -90,50 +81,12 @@ public abstract class AbstractRequestCon
         return (String)getProperty(Message.HTTP_REQUEST_METHOD);
     }
 
-    public Object getProperty(String name) {
-        return props == null ? null : props.get(name);
-    }
-
-    public Enumeration<String> getPropertyNames() {
-        final Iterator<String> it = props.keySet().iterator();
-        return new Enumeration<String>() {
-
-            @Override
-            public boolean hasMoreElements() {
-                return it.hasNext();
-            }
-
-            @Override
-            public String nextElement() {
-                return it.next();
-            }
-            
-        };
-    }
-
-
-    public void removeProperty(String name) {
-        if (props != null) {
-            props.remove(name);    
-        }
-    }
-
-
     public void setMethod(String method) throws IllegalStateException {
         checkContext();
         m.put(Message.HTTP_REQUEST_METHOD, method);
 
     }
 
-    public void setProperty(String name, Object value) {
-        if (props == null) {
-            props = new HashMap<String, Object>();
-            m.put(PROPERTY_KEY, props);
-        }    
-        props.put(name, value);    
-        
-    }
-
     protected HttpHeaders getHttpHeaders() {
         return h != null ? h : new HttpHeadersImpl(m);
     }

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java?rev=1386718&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
Mon Sep 17 16:56:24 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.jaxrs.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+
+import org.apache.cxf.message.Message;
+
+public class ReaderInterceptorContextImpl extends AbstractInterceptorContextImpl 
+    implements ReaderInterceptorContext {
+
+    private List<ReaderInterceptor> readers;
+    private InputStream is;
+    public ReaderInterceptorContextImpl(Class<?> cls,
+                                        Type type,
+                                        Annotation[] anns,
+                                        MediaType mt,
+                                        InputStream is,
+                                        Message message,
+                                        List<ReaderInterceptor> readers) {
+        super(cls, type, anns, mt, message);
+        this.is = is;
+        this.readers = readers;
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public MultivaluedMap<String, String> getHeaders() {
+        return new MetadataMap<String, String>(
+            (Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS), false,
true, true);
+    }
+
+    @Override
+    public InputStream getInputStream() {
+        return is;
+    }
+
+    @Override
+    public Object proceed() throws IOException {
+        if (readers == null || readers.isEmpty()) {
+            return null;
+        }
+        ReaderInterceptor next = readers.remove(0);
+        return next.aroundReadFrom(this);
+    }
+
+    @Override
+    public void setInputStream(InputStream stream) {
+        is = stream;
+        m.put(InputStream.class, stream);
+
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java?rev=1386718&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
Mon Sep 17 16:56:24 2012
@@ -0,0 +1,46 @@
+/**
+ * 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.jaxrs.impl;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+
+public class ReaderInterceptorMBR implements ReaderInterceptor {
+
+    private MessageBodyReader<?> reader;
+    
+    public ReaderInterceptorMBR(MessageBodyReader<?> reader) {
+        this.reader = reader;
+    }
+    
+    @SuppressWarnings({
+        "unchecked", "rawtypes"
+    })
+    @Override
+    public Object aroundReadFrom(ReaderInterceptorContext c) throws IOException, WebApplicationException
{
+        return reader.readFrom((Class)c.getType(), c.getGenericType(),
+                               c.getAnnotations(), c.getMediaType(),
+                               c.getHeaders(), c.getInputStream());
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java?rev=1386718&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
Mon Sep 17 16:56:24 2012
@@ -0,0 +1,97 @@
+/**
+ * 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.jaxrs.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+import org.apache.cxf.message.Message;
+
+public class WriterInterceptorContextImpl extends AbstractInterceptorContextImpl 
+    implements WriterInterceptorContext {
+
+    private List<WriterInterceptor> writers;
+    private OutputStream os;
+    private Object entity;
+    //CHECKSTYLE:OFF
+    public WriterInterceptorContextImpl(Object entity,
+                                        Class<?> cls,
+                                        Type type,
+                                        Annotation[] anns,
+                                        MediaType mt,
+                                        OutputStream os,
+                                        Message message,
+                                        List<WriterInterceptor> writers) {
+    //CHECKSTYLE:ON    
+        super(cls, type, anns, mt, message);
+        this.entity = entity;
+        this.os = os;
+        this.writers = writers;
+    }
+    
+    
+    @Override
+    public Object getEntity() {
+        return entity;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public MultivaluedMap<String, Object> getHeaders() {
+        return new MetadataMap<String, Object>(
+            (Map<String, List<Object>>)m.get(Message.PROTOCOL_HEADERS), false,
true, true);
+    }
+
+    @Override
+    public OutputStream getOutputStream() {
+        return os;
+    }
+
+    @Override
+    public void proceed() throws IOException {
+        if (writers == null || writers.isEmpty()) {
+            return;
+        }
+        WriterInterceptor next = writers.remove(0);
+        next.aroundWriteTo(this);
+    }
+
+    @Override
+    public void setEntity(Object object) {
+        entity = object;
+
+    }
+
+    @Override
+    public void setOutputStream(OutputStream stream) {
+        this.os = stream;
+        m.put(OutputStream.class, stream);
+
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java?rev=1386718&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
Mon Sep 17 16:56:24 2012
@@ -0,0 +1,48 @@
+/**
+ * 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.jaxrs.impl;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+public class WriterInterceptorMBW implements WriterInterceptor {
+
+    private MessageBodyWriter<Object> writer;
+    
+    public WriterInterceptorMBW(MessageBodyWriter<Object> writer) {
+        this.writer = writer;
+    }
+
+    @Override
+    public void aroundWriteTo(WriterInterceptorContext c) throws IOException, WebApplicationException
{
+        writer.writeTo(c.getEntity(), 
+                       c.getType(), 
+                       c.getGenericType(), 
+                       c.getAnnotations(), 
+                       c.getMediaType(), 
+                       c.getHeaders(), 
+                       c.getOutputStream());
+    }
+    
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1386718&r1=1386717&r2=1386718&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Mon Sep 17 16:56:24 2012
@@ -51,6 +51,8 @@ import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.WriterInterceptor;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -65,8 +67,10 @@ import org.apache.cxf.jaxrs.ext.Paramete
 import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.ext.ResponseHandler;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
+import org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
+import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
@@ -105,6 +109,23 @@ public final class ProviderFactory {
         new ArrayList<ProviderInfo<ContextResolver<?>>>(1);
     private List<ProviderInfo<ContextProvider<?>>> contextProviders = 
         new ArrayList<ProviderInfo<ContextProvider<?>>>(1);
+    
+    // ParamConverter and ParamConverterProvider is introduced in JAX-RS 2.0
+    // ParameterHandler will have to be deprecated
+    private List<ProviderInfo<ParameterHandler<?>>> paramHandlers = 
+        new ArrayList<ProviderInfo<ParameterHandler<?>>>(1);
+    
+    private List<ProviderInfo<MessageBodyReader<?>>> jaxbReaders = 
+        new ArrayList<ProviderInfo<MessageBodyReader<?>>>();
+    private List<ProviderInfo<MessageBodyWriter<?>>> jaxbWriters = 
+        new ArrayList<ProviderInfo<MessageBodyWriter<?>>>();
+    
+    private List<ProviderInfo<ReaderInterceptor>> readerInterceptors = 
+        new ArrayList<ProviderInfo<ReaderInterceptor>>(1);
+    private List<ProviderInfo<WriterInterceptor>> writerInterceptors = 
+        new ArrayList<ProviderInfo<WriterInterceptor>>(1);
+    
+    // Server specific providers
     private List<ProviderInfo<ExceptionMapper<?>>> exceptionMappers = 
         new ArrayList<ProviderInfo<ExceptionMapper<?>>>(1);
     
@@ -121,25 +142,9 @@ public final class ProviderFactory {
         new LinkedHashMap<NameKey, ProviderInfo<ContainerRequestFilter>>();
     private Map<NameKey, ProviderInfo<ContainerResponseFilter>> postMatchContainerResponseFilters
= 
         new LinkedHashMap<NameKey, ProviderInfo<ContainerResponseFilter>>();
-    
-    // ParamConverter and ParamConverterProvider is introduced in JAX-RS 2.0
-    // ParameterHandler will have to be deprecated
-    private List<ProviderInfo<ParameterHandler<?>>> paramHandlers = 
-        new ArrayList<ProviderInfo<ParameterHandler<?>>>(1);
-    
     private RequestPreprocessor requestPreprocessor;
     private ProviderInfo<Application> application;
     
-    private List<ProviderInfo<MessageBodyReader<?>>> jaxbReaders = 
-        new ArrayList<ProviderInfo<MessageBodyReader<?>>>();
-    private List<ProviderInfo<MessageBodyWriter<?>>> jaxbWriters = 
-        new ArrayList<ProviderInfo<MessageBodyWriter<?>>>();
-    
-    private Collection<ProviderInfo<?>> injectedProviders = 
-        new LinkedList<ProviderInfo<?>>();
-    
-    private Bus bus;
-    
     // Client-only providers, consider introducing ClientProviderFactory
     private List<ProviderInfo<ClientRequestFilter>> clientRequestFilters = 
         new ArrayList<ProviderInfo<ClientRequestFilter>>(1);
@@ -147,6 +152,13 @@ public final class ProviderFactory {
         new ArrayList<ProviderInfo<ClientResponseFilter>>(1);
     private List<ProviderInfo<ResponseExceptionMapper<?>>> responseExceptionMappers
= 
         new ArrayList<ProviderInfo<ResponseExceptionMapper<?>>>(1);
+   
+    // List of injected providers
+    private Collection<ProviderInfo<?>> injectedProviders = 
+        new LinkedList<ProviderInfo<?>>();
+    
+    private Bus bus;
+    
     
     private ProviderFactory(Bus bus) {
         this.bus = bus;
@@ -431,6 +443,75 @@ public final class ProviderFactory {
             }
         }
     }
+        
+    
+    public <T> List<ReaderInterceptor> createMessageBodyReaderInterceptor(Class<T>
bodyType,
+                                                            Type parameterType,
+                                                            Annotation[] parameterAnnotations,
+                                                            MediaType mediaType,
+                                                            Message m) {
+        MessageBodyReader<T> mr = createMessageBodyReader(bodyType,
+                                                      parameterType,
+                                                      parameterAnnotations,
+                                                      mediaType,
+                                                      m);
+        if (mr != null) {
+            ReaderInterceptor mbrReader = new ReaderInterceptorMBR(mr);
+            
+            int size = readerInterceptors.size();
+            List<ReaderInterceptor> interceptors = null;
+            if (size > 0) {
+                interceptors = new ArrayList<ReaderInterceptor>(size + 1);
+                for (ProviderInfo<ReaderInterceptor> p : readerInterceptors) {
+                    InjectionUtils.injectContexts(p.getProvider(), p, m);
+                    interceptors.add(p.getProvider());
+                }
+                interceptors.add(mbrReader);
+            } else {
+                interceptors = Collections.singletonList(mbrReader);
+            }
+            
+            return interceptors;
+        } else {
+            return null;
+        }
+    }
+    
+    public <T> List<WriterInterceptor> createMessageBodyWriterInterceptor(Class<T>
bodyType,
+                                                                          Type parameterType,
+                                                                          Annotation[] parameterAnnotations,
+                                                                          MediaType mediaType,
+                                                                          Message m) {
+        MessageBodyWriter<T> mw = createMessageBodyWriter(bodyType,
+                                                      parameterType,
+                                                      parameterAnnotations,
+                                                      mediaType,
+                                                      m);
+        if (mw != null) {
+            
+            @SuppressWarnings({
+                "unchecked", "rawtypes"
+            })
+            WriterInterceptor mbwWriter = new WriterInterceptorMBW((MessageBodyWriter)mw);
+              
+            int size = writerInterceptors.size();
+            List<WriterInterceptor> interceptors = null;
+            if (size > 0) {
+                interceptors = new ArrayList<WriterInterceptor>(size + 1);
+                for (ProviderInfo<WriterInterceptor> p : writerInterceptors) {
+                    InjectionUtils.injectContexts(p.getProvider(), p, m);
+                    interceptors.add(p.getProvider());
+                }
+                interceptors.add(mbwWriter);
+            } else {
+                interceptors = Collections.singletonList(mbwWriter);
+            }
+            
+            return interceptors;
+        } else {
+            return null;
+        }
+    }
     
     
     
@@ -625,6 +706,16 @@ public final class ProviderFactory {
                    null); 
             }
             
+            if (ReaderInterceptor.class.isAssignableFrom(oClass)) {
+                readerInterceptors.add(
+                   new ProviderInfo<ReaderInterceptor>((ReaderInterceptor)o, bus));
+            }
+            
+            if (WriterInterceptor.class.isAssignableFrom(oClass)) {
+                writerInterceptors.add(
+                   new ProviderInfo<WriterInterceptor>((WriterInterceptor)o, bus));
+            }
+            
             if (ClientRequestFilter.class.isAssignableFrom(oClass)) {
                 clientRequestFilters.add(
                    new ProviderInfo<ClientRequestFilter>((ClientRequestFilter)o, bus));
@@ -652,8 +743,13 @@ public final class ProviderFactory {
         sortContextResolvers();
         
         Collections.sort(preMatchContainerRequestFilters, new BindingPriorityComparator(true));
-        mapContainerFilters(postMatchContainerRequestFilters, postMatchRequestFilters);
-        mapContainerFilters(postMatchContainerResponseFilters, postMatchResponseFilters);
+        mapContainerFilters(postMatchContainerRequestFilters, postMatchRequestFilters, true);
+        mapContainerFilters(postMatchContainerResponseFilters, postMatchResponseFilters,
false);
+        Collections.sort(readerInterceptors, new BindingPriorityComparator(true));
+        Collections.sort(writerInterceptors, new BindingPriorityComparator(false));
+        
+        Collections.sort(clientRequestFilters, new BindingPriorityComparator(true));
+        Collections.sort(clientResponseFilters, new BindingPriorityComparator(false));
         
         injectContextProxies(messageReaders, messageWriters, contextResolvers, 
             requestHandlers, responseHandlers, exceptionMappers,
@@ -664,9 +760,10 @@ public final class ProviderFactory {
 //CHECKSTYLE:ON
     
     private static <T> void mapContainerFilters(Map<NameKey, ProviderInfo<T>>
map,
-                                                List<ProviderInfo<T>> postMatchFilters)
{
+                                                List<ProviderInfo<T>> postMatchFilters,
+                                                boolean ascending) {
         
-        Collections.sort(postMatchFilters, new PostMatchFilterComparator(true));
+        Collections.sort(postMatchFilters, new PostMatchFilterComparator(ascending));
         for (ProviderInfo<T> p : postMatchFilters) { 
             List<String> names = AnnotationUtils.getNameBindings(
                 p.getProvider().getClass().getAnnotations());



Mime
View raw message