當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteArrayRequestEntity類代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.methods.ByteArrayRequestEntity的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayRequestEntity類的具體用法?Java ByteArrayRequestEntity怎麽用?Java ByteArrayRequestEntity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ByteArrayRequestEntity類屬於org.apache.commons.httpclient.methods包,在下文中一共展示了ByteArrayRequestEntity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: post

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
@Override
public HttpResponse post(URL urlObj, byte[] payload, String userName, String password,
                         int timeout) {
  HttpClient client = new HttpClient();
  PostMethod method = new PostMethod(urlObj.toString());
  method.setRequestEntity(new ByteArrayRequestEntity(payload));
  method.setRequestHeader("Content-type", "application/json");
  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler());
  client.getParams().setSoTimeout(1000 * timeout);
  client.getParams().setConnectionManagerTimeout(1000 * timeout);
  if (userName != null && password != null) {
    setBasicAuthorization(method, userName, password);
  }
  try {
    int response = client.executeMethod(method);
    return new HttpResponse(response, method.getResponseBody());
  } catch (IOException e) {
    throw new RuntimeException("Failed to process post request URL: " + urlObj, e);
  } finally {
    method.releaseConnection();
  }

}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:25,代碼來源:LogiURLFetchService.java

示例2: createRequestEntity

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
/**
 * Creates the request entity that makes up the POST message body.
 * 
 * @param message message to be sent
 * @param charset character set used for the message
 * 
 * @return request entity that makes up the POST message body
 * 
 * @throws SOAPClientException thrown if the message could not be marshalled
 */
protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException {
    try {
        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
        ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset);

        if (log.isDebugEnabled()) {
            log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message)));
        }
        XMLHelper.writeNode(marshaller.marshall(message), writer);
        return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml");
    } catch (MarshallingException e) {
        throw new SOAPClientException("Unable to marshall SOAP envelope", e);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:HttpSOAPClient.java

示例3: post

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
public HttpResponse post(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId,
                         final String relationCollectionName, final Object relationshipEntityId, final byte[] body, String contentType) throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
            relationshipEntityId, null);
    String url = endpoint.getUrl();

    PostMethod req = new PostMethod(url.toString());
    if (body != null)
    {
        if (contentType == null || contentType.isEmpty())
        {
            contentType = "application/octet-stream";
        }
        ByteArrayRequestEntity requestEntity = new ByteArrayRequestEntity(body, contentType);
        req.setRequestEntity(requestEntity);
    }
    return submitRequest(req, rq);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:20,代碼來源:PublicApiHttpClient.java

示例4: doPut

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
/**
 * 處理Put請求
 * @param url
 * @param headers
 * @param object
 * @param property
 * @return
 */
public static JSONObject doPut(String url, Map<String, String> headers,String jsonString) {

	HttpClient httpClient = new HttpClient();
	
	PutMethod putMethod = new PutMethod(url);
	
	//設置header
	setHeaders(putMethod,headers);
	
	//設置put傳遞的json數據
	if(jsonString!=null&&!"".equals(jsonString)){
		putMethod.setRequestEntity(new ByteArrayRequestEntity(jsonString.getBytes()));
	}
	
	String responseStr = "";
	
	try {
		httpClient.executeMethod(putMethod);
		responseStr = putMethod.getResponseBodyAsString();
	} catch (Exception e) {
		log.error(e);
		responseStr="{status:0}";
	} 
	return JSONObject.parseObject(responseStr);
}
 
開發者ID:apicloudcom,項目名稱:Java-sdk,代碼行數:34,代碼來源:HttpUtils.java

