当前位置: 首页>>代码示例>>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;未经允许,请勿转载。