axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r482515 - in /webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2: Constants.java transport/http/RESTSender.java
Date Tue, 05 Dec 2006 06:21:41 GMT
Author: chinthaka
Date: Mon Dec  4 22:21:40 2006
New Revision: 482515

URL: http://svn.apache.org/viewvc?view=rev&rev=482515
Log:
Adding the capability to add http location parameters so that some params will as part of
the URL itself and the others in the query 
parameter list.
Need to get this working in server side as well.


Modified:
    webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/Constants.java
    webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/Constants.java?view=diff&rev=482515&r1=482514&r2=482515
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/Constants.java
(original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/Constants.java
Mon Dec  4 22:21:40 2006
@@ -243,6 +243,7 @@
         public static final String TRANSPORT_IN_URL = "TransportInURL";
 
         public static final String URL_PARAMETER_LIST = "URLParameterList";
+        public static final String URL_HTTP_LOCATION_PARAMS_LIST = "HTTPLocationParamsList";
 
         public static final String SEND_STACKTRACE_DETAILS_WITH_FAULTS = "sendStacktraceDetailsWithFaults";
 

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java?view=diff&rev=482515&r1=482514&r2=482515
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
(original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
Mon Dec  4 22:21:40 2006
@@ -37,6 +37,7 @@
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.namespace.QName;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.ByteArrayOutputStream;
@@ -63,25 +64,25 @@
         if (msgContext.getProperty(Constants.Configuration.URL_PARAMETER_LIST) != null) {
             urlParameterList = (String[]) msgContext.getProperty(Constants.Configuration.URL_PARAMETER_LIST);
         }
+
         OMElement bodypara = OMAbstractFactory.getOMFactory().createOMElement("temp", null);
 
         while (iter1.hasNext()) {
             OMElement ele = (OMElement) iter1.next();
-            boolean has = false;
+            boolean parameterFound = false;
 
             for (int i = 0; i < urlParameterList.length; i++) {
                 if (urlParameterList[i].equals(ele.getLocalName())) {
-                    has = true;
-
+                    parameterFound = true;
                     break;
                 }
             }
 
-            String parameter1;
+            String parameter;
 
-            if (has) {
-                parameter1 = ele.getLocalName() + "=" + ele.getText();
-                urlList.add(parameter1);
+            if (parameterFound) {
+                parameter = ele.getLocalName() + "=" + ele.getText();
+                urlList.add(parameter);
             } else {
                 bodypara.addChild(ele);
             }
@@ -89,10 +90,10 @@
 
         String urlString = "";
         for (int i = 0; i < urlList.size(); i++) {
-            String c = (String) urlList.get(i);
-            urlString = "".equals(urlString) ? c : (urlString + "&" + c);
-            data.urlRequest = urlString;
+            String nameValuePair = (String) urlList.get(i);
+            urlString = "".equals(urlString) ? nameValuePair : (urlString + "&" + nameValuePair);
         }
+        data.urlRequest = urlString;
 
         Iterator it = bodypara.getChildElements();
 
@@ -144,18 +145,54 @@
         }
     }
 
+    /**
+     * This will be used to support http location. User can set set of param lists and those
will be
+     * appended to the url.
+     *
+     * @param messageContext
+     * @param urlString
+     * @return - the URL after appending the properties
+     */
+    private String appendParametersToURL(MessageContext messageContext, String urlString)
throws MalformedURLException {
+        OMElement firstElement = messageContext.getEnvelope().getBody().getFirstElement();
+
+        ArrayList httpLocationParams = (ArrayList) messageContext.getProperty(
+                Constants.Configuration.URL_HTTP_LOCATION_PARAMS_LIST);
+
+        URL url = new URL(urlString);
+        String path = url.getPath();
+
+        for (int i = 0; i < httpLocationParams.size(); i++) {
+            String httpLocationParam = (String) httpLocationParams.get(i);
+            OMElement httpURLParam = firstElement.getFirstChildWithName(new QName(httpLocationParam));
+            if (httpURLParam != null) {
+                path += httpURLParam.getText();
+            }
+        }
+
+        String query = url.getQuery();
+        if (query != null && !"".equals(query)) {
+            return path + "?" + query;
+        } else {
+            return path;
+        }
+    }
+
     private void sendViaGet(MessageContext msgContext, URL url)
             throws MalformedURLException, AxisFault, IOException {
-        String param = getParam(msgContext);
+        String param = getQueryParameters(msgContext);
         GetMethod getMethod = new GetMethod();
         if (isAuthenticationEnabled(msgContext)) {
             getMethod.setDoAuthentication(true);
         }
 
+        String urlString = url.getFile();
+        urlString = appendParametersToURL(msgContext, urlString);
+
         if (param != null && param.length() > 0) {
-            getMethod.setPath(url.getFile() + "?" + param);
+            getMethod.setPath(urlString + "?" + param);
         } else {
-            getMethod.setPath(url.getFile());
+            getMethod.setPath(urlString);
         }
 
         // Serialization as "application/x-www-form-urlencoded"
@@ -205,7 +242,7 @@
         HttpClient httpClient = getHttpClient(msgContext);
 
         PostMethod postMethod = new PostMethod(url.toString());
-        if(isAuthenticationEnabled(msgContext)) {
+        if (isAuthenticationEnabled(msgContext)) {
             postMethod.setDoAuthentication(true);
         }
         String httpContentType;
@@ -228,14 +265,18 @@
 
         if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_X_WWW_FORM)) {
             reqData = createRequest(msgContext, dataout);
-            postMethod.setPath(url.getPath() + ((reqData.urlRequest) != null
+            String pathString = url.getPath();
+
+            appendParametersToURL(msgContext, pathString);
+
+            postMethod.setPath(pathString + ((reqData.urlRequest) != null
                     ? ("?" + reqData.urlRequest)
                     : ""));
 
             if (reqData.bodyRequest == null) {
                 reqData.bodyRequest = "0";
             }
-            postMethod.setRequestEntity(new AxisRESTRequestEntity(reqData.bodyRequest,httpContentType));
+            postMethod.setRequestEntity(new AxisRESTRequestEntity(reqData.bodyRequest, httpContentType));
 
         } else {
             postMethod.setPath(url.getPath());
@@ -300,7 +341,7 @@
         }
     }
 
-    public String getParam(MessageContext msgContext) {
+    public String getQueryParameters(MessageContext msgContext) {
         OMElement dataOut;
 
         dataOut = msgContext.getEnvelope().getBody().getFirstElement();
@@ -431,7 +472,8 @@
 
             // action header is not mandated in SOAP 1.2. So putting it, if available
             if (!msgCtxt.isSOAP11() && (soapActionString != null)
-                && !"".equals(soapActionString.trim()) && ! "\"\"".equals(soapActionString.trim()))
{
+                    && !"".equals(soapActionString.trim()) && ! "\"\"".equals(soapActionString.trim()))
+            {
                 contentType =
                         contentType + ";action=\"" + soapActionString + "\";";
             }
@@ -448,7 +490,7 @@
         private String contentType;
         private String postRequestBody;
 
-        public AxisRESTRequestEntity(String postRequestBody,String contentType) {
+        public AxisRESTRequestEntity(String postRequestBody, String contentType) {
             this.postRequestBody = postRequestBody;
             this.contentType = contentType;
         }



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


Mime
View raw message