use of org.apache.commons.httpclient.methods.PutMethod in project zeppelin by apache.
the class CredentialsRestApiTest method testInvalidRequest.
@Test
public void testInvalidRequest() throws IOException {
String jsonInvalidRequestEntityNull = "{\"entity\" : null, \"username\" : \"test\", \"password\" : \"testpass\"}";
String jsonInvalidRequestNameNull = "{\"entity\" : \"test\", \"username\" : null, \"password\" : \"testpass\"}";
String jsonInvalidRequestPasswordNull = "{\"entity\" : \"test\", \"username\" : \"test\", \"password\" : null}";
String jsonInvalidRequestAllNull = "{\"entity\" : null, \"username\" : null, \"password\" : null}";
PutMethod entityNullPut = httpPut("/credential", jsonInvalidRequestEntityNull);
entityNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(entityNullPut, isBadRequest());
entityNullPut.releaseConnection();
PutMethod nameNullPut = httpPut("/credential", jsonInvalidRequestNameNull);
nameNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(nameNullPut, isBadRequest());
nameNullPut.releaseConnection();
PutMethod passwordNullPut = httpPut("/credential", jsonInvalidRequestPasswordNull);
passwordNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(passwordNullPut, isBadRequest());
passwordNullPut.releaseConnection();
PutMethod allNullPut = httpPut("/credential", jsonInvalidRequestAllNull);
allNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(allNullPut, isBadRequest());
allNullPut.releaseConnection();
}
use of org.apache.commons.httpclient.methods.PutMethod in project pinot by linkedin.
the class WebHdfsV1Client method uploadSegment.
// This method is based on:
// https://hadoop.apache.org/docs/r1.0.4/webhdfs.html#CREATE
public synchronized boolean uploadSegment(String webHdfsPath, String localFilePath) {
// Step 1: Submit a HTTP PUT request without automatically following
// redirects and without sending the file data.
String firstPutReqString = String.format(WEB_HDFS_UPLOAD_PATH_TEMPLATE, _protocol, _host, _port, webHdfsPath, _overwrite, _permission);
HttpMethod firstPutReq = new PutMethod(firstPutReqString);
try {
LOGGER.info("Trying to send request: {}.", firstPutReqString);
int firstResponseCode = _httpClient.executeMethod(firstPutReq);
if (firstResponseCode != 307) {
LOGGER.error(String.format("Failed to execute the first PUT request to upload segment to webhdfs: %s. " + "Expected response code 307, but get %s. Response body: %s", firstPutReqString, firstResponseCode, firstPutReq.getResponseBodyAsString()));
return false;
}
} catch (Exception e) {
LOGGER.error(String.format("Failed to execute the first request to upload segment to webhdfs: %s.", firstPutReqString), e);
return false;
} finally {
firstPutReq.releaseConnection();
}
// Step 2: Submit another HTTP PUT request using the URL in the Location
// header with the file data to be written.
String redirectedReqString = firstPutReq.getResponseHeader(LOCATION).getValue();
PutMethod redirectedReq = new PutMethod(redirectedReqString);
File localFile = new File(localFilePath);
RequestEntity requestEntity = new FileRequestEntity(localFile, "application/binary");
redirectedReq.setRequestEntity(requestEntity);
try {
LOGGER.info("Trying to send request: {}.", redirectedReqString);
int redirectedResponseCode = _httpClient.executeMethod(redirectedReq);
if (redirectedResponseCode != 201) {
LOGGER.error(String.format("Failed to execute the redirected PUT request to upload segment to webhdfs: %s. " + "Expected response code 201, but get %s. Response: %s", redirectedReqString, redirectedResponseCode, redirectedReq.getResponseBodyAsString()));
}
return true;
} catch (IOException e) {
LOGGER.error(String.format("Failed to execute the redirected request to upload segment to webhdfs: %s.", redirectedReqString), e);
return false;
} finally {
redirectedReq.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.PutMethod in project intellij-community by JetBrains.
the class YouTrackIntegrationTest method createIssue.
@NotNull
private String createIssue(@NotNull HttpClient client) throws IOException {
// http PUT "http://trackers-tests.labs.intellij.net:8067/rest/issue" project==BTYT4TT "summary==First issue created via REST API"
final PutMethod method = new PutMethod(myRepository.getUrl() + "/rest/issue");
method.setQueryString(new NameValuePair[] { new NameValuePair("project", "BTYT4TT"), new NameValuePair("summary", "Test issue for time tracking updates (" + SHORT_TIMESTAMP_FORMAT.format(new Date()) + ")") });
final int statusCode = client.executeMethod(method);
assertEquals(HttpStatus.SC_CREATED, statusCode);
final Header locationHeader = method.getResponseHeader("Location");
assertNotNull(locationHeader);
// Otherwise there will be timeout on connection acquiring
method.releaseConnection();
return PathUtil.getFileName(locationHeader.getValue());
}
use of org.apache.commons.httpclient.methods.PutMethod in project intellij-community by JetBrains.
the class PivotalTrackerRepository method doREST.
private HttpMethod doREST(final String request, final HTTPMethod type) throws Exception {
final HttpClient client = getHttpClient();
client.getParams().setContentCharset("UTF-8");
final String uri = getUrl() + request;
final HttpMethod method = type == HTTPMethod.POST ? new PostMethod(uri) : type == HTTPMethod.PUT ? new PutMethod(uri) : new GetMethod(uri);
configureHttpMethod(method);
client.executeMethod(method);
return method;
}
use of org.apache.commons.httpclient.methods.PutMethod in project zm-mailbox by Zimbra.
the class DavRequest method getHttpMethod.
public HttpMethod getHttpMethod(String baseUrl) {
String url = mRedirectUrl;
if (url == null) {
// schedule-outbox-URL in the same report.
try {
// This will throw an exception when the URL is a relative one.
new URL(mUri);
url = mUri;
} catch (MalformedURLException e) {
url = baseUrl + mUri;
}
}
if (mDoc == null)
return new GetMethod(url) {
@Override
public String getName() {
return mMethod;
}
};
PutMethod m = new PutMethod(url) {
RequestEntity re;
@Override
public String getName() {
return mMethod;
}
@Override
protected RequestEntity generateRequestEntity() {
return re;
}
@Override
public void setRequestEntity(RequestEntity requestEntity) {
re = requestEntity;
super.setRequestEntity(requestEntity);
}
};
DocumentRequestEntity re = new DocumentRequestEntity(mDoc);
m.setRequestEntity(re);
return m;
}
Aggregations