Java 100继续穿运动衫2+;码头9+;

Java 100继续穿运动衫2+;码头9+;,java,jetty,jersey-2.0,jetty-9,Java,Jetty,Jersey 2.0,Jetty 9,我看到我的jersey+jetty服务器在请求传递给我的处理程序之前响应100 continue头。我不想发送100 Continue,而是基于请求的URI/头发送3xx响应 这是org.glassfish.jersey.servlet.WebComponent类,它调用request.getInputStream() 它调用HttpChannel来发送100 Continue报头 /** * If the associated response has the Expect header

我看到我的jersey+jetty服务器在请求传递给我的处理程序之前响应100 continue头。我不想发送100 Continue,而是基于请求的URI/头发送3xx响应

这是org.glassfish.jersey.servlet.WebComponent类,它调用request.getInputStream()

它调用HttpChannel来发送100 Continue报头

 /**
 * If the associated response has the Expect header set to 100 Continue,
 * then accessing the input stream indicates that the handler/servlet
 * is ready for the request body and thus a 100 Continue response is sent.
 *
 * @throws IOException if the InputStream cannot be created
 */
public void continue100(int available) throws IOException
{
    // If the client is expecting 100 CONTINUE, then send it now.
    // TODO: consider using an AtomicBoolean ?
    if (isExpecting100Continue())
    {
        _expect100Continue = false;

        // is content missing?
        if (available == 0)
        {
            if (_response.isCommitted())
                throw new IOException("Committed before 100 Continues");

            // TODO: break this dependency with HttpGenerator
            boolean committed = sendResponse(HttpGenerator.CONTINUE_100_INFO, null, false);
            if (!committed)
                throw new IOException("Concurrent commit while trying to send 100-Continue");
        }
    }
}

如何防止jersey+jetty发回100 continue,直到请求到达jersey标记的URI路径方法?

使用
Expect:100 continue
处理

如果您希望响应请求的该部分,则:

  • 不要尝试访问请求参数(这需要读取输入流以处理所有可能的参数源)
  • 不要尝试访问请求输入流(这意味着您正在接受
    100 Continue
    期望并准备接收实际请求正文内容)
  • 不要尝试访问请求读取器(这也会打开请求输入流)
  • 不要尝试使用servlet异步I/O层(这将打开请求inputstream和响应outputstreams)
  • 请使用HttpServletResponse发送备用状态代码和/或响应正文内容

这都是标准的Servlet/Jetty行为。

同意。但这并不能回答我的问题。我知道这些是码头层的要求。但是,由于Jersey在代码到达我的任何代码之前调用了getInputStream()方法,这是否意味着Jersey+Jetty组合没有正确实现100 continue?请重新阅读问题。我想我只回答了一半的问题,码头那边。问题不在Jetty方面,而是Jersey假设它不必处理
100 Continue
期望值的交替处理。问题是一起使用Jetty+Jersey。我明白你的意思,这就是Jetty本身的工作方式,是的,100 Continue支持得到了正确实施。但是,当使用Jetty作为带有Jersey的容器时,它会损坏。问题是让jersey+jetty combo成功地使用100,这里没有回答,我遇到了这个问题。你有没有找到绕过它的办法?
@Override
public ServletInputStream getInputStream() throws IOException
{
    if (_inputState != __NONE && _inputState != _STREAM)
        throw new IllegalStateException("READER");
    _inputState = _STREAM;

    if (_channel.isExpecting100Continue())
        _channel.continue100(_input.available());

    return _input;
}
 /**
 * If the associated response has the Expect header set to 100 Continue,
 * then accessing the input stream indicates that the handler/servlet
 * is ready for the request body and thus a 100 Continue response is sent.
 *
 * @throws IOException if the InputStream cannot be created
 */
public void continue100(int available) throws IOException
{
    // If the client is expecting 100 CONTINUE, then send it now.
    // TODO: consider using an AtomicBoolean ?
    if (isExpecting100Continue())
    {
        _expect100Continue = false;

        // is content missing?
        if (available == 0)
        {
            if (_response.isCommitted())
                throw new IOException("Committed before 100 Continues");

            // TODO: break this dependency with HttpGenerator
            boolean committed = sendResponse(HttpGenerator.CONTINUE_100_INFO, null, false);
            if (!committed)
                throw new IOException("Concurrent commit while trying to send 100-Continue");
        }
    }
}