List of usage examples for org.apache.commons.httpclient.methods ByteArrayRequestEntity ByteArrayRequestEntity
public ByteArrayRequestEntity(byte[] paramArrayOfByte)
From source file:org.eclipse.net4j.internal.http.HTTPClientConnector.java
private void request(IOHandler handler) throws IOException, HttpException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ExtendedDataOutputStream out = new ExtendedDataOutputStream(baos); handler.handleOut(out);/*from w w w . ja v a 2 s . c o m*/ out.flush(); byte[] content = baos.toByteArray(); PostMethod method = createHTTPMethod(url); method.setRequestEntity(new ByteArrayRequestEntity(content)); httpClient.executeMethod(method); InputStream bodyInputStream = method.getResponseBodyAsStream(); ExtendedDataInputStream in = new ExtendedDataInputStream(bodyInputStream); handler.handleIn(in); method.releaseConnection(); }
From source file:org.eclipse.orion.server.cf.live.cflauncher.commands.UpdateFileCommand.java
@Override public IStatus doIt() { try {/* w w w.j av a2 s .com*/ /* Construct WebDAV request to update the file. */ String path = CFLauncherConstants.cfLauncherPrefix + DAV_PATH + this.path; // launcher/dav/whatever.txt URI fileUpdateURI = new URI("https", null, this.uri, 443, path, null, null); PutMethod updateFileMethod = new PutMethod(fileUpdateURI.toString()); configureHttpMethod(updateFileMethod); /* set request body */ updateFileMethod.setRequestEntity(new ByteArrayRequestEntity(this.contents)); ServerStatus status = executeMethod(updateFileMethod); if (!status.isOK()) return status; return status; } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
From source file:org.elasticsearch.hadoop.rest.RestClient.java
private void create(String q, byte[] value) { PostMethod post = new PostMethod(q); post.setRequestEntity(new ByteArrayRequestEntity(value)); execute(post);/*from w w w. j a v a 2 s. c o m*/ }
From source file:org.elasticsearch.hadoop.rest.RestClient.java
public byte[] scroll(String scrollId) throws IOException { // use post instead of get to avoid some weird encoding issues (caused by the long URL) PostMethod post = new PostMethod("_search/scroll?scroll=" + scrollKeepAlive.toString()); post.setRequestEntity(new ByteArrayRequestEntity(scrollId.getBytes(StringUtils.UTF_8))); return execute(post); }
From source file:org.elasticsearch.hadoop.rest.RestClient.java
public void putMapping(String index, String mapping, byte[] bytes) { // create index first (if needed) - it might return 403 execute(new PutMethod(index), false); // create actual mapping PutMethod put = new PutMethod(mapping); put.setRequestEntity(new ByteArrayRequestEntity(bytes)); execute(put);// w ww . jav a 2s . co m }
From source file:org.glite.slcs.caclient.impl.CMPConnection.java
public void sendRequest(CARequest cmpRequest) throws SLCSException { byte[] requestBytes = cmpRequest.getDEREncoded(); RequestEntity entity = new ByteArrayRequestEntity(requestBytes); this.cmpServerPost.setRequestEntity(entity); HttpClient httpClient = this.cmpClient.getHttpClient(); int statusCode = 0; try {//from w w w. j a va 2 s .c o m log.debug("Sending the request to the online CA..."); statusCode = httpClient.executeMethod(this.cmpServerPost); log.debug("Status code = " + statusCode); } catch (HttpException e) { log.error("Http related error while sending the request to the online CA.", e); throw new SLCSException(e); } catch (IOException e) { log.error("IO error while sending the request to the online CA.", e); throw new SLCSException(e); } if (statusCode != 200) { // not ok log.error("Status code " + statusCode + " is unexcpected!"); throw new SLCSException("Unexpected status code from the online CA (" + statusCode + ")!"); } }
From source file:org.jasig.portlet.calendar.adapter.exchange.CommonsHttpConnection.java
protected void onSendAfterWrite(WebServiceMessage message) throws IOException { postMethod.setRequestEntity(new ByteArrayRequestEntity(requestBuffer.toByteArray())); requestBuffer = null;/*from w w w .jav a2s .c o m*/ httpClient.executeMethod(postMethod); }
From source file:org.jboss.mod_cluster.Client.java
public int runit() throws Exception { PostMethod pm = null;/*from w ww .ja v a 2 s.co m*/ GetMethod gm = null; HttpMethodBase bm = null; long starttime, endtime; if (httpClient == null) httpClient = new HttpClient(); if (fd != null) { pm = new PostMethod(URL); // InputStreamRequestEntity buf = new InputStreamRequestEntity(fd); // XXX: Ugly hack to test... byte[] buffet = new byte[6144]; for (int i = 0; i < buffet.length; i++) buffet[i] = 'a'; ByteArrayRequestEntity buf = new ByteArrayRequestEntity(buffet); pm.setRequestEntity(buf); // pm.setRequestBody(fd); pm.setHttp11(true); pm.setContentChunked(true); // pm.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED); bm = pm; } else if (post != null) { pm = new PostMethod(URL); pm.setRequestEntity(new StringRequestEntity(post, "application/x-www-form-urlencoded", "UTF8")); bm = pm; } else { gm = new GetMethod(URL); bm = gm; } if (user != null) { Credentials cred = new UsernamePasswordCredentials(user, pass); httpClient.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY, cred); } // System.out.println("Connecting to " + URL); Integer connectionTimeout = 40000; bm.getParams().setParameter("http.socket.timeout", connectionTimeout); bm.getParams().setParameter("http.connection.timeout", connectionTimeout); if (VirtualHost != null) bm.getParams().setVirtualHost(VirtualHost); httpClient.getParams().setParameter("http.socket.timeout", connectionTimeout); httpClient.getParams().setParameter("http.connection.timeout", connectionTimeout); if (jsessionid != null) { // System.out.println("jsessionid: " + jsessionid); bm.setRequestHeader("Cookie", "JSESSIONID=" + jsessionid); } try { if (gm == null) { pm.getParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY); starttime = System.currentTimeMillis(); httpResponseCode = httpClient.executeMethod(pm); endtime = System.currentTimeMillis(); } else { gm.getParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY); starttime = System.currentTimeMillis(); httpResponseCode = httpClient.executeMethod(gm); endtime = System.currentTimeMillis(); } if (httpResponseCode == 200) { response = bm.getResponseBodyAsString(); Cookie[] cookies = httpClient.getState().getCookies(); // System.out.println( "Cookies: " + cookies); if (cookies != null && cookies.length != 0) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; // System.out.println( "Cookie: " + cookie.getName() + ", Value: " + cookie.getValue()); if (cookie.getName().equals("JSESSIONID")) { if (jsessionid == null) { jsessionid = cookie.getValue(); String nodes[] = jsessionid.split("\\."); if (nodes.length == 2) node = nodes[1]; System.out.println("cookie first time: " + jsessionid); bm.releaseConnection(); return 0; // first time ok. } else { if (jsessionid.compareTo(cookie.getValue()) == 0) { if (logok) if (bm.getResponseHeader("Date") != null) System.out.println("cookie ok: " + bm.getResponseHeader("Date").toString().replace('\r', ' ') .replace('\n', ' ') + " response time: " + (endtime - starttime)); else { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); System.out.println("cookie ok: " + dateFormat.format(date) + " response time: " + (endtime - starttime)); } bm.releaseConnection(); return 0; } else { System.out.println( "cookie \"second\" time: " + cookie.getValue() + " : " + jsessionid); System.out.println("cookie changed"); bm.releaseConnection(); if (checkcookie) return -1; else if (checknode) { String nodes[] = cookie.getValue().split("\\."); if (nodes.length != 2) { System.out.println("Can't find node in cookie"); return -1; } if (nodes[1].compareTo(node) == 0) { return 0; } else { System.out.println("node " + nodes[1] + " changed too"); return -1; } } else return 0; } } } } } else { // Look in the response to make sure that there is a cookie. int len = (int) bm.getResponseContentLength(); if (jsessionid != null && bm.getResponseBodyAsString(len).indexOf(jsessionid) != -1) { bm.releaseConnection(); return 0; } if (jsessionid == null && !checkcookie) { return 0; } System.out.println("No cookies"); } Header head = bm.getResponseHeader("getRequestedSessionId"); if (head != null) { HeaderElement[] heade = head.getElements(); requestedSessionId = heade[0].getValue(); } else { requestedSessionId = null; } } else { System.out.println("response: " + httpResponseCode); System.out.println("response: " + bm.getStatusLine()); response = bm.getResponseBodyAsString(); System.out.println("response: " + response); success = false; httpClient = null; } // System.out.println("response:\n" + bm.getResponseBodyAsString(len)); } catch (HttpException e) { e.printStackTrace(); success = false; httpClient = null; } System.out.println("DONE: " + httpResponseCode); bm.releaseConnection(); return httpResponseCode; }
From source file:org.jboss.wise.core.client.jaxrs.impl.RSDynamicClientImpl.java
public InvocationResult invoke(byte[] request, WiseMapper mapper) { return invoke(new ByteArrayRequestEntity(request), mapper); }
From source file:org.jbpm.formbuilder.server.file.GuvnorFileService.java
@Override public String storeFile(String packageName, String fileName, byte[] content) throws FileException { try {/*from ww w. j a va2s . c o m*/ String assetName = stripFileExtension(fileName); String assetExt = extractFileExtension(fileName); deleteOlderVersion(packageName, fileName); HttpClient client = helper.getHttpClient(); String createUrl = helper.getRestBaseUrl() + URLEncoder.encode(packageName, GuvnorHelper.ENCODING) + "/assets/"; PostMethod create = helper.createPostMethod(createUrl); try { helper.setAuth(client, create); create.addRequestHeader("Content-Type", "application/octet-stream"); create.addRequestHeader("Accept", "application/atom+xml"); create.addRequestHeader("Slug", assetName + '.' + assetExt); create.setRequestEntity(new ByteArrayRequestEntity(content)); client.executeMethod(create); } finally { create.releaseConnection(); } return (this.baseUrl + "/org.drools.guvnor.Guvnor/api/packages/" + URLEncoder.encode(packageName, GuvnorHelper.ENCODING) + "/" + URLEncoder.encode(assetName, GuvnorHelper.ENCODING) + "." + assetExt); } catch (Exception e) { throw new FileException("Problem storing file", e); } }