use of org.apache.commons.httpclient.methods.PutMethod in project fuse-karaf by jboss-fuse.
the class CrmTest method putCustomerTest.
/**
* HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
* the update_customer.xml file to update the customer information for customer 123.
* <p/>
* On the server side, it matches the CustomerService's updateCustomer() method
*
* @throws Exception
*/
@Test
public void putCustomerTest() throws IOException {
LOG.info("Sent HTTP PUT request to update customer info");
String inputFile = this.getClass().getResource("/update_customer.xml").getFile();
File input = new File(inputFile);
PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL);
RequestEntity entity = new FileRequestEntity(input, "application/xml; charset=ISO-8859-1");
put.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
int result = 0;
try {
result = httpclient.executeMethod(put);
LOG.info("Response status code: " + result);
LOG.info("Response body: ");
LOG.info(put.getResponseBodyAsString());
} catch (IOException e) {
LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
LOG.error("You should build the 'rest' quick start and deploy it to a local Fuse before running this test");
LOG.error("Please read the README.md file in 'rest' quick start root");
fail("Connection error");
} finally {
// Release current connection to the connection pool once you are
// done
put.releaseConnection();
}
assertEquals(result, 200);
}
use of org.apache.commons.httpclient.methods.PutMethod in project fuse-karaf by jboss-fuse.
the class CrmSecureTest method putCustomerTest.
/**
* HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
* the update_customer.xml file to update the customer information for customer 123.
* <p/>
* On the server side, it matches the CustomerService's updateCustomer() method
*
* @throws Exception
*/
@Test
public void putCustomerTest() throws IOException {
LOG.info("============================================");
LOG.info("Sent HTTP PUT request to update customer info");
String inputFile = this.getClass().getResource("/update_customer.xml").getFile();
File input = new File(inputFile);
PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL);
put.getHostAuthState().setAuthScheme(scheme);
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
put.setRequestEntity(entity);
int result = 0;
try {
result = httpClient.executeMethod(put);
LOG.info("Response status code: " + result);
LOG.info("Response body: ");
LOG.info(put.getResponseBodyAsString());
} catch (IOException e) {
LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
LOG.error("You should build the 'rest' quick start and deploy it to a local Fuse before running this test");
LOG.error("Please read the README.md file in 'rest' quick start root");
fail("Connection error");
} finally {
// Release current connection to the connection pool once you are
// done
put.releaseConnection();
}
assertEquals(result, 200);
}
use of org.apache.commons.httpclient.methods.PutMethod in project ecf by eclipse.
the class TestBasicAuth method testPutBasicAuthentication.
public void testPutBasicAuthentication() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new EchoService()));
HttpState state = new HttpState();
AuthScope authscope = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test");
state.setCredentials(authscope, creds);
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
PutMethod put = new PutMethod("/test/");
put.setRequestEntity(new StringRequestEntity("Test body"));
try {
this.client.executeMethod(put);
assertEquals("Test body", put.getResponseBodyAsString());
} finally {
put.releaseConnection();
}
assertNotNull(put.getStatusLine());
assertEquals(HttpStatus.SC_OK, put.getStatusLine().getStatusCode());
Header auth = put.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = put.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
}
use of org.apache.commons.httpclient.methods.PutMethod in project entity-api by europeana.
the class HttpConnection method putURL.
/**
* This method makes PUT request for given URL and JSON body parameter.
* @param url
* @param jsonParamValue
* @return ResponseEntity that comprises response body in JSON format, headers and status code.
* @throws IOException
*/
public ResponseEntity<String> putURL(String url, String jsonParamValue) throws IOException {
HttpClient client = this.getHttpClient(CONNECTION_RETRIES, TIMEOUT_CONNECTION);
PutMethod put = new PutMethod(url);
put.setRequestBody(jsonParamValue);
try {
client.executeMethod(put);
return buildResponseEntity(put);
} finally {
put.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.PutMethod in project lobcder by skoulouzis.
the class WebDAVTest method testPutIfEtag.
public void testPutIfEtag() throws HttpException, IOException, DavException, URISyntaxException {
System.out.println("testPutIfEtag");
String testcol = root + "testResourceForPutIfEtag/";
String testuri = testcol + "iftest";
int status;
try {
MkColMethod mkcol = new MkColMethod(testcol);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
PutMethod put = new PutMethod(testuri);
String condition = "<" + testuri + "> ([" + "\"an-etag-this-testcase-invented\"" + "])";
put.setRequestEntity(new StringRequestEntity("1"));
put.setRequestHeader("If", condition);
status = client.executeMethod(put);
assertEquals("status: " + status, HttpStatus.SC_PRECONDITION_FAILED, status);
} finally {
utils.deleteResource(testuri, true);
}
}
Aggregations