You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ke...@apache.org on 2007/11/21 07:11:27 UTC

svn commit: r596948 - in /webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2: builder/BuilderUtil.java transport/http/util/RESTUtil.java

Author: keithc
Date: Tue Nov 20 22:11:26 2007
New Revision: 596948

URL: http://svn.apache.org/viewvc?rev=596948&view=rev
Log:
Adding HTTPContentNegotiation via Accept headers


Modified:
    webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
    webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java

Modified: webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java?rev=596948&r1=596947&r2=596948&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java (original)
+++ webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java Tue Nov 20 22:11:26 2007
@@ -41,6 +41,7 @@
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisMessage;
 import org.apache.axis2.description.AxisOperation;
@@ -639,12 +640,32 @@
     public static Builder getBuilderFromSelector(String type, MessageContext msgContext)
             throws AxisFault {
 
-        Builder builder = msgContext.getConfigurationContext().getAxisConfiguration()
+        AxisConfiguration configuration =
+                msgContext.getConfigurationContext().getAxisConfiguration();
+        Builder builder = configuration
                 .getMessageBuilder(type);
         if (builder != null) {
+            // Check whether the request has a Accept header if so use that as the response
+            // message type.
+            // If thats not present,
             // Setting the received content-type as the messageType to make
             // sure that we respond using the received message serialisation
             // format.
+
+            Map transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
+            if (transportHeaders != null) {
+                String acceptHeader = (String) transportHeaders.get(HTTPConstants.HEADER_ACCEPT);
+                if (acceptHeader != null) {
+                    String[] strings = acceptHeader.split(",");
+                    for (int i = 0; i < strings.length; i++) {
+                        if (configuration.getMessageFormatter(strings[i].trim()) != null) {
+                            type = strings[i];
+                            break;
+                        }
+                    }
+                }
+            }
+
             msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE, type);
         }
         return builder;

Modified: webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java?rev=596948&r1=596947&r2=596948&view=diff
==============================================================================
--- webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java (original)
+++ webservices/axis2/branches/java/1_3_post_mods/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java Tue Nov 20 22:11:26 2007
@@ -72,8 +72,13 @@
         } catch (IOException e) {
             throw AxisFault.makeFault(e);
         } finally {
-            msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
-                                   HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
+            String messageType =
+                    (String) msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE);
+            if (HTTPConstants.MEDIA_TYPE_X_WWW_FORM.equals(messageType) ||
+                    HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA.equals(messageType)) {
+                msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
+                                       HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
+            }
         }
         return invokeAxisEngine(msgContext);
     }
@@ -113,8 +118,13 @@
         catch (IOException e) {
             throw AxisFault.makeFault(e);
         } finally {
-            msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
-                                   HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
+            String messageType =
+                    (String) msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE);
+            if (HTTPConstants.MEDIA_TYPE_X_WWW_FORM.equals(messageType) ||
+                    HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA.equals(messageType)) {
+                msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
+                                       HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
+            }
         }
         return invokeAxisEngine(msgContext);
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org