当前位置: 首页>>代码示例>>Java>>正文


Java WriterInterceptorContext类代码示例

本文整理汇总了Java中javax.ws.rs.ext.WriterInterceptorContext的典型用法代码示例。如果您正苦于以下问题:Java WriterInterceptorContext类的具体用法?Java WriterInterceptorContext怎么用?Java WriterInterceptorContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WriterInterceptorContext类属于javax.ws.rs.ext包,在下文中一共展示了WriterInterceptorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {

	MessageDigest digest = null;
	try {
		digest = getInstance("MD5");
	} catch (NoSuchAlgorithmException e) {
		throw new IllegalArgumentException(e);
	}
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	DigestOutputStream digestStream = new DigestOutputStream(buffer, digest);

	OutputStream old = context.getOutputStream();
	context.setOutputStream(digestStream);
	try {
		context.proceed();

		byte[] hash = digest.digest();
		String encodedHash = getEncoder().encodeToString(hash);
		context.getHeaders().putSingle(CONTENT_MD5_STRING, encodedHash);
		byte[] content = buffer.toByteArray();
		old.write(content);
	} finally {
		context.setOutputStream(old);
	}
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:27,代码来源:ContentMD5Writer.java

示例2: testWrapsInputStream

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
public void testWrapsInputStream(String contentType) throws WebApplicationException, IOException {
	WriterInterceptorContext context = mockContext(contentType);
	OutputStream os = mock(OutputStream.class);
	when(context.getOutputStream()).thenReturn(os);

	writeInterceptor.aroundWriteTo(context);

	verifyZeroInteractions(os);

	ArgumentCaptor<OutputStream> updatedOsCapture = ArgumentCaptor.forClass(OutputStream.class);
	verify(context).setOutputStream(updatedOsCapture.capture());
	verify(context).getMediaType();
	verify(context).getOutputStream();
	verify(context).proceed();
	verifyNoMoreInteractions(context);

	OutputStream updatedOs = updatedOsCapture.getValue();

	// just make sure we have some wrapper
	assertNotSame(os, updatedOs);
	updatedOs.close();
	verify(os).close();
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:24,代码来源:WebActionBase64WriteInterceptorTest.java

示例3: testWrapsOutputStreamAlways

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Test
public void testWrapsOutputStreamAlways() throws IOException {

	WriterInterceptorContext context = mock(WriterInterceptorContext.class);
	OutputStream os = mock(OutputStream.class);
	when(context.getOutputStream()).thenReturn(os);

	ArgumentCaptor<OutputStream> updatedOsCapture = ArgumentCaptor.forClass(OutputStream.class);

	alwaysBase64WriteInterceptor.aroundWriteTo(context);

	verify(alwaysBase64WriteInterceptor).isBase64(context);

	verifyZeroInteractions(os);

	verify(context).setOutputStream(updatedOsCapture.capture());
	verify(context).proceed();
	verify(context).getOutputStream();
	verifyNoMoreInteractions(context);
	OutputStream updatedOs = updatedOsCapture.getValue();

	// just make sure we have some wrapper
	assertNotSame(os, updatedOs);
	updatedOs.close();
	verify(os).close();
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:27,代码来源:ConditionalBase64WriteInterceptorTest.java

示例4: testBase64Encoding

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
private void testBase64Encoding(byte[] bytes, String expectedBase64) throws IOException {

		WriterInterceptorContext context = mock(WriterInterceptorContext.class);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		when(context.getOutputStream()).thenReturn(baos);

		ArgumentCaptor<OutputStream> updatesOsCapture = ArgumentCaptor.forClass(OutputStream.class);

		alwaysBase64WriteInterceptor.aroundWriteTo(context);

		verify(context).setOutputStream(updatesOsCapture.capture());
		OutputStream updatedOs = updatesOsCapture.getValue();

		updatedOs.write(bytes);
		updatedOs.close();
		assertEquals(expectedBase64, baos.toString());
	}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:18,代码来源:ConditionalBase64WriteInterceptorTest.java

示例5: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
  if (!isVersioningSupported(context)) {
    context.proceed();
    return;
  }
  String targetVersion = Version.get(context);
  Object source = context.getEntity();
  if (source instanceof Collection) {
    context.setEntity(convertCollectionToLowerVersion(targetVersion, (Collection<?>)source));
  } else {
    mapper.map(source);
    context.setEntity(converter.convertToLowerVersion(targetVersion, source));
  }
  Type targetType = getVersionType(context.getGenericType(), targetVersion);
  context.setType(toClass(targetType));
  context.setGenericType(targetType);
  context.proceed();
  Version.unset(context);
}
 
开发者ID:openknowledge,项目名称:jaxrs-versioning,代码行数:21,代码来源:MessageBodyConverter.java

示例6: simpleWriterInterceptors

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Test
public void simpleWriterInterceptors() {
  Response response =
      client
          .target(mockServer.url("/writerInterceptor").uri())
          .register(
              new WriterInterceptor() {
                @Override
                public void aroundWriteTo(WriterInterceptorContext context)
                    throws IOException, WebApplicationException {
                  context.getHeaders().putSingle(HEADER_NAME, HEADER_VALUE);
                  context.proceed();
                }
              })
          .request()
          .post(Entity.json(PAYLOAD));

  assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
  assertThat(response.readEntity(String.class)).isEqualTo(HEADER_VALUE);
}
 
开发者ID:tbroyer,项目名称:jaxrs-utils,代码行数:21,代码来源:OkHttpClientEngineTest.java

示例7: testSnappyWriterInterceptor

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Test
public void testSnappyWriterInterceptor() throws IOException {

  SnappyWriterInterceptor writerInterceptor = new SnappyWriterInterceptor();

  MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
  WriterInterceptorContext mockInterceptorContext = Mockito.mock(WriterInterceptorContext.class);
  Mockito.when(mockInterceptorContext.getHeaders()).thenReturn(headers);
  Mockito.when(mockInterceptorContext.getOutputStream()).thenReturn(new ByteArrayOutputStream());
  Mockito.doNothing().when(mockInterceptorContext).setOutputStream(Mockito.any(OutputStream.class));

  // call aroundWriteTo on mock
  writerInterceptor.aroundWriteTo(mockInterceptorContext);

  // verify that setOutputStream method was called once with argument which is an instance of SnappyFramedOutputStream
  Mockito.verify(mockInterceptorContext, Mockito.times(1))
    .setOutputStream(Mockito.any(SnappyFramedOutputStream.class));

}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:TestSnappyWriterInterceptor.java

示例8: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext wic) throws IOException, WebApplicationException {
    System.out.println("MyServerWriterInterceptor");
    wic.setOutputStream(new FilterOutputStream(wic.getOutputStream()) {

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        @Override
        public void write(int b) throws IOException {
            baos.write(b);
            super.write(b);
        }

        @Override
        public void close() throws IOException {
            System.out.println("MyServerWriterInterceptor --> " + baos.toString());
            super.close();
        }
    });

    
    wic.proceed();
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:24,代码来源:MyServerWriterInterceptor.java

示例9: applyStreaming

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
/**
 * <p>applyStreaming.</p>
 *
 * @param requestContext a {@link javax.ws.rs.container.ContainerRequestContext} object.
 * @param context a {@link javax.ws.rs.ext.WriterInterceptorContext} object.
 * @throws java.io.IOException if any.
 */
protected void applyStreaming(ContainerRequestContext requestContext, WriterInterceptorContext context)
        throws IOException {

    Object entity = context.getEntity();
    StreamingProcess<Object> process = MessageHelper.getStreamingProcess(context.getEntity(), manager);

    if (process != null) {
        ContainerResponseContext responseContext =
                (ContainerResponseContext) requestContext.getProperty(RESP_PROP_N);
        responseContext.setStatusInfo(Response.Status.PARTIAL_CONTENT);
        context.getHeaders().putSingle(ACCEPT_RANGES, BYTES_RANGE);
        context.setType(StreamingOutput.class);
        context.setEntity(new MediaStreaming(
                        entity,
                requestContext.getHeaderString(MediaStreaming.RANGE),
                        process,
                        context.getMediaType(),
                        context.getHeaders()
                )
        );
    }
}
 
开发者ID:icode,项目名称:ameba,代码行数:30,代码来源:StreamingWriterInterceptor.java

示例10: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    if (!context.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH)) {
        Object entity = context.getEntity();
        StreamingProcess<Object> process = MessageHelper.getStreamingProcess(entity, manager);

        if (process != null) {
            long length = process.length(entity);

            if (length != -1)
                context.getHeaders().putSingle(HttpHeaders.CONTENT_LENGTH, length);
        }
    }

    context.proceed();
}
 
