You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2013/07/21 11:33:42 UTC

svn commit: r1505325 - in /webservices/axiom/trunk/axiom-spring-ws/src: main/java/org/apache/axiom/spring/ws/ main/java/org/apache/axiom/spring/ws/server/ main/java/org/apache/axiom/spring/ws/server/endpoint/ main/java/org/apache/axiom/spring/ws/server...

Author: veithen
Date: Sun Jul 21 09:33:41 2013
New Revision: 1505325

URL: http://svn.apache.org/r1505325
Log:
AXIOM-447: Implemented a specific optimization to prevent PayloadRootAnnotationMethodEndpointMapping from consuming/building the Axiom message.

Added:
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomOptimizationEnabler.java   (with props)
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomWebServiceMessage.java   (with props)
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/mapping/
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/mapping/AxiomPayloadRootAnnotationMethodEndpointMapping.java   (with props)
Modified:
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapBodyImpl.java
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapMessageImpl.java
    webservices/axiom/trunk/axiom-spring-ws/src/test/webapps/jdom/WEB-INF/spring-ws-servlet.xml

Added: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomOptimizationEnabler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomOptimizationEnabler.java?rev=1505325&view=auto
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomOptimizationEnabler.java (added)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomOptimizationEnabler.java Sun Jul 21 09:33:41 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.axiom.spring.ws;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.axiom.spring.ws.server.endpoint.mapping.AxiomPayloadRootAnnotationMethodEndpointMapping;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping;
+
+/**
+ * {@link BeanFactoryPostProcessor} that adjusts the configuration to enable some Axiom specific
+ * optimizations. Currently, the following optimizations are done:
+ * <ul>
+ * <li>{@link PayloadRootAnnotationMethodEndpointMapping} beans are replaced by
+ * {@link AxiomPayloadRootAnnotationMethodEndpointMapping} beans.
+ * </ul>
+ */
+public class AxiomOptimizationEnabler implements BeanFactoryPostProcessor {
+    private static final Log log = LogFactory.getLog(AxiomOptimizationEnabler.class);
+    
+    private static final Map<String,String> replacementClasses;
+    
+    static {
+        replacementClasses = new HashMap<String,String>();
+        replacementClasses.put(PayloadRootAnnotationMethodEndpointMapping.class.getName(),
+                AxiomPayloadRootAnnotationMethodEndpointMapping.class.getName());
+    }
+    
+    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
+        for (String beanName : beanFactory.getBeanDefinitionNames()) {
+            BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
+            String beanClass = beanDefinition.getBeanClassName();
+            String replacementClass = replacementClasses.get(beanClass);
+            if (replacementClass != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Changing bean class of " + beanName + " from " + beanClass + " to " + replacementClass);
+                }
+                beanDefinition.setBeanClassName(replacementClass);
+            }
+        }
+    }
+}

Propchange: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomOptimizationEnabler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomWebServiceMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomWebServiceMessage.java?rev=1505325&view=auto
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomWebServiceMessage.java (added)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomWebServiceMessage.java Sun Jul 21 09:33:41 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.axiom.spring.ws;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+
+import org.springframework.ws.WebServiceMessage;
+import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
+
+/**
+ * Interface implemented by {@link WebServiceMessage} instances created by
+ * {@link AxiomSoapMessageFactory}.
+ */
+public interface AxiomWebServiceMessage extends WebServiceMessage {
+    /**
+     * Returns the root qualified name of the payload of this message. The return value is the same
+     * as that of {@link PayloadRootUtils#getPayloadRootQName(Source, TransformerFactory)} when
+     * invoked with the {@link Source} object returned by
+     * {@link WebServiceMessage#getPayloadSource()}, but the implementation is more efficient.
+     * 
+     * @return the qualified name of they payload root element
+     */
+    QName getPayloadRootQName();
+}

