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


Java ContainerException类代码示例

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


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

示例1: writeTo

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Override
public void writeTo(final Template template, final Viewable viewable, final MediaType mediaType,
                    final MultivaluedMap<String, Object> httpHeaders, final OutputStream out) throws IOException {
    try {
        Object model = viewable.getModel();
        if (!(model instanceof Map)) {
            model = new HashMap<String, Object>() {{
                put("model", viewable.getModel());
            }};
        }
        Charset encoding = setContentType(mediaType, httpHeaders);

        template.process(model, new OutputStreamWriter(out, encoding));
    } catch (TemplateException te) {
        throw new ContainerException(te);
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:FreemarkerViewProcessor.java

示例2: stripResponse

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
private void stripResponse(ClientResponseContext responseContext) throws IOException {

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = responseContext.getEntityStream();

        final StringBuilder b = new StringBuilder();
        try {
            if (in.available() > 0) {
                ReaderWriter.writeTo(in, out);
                StringBuffer sbuf = new StringBuffer(new String(out.toByteArray()));
                if (sbuf.indexOf(ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX) == 0) {
                    if (log.isDebugEnabled()) { log.debug("Stripping "+ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX); }
                    responseContext.setEntityStream(new ByteArrayInputStream(sbuf.substring(ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX.length()).getBytes()));
                } else {
                    responseContext.setEntityStream(new ByteArrayInputStream(out.toByteArray()));
                } // end if
            } // end if
        } catch (IOException ex) {
            throw new ContainerException(ex);
        } // end try/catch

    }
 
开发者ID:jivesoftware,项目名称:jive-sdk-java-jersey,代码行数:23,代码来源:StripAllowIllegalResourceCallFilter.java

示例3: logResponse

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
private void logResponse(ClientResponseContext responseContext) throws IOException {

        String responseBody = null;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = responseContext.getEntityStream();

        final StringBuilder b = new StringBuilder();
        try {
            if (in.available() > 0) {
                ReaderWriter.writeTo(in, out);
                responseContext.setEntityStream(new ByteArrayInputStream(out.toByteArray()));
                responseBody = new String(out.toByteArray());
            } // end if
        } catch (IOException ex) {
            throw new ContainerException(ex);
        } // end try/catch

        responseBody = (responseBody == null) ? "" : "\n"+responseBody;

        log.debug("\nClient Response:\nStatus: "+responseContext.getStatus()+ responseBody);

    }
 
开发者ID:jivesoftware,项目名称:jive-sdk-java-jersey,代码行数:23,代码来源:DebugClientResponseFilter.java

示例4: filter

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext request) {
    if (predicate == null || predicate.apply(request)) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = request.getEntityStream();
        try {
            if(in.available() > 0) {
                ReaderWriter.writeTo(in, out);

                byte[] requestEntity = out.toByteArray();

                request.setEntityStream(new ByteArrayInputStream(requestEntity));
                request.setProperty(REQUEST_ENTITY, requestEntity);
            }
        } catch (IOException ex) {
            throw new ContainerException(ex);
        }
    }

}
 
开发者ID:Multifarious,项目名称:skid-road,代码行数:21,代码来源:RequestEntityBytesCaptureFilter.java

示例5: writeResponseStatusAndHeaders

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
/**
 * Writes the response status code and headers, returns an OutputStream that the Jersey application can write to.
 * @param contentLength The content length for the body
 * @param containerResponse The response object from the Jersey app
 * @return An OutputStream for Jersey to write the response body to
 * @throws ContainerException default Jersey declaration
 */