开发者ID:icode,项目名称:ameba,代码行数:20,代码来源:ContentLengthWriterInterceptor.java

示例11: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void aroundWriteTo(final WriterInterceptorContext writerInterceptorContext)
        throws IOException, WebApplicationException {
    final LoggingStream stream = (LoggingStream) writerInterceptorContext.getProperty(ENTITY_LOGGER_PROPERTY);
    writerInterceptorContext.proceed();

    final Object requestId = Requests.getProperty(LOGGING_ID_PROPERTY);
    final long id = requestId != null ? (Long) requestId : _id.incrementAndGet();
    StringBuilder b = (StringBuilder) writerInterceptorContext.getProperty(LOGGER_BUFFER_PROPERTY);
    if (b == null) {
        b = new StringBuilder();
        writerInterceptorContext.setProperty(LOGGER_BUFFER_PROPERTY, b);
    }
    printPrefixedHeaders(b, id, RESPONSE_PREFIX, HeaderUtils.asStringHeaders(writerInterceptorContext.getHeaders()));

    if (stream != null) {
        log(stream.getStringBuilder(MessageUtils.getCharset(writerInterceptorContext.getMediaType())));
    } else {
        log(b);
    }
}
 
开发者ID:icode,项目名称:ameba,代码行数:25,代码来源:LoggingFilter.java

