List of usage examples for java.net HttpURLConnection HTTP_RESET
int HTTP_RESET
To view the source code for java.net HttpURLConnection HTTP_RESET.
Click Source Link
From source file:com.adaptris.http.HttpClientTransport.java
/** * Is the HTTP response code considered to be a success. * <p>/* w ww .j a v a 2s.co m*/ * There are 7 possible HTTP codes that signify success or partial success :- * <code>200,201,202,203,204,205,206</code> * </p> * * @return true if the transaction was successful. */ private boolean wasSuccessful(HttpSession session) { boolean rc = false; switch (session.getResponseLine().getResponseCode()) { case HttpURLConnection.HTTP_ACCEPTED: case HttpURLConnection.HTTP_CREATED: case HttpURLConnection.HTTP_NO_CONTENT: case HttpURLConnection.HTTP_NOT_AUTHORITATIVE: case HttpURLConnection.HTTP_OK: case HttpURLConnection.HTTP_PARTIAL: case HttpURLConnection.HTTP_RESET: { rc = true; break; } default: { rc = false; break; } } return rc; }
From source file:jetbrains.buildServer.vmgr.agent.Utils.java
public String executeVSIFLaunch(String[] vsifs, String url, boolean requireAuth, String user, String password, BuildProgressLogger logger, boolean dynamicUserId, String buildID, String workPlacePath) throws Exception { boolean notInTestMode = true; if (logger == null) { notInTestMode = false;/*from w w w . j a v a 2 s .co m*/ } String apiURL = url + "/rest/sessions/launch"; for (int i = 0; i < vsifs.length; i++) { if (notInTestMode) { logger.message("vManager vAPI - Trying to launch vsif file: '" + vsifs[i] + "'"); } String input = "{\"vsif\":\"" + vsifs[i] + "\"}"; HttpURLConnection conn = getVAPIConnection(apiURL, requireAuth, user, password, "POST", dynamicUserId, buildID, workPlacePath, logger); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK && conn.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT && conn.getResponseCode() != HttpURLConnection.HTTP_ACCEPTED && conn.getResponseCode() != HttpURLConnection.HTTP_CREATED && conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL && conn.getResponseCode() != HttpURLConnection.HTTP_RESET) { String reason = ""; if (conn.getResponseCode() == 503) reason = "vAPI process failed to connect to remote vManager server."; if (conn.getResponseCode() == 401) reason = "Authentication Error"; if (conn.getResponseCode() == 412) reason = "vAPI requires vManager 'Integration Server' license."; if (conn.getResponseCode() == 406) reason = "VSIF file '" + vsifs[i] + "' was not found on file system, or is not accessed by the vAPI process."; String errorMessage = "Failed : HTTP error code : " + conn.getResponseCode() + " (" + reason + ")"; if (notInTestMode) { logger.message(errorMessage); logger.message(conn.getResponseMessage()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder result = new StringBuilder(); String output; while ((output = br.readLine()) != null) { result.append(output); } logger.message(result.toString()); } System.out.println(errorMessage); return errorMessage; } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder result = new StringBuilder(); String output; while ((output = br.readLine()) != null) { result.append(output); } conn.disconnect(); JSONObject tmp = JSONObject.fromObject(result.toString()); String textOut = "Session Launch Success: Session ID: " + tmp.getString("value"); if (notInTestMode) { logger.message(textOut); } else { System.out.println(textOut); } } return "success"; }
From source file:jetbrains.buildServer.vmgr.agent.Utils.java
public String executeAPI(String jSON, String apiUrl, String url, boolean requireAuth, String user, String password, String requestMethod, BuildProgressLogger logger, boolean dynamicUserId, String buildID, String workPlacePath) throws Exception { try {/* w w w . j a va 2s.c o m*/ boolean notInTestMode = true; if (logger == null) { notInTestMode = false; } String apiURL = url + "/rest" + apiUrl; if (notInTestMode) { logger.message("vManager vAPI - Trying to call vAPI '" + "/rest" + apiUrl + "'"); } String input = jSON; HttpURLConnection conn = getVAPIConnection(apiURL, requireAuth, user, password, requestMethod, dynamicUserId, buildID, workPlacePath, logger); if ("PUT".equals(requestMethod) || "POST".equals(requestMethod)) { OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); } if (conn.getResponseCode() != HttpURLConnection.HTTP_OK && conn.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT && conn.getResponseCode() != HttpURLConnection.HTTP_ACCEPTED && conn.getResponseCode() != HttpURLConnection.HTTP_CREATED && conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL && conn.getResponseCode() != HttpURLConnection.HTTP_RESET) { String reason = ""; if (conn.getResponseCode() == 503) reason = "vAPI process failed to connect to remote vManager server."; if (conn.getResponseCode() == 401) reason = "Authentication Error"; if (conn.getResponseCode() == 415) reason = "The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. Check if you selected the right request method (GET/POST/DELETE/PUT)."; if (conn.getResponseCode() == 405) reason = "The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource. Check if you selected the right request method (GET/POST/DELETE/PUT)."; if (conn.getResponseCode() == 412) reason = "vAPI requires vManager 'Integration Server' license."; String errorMessage = "Failed : HTTP error code : " + conn.getResponseCode() + " (" + reason + ")"; if (notInTestMode) { logger.message(errorMessage); logger.message(conn.getResponseMessage()); } System.out.println(errorMessage); return errorMessage; } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder result = new StringBuilder(); String output; while ((output = br.readLine()) != null) { result.append(output); } conn.disconnect(); // Flush the output into workspace String fileOutput = workPlacePath + File.separator + buildID + File.separator + "vapi.output"; FileWriter writer = new FileWriter(fileOutput); writer.append(result.toString()); writer.flush(); writer.close(); String textOut = "API Call Success: Output was saved into: " + fileOutput; if (notInTestMode) { logger.message(textOut); } else { System.out.println(textOut); } return "success"; } catch (Exception e) { e.printStackTrace(); logger.error("Failed: Error: " + e.getMessage()); return e.getMessage(); } }