public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse containerResponse)
        throws ContainerException {
    statusCode = containerResponse.getStatusInfo().getStatusCode();

    if (headers == null) {
        headers = new HashMap<>();
    }

    for (final Map.Entry<String, List<String>> e : containerResponse.getStringHeaders().entrySet()) {
        for (final String value : e.getValue()) {
            // special case for set cookies
            // RFC 2109 allows for a comma separated list of cookies in one Set-Cookie header: https://tools.ietf.org/html/rfc2109
            if (e.getKey().equals(HttpHeaders.SET_COOKIE)) {
                if (headers.containsKey(e.getKey()) && LambdaContainerHandler.getContainerConfig().isConsolidateSetCookieHeaders()) {
                    headers.put(e.getKey(), headers.get(e.getKey()) + ", " + value);
                } else {
                    headers.put(e.getKey(), containerResponse.getStringHeaders().getFirst(e.getKey()));
                    break;
                }
            } else {
                headers.put(e.getKey(), value);
            }
        }
    }

    responseBody = new ByteArrayOutputStream();

    return responseBody;
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:37,代码来源:JerseyResponseWriter.java

示例6: close

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
public void close() {
	if (closed.compareAndSet(false, true)) {
		try {
			responseWriter.writeResponse(statusType, headers, entityOutputStream);
		} catch (IOException e) {
			LOG.error("failed to write response", e);
			throw new ContainerException(e);
		}
	} else {
		LOG.warn("request has already been closed");
	}
}
 
开发者ID:bbilger,项目名称:jrestless,代码行数:13,代码来源:JRestlessHandlerContainer.java

示例7: writeTo

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void writeTo(final Template template, final Viewable viewable, final MediaType mediaType,
                    final MultivaluedMap<String, Object> httpHeaders, final OutputStream out) throws IOException {
    try {
        Object model = viewable.getModel();
        if (!(model instanceof Map)) {
            model = new HashMap<String, Object>() {{
                put("model", viewable.getModel());
            }};
        }

        VelocityContext velocityContext = new VelocityContext();
        for (String key : ((Map<String, Object>) model).keySet()) {
            velocityContext.put(key, ((Map<String, Object>) model).get(key));
        }

        Charset encoding = setContentType(mediaType, httpHeaders);

        VelocityWriter writer = new VelocityWriter(new OutputStreamWriter(out, encoding));

        template.merge(velocityContext, writer);
        writer.flush();

    } catch (VelocityException te) {
        throw new ContainerException(te);
    }
}
 
开发者ID:Feng-Zihao,项目名称:jersey-mvc-velocity,代码行数:29,代码来源:VelocityViewProcessor.java

示例8: getJsonBody

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
protected String getJsonBody(ContainerRequestContext containerRequestContext) {
    String body = null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InputStream in = containerRequestContext.getEntityStream();

    final StringBuilder b = new StringBuilder();
    try {
        //REMOVED THE in.available() CHECK AS THIS DOESNT WORK IN TOMCAT WITH JERSEY
        //SEE: https://java.net/jira/browse/JERSEY-749
        if (log.isTraceEnabled()) { log.trace("Data Available..."); }
        ReaderWriter.writeTo(in, out);
        containerRequestContext.setEntityStream(new ByteArrayInputStream(out.toByteArray()));
        body = new String(out.toByteArray());
        if (log.isTraceEnabled()) { log.trace("Data Read:\n["+body+"]"); }
    } catch (IOException ex) {
        log.error("Error while reading JSON body",ex);
        throw new ContainerException(ex);
    } // end try/catch

    if (log.isDebugEnabled()) {
        if (MediaType.APPLICATION_JSON.equals(containerRequestContext.getHeaderString(HttpHeaders.CONTENT_TYPE))) {
            log.debug("\n["+containerRequestContext.getMethod()+"] : "+containerRequestContext.getUriInfo().getPath()+"\n"+ JiveSDKUtils.getJson(body));
        } else {
            log.debug("\n["+containerRequestContext.getMethod()+"] : "+containerRequestContext.getUriInfo().getPath()+"\n"+body);
        } // end if
    } // end if

    return body;
}
 
开发者ID:jivesoftware,项目名称:jive-sdk-java-jersey,代码行数:30,代码来源:BaseContainerRequestFilter.java

示例9: writeResponseStatusAndHeaders

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Override
public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse jerseyResponse) throws ContainerException {
    int status = jerseyResponse.getStatus();

    LOGGER.debug("{}: [{}] write status and headers st:{} cl:{}", Channels.getHexText(ctx), requestId, status, contentLength);
    meterStatus(status);

    // create the netty response
    HttpResponse nettyResponse = new DefaultHttpResponse(httpVersion, HttpResponseStatus.valueOf(status));
    copyHeaders(jerseyResponse, nettyResponse);

    // add the request id to the header
    nettyResponse.headers().add(Headers.REQUEST_TRACING_HEADER, requestId);

    // add a Connection: Close header if required
    if (!keepAlive) {
        nettyResponse.headers().add(Names.CONNECTION, Values.CLOSE);
    }

    // create the content buffer if necessary
    if (contentLength < 0) {
        LOGGER.trace("{}: [{}] chunked", Channels.getHexText(ctx), requestId);
        nettyResponse.headers().add(Names.TRANSFER_ENCODING, Values.CHUNKED);
        ctx.writeAndFlush(nettyResponse);
        entityOutputStream = new EntityOutputStream(ctx, CONTENT_LENGTH_HISTOGRAM);
    } else if (contentLength == 0) {
        LOGGER.trace("{}: [{}] no content", Channels.getHexText(ctx), requestId);
        nettyResponse.headers().add(Names.CONTENT_LENGTH, 0);
        ctx.write(nettyResponse);
        entityOutputStream = new EmptyEntityOutputStream(ctx);
    } else {
        LOGGER.trace("{}: [{}] non-empty body", Channels.getHexText(ctx), requestId);
        nettyResponse.headers().add(Names.CONTENT_LENGTH, contentLength);
        ctx.write(nettyResponse); // don't flush now - only do so when all the content is written
        entityOutputStream = new EntityOutputStream(ctx, CONTENT_LENGTH_HISTOGRAM);
    }

    return entityOutputStream;
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:40,代码来源:HttpRequestHandler.java

示例10: writeResponseStatusAndHeaders

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Override
public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse responseContext) throws ContainerException {
    response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
            HttpResponseStatus.valueOf(responseContext.getStatus()));

    for (Map.Entry<String, List<Object>> header : responseContext.getHeaders().entrySet()) {

    }

    return new ByteBufOutputStream(response.content());
}
 