示例12: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Override
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
    final Object entity = context.getEntity();
    if (entity instanceof Viewable) {
        User user = (User) securityContext.getUserPrincipal();

        if ( ((Viewable) entity).getModel() instanceof ViewData) {
            ViewData model = ((ViewData) ((Viewable) entity).getModel());
            model.set("authUser", user);
            String templateName = ((Viewable) entity).getTemplateName();
            context.setEntity(new Viewable(templateName, model.getData()));
        }
    }

    context.proceed();
}
 
开发者ID:autoschool,项目名称:splinter,代码行数:17,代码来源:UserDataInterceptor.java

示例13: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    final List<String> requestHeader = httpHeaders.getRequestHeader(HttpHeaders.ACCEPT_ENCODING);
    if (requestHeader != null && requestHeader.contains("gzip")) {
        context.setOutputStream(new GZIPOutputStream(context.getOutputStream()));
        context.getHeaders().add(HttpHeaders.CONTENT_ENCODING, "gzip");
    }
    context.proceed();
}
 
开发者ID:stevespringett,项目名称:Alpine,代码行数:10,代码来源:GZipInterceptor.java

示例14: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    final LoggingStream stream = (LoggingStream) context.getProperty("client.LoggingStream");
    context.proceed();
    if (stream != null) {
        System.out.printf("Body: %s\n", stream.getString(StandardCharsets.UTF_8));
    }
    System.out.printf("-----------\n");
}
 
开发者ID:obsidian-toaster-quickstarts,项目名称:redhat-sso,代码行数:10,代码来源:LoggingFilter.java

示例15: aroundWriteTo

import javax.ws.rs.ext.WriterInterceptorContext; //导入依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
  context.proceed();
  if (logger.isTraceEnabled()) {
    logRequestBody(context);
  }
}
 
开发者ID:SK-EID,项目名称:smart-id-java-client,代码行数:8,代码来源:LoggingFilter.java


注:本文中的javax.ws.rs.ext.WriterInterceptorContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。