axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r377664 - /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/RESTSender.java
Date Tue, 14 Feb 2006 07:45:02 GMT
Author: saminda
Date: Mon Feb 13 23:45:01 2006
New Revision: 377664

URL: http://svn.apache.org/viewcvs?rev=377664&view=rev
Log:
Applying Thilini's patch. Improvement of client side REST handling. No test case is available.


Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/RESTSender.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/RESTSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/RESTSender.java?rev=377664&r1=377663&r2=377664&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/RESTSender.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/RESTSender.java
Mon Feb 13 23:45:01 2006
@@ -29,10 +29,11 @@
 public class RESTSender extends AbstractHTTPSender {
     private Log log = LogFactory.getLog(getClass());
 
+    /*Obtain two strings;one to go in the url and rest to pass in the body
+    **when doing POST in application/x-www-form-urlencoded form.
+    */
     public RequestData createRequest(MessageContext msgContext, OMElement dataout) {
 
-        // Obtain two strings;one to go in the url and rest to pass in the body
-        // when doing POST in application/x-www-form-urlencoded form.
         RequestData data = new RequestData();
         Iterator iter1 = dataout.getChildElements();
         ArrayList paraList = new ArrayList();
@@ -40,8 +41,8 @@
 
         // urlParameterList contains the parameters which go in the URL
         String[] urlParameterList = new String[0];
-        if (msgContext.getProperty(Constants.Configuration.URL_PARAMETER_LIST)!=null){
-           urlParameterList = (String[])msgContext.getProperty(Constants.Configuration.URL_PARAMETER_LIST);
+        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);
 
@@ -68,11 +69,9 @@
         }
 
         String urlString = "";
-
         for (int i = 0; i < urlList.size(); i++) {
             String c = (String) urlList.get(i);
-
-            urlString = urlString + "&" + c;
+            urlString = "".equals(urlString) ? c : (urlString + "&" + c);
             data.urlRequest = urlString;
         }
 
@@ -90,8 +89,7 @@
 
         for (int j = 0; j < paraList.size(); j++) {
             String b = (String) paraList.get(j);
-
-            paraString = paraString + "&" + b;
+            paraString = "".equals(paraString) ? b : (paraString + "&" + b);
             data.bodyRequest = paraString;
         }
 
@@ -115,7 +113,7 @@
                     (String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD);
 
             if ((httpMethod != null)
-                    && Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod))
{
+                && Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod))
{
                 this.sendViaGet(msgContext, url);
 
                 return;
@@ -138,14 +136,15 @@
         String charEncoding =
                 (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
 
-        if (charEncoding == null) {    // Default encoding scheme
+        // Default encoding scheme
+        if (charEncoding == null) {
             getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
-                    HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
-                            + MessageContext.DEFAULT_CHAR_SET_ENCODING);
+                                       HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
+                                       + MessageContext.DEFAULT_CHAR_SET_ENCODING);
         } else {
             getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
-                    HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
-                            + charEncoding);
+                                       HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
+                                       + charEncoding);
         }
 
         this.httpClient = new HttpClient();
@@ -177,14 +176,14 @@
 
             if (value != null) {
                 if ((value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0)
-                        || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0))
{
+                    || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0)) {
                     processResponse(getMethod, msgContext);
                 }
             }
         } else {
             throw new AxisFault(Messages.getMessage("transportError",
-                    String.valueOf(getMethod.getStatusCode()),
-                    getMethod.getResponseBodyAsString()));
+                                                    String.valueOf(getMethod.getStatusCode()),
+                                                    getMethod.getResponseBodyAsString()));
         }
     }
 
@@ -227,14 +226,19 @@
         if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_X_WWW_FORM)) {
             reqData = createRequest(msgContext, dataout);
             postMethod.setPath(url.getPath() + ((reqData.urlRequest) != null
-                    ? ("?" + reqData.urlRequest)
-                    : ""));
+                                                ? ("?" + reqData.urlRequest)
+                                                : ""));
+
+            if (reqData.bodyRequest == null) {
+                reqData.bodyRequest = "0";
+            }
             postMethod.setRequestEntity(new AxisRESTRequestEntity(reqData.bodyRequest,
-                    charEncoding, msgContext, httpContentType));
+                                                                  charEncoding, msgContext,
httpContentType));
+
         } else {
             postMethod.setPath(url.getPath());
             postMethod.setRequestEntity(new AxisRequestEntity(dataout, chunked, msgContext,
-                    charEncoding, soapActionString));
+                                                              charEncoding, soapActionString));
         }
 
         if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
@@ -253,14 +257,14 @@
             if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
                 httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
                 postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
-                        HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+                                            HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
             } else {
 
                 // allowing keep-alive for 1.1
                 postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
-                        HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+                                            HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
                 postMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
-                        HTTPConstants.HEADER_EXPECT_100_Continue);
+                                            HTTPConstants.HEADER_EXPECT_100_Continue);
             }
         }
 
@@ -286,7 +290,7 @@
                     String value = contenttypeHheader.getValue();
 
                     if ((value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0)
-                            || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=
0)) {
+                        || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0))
{
                         processResponse(postMethod, msgContext);
 
                         return;
@@ -295,8 +299,8 @@
             }
 
             throw new AxisFault(Messages.getMessage("transportError",
-                    String.valueOf(postMethod.getStatusCode()),
-                    postMethod.getResponseBodyAsString()));
+                                                    String.valueOf(postMethod.getStatusCode()),
+                                                    postMethod.getResponseBodyAsString()));
         } catch (Exception e) {
             log.error("Error in processing POST request", e);
         }
@@ -323,8 +327,7 @@
 
         for (int i = 0; i < count; i++) {
             String c = (String) paraList.get(i);
-
-            paraString = paraString + "&" + c;
+            paraString = "".equals(paraString) ? c : (paraString + "&" + c);
         }
 
         return paraString;
@@ -360,7 +363,6 @@
             return true;
         }
     }
-
 
     private class RequestData {
         private String bodyRequest;



Mime
View raw message