List of usage examples for org.apache.commons.httpclient HttpClient executeMethod
public int executeMethod(HttpMethod paramHttpMethod) throws IOException, HttpException
From source file:com.epam.wilma.gepard.test.messagemarker.MessageMarkingSwitch.java
/** * Set message marking to on/off.//w ww . j av a 2 s . c o m * * @param tc is the caller Test Case * @param host Wilma host:port string * @param state is the expected state of the switch * @return with response code * @throws Exception in case of error */ public String setMessageMarkingModeTo(final WilmaTestLogDecorator tc, final String host, final String state) throws Exception { String url = String.format(URL_TEMPLATE, host, state); tc.logStep("Switching message marking in Wilma to: " + url.split("messagemarking/")[1]); tc.logGetRequestEvent(url); HttpClient httpClient = new HttpClient(); GetMethod httpGet = new GetMethod(url); int statusCode = httpClient.executeMethod(httpGet); String responseCode = "status code: " + statusCode + "\n"; if (statusCode != STATUS_OK) { tc.naTestCase("Message marking switch failed."); } tc.logComment("Message marking is: " + url.split("messagemarking/")[1]); return responseCode; }
From source file:att.jaxrs.server.TagService.java
@GET @Path("/tags") public Response getTags() { GetMethod get = new GetMethod(Constants.SELECT_ALL_TAG_OPERATION); TagCollection tag = null;/*from w w w.ja v a2 s . c om*/ try { HttpClient httpClient = new HttpClient(); try { int result = httpClient.executeMethod(get); System.out.println(Constants.RESPONSE_STATUS_CODE + result); tag = Marshal.unmarshal(TagCollection.class, get.getResponseBodyAsStream()); } finally { get.releaseConnection(); } } catch (Exception e) { System.out.println(e.getMessage()); } return Response.ok(tag).build(); }
From source file:att.jaxrs.server.TagService.java
@GET @Path("/tags/{name}/") public Response getTag(@PathParam("name") Long name) { System.out.println("----invoking getTag, tag id is: " + name); GetMethod get = new GetMethod(Constants.SELECT_WITH_NAME_TAG_RESOURCE + name); TagCollection tag = new TagCollection(); try {//from www . j a v a 2 s . co m HttpClient httpClient = new HttpClient(); try { int result = httpClient.executeMethod(get); System.out.println(Constants.RESPONSE_STATUS_CODE + result); tag = Marshal.unmarshal(TagCollection.class, get.getResponseBodyAsStream()); } finally { get.releaseConnection(); } } catch (Exception e) { } return Response.ok(tag).build(); }
From source file:com.mobilefirst.fiberlink.Authenticator.java
/** * Description: Handle sending of request * @param post: the object to send//from w ww. java 2 s . co m */ private final void sendRequest(PostMethod post) { try { HttpClient client = new HttpClient(); int statusCode = client.executeMethod(post); System.out.println( "------------------------------------Begin Debug: Request Headers----------------------------------------------------------\n"); Header[] requestHeaders = post.getRequestHeaders(); for (int cn = 0; cn < requestHeaders.length; cn++) { System.out.println(requestHeaders[cn].toString()); } System.out.println( "------------------------------------Begin Debug: Response Headers----------------------------------------------------------\n"); Header[] responseHeaders = post.getResponseHeaders(); for (int cn = 0; cn < responseHeaders.length; cn++) { System.out.println(responseHeaders[cn].toString()); } System.out.println( "------------------------------------End Debug----------------------------------------------------------\n"); if (statusCode != HttpStatus.SC_OK) { System.out.println("POST method failed: " + post.getStatusLine()); } else { System.out.println("POST method succeeded: " + post.getStatusLine()); String httpResponse = post.getResponseBodyAsString(); System.out.println(httpResponse); } } catch (Exception e) { e.printStackTrace(); } }
From source file:ca.uvic.chisel.logging.eclipse.internal.network.LogUploadRunnable.java
public void run(IProgressMonitor sendMonitor) throws InterruptedException, InvocationTargetException { File[] filesToUpload = log.getCategory().getFilesToUpload(); sendMonitor.beginTask("Uploading Log " + log.getCategory().getName(), filesToUpload.length); LoggingCategory category = log.getCategory(); IMemento memento = category.getMemento(); for (File file : filesToUpload) { if (sendMonitor.isCanceled()) { throw new InterruptedException(); }//from www . j a v a2 s . c om PostMethod post = new PostMethod(category.getURL().toString()); try { Part[] parts = { new StringPart("KIND", "workbench-log"), new StringPart("CATEGORY", category.getCategoryID()), new StringPart("USER", WorkbenchLoggingPlugin.getDefault().getLocalUser()), new FilePart("WorkbenchLogger", file.getName(), file, "application/zip", null) }; post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); HttpClient client = new HttpClient(); int status = client.executeMethod(post); String resp = getData(post.getResponseBodyAsStream()); if (status != 200 || !resp.startsWith("Status: 200 Success")) { IOException ex = new IOException(resp); throw (ex); } memento.putString("lastUpload", file.getName()); file.delete(); } catch (IOException e) { throw new InvocationTargetException(e); } finally { sendMonitor.worked(1); } } sendMonitor.done(); }
From source file:com.epam.wilma.gepard.test.interceptor.InterceptorModeSwitch.java
/** * Set interceptor handling mode on/off, based on parameter. * * @param tc is the caller Test Case/*from w ww.jav a 2 s .co m*/ * @param url to Wilma instance * @return with the response code * @throws Exception in case of problem */ public String switchInterceptorMode(final GepardTestClass tc, final String url) throws Exception { String responseCode; HttpClient httpClient = new HttpClient(); GetMethod httpGet = new GetMethod(url); int statusCode; statusCode = httpClient.executeMethod(httpGet); String onOrOff = url.substring(url.lastIndexOf('/') + 1); if (tc != null) { tc.logStep("Switching interceptor usage mode in Wilma to " + onOrOff); } responseCode = "status code: " + statusCode + "\n"; return responseCode; }
From source file:com.turborep.turbotracker.home.WeatherSer.java
/** * This method is used to connect the weather webservice of world weather online. * @return weather webservice response as {@link String} * @throws WeatherException/*from w ww.ja v a2s. co m*/ */ private String connectWebservice() throws WeatherException { String aUrlStr = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=" + getZipCode() + "&format=json&num_of_days=" + getForecastDays() + "&key=" + getApiKey(); try { /** ========================= Proxy settings ================================ **/ /**System.getProperties().put("http.proxyHost", "http://192.168.43.1"); System.getProperties().put("http.proxyPort", "3128"); System.getProperties().put("http.proxyUser", "vish_pepala"); System.getProperties().put("http.proxyPassword", "S@Naidu"); System.getProperties().put("http.proxySet", "true"); /******************************************************************/ PostMethod post = new PostMethod(aUrlStr); post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1"); HttpClient httpclient = new HttpClient(); httpclient.executeMethod(post); String aResponse = post.getResponseBodyAsString(); //logger.info(aResponse); return aResponse; } catch (MalformedURLException e) { logger.error(e.getMessage(), e); WeatherException aWeatherException = new WeatherException(e.getMessage(), e); throw aWeatherException; } catch (HttpException e) { logger.error(e.getMessage(), e); WeatherException aWeatherException = new WeatherException(e.getMessage(), e); throw aWeatherException; } catch (IOException e) { logger.error(e.getMessage(), e); WeatherException aWeatherException = new WeatherException(e.getMessage(), e); throw aWeatherException; } }
From source file:com.agile_coder.poker.server.stories.steps.ResetEstimatesSteps.java
@When("I reset the estimates") public void reset() throws IOException { HttpClient client = new HttpClient(); DeleteMethod delete = new DeleteMethod(BASE_URL + "/" + sessionId + "/status"); client.executeMethod(delete); assertEquals(HttpStatus.SC_NO_CONTENT, delete.getStatusCode()); }
From source file:net.morphbank.mbsvc3.test.SendImageTest.java
public void sendImage(String strURL, String id, String originalFileName, String imageFileName) throws Exception { File input = new File(imageFileName); // Prepare HTTP post PostMethod post = new PostMethod(strURL); Part[] parts = { new StringPart("id", id), new StringPart("fileName", originalFileName), new FilePart("image", originalFileName, input) }; RequestEntity entity = new MultipartRequestEntity(parts, post.getParams()); post.setRequestEntity(entity);// w w w.jav a 2s . com // Get HTTP client HttpClient httpclient = new HttpClient(); // Execute request try { System.out.println("Trying post"); int result = httpclient.executeMethod(post); // Display status code System.out.println("Response status code: " + result); // Display response System.out.println("Response body: "); InputStream response = post.getResponseBodyAsStream(); // int j = response.read(); System.out.write(j); for (int i = response.read(); i != -1; i = response.read()) { System.out.write(i); } // System.out.flush(); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } }
From source file:exception.handler.authentication.HandledAuthenticationExceptionTest.java
@Test public void authenticationException() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); client.executeMethod(method); String message = method.getResponseBodyAsString(); assertTrue(message.contains("Called the page /login")); }