use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class TritonBlobStoreManager method finishUpload.
@Override
public String finishUpload(ExternalUploadedBlob blob) throws IOException, ServiceException {
TritonBlob tb = (TritonBlob) blob;
PostMethod post = new PostMethod(url + tb.getUploadId());
ZimbraLog.store.info("posting to %s with locator %s", post.getURI(), tb.getLocator());
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
try {
post.addRequestHeader(TritonHeaders.OBJECTID, tb.getLocator());
post.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString());
post.addRequestHeader(TritonHeaders.SERVER_TOKEN, tb.getServerToken().getToken());
int statusCode = HttpClientUtil.executeMethod(client, post);
if (statusCode == HttpStatus.SC_CREATED) {
return tb.getLocator();
} else {
ZimbraLog.store.error("failed with code %d response: %s", statusCode, post.getResponseBodyAsString());
throw ServiceException.FAILURE("unable to store blob " + statusCode + ":" + post.getStatusText(), null);
}
} finally {
post.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class TritonIncomingOutputStream method sendHttpData.
private void sendHttpData() throws IOException {
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
PostMethod post;
boolean started = false;
if (uploadUrl.isInitialized()) {
started = true;
post = new PostMethod(baseUrl + uploadUrl);
} else {
post = new PostMethod(baseUrl + "/blob");
}
try {
ZimbraLog.store.info("posting to %s", post.getURI());
HttpClientUtil.addInputStreamToHttpMethod(post, new ByteArrayInputStream(baos.toByteArray()), baos.size(), "application/octet-stream");
post.addRequestHeader(TritonHeaders.CONTENT_LENGTH, baos.size() + "");
post.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString());
post.addRequestHeader("Content-Range", "bytes " + written.longValue() + "-" + (written.longValue() + baos.size() - 1) + "/*");
if (serverToken.getToken() != null) {
post.addRequestHeader(TritonHeaders.SERVER_TOKEN, serverToken.getToken());
}
int statusCode = HttpClientUtil.executeMethod(client, post);
if (statusCode == HttpStatus.SC_OK) {
handleResponse(post);
} else if (!started && statusCode == HttpStatus.SC_SEE_OTHER) {
started = true;
uploadUrl.setUploadUrl(post.getResponseHeader(TritonHeaders.LOCATION).getValue());
handleResponse(post);
} else {
throw new IOException("Unable to append, bad response code " + statusCode);
}
} finally {
post.releaseConnection();
}
baos = new ByteArrayOutputStream(LC.triton_upload_buffer_size.intValue());
}
use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class TritonBlobStoreManager method sisCreate.
/**
* Run SIS operation against remote server. If a blob already exists for the locator the remote ref count is incremented.
* @param hash: The content hash of the blob
* @return true if blob already exists, false if not
* @throws IOException
* @throws ServiceException
*/
private boolean sisCreate(byte[] hash) throws IOException {
String locator = getLocator(hash);
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
PostMethod post = new PostMethod(blobApiUrl + locator);
ZimbraLog.store.info("SIS create URL: %s", post.getURI());
try {
post.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString());
int statusCode = HttpClientUtil.executeMethod(client, post);
if (statusCode == HttpStatus.SC_CREATED) {
//exists, ref count incremented
return true;
} else if (statusCode == HttpStatus.SC_NOT_FOUND) {
if (emptyLocator.equals(locator)) {
//empty file
return true;
} else {
//does not exist
return false;
}
} else if (statusCode == HttpStatus.SC_BAD_REQUEST) {
//does not exist, probably wrong hash algorithm
ZimbraLog.store.warn("failed with code %d response: %s", statusCode, post.getResponseBodyAsString());
return false;
} else {
//unexpected condition
ZimbraLog.store.error("failed with code %d response: %s", statusCode, post.getResponseBodyAsString());
throw new IOException("unable to SIS create " + statusCode + ":" + post.getStatusText(), null);
}
} finally {
post.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class WebClientServiceUtil method sendUndeployZimletRequestToUiNode.
public static void sendUndeployZimletRequestToUiNode(Server server, String zimlet, String authToken) throws ServiceException {
if (isServerAtLeast8dot5(server)) {
HttpClient client = ZimbraHttpConnectionManager.getExternalHttpConnMgr().newHttpClient();
HttpProxyUtil.configureProxy(client);
PostMethod method = new PostMethod(URLUtil.getServiceURL(server, "/fromservice/undeployzimlet", false));
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, zimlet);
postToUiNode(server, method, authToken);
}
}
use of org.apache.commons.httpclient.methods.PostMethod 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();
}
}
Aggregations