开发者ID:m0wfo,项目名称:netty-utils,代码行数:12,代码来源:NettyContainer.java

示例11: getFactoryClass

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
private Class<? extends MustacheFactory> getFactoryClass() {
    if (factoryClass == null) {
        return DefaultMustacheFactory.class;
    } else {
        try {
            return Class.forName(factoryClass).asSubclass(MustacheFactory.class);
        } catch (ClassNotFoundException ex) {
            throw new ContainerException("Mustache factory not found", ex);
        }
    }
}
 
开发者ID:trautonen,项目名称:jersey-mustache,代码行数:12,代码来源:MustacheFactoryHelper.java

示例12: createMustacheFactory

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
private MustacheFactory createMustacheFactory(final Class<? extends MustacheFactory> clazz) {
    try {
        if (resourceRoot != null) {
            return clazz.getConstructor(String.class).newInstance(resourceRoot);
        }
        if (fileRoot != null) {
            return clazz.getConstructor(File.class).newInstance(fileRoot);
        }
        return clazz.getConstructor().newInstance();
    } catch (Exception ex) {
        throw new ContainerException("Failed to create mustache factory", ex);
    }
}
 
开发者ID:trautonen,项目名称:jersey-mustache,代码行数:14,代码来源:MustacheFactoryHelper.java

示例13: toResponse

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Override
public Response toResponse(ContainerException exception) {
    if (TenacityExceptionMapper.isTenacityException(exception.getCause())) {
        return Response.status(statusCode).build();
    } else {
        return Response.serverError().build();
    }
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:9,代码来源:TenacityContainerExceptionMapper.java

示例14: testCreateDefinedMustacheFactoryWithInvalidConstructor

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Test(expected = ContainerException.class)
public void testCreateDefinedMustacheFactoryWithInvalidConstructor() {
    MustacheFactoryHelper helper = new MustacheFactoryHelper(CustomMustacheFactory.class.getName(), null, null, null);
    helper.createMustacheFactory();
}
 
开发者ID:trautonen,项目名称:jersey-mustache,代码行数:6,代码来源:MustacheFactoryHelperTest.java

示例15: testCreateDefinedMustacheFactoryWithInvalidClass

import org.glassfish.jersey.server.ContainerException; //导入依赖的package包/类
@Test(expected = ContainerException.class)
public void testCreateDefinedMustacheFactoryWithInvalidClass() {
    MustacheFactoryHelper helper = new MustacheFactoryHelper("this.factory.is.missing.Factory", null, null, null);
    helper.createMustacheFactory();
}
 
开发者ID:trautonen,项目名称:jersey-mustache,代码行数:6,代码来源:MustacheFactoryHelperTest.java


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