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
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
\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