com.sun.jersey.core.util.ReaderWriter Java Examples

The following examples show how to use com.sun.jersey.core.util.ReaderWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RawLoggingFilter.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void logResponse(long id, ClientResponse response) {
	StringBuilder b = new StringBuilder();

	printResponseLine(b, id, response);
	printResponseHeaders(b, id, response.getHeaders());

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	InputStream in = response.getEntityInputStream();
	try {
		ReaderWriter.writeTo(in, out);

		byte[] requestEntity = out.toByteArray();
		printEntity(b, requestEntity);
		response.setEntityInputStream(new ByteArrayInputStream(
				requestEntity));
	} catch (IOException ex) {
		throw new ClientHandlerException(ex);
	}
	log(b);
}
 
Example #2
Source File: RawLoggingFilter.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void logResponse(long id, ClientResponse response) {
	StringBuilder b = new StringBuilder();

	printResponseLine(b, id, response);
	printResponseHeaders(b, id, response.getHeaders());

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	InputStream in = response.getEntityInputStream();
	try {
		ReaderWriter.writeTo(in, out);

		byte[] requestEntity = out.toByteArray();
		printEntity(b, requestEntity);
		response.setEntityInputStream(new ByteArrayInputStream(
				requestEntity));
	} catch (IOException ex) {
		throw new ClientHandlerException(ex);
	}
	log(b);
}
 
Example #3
Source File: RawLoggingFilter.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void logResponse(long id, ClientResponse response) {
	StringBuilder b = new StringBuilder();

	printResponseLine(b, id, response);
	printResponseHeaders(b, id, response.getHeaders());

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	InputStream in = response.getEntityInputStream();
	try {
		ReaderWriter.writeTo(in, out);

		byte[] requestEntity = out.toByteArray();
		printEntity(b, requestEntity);
		response.setEntityInputStream(new ByteArrayInputStream(
				requestEntity));
	} catch (IOException ex) {
		throw new ClientHandlerException(ex);
	}
	log(b);
}
 
Example #4
Source File: RequestLogger.java    From qaf with MIT License 6 votes vote down vote up
private StringBuilder logResponse(long id, ClientResponse response) {
	StringBuilder b = new StringBuilder();

	printResponseLine(b, id, response);
	printResponseHeaders(b, id, response.getHeaders());

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	InputStream in = response.getEntityInputStream();
	try {
		ReaderWriter.writeTo(in, out);

		byte[] requestEntity = out.toByteArray();
		printEntity(b, requestEntity);
		response.setEntityInputStream(new ByteArrayInputStream(requestEntity));
	} catch (IOException ex) {
		throw new ClientHandlerException(ex);
	}
	log(b.toString());
	return b;
}
 
Example #5
Source File: Response.java    From qaf with MIT License 6 votes vote down vote up
private void setRawMessageBody() {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	InputStream in = clientResponse.getEntityInputStream();
	try {
		ReaderWriter.writeTo(in, out);

		byte[] requestEntity = out.toByteArray();
		if (requestEntity.length == 0) {
			return;
		}
		messageBody = new String(requestEntity);

		clientResponse.setEntityInputStream(new ByteArrayInputStream(requestEntity));
	} catch (IOException ex) {
	}

}
 
Example #6
Source File: RequestDecoder.java    From jersey-hmac-auth with Apache License 2.0 6 votes vote down vote up
/**
 * Under normal circumstances, the body of the request can only be read once, because it is
 * backed by an {@code InputStream}, and thus is not easily consumed multiple times. This
 * method gets the request content and resets it so it can be read again later if necessary.
 */
private byte[] safelyGetContent(HttpRequestContext request) {
    ContainerRequest containerRequest = (ContainerRequest) request;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InputStream in = containerRequest.getEntityInputStream();

    try {
        ReaderWriter.writeTo(in, out);
        byte[] content = out.toByteArray();

        // Reset the input stream so that it can be read again by another filter or resource
        containerRequest.setEntityInputStream(new ByteArrayInputStream(content));
        return content;

    } catch (IOException ex) {
        throw new ContainerException(ex);
    }
}