org.apache.http.entity.ByteArrayEntity

Here are the examples of the java api org.apache.http.entity.ByteArrayEntity taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

63 Examples 7

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

HttpRequestBase makeRequest(final String method, final String path, final ByteArrayEnreplacedy data, final Header[] headers, boolean useCoordinator) {
    String uri;
    if (this.options.isManualServerAddress()) {
        uri = this.manualServerAddress;
    } else {
        if (useCoordinator) {
            updateCoordinatorAddress();
            uri = this.coordinatorAddress.getNormalized();
        } else {
            uri = getAddress();
        }
    }
    return makeRequest(method, path, data, headers, uri);
}

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

HttpRequestBase makeRequest(final String method, final String path, final ByteArrayEnreplacedy data, final Header[] headers, String hostUri) {
    HttpRequestBase request;
    String uri = hostUri + path;
    switch(method) {
        case "GET":
            request = new HttpGet(uri);
            break;
        case "DELETE":
            request = new HttpDelete(uri);
            break;
        case "POST":
            request = new HttpPost(uri);
            ((HttpPost) request).setEnreplacedy(data);
            break;
        default:
            throw new IllegalArgumentException(String.format("%s is not a valid HTTP method", method));
    }
    if (headers != null) {
        request.setHeaders(headers);
    }
    return request;
}

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

/**
 * Sends an HTTP request to the Pilosa server.
 * <p>
 * <b>NOTE</b>: This function is experimental and may be removed in later revisions.
 * </p>
 *
 * @param method  HTTP request method (GET, POST, PATCH, DELETE, ...)
 * @param path    HTTP request path.
 * @param data    HTTP request body.
 * @param headers HTTP request headers.
 * @return the response to this request.
 */
public CloseableHttpResponse httpRequest(final String method, final String path, final ByteArrayEnreplacedy data, Header[] headers) {
    Span span = this.tracer.buildSpan("Client.HttpRequest").start();
    try {
        return clientExecute(method, path, data, headers, "HTTP request error", ReturnClientResponse.RAW_RESPONSE, false);
    } finally {
        span.finish();
    }
}

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

/**
 * Creates an index on the server using the given Index object.
 *
 * @param index index object
 * @throws HttpConflict if there already is a index with the given name
 * @see <a href="https://www.pilosa.com/docs/api-reference/#index-index-name-query">Pilosa API Reference: Query</a>
 * @see <a href="https://www.pilosa.com/docs/api-reference/#index-index-name">Pilosa API Reference: Index</a>
 */
public void createIndex(Index index) {
    Span span = this.tracer.buildSpan("Client.CreateIndex").start();
    try {
        String path = String.format("/index/%s", index.getName());
        String body = index.getOptions().toString();
        ByteArrayEnreplacedy data = new ByteArrayEnreplacedy(body.getBytes(StandardCharsets.UTF_8));
        clientExecute("POST", path, data, null, "Error while creating index");
    } finally {
        span.finish();
    }
}

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

private QueryResponse queryPath(QueryRequest request) {
    String path = String.format("/index/%s/query", request.getIndex().getName());
    Internal.QueryRequest qr = request.toProtobuf();
    ByteArrayEnreplacedy body = new ByteArrayEnreplacedy(qr.toByteArray());
    try {
        CloseableHttpResponse response = clientExecute("POST", path, body, protobufHeaders, "Error while posting query", ReturnClientResponse.RAW_RESPONSE, request.isUseCoordinator());
        HttpEnreplacedy enreplacedy = response.getEnreplacedy();
        if (enreplacedy != null) {
            try (InputStream src = enreplacedy.getContent()) {
                QueryResponse queryResponse = QueryResponse.fromProtobuf(src);
                if (!queryResponse.isSuccess()) {
                    throw new PilosaException(queryResponse.getErrorMessage());
                }
                return queryResponse;
            }
        }
        throw new PilosaException("Server returned empty response");
    } catch (IOException ex) {
        throw new PilosaException("Error while reading response", ex);
    }
}

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

void importNode(String hostUri, ImportRequest request) {
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(request.getPayload());
    HttpRequestBase httpRequest = makeRequest("POST", request.getPath(), enreplacedy, request.getHeaders(), hostUri);
    try {
        clientExecute(httpRequest, "Error while importing", ReturnClientResponse.ERROR_CHECKED_RESPONSE);
    } catch (IOException e) {
        throw new PilosaException(String.format("Error connecting to host: %s", hostUri));
    }
}

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

private void clientExecute(final String method, final String path, final ByteArrayEnreplacedy data, Header[] headers, String errorMessage) {
    clientExecute(method, path, data, headers, errorMessage, ReturnClientResponse.NO_RESPONSE, false);
}

19 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

/**
 * Creates a field on the server using the given Field object.
 *
 * @param field field object
 * @throws HttpConflict if there already is a field with the given name
 * @see <a href="https://www.pilosa.com/docs/api-reference/#index-index-name-frame-frame-name">Pilosa API Reference: Field</a>
 */
public void createField(Field field) {
    Span span = this.tracer.buildSpan("Client.CreateField").start();
    try {
        String path = String.format("/index/%s/field/%s", field.getIndex().getName(), field.getName());
        String body = field.getOptions().toString();
        ByteArrayEnreplacedy data = new ByteArrayEnreplacedy(body.getBytes(StandardCharsets.UTF_8));
        clientExecute("POST", path, data, null, "Error while creating field");
    } finally {
        span.finish();
    }
}

19 Source : HttpUriRequestConverter.java
with Apache License 2.0
from jerry-sc

private RequestBuilder addFormParams(RequestBuilder requestBuilder, Request request) {
    if (request.getRequestBody() != null) {
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(request.getRequestBody().getBody());
        enreplacedy.setContentType(request.getRequestBody().getContentType());
        requestBuilder.setEnreplacedy(enreplacedy);
    }
    return requestBuilder;
}

19 Source : AbstractHttpClient.java
with GNU General Public License v3.0
from iyangyuan

