]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-338 proper handling of POST,PUT,GET,DELETE errors when connecting. Moved...
authorLaramie Crocker <laramie@berkeley.edu>
Fri, 3 Dec 2010 19:43:05 +0000 (19:43 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Fri, 3 Dec 2010 19:43:05 +0000 (19:43 +0000)
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java
services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml

index 4bd05f791c73033ebb2a53fe8e5b5eabec57aab2..a0bdc5e98354e99bd6ce49cf000e938bc739897d 100755 (executable)
@@ -33,6 +33,7 @@ public class XmlReplay {
 \r
     public static final String DEFAULT_CONTROL = "xml-replay-control.xml";\r
     public static final String DEFAULT_MASTER_CONTROL = "xml-replay-master.xml";\r
+    public static final String DEFAULT_DEV_MASTER_CONTROL = "dev-master.xml";\r
 \r
     private String basedir = ".";  //set from constructor.\r
     public String getBaseDir(){\r
@@ -89,7 +90,7 @@ public class XmlReplay {
 \r
 \r
     public String toString(){\r
-        return "XmlReplay{"+this.basedir+", "+this.controlFileName+", "+this.defaultAuthsMap+", "+this.dump+'}';\r
+        return "XmlReplay{"+this.basedir+", "+this.defaultAuthsMap+", "+this.dump+'}';\r
     }\r
 \r
     // ============== METHODS ===========================================================\r
index 78a411e417ba42dffe1e2013fc5427e3f3c6939a..c1955575182f027e336e791c4f21a204b9912467 100755 (executable)
@@ -59,11 +59,11 @@ public class XmlReplayTransport {
         getMethod.setRequestHeader("X-XmlReplay-fromTestID", fromTestID);\r
         ServiceResult pr = new ServiceResult();\r
 \r
-        int statusCode1 = client.executeMethod(getMethod);\r
-        pr.responseCode = statusCode1;\r
         pr.fromTestID = fromTestID;\r
         pr.method = "GET";\r
         try {\r
+            int statusCode1 = client.executeMethod(getMethod);\r
+            pr.responseCode = statusCode1;\r
             pr.result = getMethod.getResponseBodyAsString();\r
             pr.responseMessage = getMethod.getStatusText();\r
             Header[] headers = getMethod.getResponseHeaders();\r
@@ -74,13 +74,13 @@ public class XmlReplayTransport {
                 pr.boundary = PayloadLogger.parseBoundary(hdrStr);\r
             }\r
             pr.contentLength = getMethod.getResponseContentLength();\r
+            getMethod.releaseConnection();\r
         } catch (Throwable t){\r
             //System.err.println("ERROR getting content from response: "+t);\r
             pr.error = t.toString();\r
         }\r
 \r
 \r
-        getMethod.releaseConnection();\r
         return pr;\r
     }\r
 \r
@@ -183,69 +183,75 @@ public class XmlReplayTransport {
 \r
     public static ServiceResult doPOST_PUT(String urlString, String content, String boundary, String method, String contentType,\r
                                            String authForTest, String fromTestID) throws Exception {\r
-        URL url = new URL(urlString);\r
-        HttpURLConnection conn;\r
-        conn = (HttpURLConnection) url.openConnection();\r
-\r
-        if (MULTIPART_MIXED.equalsIgnoreCase(contentType)){\r
-            conn.setRequestProperty("Accept", "multipart/mixed");\r
-            conn.setRequestProperty("content-type", "multipart/mixed; boundary=" + boundary);\r
-        } else {\r
-            conn.setRequestProperty("Accept", "application/xml");\r
-            conn.setRequestProperty("content-type", contentType);\r
-        }\r
-        conn.setRequestProperty("Authorization", "Basic " + authForTest);  //TODO: remove test user : hard-coded as "dGVzdDp0ZXN0"\r
-        conn.setRequestProperty("Connection", "close");\r
-        conn.setRequestProperty("X-XmlReplay-fromTestID", fromTestID);\r
-        conn.setDoOutput(true);\r
-        conn.setDoInput(true);\r
-        conn.setRequestMethod(method); // "POST" or "PUT"\r
-        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());\r
-        wr.write(content);\r
-        wr.flush();\r
-\r
         ServiceResult result = new ServiceResult();\r
+        result.method = method;\r
         try {\r
-            result.requestPayload = content;\r
-            result.responseCode = conn.getResponseCode();\r
-            //System.out.println("responseCode: "+result.responseCode);\r
-            if (400 <= result.responseCode && result.responseCode <= 499){\r
-                return result;\r
+            URL url = new URL(urlString);\r
+            HttpURLConnection conn;\r
+            conn = (HttpURLConnection) url.openConnection();\r
+\r
+            if (MULTIPART_MIXED.equalsIgnoreCase(contentType)){\r
+                conn.setRequestProperty("Accept", "multipart/mixed");\r
+                conn.setRequestProperty("content-type", "multipart/mixed; boundary=" + boundary);\r
+            } else {\r
+                conn.setRequestProperty("Accept", "application/xml");\r
+                conn.setRequestProperty("content-type", contentType);\r
             }\r
-            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));\r
-            String line;\r
-            StringBuffer sb = new StringBuffer();\r
-            while ((line = rd.readLine()) != null) {\r
-                sb.append(line).append("\r\n");\r
+            conn.setRequestProperty("Authorization", "Basic " + authForTest);  //TODO: remove test user : hard-coded as "dGVzdDp0ZXN0"\r
+            conn.setRequestProperty("Connection", "close");\r
+            conn.setRequestProperty("X-XmlReplay-fromTestID", fromTestID);\r
+            conn.setDoOutput(true);\r
+            conn.setDoInput(true);\r
+            conn.setRequestMethod(method); // "POST" or "PUT"\r
+            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());\r
+            wr.write(content);\r
+            wr.flush();\r
+\r
+\r
+            try {\r
+                result.requestPayload = content;\r
+                result.responseCode = conn.getResponseCode();\r
+                //System.out.println("responseCode: "+result.responseCode);\r
+                if (400 <= result.responseCode && result.responseCode <= 499){\r
+                    return result;\r
+                }\r
+                BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));\r
+                String line;\r
+                StringBuffer sb = new StringBuffer();\r
+                while ((line = rd.readLine()) != null) {\r
+                    sb.append(line).append("\r\n");\r
+                }\r
+                String msg = sb.toString();\r
+                result.result = msg;\r
+                result.boundary = PayloadLogger.parseBoundary(conn.getHeaderField("CONTENT-TYPE"));\r
+\r
+                rd.close();\r
+            } catch (Throwable t){\r
+                //System.err.println("ERROR getting content from response: "+t);\r
+                result.error = t.toString();\r
             }\r
-            String msg = sb.toString();\r
-            result.result = msg;\r
-            result.boundary = PayloadLogger.parseBoundary(conn.getHeaderField("CONTENT-TYPE"));\r
+            wr.close();\r
 \r
-            rd.close();\r
-        } catch (Throwable t){\r
-            //System.err.println("ERROR getting content from response: "+t);\r
-            result.error = t.toString();\r
-        }\r
-        wr.close();\r
-\r
-\r
-        String deleteURL = "";\r
-        String location = "";\r
-        Map<String, List<String>> headers = conn.getHeaderFields();\r
-        List<String> locations = headers.get("Location");\r
-        if (locations != null){\r
-            String locationZero = locations.get(0);\r
-            if (locationZero != null){\r
-                String[] segments = locationZero.split("/");\r
-                location = segments[segments.length - 1];\r
-                deleteURL = Tools.glue(urlString, "/", location);\r
+\r
+            String deleteURL = "";\r
+            String location = "";\r
+            Map<String, List<String>> headers = conn.getHeaderFields();\r
+            List<String> locations = headers.get("Location");\r
+            if (locations != null){\r
+                String locationZero = locations.get(0);\r
+                if (locationZero != null){\r
+                    String[] segments = locationZero.split("/");\r
+                    location = segments[segments.length - 1];\r
+                    deleteURL = Tools.glue(urlString, "/", location);\r
+                }\r
             }\r
+            result.location = location;\r
+            result.deleteURL = deleteURL;\r
+            result.CSID = location;\r
+\r
+        } catch (Throwable t2){\r
+            result.error = "ERROR in XmlReplayTransport: "+t2;\r
         }\r
-        result.location = location;\r
-        result.deleteURL = deleteURL;\r
-        result.CSID = location;\r
-        result.method = method;\r
         return result;\r
     }\r
 \r
index 82c0a15c15e3de69f5d67d71d75c53995604366e..0625693163492507a172f42668d8a9dd9f9c15b8 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <xmlReplayMaster>\r
 <!-- Use this file to drive local testing.  Check it in or don't ... no automated tests should reference this file. -->\r
-    <protoHostPort>http://localhost:8280</protoHostPort>\r
+    <protoHostPort>http://localhost:8180</protoHostPort>\r
     \r
     <!-- legal values for dumpServiceResult=[minimal,detailed,full] -->\r
     <dump payloads="false" dumpServiceResult="minimal" />\r