本文整理匯總了Java中javax.ws.rs.client.ClientResponseContext.setEntityStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientResponseContext.setEntityStream方法的具體用法?Java ClientResponseContext.setEntityStream怎麽用?Java ClientResponseContext.setEntityStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.ws.rs.client.ClientResponseContext
的用法示例。
在下文中一共展示了ClientResponseContext.setEntityStream方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filter
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext)
throws IOException {
final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY);
final long id = requestId != null ? (Long) requestId : _id.incrementAndGet();
StringBuilder b = (StringBuilder) requestContext.getProperty(LOGGER_BUFFER_PROPERTY);
if (b == null) {
b = new StringBuilder();
requestContext.setProperty(LOGGER_BUFFER_PROPERTY, b);
}
printResponseLine(b, "Client response received", id, responseContext.getStatus());
printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders());
if (printEntity && responseContext.hasEntity() && isSupportPrintType(responseContext.getMediaType())) {
responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(),
MessageUtils.getCharset(responseContext.getMediaType())));
}
log(b);
}
示例2: filter
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
if (LOG.isTraceEnabled()) {
LOG.trace("Response status: {} {}", responseContext.getStatus(), responseContext.getStatusInfo().toString());
LOG.trace("Response headers: {}", responseContext.getHeaders());
InputStream stream = responseContext.getEntityStream();
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = stream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
stream.close();
LOG.trace("Response body: {}", result.toString("UTF-8"));
responseContext.setEntityStream(new ByteArrayInputStream(result.toByteArray()));
}
}
示例3: stripResponse
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private void stripResponse(ClientResponseContext responseContext) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = responseContext.getEntityStream();
final StringBuilder b = new StringBuilder();
try {
if (in.available() > 0) {
ReaderWriter.writeTo(in, out);
StringBuffer sbuf = new StringBuffer(new String(out.toByteArray()));
if (sbuf.indexOf(ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX) == 0) {
if (log.isDebugEnabled()) { log.debug("Stripping "+ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX); }
responseContext.setEntityStream(new ByteArrayInputStream(sbuf.substring(ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX.length()).getBytes()));
} else {
responseContext.setEntityStream(new ByteArrayInputStream(out.toByteArray()));
} // end if
} // end if
} catch (IOException ex) {
throw new ContainerException(ex);
} // end try/catch
}
示例4: logResponse
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private void logResponse(ClientResponseContext responseContext) throws IOException {
String responseBody = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = responseContext.getEntityStream();
final StringBuilder b = new StringBuilder();
try {
if (in.available() > 0) {
ReaderWriter.writeTo(in, out);
responseContext.setEntityStream(new ByteArrayInputStream(out.toByteArray()));
responseBody = new String(out.toByteArray());
} // end if
} catch (IOException ex) {
throw new ContainerException(ex);
} // end try/catch
responseBody = (responseBody == null) ? "" : "\n"+responseBody;
log.debug("\nClient Response:\nStatus: "+responseContext.getStatus()+ responseBody);
}
示例5: logResponseBody
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private void logResponseBody(ClientResponseContext responseContext) throws IOException {
Charset charset = MessageUtils.getCharset(responseContext.getMediaType());
InputStream entityStream = responseContext.getEntityStream();
byte[] bodyBytes = readInputStreamBytes(entityStream);
responseContext.setEntityStream(new ByteArrayInputStream(bodyBytes));
logger.trace("Response body: " + new String(bodyBytes, charset));
}
示例6: getResponseEntity
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private String getResponseEntity(final ClientResponseContext clientResponseContext) throws IOException {
if (shouldLogEntity(clientResponseContext)) {
final InterceptingInputStream s = new InterceptingInputStream(clientResponseContext.getEntityStream());
clientResponseContext.setEntityStream(s);
logger.debug("Response body is: {}", s.getContents());
return s.getContents();
} else {
return "";
}
}
示例7: filter
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
boolean needDecrypt = AuthenticationVariable.getAuthenticationVariable().isCrypt();
URI uriInfo = requestContext.getUri();
String path = uriInfo.getPath();
boolean docRequest = path.endsWith("/swagger");
if (needDecrypt && !(docRequest && BaseConfiguration.IS_DEBUG)) {
InputStream entityStream = responseContext.getEntityStream();
BufferedReader br = new BufferedReader(new InputStreamReader(entityStream));
String line = "";
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line);
}
String context = sb.toString();
String key = AuthenticationVariable.getAuthenticationVariable().getKey();
Assert.notNullString(key, "鑒權秘鑰獲取失敗!", HttpStatus.SC_UNAUTHORIZED, JahhanErrorCode.NO_AUTHORITY);
context = aesCrypto.decrypt(context, key);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
out.write(context.getBytes());
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
responseContext.setEntityStream(in);
} catch (Exception e) {
JahhanException.throwException(JahhanErrorCode.UNKNOW_ERROR, "未知錯誤", e);
} finally {
out.close();
}
}
}
示例8: getResponseBody
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private String getResponseBody(ClientResponseContext context) {
try (InputStream entityStream = context.getEntityStream()) {
if (entityStream != null) {
byte[] bytes = IOUtils.toByteArray(entityStream);
context.setEntityStream(new ByteArrayInputStream(bytes));
return new String(bytes);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failure during reading the response body", e);
context.setEntityStream(new ByteArrayInputStream(new byte[0]));
}
return "";
}
示例9: filter
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException
{
if (requestContext == null || responseContext == null || responseContext.getStatus() != Response.Status.FOUND.getStatusCode()) {
return;
}
log.debug("Processing redirect for " + requestContext.getMethod() + " " + requestContext.getUri().toASCIIString() + " to " + responseContext.getLocation().toASCIIString());
Client inClient = requestContext.getClient();
Object entity = requestContext.getEntity();
MultivaluedMap<String, Object> headers = requestContext.getHeaders();
String method = requestContext.getMethod();
Response resp;
if ("POST".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method)) {
resp = inClient.target(responseContext.getLocation())
.request(requestContext.getMediaType())
.headers(headers)
.method(requestContext.getMethod(), Entity.entity(new GenericEntity<JAXBElement<?>>((JAXBElement<?>)entity) {}, NsiConstants.NSI_DDS_V1_XML));
}
else {
resp = inClient.target(responseContext.getLocation())
.request(requestContext.getMediaType())
.headers(headers)
.method(requestContext.getMethod());
}
responseContext.setEntityStream((InputStream) resp.getEntity());
responseContext.setStatusInfo(resp.getStatusInfo());
responseContext.setStatus(resp.getStatus());
responseContext.getHeaders().putAll(resp.getStringHeaders());
log.debug("Processing redirect with result " + resp.getStatus());
}
示例10: filter
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext)
throws IOException {
final long id = aid.incrementAndGet();
final StringBuilder b = new StringBuilder();
printResponseLine(b, "Client response received", id, responseContext.getStatus());
printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders());
if (printEntity && responseContext.hasEntity()) {
responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream()));
}
log(b);
}
示例11: filter
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
if (!responseContext.getStatusInfo().getFamily().equals(Response.Status.Family.REDIRECTION)) {
return;
}
Response resp = requestContext.getClient().target(responseContext.getLocation()).request()
.method(requestContext.getMethod());
responseContext.setEntityStream((InputStream) resp.getEntity());
responseContext.setStatusInfo(resp.getStatusInfo());
responseContext.setStatus(resp.getStatus());
}
示例12: JaxrsContextRamlResponse
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
public JaxrsContextRamlResponse(ClientResponseContext context) {
this.context = context;
try {
content = IoUtils.readIntoByteArray(context.getEntityStream());
context.setEntityStream(new ByteArrayInputStream(content));
} catch (IOException e) {
throw new RamlCheckerException("Could not get response content", e);
}
}
示例13: populateResponseContext
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private void populateResponseContext(ClientResponseContext responseContext, Response response) {
responseContext.setEntityStream((InputStream) response.getEntity());
responseContext.setStatusInfo(response.getStatusInfo());
responseContext.setStatus(response.getStatus());
}