public SimpleResponse post(String url, byte[] bytes, HttpOptions options) {
    HttpPost request = new HttpPost(url);
    if (options == null) {
        options = new HttpOptions() {
        };
    }
    ByteArrayEnreplacedy enreplacedy = null;
    try {
        enreplacedy = new ByteArrayEnreplacedy(bytes, ContentType.APPLICATION_OCTET_STREAM);
    } catch (Exception e) {
        throw new SecurityException(e);
    }
    request.setEnreplacedy(enreplacedy);
    return sendRequest(request, options);
}

19 Source : RequestExecutor.java
with Apache License 2.0
from camunda

protected ByteArrayEnreplacedy serializeRequest(RequestDto dto) throws EngineClientException {
    byte[] serializedRequest = null;
    try {
        serializedRequest = objectMapper.writeValueAsBytes(dto);
    } catch (JsonProcessingException e) {
        throw LOG.exceptionWhileSerializingJsonObject(dto, e);
    }
    ByteArrayEnreplacedy byteArrayEnreplacedy = null;
    if (serializedRequest != null) {
        byteArrayEnreplacedy = new ByteArrayEnreplacedy(serializedRequest);
    }
    return byteArrayEnreplacedy;
}

19 Source : ByteArrayEntityBuilderProvider.java
with Apache License 2.0
from braveMind

/**
 * Created by jun
 * 17/6/8 下午3:07.
 * des:发送 requestBody
 */
public clreplaced ByteArrayEnreplacedyBuilderProvider implements HttpEnreplacedyProviderService<ByteArrayEnreplacedy> {

    private ByteArrayEnreplacedy httpEnreplacedy;

    public ByteArrayEnreplacedyBuilderProvider(String requestBody) {
        try {
            this.httpEnreplacedy = new ByteArrayEnreplacedy(requestBody.getBytes("UTF-8"));
            httpEnreplacedy.setContentType("application/json");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    @Override
    public ByteArrayEnreplacedy provider() {
        return this.httpEnreplacedy;
    }

    @Override
    public HttpEnreplacedy builder() {
        return this.httpEnreplacedy;
    }
}

18 Source : ApacheHttpRequestRecordReplayer.java
with Apache License 2.0
from vy

private static void addHttpRequestPayload(HttpRequestRecord record, HttpEnreplacedyEnclosingRequest request) {
    HttpRequestPayload payload = record.getPayload();
    byte[] payloadBytes = payload.getBytes();
    if (payloadBytes.length > 0) {
        ByteArrayEnreplacedy payloadEnreplacedy = new ByteArrayEnreplacedy(payloadBytes);
        request.setEnreplacedy(payloadEnreplacedy);
    }
}

18 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

// protected long[] translateKeys(Internal.TranslateKeysRequest request) throws IOException {
public long[] translateKeys(Internal.TranslateKeysRequest request) throws IOException {
    String path = "/internal/translate/keys";
    ByteArrayEnreplacedy body = new ByteArrayEnreplacedy(request.toByteArray());
    CloseableHttpResponse response = clientExecute("POST", path, body, protobufHeaders, "Error while posting translateKey", ReturnClientResponse.RAW_RESPONSE, false);
    HttpEnreplacedy enreplacedy = response.getEnreplacedy();
    if (enreplacedy != null) {
        InputStream src = enreplacedy.getContent();
        Internal.TranslateKeysResponse translateKeysResponse = Internal.TranslateKeysResponse.parseFrom(src);
        List<Long> values = translateKeysResponse.getIDsList();
        long[] result = new long[values.size()];
        int i = 0;
        for (Long v : values) {
            result[i++] = v.longValue();
        }
        return result;
    }
    throw new PilosaException("Server returned empty response");
}

18 Source : PilosaClient.java
with BSD 3-Clause "New" or "Revised" License
from pilosa

private CloseableHttpResponse clientExecute(final String method, final String path, final ByteArrayEnreplacedy data, Header[] headers, String errorMessage, ReturnClientResponse returnResponse, boolean useCoordinator) {
    if (this.client == null) {
        connect();
    }
    CloseableHttpResponse response = null;
    // try at most MAX_HOSTS non-failed hosts; protect against broken cluster.removeHost
    for (int i = 0; i < MAX_HOSTS; i++) {
        HttpRequestBase request = makeRequest(method, path, data, headers, useCoordinator);
        logger.debug("Request: {} {}", request.getMethod(), request.getURI());
        try {
            response = clientExecute(request, errorMessage, returnResponse);
            break;
        } catch (IOException ex) {
            if (useCoordinator) {
                logger.warn("Removed coordinator {} due to {}", this.coordinatorAddress, ex);
                this.coordinatorAddress = null;
            } else {
                this.cluster.removeHost(this.currentAddress);
                logger.warn("Removed {} from the cluster due to {}", this.currentAddress, ex);
                this.currentAddress = null;
            }
        }
    }
    if (response == null) {
        throw new PilosaException(String.format("Tried %s hosts, still failing", MAX_HOSTS));
    }
    return response;
}

18 Source : HttpServiceClient.java
with Apache License 2.0
from jd-tiger

/**
 * @param version: meta version
 * @param key:     zookeeper db key
 * @return
 * @throws Exception
 */
public Http.Response kill(long version, String key) throws Exception {
    LogUtils.debug.debug("kill on client ");
    byte[] req = Http.KillRequest.marshal(new Http.KillRequest(key, version));
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(req);
    String url = this.urlPre + "/kill";
    return execute(enreplacedy, url, bytes -> Http.Response.unmarshalJson(bytes), () -> Http.Response.FAILURE);
}

18 Source : HttpServiceAgent.java
with Apache License 2.0
from bubicn

/**
 * 创建请求;
 *
 * @return
 */
private HttpUriRequest buildRequest(ServiceRequest request) {
    ByteBuffer bodyBytes = null;
    if (request.getBody() != null) {
        // bodyStream = new ByteArrayInputStream(request.getBody().array());
        bodyBytes = request.getBody();
    }
    Properties reqParams = request.getRequestParams();
    switch(request.getHttpMethod()) {
        case GET:
            return new HttpGet(request.getUri());
        case POST:
            HttpPost httppost = new HttpPost(request.getUri());
            if (reqParams != null) {
                // 以 form 表单提交;
                Set<String> propNames = reqParams.stringPropertyNames();
                List<NameValuePair> formParams = new ArrayList<>();
                for (String propName : propNames) {
                    formParams.add(new BasicNameValuePair(propName, reqParams.getProperty(propName)));
                }
                UrlEncodedFormEnreplacedy formEnreplacedy = new UrlEncodedFormEnreplacedy(formParams, Consts.UTF_8);
                httppost.setEnreplacedy(formEnreplacedy);
                // 设置默认的 Content-Type;
                httppost.setHeader(formEnreplacedy.getContentType());
            }
            if (bodyBytes != null) {
                // 查询参数以 Stream body 方式提交;
                ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(bodyBytes.array());
                // HttpEnreplacedy streamEnreplacedy = new InputStreamEnreplacedy(bodyStream);
                httppost.setEnreplacedy(enreplacedy);
                // 设置默认的 Content-Type;
                httppost.setHeader(enreplacedy.getContentType());
            }
            return httppost;
        case PUT:
            HttpPut httpput = new HttpPut(request.getUri());
            if (reqParams != null) {
                // 以 form 表单提交;
                Set<String> propNames = reqParams.stringPropertyNames();
                List<NameValuePair> formParams = new ArrayList<>();
                for (String propName : propNames) {
                    formParams.add(new BasicNameValuePair(propName, reqParams.getProperty(propName)));
                }
                UrlEncodedFormEnreplacedy formEnreplacedy = new UrlEncodedFormEnreplacedy(formParams, Consts.UTF_8);
                httpput.setEnreplacedy(formEnreplacedy);
            }
            if (bodyBytes != null) {
                // 查询参数以 Stream body 方式提交;
                ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(bodyBytes.array());
                // HttpEnreplacedy streamEnreplacedy = new InputStreamEnreplacedy(bodyStream);
                httpput.setEnreplacedy(enreplacedy);
            }
            return httpput;
        case DELETE:
            // HttpDelete httpDelete = new HttpDelete(uri);
            LocalHttpDelete httpDelete = new LocalHttpDelete(request.getUri());
            // 查询参数以 delete body 方式提交
            if (bodyBytes != null) {
                ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(bodyBytes.array());
                // HttpEnreplacedy enreplacedy = new InputStreamEnreplacedy(bodyStream);
                httpDelete.setEnreplacedy(enreplacedy);
            }
            // HttpEnreplacedy enreplacedy = new InputStreamEnreplacedy(bodyStream);
            // httpDelete.setEnreplacedy(enreplacedy);
            return httpDelete;
        default:
            throw new UnsupportedOperationException("Unsupported http method '" + request.getHttpMethod() + "'!");
    }
}

18 Source : HttpClient.java
with Apache License 2.0
from aliyun

private ByteArrayEnreplacedy generateGZIPCompressEnreplacedy(String json) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzip = null;
    try {
        gzip = new GZIPOutputStream(baos);
        gzip.write(json.getBytes(DEFAULT_CHARSET));
    } catch (IOException e) {
        throw new HttpClientException(e);
    } finally {
        if (gzip != null) {
            try {
                gzip.close();
            } catch (IOException e) {
                throw new HttpClientException(e);
            }
        }
    }
    ByteArrayEnreplacedy byteEnreplacedy = new ByteArrayEnreplacedy(baos.toByteArray());
    byteEnreplacedy.setContentType("application/json");
    byteEnreplacedy.setContentEncoding("gzip");
    return byteEnreplacedy;
}

17 Source : ManualClosingApacheHttpClient43Engine.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Build the HttpEnreplacedy to be sent to the Service as part of (POST) request. Creates a off-memory
 * {@link FileExposingFileEnreplacedy} or a regular in-memory {@link ByteArrayEnreplacedy} depending on if the request
 * OutputStream fit into memory when built by calling.
 *
 * @param request -
 * @return - the built HttpEnreplacedy
 * @throws IOException -
 */
protected HttpEnreplacedy buildEnreplacedy(final ClientInvocation request) throws IOException {
    AbstractHttpEnreplacedy enreplacedyToBuild = null;
    DeferredFileOutputStream memoryManagedOutStream = writeRequestBodyToOutputStream(request);
    if (memoryManagedOutStream.isInMemory()) {
        ByteArrayEnreplacedy enreplacedyToBuildByteArray = new ByteArrayEnreplacedy(memoryManagedOutStream.getData());
        enreplacedyToBuildByteArray.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString()));
        enreplacedyToBuild = enreplacedyToBuildByteArray;
    } else {
        enreplacedyToBuild = new FileExposingFileEnreplacedy(memoryManagedOutStream.getFile(), request.getHeaders().getMediaType().toString());
    }
    if (request.isChunked()) {
        enreplacedyToBuild.setChunked(true);
    }
    return (HttpEnreplacedy) enreplacedyToBuild;
}

