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


Java ClientInvocation類代碼示例

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


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

示例1: loadHttpMethod

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
protected void loadHttpMethod(final ClientInvocation request, HttpRequestBase httpMethod)
    throws Exception {
  if (request.getEntity() != null) {
    if (httpMethod instanceof HttpGet) {
      throw new ProcessingException("A GET request cannot have a body.");
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    request.getDelegatingOutputStream().setDelegate(baos);
    try {
      HttpEntity entity = buildEntity(request);
      HttpPost post = (HttpPost) httpMethod;
      commitHeaders(request, httpMethod);
      post.setEntity(entity);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  } else // no body
  {
    commitHeaders(request, httpMethod);
  }
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:23,代碼來源:ApacheHttpClient4Dot3Engine.java

示例2: buildEntity

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
/**
 * Build the HttpEntity to be sent to the Service as part of (POST) request. Creates a off-memory
 * {@link FileExposingFileEntity} or a regular in-memory {@link ByteArrayEntity} depending on if the request
 * OutputStream fit into memory when built by calling.
 *
 * @param request -
 * @return - the built HttpEntity
 * @throws IOException -
 */
protected HttpEntity buildEntity(final ClientInvocation request) throws IOException {
  HttpEntity entityToBuild = null;
  DeferredFileOutputStream memoryManagedOutStream = writeRequestBodyToOutputStream(request);

  if (memoryManagedOutStream.isInMemory()) {
    ByteArrayEntity entityToBuildByteArray =
        new ByteArrayEntity(memoryManagedOutStream.getData());
    entityToBuildByteArray.setContentType(
        new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString()));
    entityToBuild = entityToBuildByteArray;
  } else {
    File requestBodyFile = memoryManagedOutStream.getFile();
    requestBodyFile.deleteOnExit();
    entityToBuild = new FileExposingFileEntity(
        memoryManagedOutStream.getFile(), request.getHeaders().getMediaType().toString());
  }

  return entityToBuild;
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:29,代碼來源:ApacheHttpClient4Dot3Engine.java

示例3: createRequest

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
private MockHttpRequest createRequest(ClientInvocation request) {
  MockHttpRequest mockRequest =
      MockHttpRequest.create(request.getMethod(), request.getUri(), baseUri);

  if (request.getEntity() != null) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    request.getDelegatingOutputStream().setDelegate(baos);
    try {
      request.writeRequestBody(request.getEntityStream());
      baos.close();
    } catch (IOException ioe) {
      throw new RuntimeException(ioe);
    }
    mockRequest.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
  }

  MultivaluedMap<String, String> requestHeaders = request.getHeaders().asMap();
  mockRequest.getMutableHeaders().putAll(requestHeaders);
  copyCookies(mockRequest, requestHeaders);

  return mockRequest;
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:23,代碼來源:InProcessClientHttpEngine.java

示例4: commitHeaders

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
protected void commitHeaders(ClientInvocation request, HttpRequestBase httpMethod) {
  MultivaluedMap<String, String> headers = request.getHeaders().asMap();
  for (Map.Entry<String, List<String>> header : headers.entrySet()) {
    List<String> values = header.getValue();
    for (String value : values) {
      //               System.out.println(String.format("setting %s = %s", header.getKey(), value));
      httpMethod.addHeader(header.getKey(), value);
    }
  }
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:11,代碼來源:ApacheHttpClient4Dot3Engine.java

示例5: writeRequestBodyToOutputStream

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
/**
 * Creates the request OutputStream, to be sent to the end Service invoked, as a
 * <a href="http://commons.apache.org/io/api-release/org/apache/commons/io/output/DeferredFileOutputStream.html"
 * >DeferredFileOutputStream</a>.
 *
 *
 * @param request -
 * @return - DeferredFileOutputStream with the ClientRequest written out per HTTP specification.
 * @throws IOException -
 */
private DeferredFileOutputStream writeRequestBodyToOutputStream(final ClientInvocation request)
    throws IOException {
  DeferredFileOutputStream memoryManagedOutStream =
      new DeferredFileOutputStream(
          this.fileUploadInMemoryThresholdLimit * getMemoryUnitMultiplier(),
          getTempfilePrefix(), ".tmp", this.fileUploadTempFileDir);
  request.getDelegatingOutputStream().setDelegate(memoryManagedOutStream);
  request.writeRequestBody(request.getEntityStream());
  memoryManagedOutStream.close();
  return memoryManagedOutStream;
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:22,代碼來源:ApacheHttpClient4Dot3Engine.java

示例6: invoke

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
@Override
public ClientResponse invoke(ClientInvocation request) {
  Request req = createRequest(request);
  Response response;
  try {
    response = client.newCall(req).execute();
  } catch (IOException e) {
    throw new ProcessingException("Unable to invoke request", e);
  }
  return createResponse(request, response);
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:12,代碼來源:OkHttpClientEngine.java

示例7: createRequest

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
private Request createRequest(ClientInvocation request) {
  Request.Builder builder =
      new Request.Builder()
          .method(request.getMethod(), createRequestBody(request))
          .url(request.getUri().toString());
  for (Map.Entry<String, List<String>> header : request.getHeaders().asMap().entrySet()) {
    String headerName = header.getKey();
    for (String headerValue : header.getValue()) {
      builder.addHeader(headerName, headerValue);
    }
  }
  return builder.build();
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:14,代碼來源:OkHttpClientEngine.java

示例8: createRequestBody

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
private RequestBody createRequestBody(final ClientInvocation request) {
  if (request.getEntity() == null) {
    return null;
  }

  // NOTE: this will invoke WriterInterceptors which can possibly change the request,
  // so it must be done first, before reading any header.
  final Buffer buffer = new Buffer();
  try {
    request.writeRequestBody(buffer.outputStream());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }

  javax.ws.rs.core.MediaType mediaType = request.getHeaders().getMediaType();
  final MediaType contentType =
      (mediaType == null) ? null : MediaType.parse(mediaType.toString());

  return new RequestBody() {
    @Override
    public long contentLength() throws IOException {
      return buffer.size();
    }

    @Override
    public MediaType contentType() {
      return contentType;
    }

    @Override
    public void writeTo(BufferedSink sink) throws IOException {
      buffer.copyTo(sink.buffer(), 0, buffer.size());
    }
  };
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:36,代碼來源:OkHttpClientEngine.java

示例9: invoke

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
@Override
public ClientResponse invoke(ClientInvocation request) {
  MockHttpRequest mockRequest = createRequest(request);

  MockHttpResponse mockResponse = new MockHttpResponse();
  dispatcher.invoke(mockRequest, mockResponse);

  return createResponse(request, mockResponse);
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:10,代碼來源:InProcessClientHttpEngine.java

示例10: createResponse

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
private ClientResponse createResponse(
    final ClientInvocation request, final MockHttpResponse mockResponse) {
  ClientResponse response =
      new ClientResponse(request.getClientConfiguration()) {
        private InputStream inputStream;

        @Override
        protected InputStream getInputStream() {
          if (inputStream == null) {
            inputStream = new ByteArrayInputStream(mockResponse.getOutput());
          }
          return inputStream;
        }

        @Override
        protected void setInputStream(InputStream is) {
          inputStream = is;
        }

        @Override
        public void releaseConnection() throws IOException {
          // no-op
        }
      };

  response.setStatus(mockResponse.getStatus());
  response.setHeaders(
      transformHeaders(mockResponse.getOutputHeaders(), mockResponse.getNewCookies()));

  return response;
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:32,代碼來源:InProcessClientHttpEngine.java

示例11: createResponse

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
private ClientResponse createResponse(ClientInvocation request, final Response response) {
  ClientResponse clientResponse =
      new ClientResponse(request.getClientConfiguration()) {
        private InputStream stream;

        @Override
        protected InputStream getInputStream() {
          if (stream == null) {
            stream = response.body().byteStream();
          }
          return stream;
        }

        @Override
        protected void setInputStream(InputStream is) {
          stream = is;
        }

        @Override
        public void releaseConnection() throws IOException {
          // Stream might have been entirely replaced, so we need to close it independently from response.body()
          Throwable primaryExc = null;
          try {
            if (stream != null) {
              stream.close();
            }
          } catch (Throwable t) {
            primaryExc = t;
            throw t;
          } finally {
            if (primaryExc != null) {
              try {
                response.body().close();
              } catch (Throwable suppressedExc) {
                primaryExc.addSuppressed(suppressedExc);
              }
            } else {
              response.body().close();
            }
          }
        }
      };

  clientResponse.setStatus(response.code());
  clientResponse.setHeaders(transformHeaders(response.headers()));

  return clientResponse;
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:49,代碼來源:OkHttpClientEngine.java

示例12: createResponse

import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; //導入依賴的package包/類
private ClientResponse createResponse(ClientInvocation request, final Response response) {
  ClientResponse clientResponse =
      new ClientResponse(request.getClientConfiguration()) {
        private InputStream stream;

        @Override
        protected InputStream getInputStream() {
          if (stream == null) {
            try {
              stream = response.body().byteStream();
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }
          return stream;
        }

        @Override
        protected void setInputStream(InputStream is) {
          stream = is;
        }

        @Override
        public void releaseConnection() throws IOException {
          // Stream might have been entirely replaced, so we need to close it independently from response.body()
          Throwable primaryExc = null;
          try {
            if (stream != null) {
              stream.close();
            }
          } catch (Throwable t) {
            primaryExc = t;
            throw t;
          } finally {
            if (primaryExc != null) {
              try {
                response.body().close();
              } catch (Throwable suppressedExc) {
                primaryExc.addSuppressed(suppressedExc);
              }
            } else {
              response.body().close();
            }
          }
        }
      };

  clientResponse.setStatus(response.code());
  clientResponse.setHeaders(transformHeaders(response.headers()));

  return clientResponse;
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:53,代碼來源:OkHttpClientEngine.java


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