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


Java ClientResponseContext.setEntityStream方法代碼示例

本文整理匯總了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);
}
 
開發者ID:icode,項目名稱:ameba,代碼行數:26,代碼來源:LoggingFilter.java

示例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()));
    }
}
 
開發者ID:KTH,項目名稱:camel-alma,代碼行數:20,代碼來源:AlmaResponseFilter.java

示例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

    }
 
開發者ID:jivesoftware,項目名稱:jive-sdk-java-jersey,代碼行數:23,代碼來源:StripAllowIllegalResourceCallFilter.java

示例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);

    }
 
開發者ID:jivesoftware,項目名稱:jive-sdk-java-jersey,代碼行數:23,代碼來源:DebugClientResponseFilter.java

示例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));
}
 
開發者ID:SK-EID,項目名稱:smart-id-java-client,代碼行數:8,代碼來源:LoggingFilter.java

示例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 "";
    }
}
 
開發者ID:RoboZonky,項目名稱:robozonky,代碼行數:11,代碼來源:RoboZonkyFilter.java

示例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();
		}
	}
}
 
開發者ID:nince-wyj,項目名稱:jahhan,代碼行數:31,代碼來源:CryptoFilter.java

示例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 "";
}
 
開發者ID:jenkinsci,項目名稱:gitlab-plugin,代碼行數:14,代碼來源:ResteasyGitLabClientBuilder.java

示例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());
}
 
開發者ID:BandwidthOnDemand,項目名稱:nsi-dds,代碼行數:35,代碼來源:RestClient.java

示例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);
}
 
開發者ID:docker-java,項目名稱:docker-java,代碼行數:16,代碼來源:LoggingFilter.java

示例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());
}
 
開發者ID:docker-java,項目名稱:docker-java,代碼行數:13,代碼來源:FollowRedirectsFilter.java

示例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);
    }
}
 
開發者ID:nidi3,項目名稱:raml-tester,代碼行數:10,代碼來源:JaxrsContextRamlResponse.java

示例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());
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:6,代碼來源:FollowRedirectsFilter.java


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