本文整理汇总了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
}
示例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);
}
示例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());
}
}
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}