示例5: addPrinterHW

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
@Override
public void addPrinterHW(final PrinterHWList printerHWList)
{
	final byte[] data = beanEncoder.encode(printerHWList);

	final URL url = getURL(PRTRestServiceConstants.PATH_AddPrinterHW);
	final PostMethod httpPost = new PostMethod(url.toString());

	final RequestEntity entity = new ByteArrayRequestEntity(data, beanEncoder.getContentType());
	httpPost.setRequestEntity(entity);

	int result = -1;
	try
	{
		result = executeHttpPost(httpPost);
	}
	catch (final Exception e)
	{
		throw new PrintConnectionEndpointException("Cannot POST to " + url, e);
	}

	if (result != 200)
	{
		throw new PrintConnectionEndpointException("Error " + result + " while posting on " + url);
	}
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:27,代碼來源:RestHttpPrintConnectionEndpoint.java

示例6: executeInternal

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
@Override
public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] output) throws IOException {
	for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
		String headerName = entry.getKey();
		for (String headerValue : entry.getValue()) {
			httpMethod.addRequestHeader(headerName, headerValue);
		}
	}
	if (this.httpMethod instanceof EntityEnclosingMethod) {
		EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) this.httpMethod;
		RequestEntity requestEntity = new ByteArrayRequestEntity(output);
		entityEnclosingMethod.setRequestEntity(requestEntity);
	}
	this.httpClient.executeMethod(this.httpMethod);
	return new CommonsClientHttpResponse(this.httpMethod);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:17,代碼來源:CommonsClientHttpRequest.java

示例7: getSendByteArrayMethod

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
public PutMethod getSendByteArrayMethod(byte[] content, String service) throws Exception {
    // Prepare HTTP put
    // 
    String urlString = constructUrl(service);
    log.logDebug(toString(), Messages.getString("SlaveServer.DEBUG_ConnectingTo", urlString)); //$NON-NLS-1$
    PutMethod putMethod = new PutMethod(urlString);
    
    // Request content will be retrieved directly from the input stream
    // 
    RequestEntity entity = new ByteArrayRequestEntity(content);
    
    putMethod.setRequestEntity(entity);
    putMethod.setDoAuthentication(true);
    putMethod.addRequestHeader(new Header("Content-Type", "text/xml;charset=" + Const.XML_ENCODING));
    
    return putMethod;
}
 
開發者ID:icholy,項目名稱:geokettle-2.0,代碼行數:18,代碼來源:SlaveServer.java

示例8: getSendByteArrayMethod

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
public PostMethod getSendByteArrayMethod(byte[] content, String service) throws Exception {
    // Prepare HTTP put
    // 
    String urlString = constructUrl(service);
    log.logDebug(BaseMessages.getString(PKG, "SlaveServer.DEBUG_ConnectingTo", urlString)); //$NON-NLS-1$
    PostMethod postMethod = new PostMethod(urlString);
    
    // Request content will be retrieved directly from the input stream
    // 
    RequestEntity entity = new ByteArrayRequestEntity(content);
    
    postMethod.setRequestEntity(entity);
    postMethod.setDoAuthentication(true);
    postMethod.addRequestHeader(new Header("Content-Type", "text/xml;charset=" + Const.XML_ENCODING));
    
    return postMethod;
}
 
開發者ID:yintaoxue,項目名稱:read-open-source-code,代碼行數:18,代碼來源:SlaveServer.java

示例9: getSendByteArrayMethod

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
public PostMethod getSendByteArrayMethod(byte[] content, String service) throws Exception {
    // Prepare HTTP put
    // 
    String urlString = constructUrl(service);
    if(log.isDebug()) log.logDebug(BaseMessages.getString(PKG, "SlaveServer.DEBUG_ConnectingTo", urlString)); //$NON-NLS-1$
    PostMethod postMethod = new PostMethod(urlString);
    
    // Request content will be retrieved directly from the input stream
    // 
    RequestEntity entity = new ByteArrayRequestEntity(content);
    
    postMethod.setRequestEntity(entity);
    postMethod.setDoAuthentication(true);
    postMethod.addRequestHeader(new Header("Content-Type", "text/xml;charset=" + Const.XML_ENCODING));
    
    return postMethod;
}
 
開發者ID:bsspirit,項目名稱:kettle-4.4.0-stable,代碼行數:18,代碼來源:SlaveServer.java

