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


Java ClientRequestContext.getEntity方法代碼示例

本文整理匯總了Java中javax.ws.rs.client.ClientRequestContext.getEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientRequestContext.getEntity方法的具體用法?Java ClientRequestContext.getEntity怎麽用?Java ClientRequestContext.getEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.client.ClientRequestContext的用法示例。


在下文中一共展示了ClientRequestContext.getEntity方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: logRequest

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
private void logRequest(ClientRequestContext requestContext) throws IOException {

        Object requestBody = requestContext.getEntity();

        if (log.isTraceEnabled()) {
            StringBuffer sbuf = new StringBuffer("\nHeaders:");
            sbuf.append("\n--- BEGIN ---");
            MultivaluedMap<String,String> headers = requestContext.getStringHeaders();
            for (String key : headers.keySet()) {
                sbuf.append("\n").append(key).append("=").append(headers.get(key));
            } // end for key
            sbuf.append("\n--- END ---");
            log.trace(sbuf.toString());
            sbuf = null;
        } // end if

        if (MediaType.APPLICATION_JSON.equals(requestContext.getHeaderString(HttpHeaders.CONTENT_TYPE))) {
            log.debug("\n["+requestContext.getMethod()+"] : "+requestContext.getUri().toString()+"\n"+JiveSDKUtils.getJson(requestBody));
        } else {
            log.debug("\n["+requestContext.getMethod()+"] : "+requestContext.getUri().toString()+"\n"+requestBody);
        } // end if

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

示例2: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter( ClientRequestContext context ) throws IOException {

    if (debugLevel == RESTDebugLevel.NONE || debugLevel == RESTDebugLevel.TARGET_URI) {
        return;
    }

    MultivaluedMap<String, Object> reqHeaders = context.getHeaders();
    StringBuilder requestMessage = new StringBuilder();
    requestMessage.append("Sending the following request: \n");
    if ( (debugLevel & RESTDebugLevel.HEADERS) == RESTDebugLevel.HEADERS) {
        requestMessage.append(context.getMethod() + " " + context.getUri() + " \n");

        for (Entry<String, List<Object>> reqHeaderEntry : reqHeaders.entrySet()) {
            requestMessage.append(reqHeaderEntry.getKey() + ": "
                                  + Arrays.toString(reqHeaderEntry.getValue().toArray()) + " \n");
        }
    }
    if ( (debugLevel & RESTDebugLevel.BODY) == RESTDebugLevel.BODY && context.hasEntity()) {
        //log request body
        Object entity = context.getEntity();
        if (entity instanceof Form) {
            requestMessage.append("Body: " + ((Form) entity).asMap());
        } else {
            requestMessage.append("Body: " + entity.toString());
        }
    }
    log.info(requestMessage);
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:30,代碼來源:RestClient.java

示例3: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Target: {}", requestContext.getUri().toString());
        LOG.trace("Method: {}", requestContext.getMethod());
        LOG.trace("Headers: {}", requestContext.getStringHeaders());
        if (requestContext.getEntity() != null) {
            LOG.trace(requestContext.getEntity().toString());
        }
    }
}
 
開發者ID:KTH,項目名稱:camel-alma,代碼行數:12,代碼來源:AlmaRequestFilter.java

示例4: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的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

示例5: filterOutgoingResponse

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
/**
 * @param requestContext
 * @param responseContext
 */
@SuppressWarnings("resource")
public static void filterOutgoingResponse(final ClientRequestContext requestContext,
		final ClientResponseContext responseContext) {

	final String methodName = "filterOutgoingResponse";

	InputStream entityStream = null;

	StringBuilder message = new StringBuilder();

	try {

		entityStream = responseContext.getEntityStream();

		message = new StringBuilder();
		message.append("JAX-RS ");
		if (null != requestContext.getEntity()) {

			message.append("\n");
			final ObjectMapper mapper = new ObjectMapper();

			try {
				message.append(mapper.writerWithDefaultPrettyPrinter()
						.writeValueAsString(responseContext.getEntityStream()));

			} catch (final Exception e) {
				throw new TestingException("Unable to log outgoing response.", e);
			}
		}

	} finally {
		JprResponseUtilHelper.closeResources(entityStream);

	}
	JpcLoggingCacheHelper.getLogger().logModeLifecycle(JprResponseUtilHelper.CLASS_NAME, methodName,
			message.toString());

	return;
}
 
開發者ID:gtcGroup,項目名稱:jped-parent-project,代碼行數:44,代碼來源:JprResponseUtilHelper.java

示例6: filterIncomingJsonRequest

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
/**
 * @param requestContext
 */
public static void filterIncomingJsonRequest(final ClientRequestContext requestContext) {

	final String methodName = "filterIncomingRequest";

	final StringBuilder message = new StringBuilder();
	message.append("JAX-RS ");
	message.append(requestContext.getMethod());
	message.append(": ");
	message.append(requestContext.getUri().toString());

	if (null != requestContext.getEntity()) {

		message.append("\n");
		final ObjectMapper mapper = new ObjectMapper();
		mapper.enable(SerializationFeature.INDENT_OUTPUT);

		try {
			message.append(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestContext.getEntity()));

		} catch (final Exception e) {
			throw new TestingException("Unable to log incoming request.", e);
		}
	}

	JpcLoggingCacheHelper.getLogger().logModeLifecycle(JprRequestUtilHelper.CLASS_NAME, methodName,
			message.toString());

	return;
}
 