17 Source : HttpHelper.java
with GNU General Public License v3.0
from liaozhoubei

/**
 * post请求,获取返回字符串内容
 */
public static void post(String url, byte[] bytes, HttpCallbackListener httpCallbackListener) {
    HttpPost httpPost = new HttpPost(url);
    ByteArrayEnreplacedy byteArrayEnreplacedy = new ByteArrayEnreplacedy(bytes);
    httpPost.setEnreplacedy(byteArrayEnreplacedy);
    execute(url, httpPost, httpCallbackListener);
}

17 Source : HttpDownloadHandler.java
with Apache License 2.0
from heyingcai

private RequestBuilder addFormParams(RequestBuilder requestBuilder, Seed seed) {
    if (seed.getRequestBody() != null) {
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(seed.getRequestBody().getBody());
        enreplacedy.setContentType(seed.getRequestBody().getContentType());
        requestBuilder.setEnreplacedy(enreplacedy);
    }
    return requestBuilder;
}

17 Source : RequestExecutor.java
with Apache License 2.0
from camunda

protected <T> T postRequest(String resourceUrl, RequestDto requestDto, Clreplaced<T> responseClreplaced) throws EngineClientException {
    ByteArrayEnreplacedy serializedRequest = serializeRequest(requestDto);
    HttpUriRequest httpRequest = RequestBuilder.post(resourceUrl).addHeader(HEADER_USER_AGENT).addHeader(HEADER_CONTENT_TYPE_JSON).setEnreplacedy(serializedRequest).build();
    return executeRequest(httpRequest, responseClreplaced);
}

