本文整理汇总了Java中javax.ws.rs.ext.ReaderInterceptorContext类的典型用法代码示例。如果您正苦于以下问题:Java ReaderInterceptorContext类的具体用法?Java ReaderInterceptorContext怎么用?Java ReaderInterceptorContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReaderInterceptorContext类属于javax.ws.rs.ext包,在下文中一共展示了ReaderInterceptorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWrapsInputStream
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
public void testWrapsInputStream(String contentType) throws WebApplicationException, IOException {
ReaderInterceptorContext context = mockContext(contentType);
InputStream is = mock(InputStream.class);
when(context.getInputStream()).thenReturn(is);
readInterceptor.aroundReadFrom(context);
verifyZeroInteractions(is);
ArgumentCaptor<InputStream> updatedIsCapture = ArgumentCaptor.forClass(InputStream.class);
verify(context).setInputStream(updatedIsCapture.capture());
verify(context).getMediaType();
verify(context).getInputStream();
verify(context).proceed();
verifyNoMoreInteractions(context);
InputStream updatedIs = updatedIsCapture.getValue();
// just make sure we have some wrapper
assertNotSame(is, updatedIs);
updatedIs.close();
verify(is).close();
}
示例2: testWrapsInputStreamAlways
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
@Test
public void testWrapsInputStreamAlways() throws WebApplicationException, IOException {
ReaderInterceptorContext context = mock(ReaderInterceptorContext.class);
InputStream is = mock(InputStream.class);
when(context.getInputStream()).thenReturn(is);
alwaysBase64ReadInterceptor.aroundReadFrom(context);
verifyZeroInteractions(is);
ArgumentCaptor<InputStream> updatedIsCapture = ArgumentCaptor.forClass(InputStream.class);
verify(context).setInputStream(updatedIsCapture.capture());
verify(context).proceed();
verify(context).getInputStream();
verifyNoMoreInteractions(context);
InputStream updatedIs = updatedIsCapture.getValue();
verify(alwaysBase64ReadInterceptor).isBase64(context);
// just make sure we have some wrapper
assertNotSame(is, updatedIs);
updatedIs.close();
verify(is).close();
}
示例3: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
if (!isVersioningSupported(context)) {
return context.proceed();
}
String sourceVersion = Version.get(context);
Type targetType = context.getGenericType();
Type sourceType = getVersionType(targetType, sourceVersion);
context.setType(toClass(sourceType));
context.setGenericType(sourceType);
Object sourceObject = context.proceed();
Object target;
if (sourceObject instanceof Collection) {
target = convertCollectionToHigherVersion(targetType, (Collection<?>)sourceObject, sourceVersion);
} else {
target = converter.convertToHigherVersion(toClass(targetType), sourceObject, sourceVersion);
}
context.setType(toClass(targetType));
context.setGenericType(targetType);
return target;
}
示例4: testSnappyReaderInterceptor
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
@Test
public void testSnappyReaderInterceptor() throws IOException {
SnappyReaderInterceptor readerInterceptor = new SnappyReaderInterceptor();
MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.put(SnappyReaderInterceptor.CONTENT_ENCODING, Arrays.asList(SnappyReaderInterceptor.SNAPPY));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
SnappyFramedOutputStream snappyFramedOutputStream = new SnappyFramedOutputStream(byteArrayOutputStream);
snappyFramedOutputStream.write("Hello".getBytes());
ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ReaderInterceptorContext mockInterceptorContext = Mockito.mock(ReaderInterceptorContext.class);
Mockito.when(mockInterceptorContext.getHeaders()).thenReturn(headers);
Mockito.when(mockInterceptorContext.getInputStream()).thenReturn(inputStream);
Mockito.doNothing().when(mockInterceptorContext).setInputStream(Mockito.any(InputStream.class));
// call aroundReadFrom on mock
readerInterceptor.aroundReadFrom(mockInterceptorContext);
// verify that setInputStream method was called once with argument which is an instance of SnappyFramedInputStream
Mockito.verify(mockInterceptorContext, Mockito.times(1))
.setInputStream(Mockito.any(SnappyFramedInputStream.class));
}
示例5: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
Object object = context.proceed();
if (context.getProperty(EMPTY_PAYLOAD) != TRUE) {
return object;
}
if (object instanceof Collection) {
Collection<?> collection = (Collection<?>) object;
if (collection.isEmpty()) {
throw new EmptyPayloadException();
}
} else if (object instanceof Map) {
Map<?, ?> map = (Map<?, ?>) object;
if (map.isEmpty()) {
throw new EmptyPayloadException();
}
} else if (object == null) {
throw new EmptyPayloadException();
}
return object;
}
示例6: 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();
}
示例7: 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);
}
}
示例8: 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();
}
示例9: 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
示例10: 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
示例11: 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
示例12: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
final List<String> header = context.getHeaders().get(HttpHeaders.CONTENT_ENCODING);
if (header != null && header.contains("gzip")) {
context.setInputStream(new GZIPInputStream(context.getInputStream()));
}
return context.proceed();
}
示例13: testDoesNotWrapInputStream
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
public void testDoesNotWrapInputStream(String contentType) throws WebApplicationException, IOException {
ReaderInterceptorContext context = mockContext(contentType);
InputStream is = mock(InputStream.class);
when(context.getInputStream()).thenReturn(is);
readInterceptor.aroundReadFrom(context);
verifyZeroInteractions(is);
verify(context).getMediaType();
verify(context).proceed();
verifyNoMoreInteractions(context);
}
示例14: mockContext
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
private static ReaderInterceptorContext mockContext(String contentType) {
ReaderInterceptorContext context = mock(ReaderInterceptorContext.class);
if (contentType != null) {
when(context.getMediaType()).thenReturn(MediaType.valueOf(contentType));
}
return context;
}
示例15: aroundReadFrom
import javax.ws.rs.ext.ReaderInterceptorContext; //导入依赖的package包/类
@Override
public final Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
if (isBase64(context)) {
context.setInputStream(Base64.getDecoder().wrap(context.getInputStream()));
}
return context.proceed();
}