use of org.apache.commons.httpclient.methods.PutMethod in project zeppelin by apache.
the class CredentialsRestApiTest method testPutUserCredentials.
public void testPutUserCredentials(String requestData) throws IOException {
PutMethod putMethod = httpPut("/credential", requestData);
putMethod.addRequestHeader("Origin", "http://localhost");
assertThat(putMethod, isAllowed());
putMethod.releaseConnection();
}
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 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 zm-mailbox by Zimbra.
the class UserServlet method doHttpOp.
private static Pair<Header[], HttpMethod> doHttpOp(ZAuthToken authToken, HttpMethod method) throws ServiceException {
// create an HTTP client with the same cookies
String url = "";
String hostname = "";
try {
url = method.getURI().toString();
hostname = method.getURI().getHost();
} catch (IOException e) {
log.warn("can't parse target URI", e);
}
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
Map<String, String> cookieMap = authToken.cookieMap(false);
if (cookieMap != null) {
HttpState state = new HttpState();
for (Map.Entry<String, String> ck : cookieMap.entrySet()) {
state.addCookie(new org.apache.commons.httpclient.Cookie(hostname, ck.getKey(), ck.getValue(), "/", null, false));
}
client.setState(state);
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
}
if (method instanceof PutMethod) {
long contentLength = ((PutMethod) method).getRequestEntity().getContentLength();
if (contentLength > 0) {
// 100kbps in millis
int timeEstimate = Math.max(10000, (int) (contentLength / 100));
// cannot set connection time using our ZimbrahttpConnectionManager,
// see comments in ZimbrahttpConnectionManager.
// actually, length of the content to Put should not be a factor for
// establishing a connection, only read time out matter, which we set
// client.getHttpConnectionManager().getParams().setConnectionTimeout(timeEstimate);
method.getParams().setSoTimeout(timeEstimate);
}
}
try {
int statusCode = HttpClientUtil.executeMethod(client, method);
if (statusCode == HttpStatus.SC_NOT_FOUND || statusCode == HttpStatus.SC_FORBIDDEN)
throw MailServiceException.NO_SUCH_ITEM(-1);
else if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_NO_CONTENT)
throw ServiceException.RESOURCE_UNREACHABLE(method.getStatusText(), null, new ServiceException.InternalArgument(HTTP_URL, url, ServiceException.Argument.Type.STR), new ServiceException.InternalArgument(HTTP_STATUS_CODE, statusCode, ServiceException.Argument.Type.NUM));
List<Header> headers = new ArrayList<Header>(Arrays.asList(method.getResponseHeaders()));
headers.add(new Header("X-Zimbra-Http-Status", "" + statusCode));
return new Pair<Header[], HttpMethod>(headers.toArray(new Header[0]), method);
} catch (HttpException e) {
throw ServiceException.RESOURCE_UNREACHABLE("HttpException while fetching " + url, e);
} catch (IOException e) {
throw ServiceException.RESOURCE_UNREACHABLE("IOException while fetching " + url, e);
}
}
use of org.apache.commons.httpclient.methods.PutMethod in project zm-mailbox by Zimbra.
the class TestCalDav method testAppleStyleGroup.
@Test
public void testAppleStyleGroup() throws ServiceException, IOException {
Account dav1 = users[1].create();
String contactsFolderUrl = getFolderUrl(dav1, "Contacts");
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(rachelVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(blueGroupCreate.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String groupLocation = null;
for (Header hdr : exe.respHeaders) {
if ("Location".equals(hdr.getName())) {
groupLocation = hdr.getValue();
}
}
assertNotNull("Location Header returned when creating Group", groupLocation);
postMethod = new PostMethod(contactsFolderUrl);
addBasicAuthHeaderForUser(postMethod, dav1);
postMethod.addRequestHeader("Content-Type", "text/vcard");
postMethod.setRequestEntity(new ByteArrayRequestEntity(parisVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
String url = String.format("%s%s", contactsFolderUrl, "F53A6F96-566F-46CC-8D48-A5263FAB5E38.vcf");
PutMethod putMethod = new PutMethod(url);
addBasicAuthHeaderForUser(putMethod, dav1);
putMethod.addRequestHeader("Content-Type", "text/vcard");
putMethod.setRequestEntity(new ByteArrayRequestEntity(blueGroupModify.getBytes(), MimeConstants.CT_TEXT_VCARD));
HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_NO_CONTENT);
GetMethod getMethod = new GetMethod(url);
addBasicAuthHeaderForUser(getMethod, dav1);
getMethod.addRequestHeader("Content-Type", "text/vcard");
exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
String respBody = new String(exe.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
String[] expecteds = { "X-ADDRESSBOOKSERVER-KIND:group", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:BE43F16D-336E-4C3E-BAE6-22B8F245A986", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:07139DE2-EA7B-46CB-A970-C4DF7F72D9AE" };
for (String expected : expecteds) {
assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
}
// members are actually stored in a different way. Make sure it isn't a fluke
// that the GET response contained the correct members by checking that the members
// appear where expected in a search hit.
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSortBy("dateDesc");
searchRequest.setLimit(8);
searchRequest.setSearchTypes("contact");
searchRequest.setQuery("in:Contacts");
ZMailbox mbox = users[1].getZMailbox();
SearchResponse searchResp = mbox.invokeJaxb(searchRequest);
assertNotNull("JAXB SearchResponse object", searchResp);
List<SearchHit> hits = searchResp.getSearchHits();
assertNotNull("JAXB SearchResponse hits", hits);
assertEquals("JAXB SearchResponse hits", 3, hits.size());
boolean seenGroup = false;
for (SearchHit hit : hits) {
ContactInfo contactInfo = (ContactInfo) hit;
if ("BlueGroup".equals(contactInfo.getFileAs())) {
seenGroup = true;
assertEquals("Number of members of group in search hit", 2, contactInfo.getContactGroupMembers().size());
}
ZimbraLog.test.info("Hit %s class=%s", hit, hit.getClass().getName());
}
assertTrue("Seen group", seenGroup);
}
Aggregations