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 2011/01/21 19:06:01 UTC
svn commit: r1061941 - in
/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs:
interceptor/JAXRSOutInterceptor.java
provider/AbstractConfigurableProvider.java
provider/JAXBElementProvider.java utils/InjectionUtils.java
Author: sergeyb
Date: Fri Jan 21 18:06:01 2011
New Revision: 1061941
URL: http://svn.apache.org/viewvc?rev=1061941&view=rev
Log:
[CXF-3261] Removing reflective calls from the JAXRSOutInterceptor
Modified:
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/AbstractConfigurableProvider.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/utils/InjectionUtils.java
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=1061941&r1=1061940&r2=1061941&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 Fri Jan 21 18:06:01 2011
@@ -54,6 +54,7 @@ import org.apache.cxf.jaxrs.lifecycle.Re
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.model.ProviderInfo;
+import org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -291,12 +292,14 @@ public class JAXRSOutInterceptor extends
return false;
}
Object outBuf = m.getContextualProperty(OUT_BUFFERING);
- boolean enabled = Boolean.TRUE.equals(outBuf) || "true".equals(outBuf);
- if (!enabled && outBuf == null) {
- enabled = InjectionUtils.invokeBooleanGetter(w, "getEnableBuffering");
+ boolean enabled = MessageUtils.isTrue(outBuf);
+ boolean configurableProvider = w instanceof AbstractConfigurableProvider;
+ if (!enabled && outBuf == null && configurableProvider) {
+ enabled = ((AbstractConfigurableProvider)w).getEnableBuffering();
}
if (enabled) {
- boolean streamingOn = InjectionUtils.invokeBooleanGetter(w, "getEnableStreaming");
+ boolean streamingOn = configurableProvider
+ ? ((AbstractConfigurableProvider)w).getEnableStreaming() : false;
if (streamingOn) {
m.setContent(XMLStreamWriter.class, new CachingXmlEventWriter());
} else {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java?rev=1061941&r1=1061940&r2=1061941&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java Fri Jan 21 18:06:01 2011
@@ -30,42 +30,116 @@ public abstract class AbstractConfigurab
private List<String> consumeMediaTypes;
private List<String> produceMediaTypes;
private boolean enableBuffering;
+ private boolean enableStreaming;
private Bus bus;
+ /**
+ * Sets the Bus
+ * @param b
+ */
public void setBus(Bus b) {
if (bus != null) {
bus = b;
}
}
+ /**
+ * Gets the Bus.
+ * Providers may use the bus to resolve resource references.
+ * Example:
+ * ResourceUtils.getResourceStream(reference, this.getBus())
+ *
+ * @return
+ */
public Bus getBus() {
return bus != null ? bus : BusFactory.getThreadDefaultBus();
}
+ /**
+ * Sets custom Consumes media types; can be used to override static
+ * {@link Consumes} annotation value set on the provider.
+ * @param types the media types
+ */
public void setConsumeMediaTypes(List<String> types) {
consumeMediaTypes = types;
}
+ /**
+ * Gets the custom Consumes media types
+ * @return media types
+ */
public List<String> getConsumeMediaTypes() {
return consumeMediaTypes;
}
+ /**
+ * Sets custom Produces media types; can be used to override static
+ * {@link Produces} annotation value set on the provider.
+ * @param types the media types
+ */
public void setProduceMediaTypes(List<String> types) {
produceMediaTypes = types;
}
+ /**
+ * Gets the custom Produces media types
+ * @return media types
+ */
public List<String> getProduceMediaTypes() {
return produceMediaTypes;
}
+ /**
+ * Enables the buffering mode. If set to true then the runtime will ensure
+ * that the provider writes to a cached stream.
+ *
+ * For example, the JAXB marshalling process may fail after the initial XML
+ * tags have already been written out to the HTTP output stream. Enabling
+ * the buffering ensures no incomplete payloads are sent back to clients
+ * in case of marshalling errors at the cost of the initial buffering - which
+ * might be negligible for small payloads.
+ *
+ * @param enableBuf the value of the buffering mode, false is default.
+ */
public void setEnableBuffering(boolean enableBuf) {
enableBuffering = enableBuf;
}
+ /**
+ * Gets the value of the buffering mode
+ * @return true if the buffering is enabled
+ */
public boolean getEnableBuffering() {
return enableBuffering;
}
+ /**
+ * Enables the support for streaming. XML-aware providers which prefer
+ * writing to Stax XMLStreamWriter can set this value to true. Additionally,
+ * if the streaming and the buffering modes are enabled, the runtime will
+ * ensure the XMLStreamWriter events are cached properly.
+ * @param enableStream the value of the streaming mode, false is default.
+ */
+ public void setEnableStreaming(boolean enableStream) {
+ enableStreaming = enableStream;
+ }
+
+ /**
+ * Gets the value of the streaming mode
+ * @return true if the streaming is enabled
+ */
+ public boolean getEnableStreaming() {
+ return enableStreaming;
+ }
+
+ /**
+ * Gives providers a chance to introspect the JAX-RS model classes.
+ * For example, the JAXB provider may use the model classes to create
+ * a single composite JAXBContext supporting all the JAXB-annotated
+ * root resource classes/types.
+ *
+ * @param resources
+ */
public void init(List<ClassResourceInfo> resources) {
// complete
}
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=1061941&r1=1061940&r2=1061941&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 Fri Jan 21 18:06:01 2011
@@ -76,7 +76,6 @@ public class JAXBElementProvider extends
Marshaller.JAXB_SCHEMA_LOCATION});
private Map<String, Object> mProperties = Collections.emptyMap();
- private boolean enableStreaming;
private ValidationEventHandler eventHandler;
public JAXBElementProvider() {
@@ -105,14 +104,6 @@ public class JAXBElementProvider extends
eventHandler = handler;
}
- public void setEnableStreaming(boolean enableStream) {
- enableStreaming = enableStream;
- }
-
- public boolean getEnableStreaming() {
- return enableStreaming;
- }
-
public void setEnableBuffering(boolean enableBuf) {
super.setEnableBuffering(enableBuf);
}
@@ -425,7 +416,7 @@ public class JAXBElementProvider extends
}
}
}
- if (writer == null && enableStreaming) {
+ if (writer == null && getEnableStreaming()) {
writer = StaxUtils.createXMLStreamWriter(os);
}
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1061941&r1=1061940&r2=1061941&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Fri Jan 21 18:06:01 2011
@@ -133,16 +133,6 @@ public final class InjectionUtils {
return result == null ? Object.class : result;
}
- public static boolean invokeBooleanGetter(Object o, String name) {
- try {
- Method method = o.getClass().getMethod(name, new Class[]{});
- return (Boolean)method.invoke(o, new Object[]{});
- } catch (Exception ex) {
- LOG.finest("Can not invoke method " + name + " on object of class " + o.getClass().getName());
- }
- return false;
- }
-
public static Method checkProxy(Method methodToInvoke, Object resourceObject) {
if (Proxy.class.isInstance(resourceObject)) {
for (Class<?> c : resourceObject.getClass().getInterfaces()) {