use of org.apache.commons.httpclient.HttpMethod in project zm-mailbox by Zimbra.
the class UserServlet method putRemoteResource.
public static Pair<Header[], HttpInputStream> putRemoteResource(ZAuthToken authToken, String url, InputStream req, Header[] headers) throws ServiceException, IOException {
StringBuilder u = new StringBuilder(url);
u.append("?").append(QP_AUTH).append('=').append(AUTH_COOKIE);
PutMethod method = new PutMethod(u.toString());
String contentType = "application/octet-stream";
if (headers != null) {
for (Header hdr : headers) {
String name = hdr.getName();
method.addRequestHeader(hdr);
if (name.equals("Content-Type"))
contentType = hdr.getValue();
}
}
method.setRequestEntity(new InputStreamRequestEntity(req, contentType));
Pair<Header[], HttpMethod> pair = doHttpOp(authToken, method);
return new Pair<Header[], HttpInputStream>(pair.getFirst(), new HttpInputStream(pair.getSecond()));
}
use of org.apache.commons.httpclient.HttpMethod in project zm-mailbox by Zimbra.
the class UserServlet method getRemoteResource.
public static Pair<Header[], byte[]> getRemoteResource(ZAuthToken authToken, String url) throws ServiceException {
HttpMethod get = null;
try {
Pair<Header[], HttpMethod> pair = doHttpOp(authToken, new GetMethod(url));
get = pair.getSecond();
return new Pair<Header[], byte[]>(pair.getFirst(), get.getResponseBody());
} catch (IOException x) {
throw ServiceException.FAILURE("Can't read response body " + url, x);
} finally {
if (get != null) {
get.releaseConnection();
}
}
}
use of org.apache.commons.httpclient.HttpMethod in project zm-mailbox by Zimbra.
the class ZimbraServlet method proxyServletRequest.
public static void proxyServletRequest(HttpServletRequest req, HttpServletResponse resp, Server server, String uri, AuthToken authToken) throws IOException, ServiceException {
if (server == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "cannot find remote server");
return;
}
HttpMethod method;
String url = getProxyUrl(req, server, uri);
mLog.debug("Proxy URL = %s", url);
if (req.getMethod().equalsIgnoreCase("GET")) {
method = new GetMethod(url.toString());
} else if (req.getMethod().equalsIgnoreCase("POST") || req.getMethod().equalsIgnoreCase("PUT")) {
PostMethod post = new PostMethod(url.toString());
post.setRequestEntity(new InputStreamRequestEntity(req.getInputStream()));
method = post;
} else {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "cannot proxy method: " + req.getMethod());
return;
}
HttpState state = new HttpState();
String hostname = method.getURI().getHost();
if (authToken != null) {
authToken.encode(state, false, hostname);
}
try {
proxyServletRequest(req, resp, method, state);
} finally {
method.releaseConnection();
}
}
use of org.apache.commons.httpclient.HttpMethod in project zm-mailbox by Zimbra.
the class TestAccessKeyGrant method testCalendarGet_guest.
/*
* use zmmailbox to grant guest access:
* zmmailbox -z -m user1@phoebe.mac mfg Calendar guest g1@guest.com zzz r
*/
public void testCalendarGet_guest() throws Exception {
HttpState initialState = new HttpState();
/*
Cookie authCookie = new Cookie(restURL.getURL().getHost(), "ZM_AUTH_TOKEN", mAuthToken, "/", null, false);
Cookie sessionCookie = new Cookie(restURL.getURL().getHost(), "JSESSIONID", mSessionId, "/zimbra", null, false);
initialState.addCookie(authCookie);
initialState.addCookie(sessionCookie);
*/
String guestName = "g1@guest.com";
String guestPassword = "zzz";
Credentials loginCredentials = new UsernamePasswordCredentials(guestName, guestPassword);
initialState.setCredentials(AuthScope.ANY, loginCredentials);
HttpClient client = new HttpClient();
client.setState(initialState);
String url = getRestCalendarUrl(OWNER_NAME);
System.out.println("REST URL: " + url);
HttpMethod method = new GetMethod(url);
executeHttpMethod(client, method);
}
use of org.apache.commons.httpclient.HttpMethod in project zm-mailbox by Zimbra.
the class TestAccessKeyGrant method disable_testCalendarGet_Yahoo_accesskey.
/*
* setup:
*
* 1. use zmmailbox to grant key access: zmmailbox -z -d -r soap12
* -d: debug, so it shows soap trace
* -z: default admin auth
* -r soap12: use soap12 protocol, it's easier to read than json
*
* mbox> sm user1
* mbox user1@phoebe.mac> mfg Calendar key k1@key.com r
*
* grab the access key from the FolderActionResponse:
* <FolderActionResponse xmlns="urn:zimbraMail">
* <action d="k1@key.com" key="3c4877ed3948511cee39379debbf968d" op="grant" zid="k1@key.com" id="10"/>
* </FolderActionResponse>
*
* 2. paste the access key to the test (TODO, automate it)
*
* 3. In com.zimbra.cs.service.AuthProvider, uncomment // register(new com.zimbra.qa.unittest.TestAccessKeyGrant.DummyAuthProvider());
*
* 4. ant deploy-war
*
* 5. modify localconfig.xml, add:
* <key name="zimbra_auth_provider">
* <value>DUMMY_AUTH_PROVIDER</value>
* </key>
*
* 6. retstart server
*
* ready to run the test
*/
public void disable_testCalendarGet_Yahoo_accesskey() throws Exception {
HttpClient client = new HttpClient();
String accessKey = "3c4877ed3948511cee39379debbf968d-bogus";
String url = getRestCalendarUrl(OWNER_NAME);
/*
* the Yahoo accesskey URL is:
* /home/yid/Calendar/Folder.ics?k=accesskey&h=yid
*/
url = url + "?k=" + accessKey + "&h=" + getAccountId(OWNER_NAME);
System.out.println("REST URL: " + url);
HttpMethod method = new GetMethod(url);
executeHttpMethod(client, method);
}
Aggregations