示例10: setRequestAuthentication

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
@Override
public void setRequestAuthentication(HttpMethod method, byte[] message) throws IOException
{
    if (method instanceof PostMethod)
    {
        // encrypt body
        Pair<byte[], AlgorithmParameters> encrypted = encryptor.encrypt(KeyProvider.ALIAS_SOLR, null, message);
        setRequestAlgorithmParameters(method, encrypted.getSecond());

        ((PostMethod) method).setRequestEntity(new ByteArrayRequestEntity(encrypted.getFirst(), "application/octet-stream"));
    }

    long requestTimestamp = System.currentTimeMillis();

    // add MAC header
    byte[] mac = macUtils.generateMAC(KeyProvider.ALIAS_SOLR, new MACInput(message, requestTimestamp, getLocalIPAddress()));

    if (logger.isDebugEnabled())
    {
        logger.debug("Setting MAC " + mac + " on HTTP request " + method.getPath());
        logger.debug("Setting timestamp " + requestTimestamp + " on HTTP request " + method.getPath());
    }

    if (overrideMAC)
    {
        mac[0] += (byte) 1;
    }
    setRequestMac(method, mac);

    if (overrideTimestamp)
    {
        requestTimestamp += 60000;
    }
    // prevent replays
    setRequestTimestamp(method, requestTimestamp);
}
 
開發者ID:Alfresco,項目名稱:alfresco-solrclient,代碼行數:37,代碼來源:SOLRAPIClientTest.java

示例11: put

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
/**
 * Send a PUT request
 * @param cluster the cluster definition
 * @param path the path or URI
 * @param headers the HTTP headers to include, <tt>Content-Type</tt> must be
 * supplied
 * @param content the content bytes
 * @return a Response object with response detail
 * @throws IOException
 */
public Response put(Cluster cluster, String path, Header[] headers, 
    byte[] content) throws IOException {
  PutMethod method = new PutMethod();
  try {
    method.setRequestEntity(new ByteArrayRequestEntity(content));
    int code = execute(cluster, method, headers, path);
    headers = method.getResponseHeaders();
    content = method.getResponseBody();
    return new Response(code, headers, content);
  } finally {
    method.releaseConnection();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,代碼來源:Client.java

示例12: post

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
/**
 * Send a POST request
 * @param cluster the cluster definition
 * @param path the path or URI
 * @param headers the HTTP headers to include, <tt>Content-Type</tt> must be
 * supplied
 * @param content the content bytes
 * @return a Response object with response detail
 * @throws IOException
 */
public Response post(Cluster cluster, String path, Header[] headers, 
    byte[] content) throws IOException {
  PostMethod method = new PostMethod();
  try {
    method.setRequestEntity(new ByteArrayRequestEntity(content));
    int code = execute(cluster, method, headers, path);
    headers = method.getResponseHeaders();
    content = method.getResponseBody();
    return new Response(code, headers, content);
  } finally {
    method.releaseConnection();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,代碼來源:Client.java

示例13: executePost

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
private PostMethod executePost(String uri, byte[] body) throws IOException {
  HttpClient cli = new HttpClient();
  final PostMethod post = new PostMethod(URI + ":" + source.port + uri);
  post.setRequestEntity(new ByteArrayRequestEntity(body));
  cli.executeMethod(post);
  return post;
}
 
開發者ID:yandex,項目名稱:opentsdb-flume,代碼行數:8,代碼來源:LegacyHttpSourceTest.java

示例14: httpPost

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
protected static PostMethod httpPost(String path, String body) throws IOException {
  LOG.info("Connecting to {}", url + path);
  HttpClient httpClient = new HttpClient();
  PostMethod postMethod = new PostMethod(url + path);
  postMethod.addRequestHeader("Origin", url);
  RequestEntity entity = new ByteArrayRequestEntity(body.getBytes("UTF-8"));
  postMethod.setRequestEntity(entity);
  httpClient.executeMethod(postMethod);
  LOG.info("{} - {}", postMethod.getStatusCode(), postMethod.getStatusText());
  return postMethod;
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:12,代碼來源:AbstractTestRestApi.java

示例15: httpPut

import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; //導入依賴的package包/類
protected static PutMethod httpPut(String path, String body) throws IOException {
  LOG.info("Connecting to {}", url + path);
  HttpClient httpClient = new HttpClient();
  PutMethod putMethod = new PutMethod(url + path);
  putMethod.addRequestHeader("Origin", url);
  RequestEntity entity = new ByteArrayRequestEntity(body.getBytes("UTF-8"));
  putMethod.setRequestEntity(entity);
  httpClient.executeMethod(putMethod);
  LOG.info("{} - {}", putMethod.getStatusCode(), putMethod.getStatusText());
  return putMethod;
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:12,代碼來源:AbstractTestRestApi.java


注:本文中的org.apache.commons.httpclient.methods.ByteArrayRequestEntity類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。