本文整理汇总了Java中javax.ws.rs.ext.ReaderInterceptorContext.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ReaderInterceptorContext.getInputStream方法的具体用法?Java ReaderInterceptorContext.getInputStream怎么用?Java ReaderInterceptorContext.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.ext.ReaderInterceptorContext
的用法示例。
在下文中一共展示了ReaderInterceptorContext.getInputStream方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext ric) throws IOException, WebApplicationException {
System.out.println("MyClientReaderInterceptor");
final InputStream old = ric.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c;
while ((c = old.read()) != -1) {
baos.write(c);
}
System.out.println("MyClientReaderInterceptor --> " + baos.toString());
ric.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
return ric.proceed();
}
示例2: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext readerInterceptorContext) throws IOException, WebApplicationException {
final InputStream originalInputStream = readerInterceptorContext.getInputStream();
readerInterceptorContext.setInputStream(new InputStream() {
@Override
public int read() throws IOException {
boolean isOk;
int b;
do {
b = originalInputStream.read();
isOk = b == -1 || Character.isLetterOrDigit(b) || Character.isWhitespace(b) || b == ((int) '.');
} while (!isOk);
return b;
}
});
try {
return readerInterceptorContext.proceed();
} finally {
readerInterceptorContext.setInputStream(originalInputStream);
}
}
示例3: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
InputStream originalInputStream = context.getInputStream();
if (!originalInputStream.markSupported())
originalInputStream = new BufferedInputStream(originalInputStream);
// Test, if it contains data. We only try to unzip, if it is not empty.
originalInputStream.mark(5);
int read = originalInputStream.read();
originalInputStream.reset();
if (read > -1)
context.setInputStream(new GZIPInputStream(originalInputStream));
else {
context.setInputStream(originalInputStream); // We might have wrapped it with our BufferedInputStream!
logger.debug("aroundReadFrom: originalInputStream is empty! Skipping GZIP.");
}
return context.proceed();
}
示例4: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext interceptorContext)
throws IOException, WebApplicationException {
logger.info("ServerReaderInterceptor invoked");
InputStream inputStream = interceptorContext.getInputStream();
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
String requestContent = new String(bytes);
requestContent = requestContent + ".Request changed in ServerReaderInterceptor.";
interceptorContext.setInputStream(new ByteArrayInputStream(requestContent.getBytes()));
return interceptorContext.proceed();
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:13,代码来源:ServerReaderInterceptor.java
示例5: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext interceptorContext)
throws IOException, WebApplicationException {
logger.info("ClientSecondReaderInterceptor invoked.");
InputStream inputStream = interceptorContext.getInputStream();
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
String requestContent = new String(bytes);
requestContent = requestContent + " Request changed in ClientSecondReaderInterceptor.";
interceptorContext.setInputStream(new ByteArrayInputStream(requestContent.getBytes()));
return interceptorContext.proceed();
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:13,代码来源:ClientSecondReaderInterceptor.java
示例6: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext interceptorContext)
throws IOException, WebApplicationException {
logger.info("ClientFirstReaderInterceptor invoked");
InputStream inputStream = interceptorContext.getInputStream();
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
String requestContent = new String(bytes);
requestContent = requestContent + ".Request changed in ClientFirstReaderInterceptor.";
interceptorContext.setInputStream(new ByteArrayInputStream(requestContent.getBytes()));
return interceptorContext.proceed();
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:13,代码来源:ClientFirstReaderInterceptor.java
示例7: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom (ReaderInterceptorContext context)
throws IOException, WebApplicationException {
final InputStream originalInputStream = context.getInputStream();
context.setInputStream(new GZIPInputStream(originalInputStream));
return context.proceed();
}
示例8: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
if (context.getHeaders().containsKey("Content-Encoding") &&
context.getHeaders().get("Content-Encoding").contains("snappy")) {
InputStream originalInputStream = context.getInputStream();
context.setInputStream(new SnappyFramedInputStream(originalInputStream, true));
}
return context.proceed();
}
示例9: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
if (context.getHeaders().containsKey(CONTENT_ENCODING) &&
context.getHeaders().get(CONTENT_ENCODING).contains(SNAPPY)) {
InputStream originalInputStream = context.getInputStream();
context.setInputStream(new SnappyFramedInputStream(originalInputStream, true));
}
return context.proceed();
}
示例10: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext readerInterceptorContext)
throws IOException, WebApplicationException {
logger.info("Enters RestSkolReaderInterceptor.aroundReadFrom()");
final InputStream inputStream = readerInterceptorContext.getInputStream();
readerInterceptorContext.setInputStream(new GZIPInputStream(inputStream));
return readerInterceptorContext.proceed();
}
示例11: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext ric) throws IOException, WebApplicationException {
System.out.println("MyClientReaderInterceptor");
// ric.setInputStream(new FilterInputStream(ric.getInputStream()) {
//
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
//
// @Override
// public int read(byte[] b, int off, int len) throws IOException {
// baos.write(b, off, len);
//// System.out.println("@@@@@@ " + b);
// return super.read(b, off, len);
// }
//
// @Override
// public void close() throws IOException {
// System.out.println("### " + baos.toString());
// super.close();
// }
// });
final InputStream old = ric.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c;
while ((c = old.read()) != -1) {
baos.write(c);
}
System.out.println("MyClientReaderInterceptor --> " + baos.toString());
ric.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
return ric.proceed();
}
示例12: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext ric) throws IOException, WebApplicationException {
System.out.println("MyServerReaderInterceptor");
final InputStream old = ric.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c;
while ((c = old.read()) != -1) {
baos.write(c);
}
System.out.println("MyClientReaderInterceptor --> " + baos.toString());
ric.setInputStream(new ByteArrayInputStream(baos.toByteArray()));
return ric.proceed();
}
示例13: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context)
throws IOException, WebApplicationException {
final InputStream originalInputStream = context.getInputStream();
context.setInputStream(new GZIPInputStream(originalInputStream));
return context.proceed();
}
示例14: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
// Validate if name bound or if CSRF property enabled and a POST
final Method controller = resourceInfo.getResourceMethod();
if (needsValidation(controller)) {
CsrfToken token = csrfTokenManager.getToken()
.orElseThrow(() -> new CsrfValidationException(messages.get("CsrfFailed", "missing token")));
// First check if CSRF token is in header
final String csrfToken = context.getHeaders().getFirst(token.getHeaderName());
if (token.getValue().equals(csrfToken)) {
return context.proceed();
}
// Otherwise, it must be a form parameter
final MediaType contentType = context.getMediaType();
if (!isSupportedMediaType(contentType)) {
throw new CsrfValidationException(messages.get("UnableValidateCsrf", context.getMediaType()));
}
// Ensure stream can be restored for next interceptor
ByteArrayInputStream bais;
final InputStream is = context.getInputStream();
if (is instanceof ByteArrayInputStream) {
bais = (ByteArrayInputStream) is;
} else {
bais = copyStream(is);
}
// Validate CSRF
boolean validated = false;
final String charset = contentType.getParameters().get("charset");
final String entity = toString(bais, charset != null ? charset : DEFAULT_CHARSET);
final String[] pairs = entity.split("\\&");
for (int i = 0; i < pairs.length; i++) {
final String[] fields = pairs[i].split("=");
final String nn = URLDecoder.decode(fields[0], DEFAULT_CHARSET);
// Is this the CSRF field?
if (token.getParamName().equals(nn)) {
final String vv = URLDecoder.decode(fields[1], DEFAULT_CHARSET);
// If so then check the token
if (token.getValue().equals(vv)) {
validated = true;
break;
}
throw new CsrfValidationException(messages.get("CsrfFailed", "mismatching tokens"));
}
}
if (!validated) {
throw new CsrfValidationException(messages.get("CsrfFailed", "missing field"));
}
// Restore stream and proceed
bais.reset();
context.setInputStream(bais);
}
return context.proceed();
}