cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Made a mistake, restoring the caching providers
Date Thu, 15 Jan 2015 14:41:34 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes a46de68ef -> 9b547bf70


Made a mistake, restoring the caching providers


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/9b547bf7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/9b547bf7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/9b547bf7

Branch: refs/heads/3.0.x-fixes
Commit: 9b547bf708d3220efe10a9010967c9f2078a73ed
Parents: a46de68
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Jan 15 14:40:16 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Jan 15 14:41:16 2015 +0000

----------------------------------------------------------------------
 .../provider/CachingMessageBodyReader.java      | 101 ++++++++++++++++++
 .../provider/CachingMessageBodyWriter.java      | 103 +++++++++++++++++++
 2 files changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9b547bf7/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
new file mode 100644
index 0000000..7cfcea6
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
@@ -0,0 +1,101 @@
+/**
+ * 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.provider;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.List;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+
+@Provider
+public class CachingMessageBodyReader<T> extends AbstractCachingMessageProvider<T>
+    implements MessageBodyReader<T> {
+    
+    private List<MessageBodyReader<T>> delegatingReaders;
+    
+    public boolean isReadable(Class<?> type, Type gType, Annotation[] anns, MediaType
mt) {
+        if (delegatingReaders != null) {
+            return getDelegatingReader(type, gType, anns, mt) != null;
+        } else {
+            return isProviderKeyNotSet();
+        }
+    }
+
+    private MessageBodyReader<T> getDelegatingReader(Class<?> type, Type gType,
Annotation[] anns, MediaType mt) {
+        for (MessageBodyReader<T> reader: delegatingReaders) {
+            if (reader.isReadable(type, gType, anns, mt)) {
+                return reader;
+            }
+        }
+        return null;
+    }
+    
+    public T readFrom(Class<T> type, Type gType, Annotation[] anns, MediaType mt,
+                        MultivaluedMap<String, String> theheaders, InputStream is)

+        throws IOException, WebApplicationException {
+        this.setObject(
+            getReader(type, gType, anns, mt).readFrom(type, gType, anns, mt, theheaders,
is));
+        return getObject();
+    }
+    
+    
+    protected MessageBodyReader<T> getReader(Class<?> type, Type gType, Annotation[]
anns, MediaType mt) {
+        if (delegatingReaders != null) {
+            return getDelegatingReader(type, gType, anns, mt);
+        }
+        MessageBodyReader<T> r = null;
+        
+        mc.put(ACTIVE_JAXRS_PROVIDER_KEY, this);
+        try {
+            @SuppressWarnings("unchecked")
+            Class<T> actualType = (Class<T>)type;
+            r = mc.getProviders().getMessageBodyReader(actualType, gType, anns, mt);
+        } finally {
+            mc.put(ACTIVE_JAXRS_PROVIDER_KEY, null); 
+        }
+        
+        if (r == null) {
+            org.apache.cxf.common.i18n.Message message = 
+                new org.apache.cxf.common.i18n.Message("NO_MSG_READER", BUNDLE, type);
+            LOG.severe(message.toString());
+            throw ExceptionUtils.toNotAcceptableException(null, null);
+        }
+        return r;
+    }
+
+    public void setDelegatingReader(MessageBodyReader<T> reader) {
+        this.delegatingReaders = Collections.singletonList(reader);
+    }
+    
+    public void setDelegatingReaders(List<MessageBodyReader<T>> readers) {
+        this.delegatingReaders = readers;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/9b547bf7/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
new file mode 100644
index 0000000..74c48b5
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
@@ -0,0 +1,103 @@
+/**
+ * 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.provider;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.List;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+
+@Provider
+public class CachingMessageBodyWriter<T> extends AbstractCachingMessageProvider<T>
+    implements MessageBodyWriter<T> {
+    
+    private List<MessageBodyWriter<T>> delegatingWriters;
+    
+    public long getSize(T t, Class<?> type, Type gType, Annotation[] anns, MediaType
mediaType) {
+        return -1;
+    }
+
+    public boolean isWriteable(Class<?> type, Type gType, Annotation[] anns, MediaType
mt) {
+        if (delegatingWriters != null) {
+            return getDelegatingWriter(type, gType, anns, mt) != null;
+        } else {
+            return isProviderKeyNotSet();
+        }
+    }
+
+    private MessageBodyWriter<T> getDelegatingWriter(Class<?> type, Type gType,
Annotation[] anns, MediaType mt) {
+        for (MessageBodyWriter<T> writer: delegatingWriters) {
+            if (writer.isWriteable(type, gType, anns, mt)) {
+                return writer;
+            }
+        }
+        return null;
+    }
+    
+    public void writeTo(T obj, Class<?> type, Type gType, Annotation[] anns, MediaType
mt,
+                        MultivaluedMap<String, Object> theheaders, OutputStream os)

+        throws IOException, WebApplicationException {
+        this.setObject(obj);
+        getWriter(type, gType, anns, mt).writeTo(getObject(), type, gType, anns, mt, theheaders,
os);
+    }
+    
+    
+    protected MessageBodyWriter<T> getWriter(Class<?> type, Type gType, Annotation[]
anns, MediaType mt) {
+        if (delegatingWriters != null) {
+            return getDelegatingWriter(type, gType, anns, mt);
+        }
+        MessageBodyWriter<T> w = null;
+        
+        mc.put(ACTIVE_JAXRS_PROVIDER_KEY, this);
+        try {
+            @SuppressWarnings("unchecked")
+            Class<T> actualType = (Class<T>)type;
+            w = mc.getProviders().getMessageBodyWriter(actualType, gType, anns, mt);
+        } finally {
+            mc.put(ACTIVE_JAXRS_PROVIDER_KEY, null); 
+        }
+        
+        if (w == null) {
+            org.apache.cxf.common.i18n.Message message = 
+                new org.apache.cxf.common.i18n.Message("NO_MSG_WRITER", BUNDLE, type);
+            LOG.severe(message.toString());
+            throw ExceptionUtils.toInternalServerErrorException(null, null);
+        }
+        return w;
+    }
+    
+    public void setDelegatingWriter(MessageBodyWriter<T> writer) {
+        this.delegatingWriters = Collections.singletonList(writer);
+    }
+    
+    public void setDelegatingWriters(List<MessageBodyWriter<T>> writers) {
+        this.delegatingWriters = writers;
+    }
+}


Mime
View raw message