16 Source : ModelsActionIT.java
with Apache License 2.0
from zentity-io

@Test
public void testCannotCreateInvalidEnreplacedyType() throws Exception {
    destroyTestResources();
    ByteArrayEnreplacedy testEnreplacedyModelA = new ByteArrayEnreplacedy(readFile("TestEnreplacedyModelA.json"), ContentType.APPLICATION_JSON);
    Request request = new Request("POST", "_zenreplacedy/models/_anInvalidType");
    request.setEnreplacedy(testEnreplacedyModelA);
    try {
        client().performRequest(request);
        fail("expected failure");
    } catch (ResponseException ex) {
        Response response = ex.getResponse();
        replacedertEquals(400, response.getStatusLine().getStatusCode());
        JsonNode json = Json.MAPPER.readTree(response.getEnreplacedy().getContent());
        replacedertEquals(400, json.get("status").asInt());
        replacedertTrue("response has error field", json.has("error"));
        JsonNode errorJson = json.get("error");
        replacedertTrue("error has type field", errorJson.has("type"));
        replacedertEquals("validation_exception", errorJson.get("type").textValue());
        replacedertTrue("error has reason field", errorJson.has("reason"));
        replacedertTrue(errorJson.get("reason").textValue().contains("Invalid name [_anInvalidType]"));
    } finally {
        destroyTestResources();
    }
}

16 Source : HttpComponentsHttpInvokerRequestExecutor.java
with MIT License
from Vip-Augus

/**
 * Set the given serialized remote invocation as request body.
 * <p>The default implementation simply sets the serialized invocation as the
 * HttpPost's request body. This can be overridden, for example, to write a
 * specific encoding and to potentially set appropriate HTTP request headers.
 * @param config the HTTP invoker configuration that specifies the target service
 * @param httpPost the HttpPost to set the request body on
 * @param baos the ByteArrayOutputStream that contains the serialized
 * RemoteInvocation object
 * @throws java.io.IOException if thrown by I/O methods
 */
protected void setRequestBody(HttpInvokerClientConfiguration config, HttpPost httpPost, ByteArrayOutputStream baos) throws IOException {
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(baos.toByteArray());
    enreplacedy.setContentType(getContentType());
    httpPost.setEnreplacedy(enreplacedy);
}

16 Source : HttpTransport.java
with Apache License 2.0
from Nextdoor

protected HttpResponse sendBatchCompressed(HttpPost httpPost, byte[] raw) throws TransportException {
    /*
     * Write gzip data to Enreplacedy and set content encoding to gzip
     */
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(raw, ContentType.DEFAULT_BINARY);
    enreplacedy.setContentEncoding("gzip");
    httpPost.addHeader(new BasicHeader("Accept-Encoding", "gzip"));
    httpPost.setEnreplacedy(enreplacedy);
    /*
     * Make call
     */
    HttpResponse resp = null;
    try {
        resp = this.client.execute(httpPost);
    } catch (IOException e) {
        throw new TransportException("failed to make call", e);
    }
    return resp;
}

16 Source : BaseApacheHttpClient.java
with Apache License 2.0
from i-Cell-Mobilsoft-Open-Source

/**
 * Send http PUT request.
 *
 * @param url
 *            URL
 * @param contentType
 *            content type
 * @param request
 *            http request
 * @return {@link HttpResponse}
 * @throws BaseException
 *             if any exception occurs
 */
public HttpResponse sendClientBasePut(String url, ContentType contentType, byte[] request) throws BaseException {
    HttpPut put = new HttpPut(url);
    // HttpClient client = new ContentEncodingHttpClient();
    RequestConfig config = createRequestConfig().build();
    CloseableHttpClient client = createHttpClientBuilder(config).build();
    // SSL lekezeles
    handleSSL(client, put.getURI());
    // add header
    put.setHeader(HttpHeaders.CONTENT_TYPE, contentType.getMimeType());
    try {
        ByteArrayEnreplacedy byteEnreplacedyRequest = new ByteArrayEnreplacedy(request);
        put.setEnreplacedy(byteEnreplacedyRequest);
        // modositasi lehetoseg
        beforePut(put);
        // kiloggoljuk a requestet
        logRequest(put, org.apache.commons.lang3.StringUtils.abbreviate(new String(request), 80));
        // kuldjuk
        return client.execute(put);
    } catch (ClientProtocolException e) {
        throw new TechnicalException(CoffeeFaultType.OPERATION_FAILED, "HTTP protocol exception: " + e.getLocalizedMessage(), e);
    } catch (IOException e) {
        throw new TechnicalException(CoffeeFaultType.OPERATION_FAILED, "IOException in call: " + e.getLocalizedMessage(), e);
    }
}

15 Source : Http1ServerTest.java
with Apache License 2.0
from sofastack