Propchange: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/AxiomWebServiceMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapBodyImpl.java?rev=1505325&r1=1505324&r2=1505325&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapBodyImpl.java (original)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapBodyImpl.java Sun Jul 21 09:33:41 2013
@@ -34,8 +34,7 @@ final class SoapBodyImpl extends SoapEle
     }
 
     public Source getPayloadSource() {
-        // TODO: need to optimize this so that we can use cache=false whenever possible
-        return axiomNode.getFirstElement().getSAXSource(true);
+        return axiomNode.getFirstElement().getSAXSource(false);
     }
 
     public Result getPayloadResult() {

Modified: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapMessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapMessageImpl.java?rev=1505325&r1=1505324&r2=1505325&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapMessageImpl.java (original)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/SoapMessageImpl.java Sun Jul 21 09:33:41 2013
@@ -23,13 +23,17 @@ import java.io.OutputStream;
 import java.util.Iterator;
 
 import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
+import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.soap.SOAP11Version;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.springframework.ws.mime.Attachment;
 import org.springframework.ws.mime.AttachmentException;
 import org.springframework.ws.soap.AbstractSoapMessage;
@@ -39,7 +43,9 @@ import org.springframework.ws.transport.
 import org.springframework.ws.transport.TransportOutputStream;
 import org.w3c.dom.Document;
 
-final class SoapMessageImpl extends AbstractSoapMessage {
+final class SoapMessageImpl extends AbstractSoapMessage implements AxiomWebServiceMessage {
+    private static final Log log = LogFactory.getLog(SoapMessageImpl.class);
+    
     private final SOAPMessage axiomMessage;
     private SoapEnvelopeImpl envelope;
     
@@ -115,4 +121,16 @@ final class SoapMessageImpl extends Abst
             throw new SoapMessageSerializationException("Message serialization failure", ex);
         }
     }
+
+    public QName getPayloadRootQName() {
+        log.debug("Getting the QName of the payload root element");
+        SOAPEnvelope envelope = axiomMessage.getSOAPEnvelope();
+        OMNamespace ns = envelope.getSOAPBodyFirstElementNS();
+        String localName = envelope.getSOAPBodyFirstElementLocalName();
+        QName qname = new QName(ns.getNamespaceURI(), localName, ns.getPrefix());
+        if (log.isDebugEnabled()) {
+            log.debug("Payload root QName is " + qname);
+        }
+        return qname;
+    }
 }

Added: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/mapping/AxiomPayloadRootAnnotationMethodEndpointMapping.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/mapping/AxiomPayloadRootAnnotationMethodEndpointMapping.java?rev=1505325&view=auto
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/mapping/AxiomPayloadRootAnnotationMethodEndpointMapping.java (added)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/mapping/AxiomPayloadRootAnnotationMethodEndpointMapping.java Sun Jul 21 09:33:41 2013
@@ -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.axiom.spring.ws.server.endpoint.mapping;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.spring.ws.AxiomOptimizationEnabler;
+import org.apache.axiom.spring.ws.AxiomWebServiceMessage;
+import org.springframework.ws.WebServiceMessage;
+import org.springframework.ws.context.MessageContext;
+import org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping;
+
+/**
+ * Replacement for {@link PayloadRootAnnotationMethodEndpointMapping} that can leverage Axiom
+ * specific optimizations, namely {@link AxiomWebServiceMessage#getPayloadRootQName()}.
+ * <p>
+ * Typically this class is not configured explicitly. Instead it is automatically configured by
+ * {@link AxiomOptimizationEnabler}.
+ */
+public class AxiomPayloadRootAnnotationMethodEndpointMapping extends PayloadRootAnnotationMethodEndpointMapping {
+    @Override
+    protected QName getLookupKeyForMessage(MessageContext messageContext) throws Exception {
+        WebServiceMessage request = messageContext.getRequest();
+        if (request instanceof AxiomWebServiceMessage) {
+            return ((AxiomWebServiceMessage)request).getPayloadRootQName();
+        } else {
+            return super.getLookupKeyForMessage(messageContext);
+        }
+    }
+}

Propchange: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/server/endpoint/mapping/AxiomPayloadRootAnnotationMethodEndpointMapping.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/axiom-spring-ws/src/test/webapps/jdom/WEB-INF/spring-ws-servlet.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/test/webapps/jdom/WEB-INF/spring-ws-servlet.xml?rev=1505325&r1=1505324&r2=1505325&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/test/webapps/jdom/WEB-INF/spring-ws-servlet.xml (original)
+++ webservices/axiom/trunk/axiom-spring-ws/src/test/webapps/jdom/WEB-INF/spring-ws-servlet.xml Sun Jul 21 09:33:41 2013
@@ -29,6 +29,7 @@
     <context:component-scan base-package="org.apache.axiom.spring.ws.test.jdom"/>
     
     <bean name="messageFactory" class="org.apache.axiom.spring.ws.AxiomSoapMessageFactory"/>
+    <bean class="org.apache.axiom.spring.ws.AxiomOptimizationEnabler"/>
     
     <sws:annotation-driven/>
 </beans>