List of usage examples for org.apache.commons.httpclient.methods PostMethod getParameter
public NameValuePair getParameter(String paramString)
From source file:de.linsin.alterego.notification.AppNotificationServiceTest.java
@Test public void test_setup_postmethod() { String msg = "mymssage"; String title = "mytitle"; PostMethod method = classUnderTest.setUp(title, msg); assertEquals(MYCREDS, method.getParameter(USER_CREDENTIALS).getValue()); assertEquals(msg, method.getParameter(NOTIFICATION_LONG_MESSAGE).getValue()); assertEquals(title, method.getParameter(NOTIFICATION_TITLE).getValue()); assertEquals("2", method.getParameter(MESSAGE_LEVEL).getValue()); }
From source file:com.thoughtworks.go.agent.service.RemoteRegistrationRequesterTest.java
private TypeSafeMatcher<HttpMethod> hasAllParams(final String uuid) { return new TypeSafeMatcher<HttpMethod>() { @Override/*from w ww . j av a 2 s. c om*/ public boolean matchesSafely(HttpMethod item) { PostMethod postMethod = (PostMethod) item; assertThat(postMethod.getParameter("hostname").getValue(), is("cruise.com")); assertThat(postMethod.getParameter("uuid").getValue(), is(uuid)); String workingDir = SystemUtil.currentWorkingDirectory(); assertThat(postMethod.getParameter("location").getValue(), is(workingDir)); assertThat(postMethod.getParameter("operating_system").getValue(), is("minix")); assertThat(postMethod.getParameter("agentAutoRegisterKey").getValue(), is("t0ps3cret")); assertThat(postMethod.getParameter("agentAutoRegisterResources").getValue(), is("linux, java")); assertThat(postMethod.getParameter("agentAutoRegisterEnvironments").getValue(), is("uat, staging")); assertThat(postMethod.getParameter("agentAutoRegisterHostname").getValue(), is("agent01.example.com")); return true; } public void describeTo(Description description) { description.appendText("params containing"); } }; }
From source file:com.cloud.cluster.ClusterServiceServletImpl.java
private String executePostMethod(HttpClient client, PostMethod method) { int response = 0; String result = null;//from www. jav a 2s. com try { long startTick = System.currentTimeMillis(); response = client.executeMethod(method); if (response == HttpStatus.SC_OK) { result = method.getResponseBodyAsString(); if (s_logger.isDebugEnabled()) { s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + (System.currentTimeMillis() - startTick) + " ms"); } } else { s_logger.error("Invalid response code : " + response + ", from : " + _serviceUrl + ", method : " + method.getParameter("method") + " responding time: " + (System.currentTimeMillis() - startTick)); } } catch (HttpException e) { s_logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method")); } catch (IOException e) { s_logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method")); } catch (Throwable e) { s_logger.error("Exception from : " + _serviceUrl + ", method : " + method.getParameter("method") + ", exception :", e); } finally { method.releaseConnection(); } return result; }
From source file:org.pentaho.di.trans.dataservice.jdbc.RemoteClientTest.java
@Test public void testQuery() throws Exception { String sql = "SELECT * FROM myService\nWHERE id = 3"; String debugTrans = "/tmp/genTrans.ktr"; int maxRows = 200; when(connection.getDebugTransFilename()).thenReturn(debugTrans); when(connection.getParameters()).thenReturn(ImmutableMap.of("PARAMETER_ECHO", "hello world")); when(httpClient.executeMethod(isA(PostMethod.class))).thenReturn(200); MockDataInput mockDataInput = new MockDataInput(); mockDataInput.writeUTF("Query Response"); when(execMethod.getResponseBodyAsStream()).thenReturn(mockDataInput.toDataInputStream()); DataInputStream queryResponse = remoteClient.query(sql, maxRows); verify(httpClient).executeMethod(httpMethodCaptor.capture()); PostMethod httpMethod = (PostMethod) httpMethodCaptor.getValue(); assertThat(httpMethod.getURI().toString(), equalTo("http://localhost:9080/pentaho-di/kettle/sql/")); assertThat(httpMethod.getRequestHeader("SQL").getValue(), equalTo("SELECT * FROM myService WHERE id = 3")); assertThat(httpMethod.getRequestHeader("MaxRows").getValue(), equalTo("200")); assertThat(httpMethod.getParameter("SQL").getValue(), equalTo("SELECT * FROM myService WHERE id = 3")); assertThat(httpMethod.getParameter("MaxRows").getValue(), equalTo("200")); assertThat(httpMethod.getParameter("debugtrans").getValue(), equalTo(debugTrans)); assertThat(httpMethod.getParameter("PARAMETER_ECHO").getValue(), equalTo("hello world")); assertThat(queryResponse.readUTF(), equalTo("Query Response")); }
From source file:org.pentaho.di.trans.dataservice.jdbc.RemoteClientTest.java
@Test public void testLargeQuery() throws Exception { String sql = "SELECT * FROM myService\nWHERE id = 3 /" + StringUtils.repeat("*", 8000) + "/"; when(connection.getDebugTransFilename()).thenReturn(null); when(connection.getParameters()).thenReturn(ImmutableMap.<String, String>of()); when(httpClient.executeMethod(isA(PostMethod.class))).thenReturn(200); MockDataInput mockDataInput = new MockDataInput(); mockDataInput.writeUTF("Query Response"); when(execMethod.getResponseBodyAsStream()).thenReturn(mockDataInput.toDataInputStream()); DataInputStream queryResponse = remoteClient.query(sql, 200); verify(httpClient).executeMethod(httpMethodCaptor.capture()); PostMethod httpMethod = (PostMethod) httpMethodCaptor.getValue(); assertThat(httpMethod.getURI().toString(), equalTo("http://localhost:9080/pentaho-di/kettle/sql/")); assertThat(httpMethod.getRequestHeader("SQL"), is(nullValue())); assertThat(httpMethod.getRequestHeader("MaxRows"), is(nullValue())); assertThat(httpMethod.getParameter("SQL").getValue(), equalTo("SELECT * FROM myService WHERE id = 3 /" + StringUtils.repeat("*", 8000) + "/")); assertThat(httpMethod.getParameter("MaxRows").getValue(), equalTo("200")); assertThat(queryResponse.readUTF(), equalTo("Query Response")); }
From source file:org.svenk.redmine.core.client.AbstractRedmineClient.java
public void uploadAttachment(int ticketId, String fileName, String comment, String description, AbstractTaskAttachmentSource source, IProgressMonitor monitor) throws RedmineException { PostMethod method = new PostMethod(REDMINE_URL_TICKET_EDIT + ticketId); //assigned by RedmineAuthenticityTokenAspect NameValuePair tokenValue = method.getParameter(CLIENT_FIELD_CSRF_TOKEN); List<Part> parts = new ArrayList<Part>(4); parts.add(new StringPart(CLIENT_FIELD_ATTACHMENT_DESCRIPTION, description, characterEncoding)); parts.add(new StringPart(CLIENT_FIELD_ATTACHMENT_NOTES, comment, characterEncoding)); if (tokenValue != null) { parts.add(new StringPart(CLIENT_FIELD_CSRF_TOKEN, tokenValue == null ? "" : tokenValue.getValue(), //$NON-NLS-1$ characterEncoding));/*from w w w . jav a 2 s. co m*/ } //Workaround: http://rack.lighthouseapp.com/projects/22435/tickets/79-multipart-handling-incorrectly-assuming-file-upload for (Part part : parts) { ((StringPart) part).setContentType(null); } parts.add(new FilePart(CLIENT_FIELD_ATTACHMENT_FILE, new TaskAttachmentPartSource(source, fileName), source.getContentType(), this.httpClient.getParams().getContentCharset())); method.setRequestEntity( new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), method.getParams())); String errorMsg = executeMethod(method, submitErrorParser, monitor, HttpStatus.SC_OK, HttpStatus.SC_MOVED_TEMPORARILY); if (errorMsg != null) { throw new RedmineStatusException(IStatus.INFO, errorMsg); } }