@Test
public void testHttp1Json() throws Exception {
    // 只有1个线程 执行
    ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(12300).setProtocol(RpcConstants.PROTOCOL_TYPE_HTTP).setDaemon(true);
    // 发布一个服务,每个请求要执行1秒
    ProviderConfig<HttpService> providerConfig = new ProviderConfig<HttpService>().setInterfaceId(HttpService.clreplaced.getName()).setRef(new HttpServiceImpl()).setApplication(new ApplicationConfig().setAppName("serverApp")).setServer(serverConfig).setUniqueId("uuu").setRegister(false);
    providerConfig.export();
    HttpClient httpclient = HttpClientBuilder.create().build();
    {
        // POST jackson不存在的接口
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService/adasdad";
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader(RemotingConstants.HEAD_SERIALIZE_TYPE, "json");
        ExampleObj obj = new ExampleObj();
        obj.setId(1);
        obj.setName("xxx");
        byte[] bytes = mapper.writeValueAsBytes(obj);
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(bytes, ContentType.create("application/json"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(404, httpResponse.getStatusLine().getStatusCode());
        replacedert.replacedertNotNull(getStringContent(httpResponse));
    }
    {
        // POST 不存在的方法
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService:uuu/adasdad";
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader(RemotingConstants.HEAD_SERIALIZE_TYPE, "json");
        ExampleObj obj = new ExampleObj();
        obj.setId(1);
        obj.setName("xxx");
        byte[] bytes = mapper.writeValueAsBytes(obj);
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(bytes, ContentType.create("application/json"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(404, httpResponse.getStatusLine().getStatusCode());
        replacedert.replacedertNotNull(getStringContent(httpResponse));
    }
    {
        // POST 不传 HEAD_SERIALIZE_TYPE
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService:uuu/object";
        HttpPost httpPost = new HttpPost(url);
        ExampleObj obj = new ExampleObj();
        obj.setId(1);
        obj.setName("xxx");
        byte[] bytes = mapper.writeValueAsBytes(obj);
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(bytes, ContentType.create("application/json"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(200, httpResponse.getStatusLine().getStatusCode());
        byte[] data = EnreplacedyUtils.toByteArray(httpResponse.getEnreplacedy());
        ExampleObj result = mapper.readValue(data, ExampleObj.clreplaced);
        replacedert.replacedertEquals("xxxxx", result.getName());
    }
    {
        // POST 正常请求
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService:uuu/object";
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader(RemotingConstants.HEAD_SERIALIZE_TYPE, "json");
        ExampleObj obj = new ExampleObj();
        obj.setId(1);
        obj.setName("xxx");
        byte[] bytes = mapper.writeValueAsBytes(obj);
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(bytes, ContentType.create("application/json"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(200, httpResponse.getStatusLine().getStatusCode());
        byte[] data = EnreplacedyUtils.toByteArray(httpResponse.getEnreplacedy());
        ExampleObj result = mapper.readValue(data, ExampleObj.clreplaced);
        replacedert.replacedertEquals("xxxxx", result.getName());
    }
}

15 Source : HttpWarmer.java
with BSD 3-Clause "New" or "Revised" License
from salesforce

/**
 * Executes an {@link HttpRequest} while swallowing all exceptions.
 */
protected void doNext() throws Exception {
    final HttpWarmerMethods warmerMethods = HttpWarmerMethods.valueOf(this.method.toUpperCase());
    for (final String url : urls) {
        try {
            logger.debug(LOGGER_PREFIX + "calling {} method on url {}", this.method, this.urls);
            final HttpUriRequest httpRequest = warmerMethods.run(url);
            // add body if present
            if (!Strings.isNullOrEmpty(this.body)) {
                final ByteArrayEnreplacedy body = new ByteArrayEnreplacedy(this.body.getBytes());
                ((HttpEnreplacedyEnclosingRequestBase) httpRequest).setEnreplacedy(body);
            }
            // add headers
            this.headers.forEach(httpRequest::addHeader);
            // make the call and follow redirects
            final HttpResponse response = this.client.execute(httpRequest);
            logger.debug(LOGGER_PREFIX + "got response code {} from url {}", response.getStatusLine(), url);
        } catch (Exception e) {
            logger.warn(LOGGER_PREFIX + "failed to call url: {} with error message: {}", url, e.getMessage());
            throw e;
        }
    }
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests receiving a StreamingOutput with a non-standard content-type.
 */
@Test
public void testStreamingAcceptMatchesReturnedContentType() throws Exception {
    HttpPut put = new HttpPut(strmTestUri);
    byte[] barr = new byte[100000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(barr);
    enreplacedy.setContentType("any/type");
    put.setEnreplacedy(enreplacedy);
    HttpResponse resp = httpClient.execute(put);
    replacedertEquals(204, resp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(strmTestUri);
    get.addHeader("Accept", "mytype/subtype");
    resp = httpClient.execute(get);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[barr.length];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("mytype/subtype", resp.getFirstHeader("Content-Type").getValue());
    Header contentLengthHeader = resp.getFirstHeader("Content-Length");
    replacedertNull(contentLengthHeader == null ? "null" : contentLengthHeader.getValue(), contentLengthHeader);
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests receiving an empty byte array.
 */
@Test
public void testByteArrayAcceptMatchesReturnContentType() throws Exception {
    HttpPut put = new HttpPut(byteArrayTestUri);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy putReq = new ByteArrayEnreplacedy(barr);
    putReq.setContentType("any/type");
    put.setEnreplacedy(putReq);
    HttpResponse putResp = httpClient.execute(put);
    replacedertEquals(204, putResp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(byteArrayTestUri);
    get.addHeader("Accept", "mytype/subtype");
    HttpResponse getResp = httpClient.execute(get);
    replacedertEquals(200, getResp.getStatusLine().getStatusCode());
    InputStream is = getResp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[1000];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("mytype/subtype", getResp.getFirstHeader("Content-Type").getValue());
    replacedertEquals(barr.length, Integer.valueOf(getResp.getFirstHeader("Content-Length").getValue()).intValue());
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests putting and then getting a byte array.
 *
 * @throws HttpException
 * @throws IOException
 */
@Test
public void testPutInputStream() throws HttpException, IOException {
    HttpPut put = new HttpPut(isTestUri);
    byte[] barr = new byte[50000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy putReq = new ByteArrayEnreplacedy(barr);
    putReq.setContentType("bytes/array");
    put.setEnreplacedy(putReq);
    HttpResponse resp = httpClient.execute(put);
    replacedertEquals(204, resp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(isTestUri);
    resp = httpClient.execute(get);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[barr.length];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    String contentType = (resp.getFirstHeader("Content-Type") == null) ? null : resp.getFirstHeader("Content-Type").getValue();
    replacedertNotNull(contentType);
    // Original test expects Content-Length header to be null, too
    replacedertNull(resp.getFirstHeader("Content-Length"));
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests receiving a DataSource with any media type.
 */
@Test
public void testDSAcceptMatchesReturnContentType() throws Exception {
    HttpPut put = new HttpPut(dsTestURI);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy putReq = new ByteArrayEnreplacedy(barr);
    putReq.setContentType("any/type");
    put.setEnreplacedy(putReq);
    HttpResponse putResp = httpClient.execute(put);
    replacedertEquals(204, putResp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(dsTestURI);
    get.addHeader("Accept", "mytype/subtype");
    HttpResponse getResp = httpClient.execute(get);
    replacedertEquals(200, getResp.getStatusLine().getStatusCode());
    InputStream is = getResp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[1000];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("mytype/subtype", getResp.getFirstHeader("Content-Type").getValue());
    replacedertEquals("1000", getResp.getFirstHeader("Content-Length").getValue());
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests putting and then getting a DataSource enreplacedy.
 */
@Test
public void testPutDataSource() throws Exception {
    HttpPut put = new HttpPut(dsTestURI);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy putReq = new ByteArrayEnreplacedy(barr);
    putReq.setContentType("bytes/array");
    put.setEnreplacedy(putReq);
    HttpResponse putResp = httpClient.execute(put);
    replacedertEquals(204, putResp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(dsTestURI);
    HttpResponse getResp = httpClient.execute(get);
    replacedertEquals(200, getResp.getStatusLine().getStatusCode());
    InputStream is = getResp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[1000];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    String contentType = getResp.getFirstHeader("Content-Type").getValue();
    String contentLength = getResp.getFirstHeader("Content-Length").getValue();
    // ccording to spec,default content-type for response is application/octet-stream
    replacedertEquals("application/octet-stream", contentType);
    replacedertEquals("1000", contentLength);
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests putting and then getting a byte array.
 */
@Test
public void testPutByteArray() throws Exception {
    HttpPut put = new HttpPut(byteArrayTestUri);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy postReq = new ByteArrayEnreplacedy(barr);
    postReq.setContentType("bytes/array");
    put.setEnreplacedy(postReq);
    HttpResponse resp = httpClient.execute(put);
    replacedertEquals(204, resp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(byteArrayTestUri);
    HttpResponse getResp = httpClient.execute(get);
    replacedertEquals(200, getResp.getStatusLine().getStatusCode());
    InputStream is = getResp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[1000];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    String contentType = (getResp.getFirstHeader("Content-Type") == null) ? null : getResp.getFirstHeader("Content-Type").getValue();
    int length = Integer.valueOf(getResp.getFirstHeader("Content-Length").getValue()).intValue();
    replacedertNotNull("text/xml", contentType);
    replacedertEquals(barr.length, length);
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests putting and then getting a StreamingOutput.
 */
@Test
public void testPutStreamngOutput() throws Exception {
    HttpPut put = new HttpPut(strmTestUri);
    byte[] barr = new byte[100000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(barr);
    enreplacedy.setContentType("bytes/array");
    put.setEnreplacedy(enreplacedy);
    HttpResponse resp = httpClient.execute(put);
    replacedertEquals(204, resp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(strmTestUri);
    resp = httpClient.execute(get);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[barr.length];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    String contentType = (resp.getFirstHeader("Content-Type") == null) ? null : resp.getFirstHeader("Content-Type").getValue();
    replacedertEquals("application/octet-stream", contentType);
    Header contentLengthHeader = resp.getFirstHeader("Content-Length");
    replacedertNull(contentLengthHeader == null ? "null" : contentLengthHeader.getValue(), contentLengthHeader);
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests receiving an empty byte array.
 */
@Test
public void testFileAcceptMatchesReturnContentType() throws Exception {
    HttpPut put = new HttpPut(fileTestUri);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy putReq = new ByteArrayEnreplacedy(barr);
    putReq.setContentType("any/type");
    put.setEnreplacedy(putReq);
    HttpResponse putResp = httpClient.execute(put);
    replacedertEquals(204, putResp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(fileTestUri);
    get.addHeader("Accept", "mytype/subtype");
    HttpResponse resp = httpClient.execute(get);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[1000];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("mytype/subtype", resp.getFirstHeader("Content-Type").getValue());
    replacedertEquals(barr.length, Integer.valueOf(resp.getFirstHeader("Content-Length").getValue()).intValue());
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests receiving an empty byte array.
 */
@Test
public void testISAcceptMatchesReturnContentType() throws Exception {
    HttpPut put = new HttpPut(isTestUri);
    byte[] barr = new byte[100000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy putReq = new ByteArrayEnreplacedy(barr);
    putReq.setContentType("any/type");
    put.setEnreplacedy(putReq);
    HttpResponse resp = httpClient.execute(put);
    replacedertEquals(204, resp.getStatusLine().getStatusCode());
    HttpGet get = new HttpGet(isTestUri);
    get.addHeader("Accept", "mytype/subtype");
    resp = httpClient.execute(get);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[barr.length];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("mytype/subtype", resp.getFirstHeader("Content-Type").getValue());
    // Original test expects Content-Length header to be null, too
    replacedertNull(resp.getFirstHeader("Content-Length"));
}

15 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Verify that we can send a DataSource and receive a DataSource. The 'POST'
 * method on the resource we are calling is a simple echo.
 */
@Test
public void testPOSTDataSource() throws Exception {
    String postUri = getStandardTestURI() + "/dstest";
    HttpPost post = new HttpPost(postUri);
    String input = "This is some test input";
    ByteArrayEnreplacedy postReq = new ByteArrayEnreplacedy(input.getBytes());
    postReq.setContentType("application/datasource");
    post.setEnreplacedy(postReq);
    HttpResponse resp = httpClient.execute(post);
    // just use our provider to read the response (original comment)
    // But why go to this much trouble???
    DataSourceProvider provider = new DataSourceProvider();
    DataSource returnedData = provider.readFrom(DataSource.clreplaced, null, null, new MediaType("application", "datasource"), null, resp.getEnreplacedy().getContent());
    replacedertNotNull(returnedData);
    replacedertNotNull(returnedData.getInputStream());
    byte[] responseBytes = new byte[input.getBytes().length];
    returnedData.getInputStream().read(responseBytes);
    replacedertNotNull(responseBytes);
    String response = new String(responseBytes);
    replacedertEquals("This is some test input", response);
}

15 Source : BaseApacheHttpClient.java
with Apache License 2.0
from i-Cell-Mobilsoft-Open-Source

/**
 * Send http POST request.
 *
 * @param url
 *            URL
 * @param contentType
 *            content type
 * @param request
 *            http request
 * @return {@link HttpResponse}
 * @throws BaseException
 *             if any exception occurs
 */
public HttpResponse sendClientBasePost(String url, ContentType contentType, byte[] request) throws BaseException {
    HttpPost post = new HttpPost(url);
    // HttpClient client = new ContentEncodingHttpClient();
    RequestConfig config = createRequestConfig().build();
    CloseableHttpClient client = createHttpClientBuilder(config).build();
    // SSL lekezeles
    handleSSL(client, post.getURI());
    // add header
    post.setHeader(HttpHeaders.CONTENT_TYPE, contentType.getMimeType());
    try {
        ByteArrayEnreplacedy byteEnreplacedyRequest = new ByteArrayEnreplacedy(request);
        post.setEnreplacedy(byteEnreplacedyRequest);
        // modositasi lehetoseg
        beforePost(post);
        // kiloggoljuk a requestet
        logRequest(post, org.apache.commons.lang3.StringUtils.abbreviate(new String(request), 80));
        // kuldjuk
        return client.execute(post);
    } catch (ClientProtocolException e) {
        throw new TechnicalException(CoffeeFaultType.OPERATION_FAILED, "HTTP protocol exception: " + e.getLocalizedMessage(), e);
    } catch (IOException e) {
        throw new TechnicalException(CoffeeFaultType.OPERATION_FAILED, "IOException in call: " + e.getLocalizedMessage(), e);
    }
}

14 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests a resource method invoked with a ByteArrayInputStream as a
 * parameter. This should fail with a 500 since the reader has no way to
 * necessarily wrap it to the type.
 */
// TODO: this should be workable after we bring back CXF 5846
// @Test
public void testInputStreamImplementation() throws Exception {
    String uri = isTestUri + "/subclreplacedes/shouldfail";
    HttpPost post = new HttpPost(uri);
    byte[] barr = new byte[100000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy postReq = new ByteArrayEnreplacedy(barr);
    postReq.setContentType("any/type");
    post.setEnreplacedy(postReq);
    HttpResponse resp = httpClient.execute(post);
    // according to spec, we can not put a subclreplaced or implementation clreplaced, so we need return 500
    replacedertEquals(500, resp.getStatusLine().getStatusCode());
}

14 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests a resource method invoked with a SAXSource as a parameter. This
 * should fail with a 500 since the reader has no way to necessarily wrap it
 * to the type.
 */
// TODO: this should be workable after we bring back CXF 5846
// @Test
public void testSourceSubclreplacedImplementation() throws Exception {
    String uri = srcTestUri + "/subclreplacedes/shouldfail";
    HttpPost post = new HttpPost(uri);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(barr);
    enreplacedy.setContentType("application/xml");
    post.setEnreplacedy(enreplacedy);
    HttpResponse resp = httpClient.execute(post);
    replacedertEquals(500, resp.getStatusLine().getStatusCode());
}

14 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests a resource method invoked with a BufferedReader as a parameter.
 * This should fail with a 415 since the reader has no way to necessarily
 * wrap it to the type.
 */
// TODO: this should be workable after we bring back CXF 5846
// @Test
public void testReaderInputStreamImplementation() throws Exception {
    HttpPost post = new HttpPost(readerTestUri + "/subclreplacedes/shouldfail");
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(barr);
    enreplacedy.setContentType("any/type");
    post.setEnreplacedy(enreplacedy);
    HttpResponse resp = httpClient.execute(post);
    // according to spec, we can not put a subclreplaced or implementation clreplaced, so we need return 500
    replacedertEquals(500, resp.getStatusLine().getStatusCode());
}

14 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests posting to a DataSource subclreplaced. This should result in a 500
 * error.
 */
// @Test
// TODO
public void testPostDataSourceSubclreplaced() throws Exception {
    String postUri = dsTestURI + "/subclreplaced/should/fail";
    HttpPost post = new HttpPost(postUri);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy postReq = new ByteArrayEnreplacedy(barr);
    postReq.setContentType("text/plain");
    post.setEnreplacedy(postReq);
    post.addHeader("Accept", "text/plain");
    HttpResponse resp = httpClient.execute(post);
    // This is supported via CXF-5835
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
}

14 Source : ByteArrayPost.java
with Apache License 2.0
from landy8530

@Override
HttpRequestBase createRequest(String url) throws IOException {
    HttpPost post = new HttpPost(url);
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(this.bytes);
    enreplacedy.setContentType("binary/octet-stream");
    enreplacedy.setChunked(this.chunked);
    post.setEnreplacedy(enreplacedy);
    return post;
}

14 Source : ServiceCombClient.java
with Apache License 2.0
from huaweicloud

public boolean registerSchema(String microserviceId, String schemaId, String schemaContent) throws RemoteOperationException {
    Response response = null;
    SchemaRequest request = new SchemaRequest();
    request.setSchema(schemaContent);
    request.setSummary(calcSchemaSummary(schemaContent));
    try {
        String formatUrl = buildURI("/registry/microservices/" + microserviceId + "/schemas/" + schemaId);
        byte[] body = JsonUtils.OBJ_MAPPER.writeValueAsBytes(request);
        ByteArrayEnreplacedy byteArrayEnreplacedy = new ByteArrayEnreplacedy(body);
        response = httpTransport.sendPutRequest(formatUrl, byteArrayEnreplacedy);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            LOGGER.info("register schema {}/{} success.", microserviceId, schemaId);
            return true;
        }
        LOGGER.error("Register schema {}/{} failed, code:{} , msg:{} ", microserviceId, schemaId, response.getStatusCode(), response.getContent());
        return false;
    } catch (JsonProcessingException e) {
        LOGGER.error("registerSchema serialization failed : {}", e.getMessage());
    } catch (URISyntaxException e) {
        throw new RemoteOperationException("build url failed.", e);
    } catch (RemoteServerUnavailableException e) {
        throw new RemoteOperationException("read response failed. ", e);
    }
    return false;
}

13 Source : Http1ServerTest.java
with Apache License 2.0
from sofastack

@Test
public void testHttp1Protobuf() throws Exception {
    // 只有1个线程 执行
    ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(12300).setProtocol(RpcConstants.PROTOCOL_TYPE_HTTP).setDaemon(true);
    // 发布一个服务,每个请求要执行1秒
    ProviderConfig<HttpService> providerConfig = new ProviderConfig<HttpService>().setInterfaceId(HttpService.clreplaced.getName()).setRef(new HttpServiceImpl()).setApplication(new ApplicationConfig().setAppName("serverApp")).setServer(serverConfig).setUniqueId("uuu").setRegister(false);
    providerConfig.export();
    HttpClient httpclient = HttpClientBuilder.create().build();
    {
        // POST 不存在的接口
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService/adasdad";
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader(RemotingConstants.HEAD_SERIALIZE_TYPE, "protobuf");
        Ecreplacedquest request = Ecreplacedquest.newBuilder().setGroup(Group.A).setName("xxx").build();
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(request.toByteArray(), ContentType.create("application/protobuf"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(404, httpResponse.getStatusLine().getStatusCode());
        replacedert.replacedertNotNull(getStringContent(httpResponse));
    }
    {
        // POST 不存在的方法
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService:uuu/adasdad";
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader(RemotingConstants.HEAD_SERIALIZE_TYPE, "protobuf");
        Ecreplacedquest request = Ecreplacedquest.newBuilder().setGroup(Group.A).setName("xxx").build();
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(request.toByteArray(), ContentType.create("application/protobuf"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(404, httpResponse.getStatusLine().getStatusCode());
        replacedert.replacedertNotNull(getStringContent(httpResponse));
    }
    {
        // POST 不传 HEAD_SERIALIZE_TYPE
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService:uuu/echoPb";
        HttpPost httpPost = new HttpPost(url);
        Ecreplacedquest request = Ecreplacedquest.newBuilder().setGroup(Group.A).setName("xxx").build();
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(request.toByteArray(), ContentType.create("application/protobuf"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(200, httpResponse.getStatusLine().getStatusCode());
        byte[] data = EnreplacedyUtils.toByteArray(httpResponse.getEnreplacedy());
        Ecreplacedsponse response = Ecreplacedsponse.parseFrom(data);
        replacedert.replacedertEquals("helloxxx", response.getMessage());
    }
    {
        // POST 正常请求
        String url = "http://127.0.0.1:12300/com.alipay.sofa.rpc.server.http.HttpService:uuu/echoPb";
        HttpPost httpPost = new HttpPost(url);
        Ecreplacedquest request = Ecreplacedquest.newBuilder().setGroup(Group.A).setName("xxx").build();
        httpPost.setHeader(RemotingConstants.HEAD_SERIALIZE_TYPE, "protobuf");
        ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(request.toByteArray(), ContentType.create("application/protobuf"));
        httpPost.setEnreplacedy(enreplacedy);
        HttpResponse httpResponse = httpclient.execute(httpPost);
        replacedert.replacedertEquals(200, httpResponse.getStatusLine().getStatusCode());
        byte[] data = EnreplacedyUtils.toByteArray(httpResponse.getEnreplacedy());
        Ecreplacedsponse response = Ecreplacedsponse.parseFrom(data);
        replacedert.replacedertEquals("helloxxx", response.getMessage());
    }
}

13 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests posting a byte array.
 */
@Test
public void testPostByteArray() throws Exception {
    HttpPost post = new HttpPost(byteArrayTestUri);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    post.addHeader(new BasicHeader("Accept", "text/plain"));
    ByteArrayEnreplacedy postReq = new ByteArrayEnreplacedy(barr);
    postReq.setContentType("text/plain");
    post.setEnreplacedy(postReq);
    HttpResponse resp = httpClient.execute(post);
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[1000];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    replacedertEquals("text/plain", resp.getFirstHeader("Content-Type").getValue());
    replacedertEquals(barr.length, Integer.valueOf(resp.getFirstHeader("Content-Length").getValue()).intValue());
}

13 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests posting to an InputStream
 */
@Test
public void testPostInputStream() throws Exception {
    HttpPost post = new HttpPost(isTestUri);
    byte[] barr = new byte[50000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy postReq = new ByteArrayEnreplacedy(barr);
    postReq.setContentType("text/plain");
    post.setEnreplacedy(postReq);
    post.addHeader("Accept", "text/plain");
    HttpResponse resp = httpClient.execute(post);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[barr.length];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("text/plain", resp.getFirstHeader("Content-Type").getValue());
    // Original test expects Content-Length header to be null, too
    replacedertNull(resp.getFirstHeader("Content-Length"));
}

13 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests posting to a DataSource enreplacedy parameter.
 */
@Test
public void testPostDataSource() throws Exception {
    HttpPost post = new HttpPost(dsTestURI);
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy postReq = new ByteArrayEnreplacedy(barr);
    postReq.setContentType("text/plain");
    post.setEnreplacedy(postReq);
    post.addHeader("Accept", "text/plain");
    HttpResponse resp = httpClient.execute(post);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[1000];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("text/plain", resp.getFirstHeader("Content-Type").getValue());
    replacedertEquals("1000", resp.getFirstHeader("Content-Length").getValue());
}

13 Source : StandardProvidersTest.java
with Eclipse Public License 1.0
from OpenLiberty

/**
 * Tests posting to a StreamingOutput and then returning StreamingOutput.
 */
@Test
public void testPostStreamingOutput() throws Exception {
    HttpPost post = new HttpPost(strmTestUri);
    byte[] barr = new byte[50000];
    Random r = new Random();
    r.nextBytes(barr);
    ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(barr);
    enreplacedy.setContentType("text/plain");
    post.setEnreplacedy(enreplacedy);
    post.addHeader("Accept", "text/plain");
    HttpResponse resp = httpClient.execute(post);
    replacedertEquals(200, resp.getStatusLine().getStatusCode());
    InputStream is = resp.getEnreplacedy().getContent();
    byte[] receivedBArr = new byte[barr.length];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(receivedBArr);
    int checkEOF = dis.read();
    replacedertEquals(-1, checkEOF);
    for (int c = 0; c < barr.length; ++c) {
        replacedertEquals(barr[c], receivedBArr[c]);
    }
    replacedertEquals("text/plain", resp.getFirstHeader("Content-Type").getValue());
    Header contentLengthHeader = resp.getFirstHeader("Content-Length");
    replacedertNull(contentLengthHeader == null ? "null" : contentLengthHeader.getValue(), contentLengthHeader);
}

See More Examples