開發者ID:gtcGroup,項目名稱:jped-parent-project,代碼行數:33,代碼來源:JprRequestUtilHelper.java

示例7: filterIncomingJsonRequest

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
/**
 * @param requestContext
 */
public static void filterIncomingJsonRequest(final ClientRequestContext requestContext) {

	final String methodName = "filterIncomingRequest";

	final StringBuilder message = new StringBuilder();
	message.append("JAX-RS ");
	message.append(requestContext.getMethod());
	message.append(": ");
	message.append(requestContext.getUri().toString());

	if (null != requestContext.getEntity()) {

		message.append("\n");
		final ObjectMapper mapper = new ObjectMapper();
		mapper.enable(SerializationFeature.INDENT_OUTPUT);

		try {
			message.append(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestContext.getEntity()));

		} catch (final Exception e) {
			throw new JprConvertException(new JpcBasicExceptionPO().setClassName(JprRequestUtilHelper.CLASS_NAME)
					.setMessage("Unable to log incoming request."), e);
		}
	}

	JpcLoggingCacheHelper.getLogger().logModeLifecycle(JprRequestUtilHelper.CLASS_NAME, methodName,
			message.toString());

	return;
}
 
開發者ID:gtcGroup,項目名稱:jped-parent-project,代碼行數:34,代碼來源:JprRequestUtilHelper.java

示例8: obtainObjectPay

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
/**
 * Generates a payload based on request context. On empty content use url as content.
 * @param requestContext
 * @return payload based on content
 */
private Payload obtainObjectPay(ClientRequestContext requestContext){
    Payload objectPay = null;

    Object object = requestContext.getEntity();
    if (object != null)
    {
        // buffer into which myBean will be serialized
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Class<Object> type = (Class<Object>) requestContext.getEntityClass();
        GenericType<Object> genericType = new GenericType<Object>(type) {
        };

        // get most appropriate MBW
        final MessageBodyWriter<Object> messageBodyWriter =
                workers.getMessageBodyWriter(type, type,
                        new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE);

        try {
            // use the MBW to serialize myBean into baos
            messageBodyWriter.writeTo(object,
                    object.getClass(), genericType.getType(), new Annotation[] {},
                    MediaType.APPLICATION_JSON_TYPE,
                    new MultivaluedHashMap<String, Object>(),
                    baos);
        } catch (IOException e) {
            throw new RuntimeException(
                    "Error while serializing MyBean.", e);
        }

        String stringJsonOutput = baos.toString();
        if (logger.isDebugEnabled())
            logger.debug("Entity.toString():: " + stringJsonOutput);

        //There is a short limitation for http headers. It depends on server.
        //As message payload grows, payload in header is growing too, so we must set a limit.
        //It means that we are only signing, validating and checking message integrity of first 1024 characters
        //Same logic is applied in server side
        if (stringJsonOutput != null
                && stringJsonOutput.length() > PAYLOAD_HEADER_MAX_SIZE)
            stringJsonOutput = stringJsonOutput.substring(0, PAYLOAD_HEADER_MAX_SIZE);

        objectPay = new Payload(stringJsonOutput);
    }
    //If request entity is null (usually GET methods) use URI as payload
    else {
        String reqUri = getUri(requestContext);
        objectPay = new Payload(reqUri);
    }
    return objectPay;
}
 
開發者ID:Appverse,項目名稱:appverse-server,代碼行數:56,代碼來源:JWSJerseyFilter.java

示例9: filterOutgoingResponse

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
/**
 * @param requestContext
 * @param responseContext
 */
@SuppressWarnings("resource")
public static void filterOutgoingResponse(final ClientRequestContext requestContext,
		final ClientResponseContext responseContext) {

	final String methodName = "filterOutgoingResponse";

	InputStream entityStream = null;

	StringBuilder message = new StringBuilder();

	try {

		entityStream = responseContext.getEntityStream();

		message = new StringBuilder();
		message.append("JAX-RS ");
		if (null != requestContext.getEntity()) {

			message.append("\n");
			final ObjectMapper mapper = new ObjectMapper();

			try {
				message.append(mapper.writerWithDefaultPrettyPrinter()
						.writeValueAsString(responseContext.getEntityStream()));

			} catch (final Exception e) {
				throw new JprConvertException(
						new JpcBasicExceptionPO().setClassName(JprResponseUtilHelper.CLASS_NAME)
								.setMessage("Unable to log outgoing response."),
						e);
			}
		}

	} finally {
		JprResponseUtilHelper.closeResources(entityStream);

	}
	JpcLoggingCacheHelper.getLogger().logModeLifecycle(JprResponseUtilHelper.CLASS_NAME, methodName,
			message.toString());

	return;
}
 
開發者ID:gtcGroup,項目名稱:jped-parent-project,代碼行數:47,代碼來源:JprResponseUtilHelper.java


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