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


Java Http2Exception类代码示例

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


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

示例1: getHttpRequest

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
public FullHttpRequest getHttpRequest() {
  if (h1Request != null) {
    return h1Request;
  }

  if (h2Headers != null) {
    try {
      // Fake out a full HTTP request.
      FullHttpRequest synthesizedRequest =
          HttpConversionUtil.toFullHttpRequest(0, h2Headers, alloc, true);
      if (data != null) {
        synthesizedRequest.replace(data);
      }

      return synthesizedRequest;
    } catch (Http2Exception e) {
      // TODO(JR): Do something more meaningful with this exception
      e.printStackTrace();
    }
  }

  throw new IllegalStateException("Cannot get the http request for an empty XrpcRequest");
}
 
开发者ID:Nordstrom,项目名称:xrpc,代码行数:24,代码来源:XrpcRequest.java

示例2: onRstStreamRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception {
    final HttpResponseWrapper res = removeResponse(streamIdToId(streamId));
    if (res == null) {
        if (conn.streamMayHaveExisted(streamId)) {
            if (logger.isDebugEnabled()) {
                logger.debug("{} Received a late RST_STREAM frame for a closed stream: {}",
                             ctx.channel(), streamId);
            }
        } else {
            throw connectionError(PROTOCOL_ERROR,
                                  "received a RST_STREAM frame for an unknown stream: %d", streamId);
        }
        return;
    }

    res.close(ClosedSessionException.get());
}
 
开发者ID:line,项目名称:armeria,代码行数:19,代码来源:Http2ResponseDecoder.java

示例3: statusFromThrowable

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
public static Status statusFromThrowable(Throwable t) {
  Status s = Status.fromThrowable(t);
  if (s.getCode() != Status.Code.UNKNOWN) {
    return s;
  }
  if (t instanceof ClosedChannelException) {
    // ClosedChannelException is used any time the Netty channel is closed. Proper error
    // processing requires remembering the error that occurred before this one and using it
    // instead.
    //
    // Netty uses an exception that has no stack trace, while we would never hope to show this to
    // users, if it happens having the extra information may provide a small hint of where to
    // look.
    ClosedChannelException extraT = new ClosedChannelException();
    extraT.initCause(t);
    return Status.UNKNOWN.withDescription("channel closed").withCause(extraT);
  }
  if (t instanceof IOException) {
    return Status.UNAVAILABLE.withDescription("io exception").withCause(t);
  }
  if (t instanceof Http2Exception) {
    return Status.INTERNAL.withDescription("http2 exception").withCause(t);
  }
  return s;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:Utils.java

示例4: onHeadersRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
        int padding, boolean endOfStream) throws Http2Exception {
    String path = headers.path().toString();
    RequestResponder responder;
    if (path.startsWith(ECHO_STREAM_PATH)) {
        responder = new EchoStreamResponder();
    } else if (path.startsWith(ECHO_TRAILERS_PATH)) {
        responder = new EchoTrailersResponder();
    } else if (path.startsWith(ECHO_ALL_HEADERS_PATH)) {
        responder = new EchoAllHeadersResponder();
    } else if (path.startsWith(ECHO_HEADER_PATH)) {
        responder = new EchoHeaderResponder();
    } else if (path.startsWith(ECHO_METHOD_PATH)) {
        responder = new EchoMethodResponder();
    } else {
        responder = new RequestResponder();
    }

    responder.onHeadersRead(ctx, streamId, endOfStream, headers);

    if (!endOfStream) {
        mResponderMap.put(streamId, responder);
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:26,代码来源:Http2TestHandler.java

示例5: goAwayDebugData

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
private static String goAwayDebugData(Http2Exception http2Ex, Throwable cause) {
    final StringBuilder buf = new StringBuilder(256);
    final String type;
    final String message;

    if (http2Ex != null) {
        type = http2Ex.getClass().getName();
        message = http2Ex.getMessage();
    } else {
        type = null;
        message = null;
    }

    buf.append("type: ");
    buf.append(MoreObjects.firstNonNull(type, "n/a"));
    buf.append(", message: ");
    buf.append(MoreObjects.firstNonNull(message, "n/a"));
    buf.append(", cause: ");
    buf.append(cause != null ? Throwables.getStackTraceAsString(cause) : "n/a");

    return buf.toString();
}
 
开发者ID:line,项目名称:armeria,代码行数:23,代码来源:AbstractHttp2ConnectionHandler.java

示例6: outboundCookiesMustBeMergedForHttp1

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Test
public void outboundCookiesMustBeMergedForHttp1() throws Http2Exception {
    final HttpHeaders in = new DefaultHttpHeaders();

    in.add(HttpHeaderNames.COOKIE, "a=b; c=d");
    in.add(HttpHeaderNames.COOKIE, "e=f;g=h");
    in.addObject(HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8);
    in.add(HttpHeaderNames.COOKIE, "i=j");
    in.add(HttpHeaderNames.COOKIE, "k=l;");

    final io.netty.handler.codec.http.HttpHeaders out =
            new io.netty.handler.codec.http.DefaultHttpHeaders();

    toNettyHttp1(0, in, out, HttpVersion.HTTP_1_1, false, true);
    assertThat(out.getAll(HttpHeaderNames.COOKIE))
            .containsExactly("a=b; c=d; e=f; g=h; i=j; k=l");
}
 
开发者ID:line,项目名称:armeria,代码行数:18,代码来源:ArmeriaHttpUtilTest.java

示例7: onDataRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Override
    public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream)
            throws Http2Exception {

        HTTPCarbonMessage cMsg = streamIdRequestMap.get(streamId);
        if (cMsg != null) {
            cMsg.addHttpContent(new DefaultLastHttpContent(data.retain()));
            if (endOfStream) {
                cMsg.setEndOfMsgAdded(true);
//                if (HTTPTransportContextHolder.getInstance().getHandlerExecutor() != null) {
//                    HTTPTransportContextHolder.getInstance().getHandlerExecutor().executeAtSourceRequestSending(cMsg);
//                }
            }
        }
        return data.readableBytes() + padding;
    }
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:17,代码来源:HTTP2SourceHandler.java

示例8: onDataRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Override
public int onDataRead(
    ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream)
    throws Http2Exception {
  if (isServer) {
    ctx.fireChannelRead(
        Http2Request.build(
            streamId,
            new DefaultHttp2DataFrame(data.retain(), endOfStream, padding),
            endOfStream));
  } else {
    ctx.fireChannelRead(
        Http2Response.build(
            streamId,
            new DefaultHttp2DataFrame(data.retain(), endOfStream, padding),
            endOfStream));
  }
  return data.readableBytes() + padding;
}
 
开发者ID:xjdr,项目名称:xio,代码行数:20,代码来源:Http2FrameForwarder.java

示例9: onHeadersRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Override
public void onHeadersRead(
    ChannelHandlerContext ctx,
    int streamId,
    Http2Headers headers,
    int streamDependency,
    short weight,
    boolean exclusive,
    int padding,
    boolean endStream)
    throws Http2Exception {
  if (isServer) {
    ctx.fireChannelRead(Http2Request.build(streamId, headers, endStream));
  } else {
    ctx.fireChannelRead(Http2Response.build(streamId, headers, endStream));
  }
}
 
开发者ID:xjdr,项目名称:xio,代码行数:18,代码来源:Http2FrameForwarder.java

示例10: forcefulClose

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
    ChannelPromise promise) throws Exception {
  close(ctx, promise);
  connection().forEachActiveStream(new Http2StreamVisitor() {
    @Override
    public boolean visit(Http2Stream stream) throws Http2Exception {
      NettyServerStream.TransportState serverStream = serverStream(stream);
      if (serverStream != null) {
        serverStream.transportReportStatus(msg.getStatus());
        resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
      }
      stream.close();
      return true;
    }
  });
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:NettyServerHandler.java

示例11: onPingRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
  if (!keepAliveEnforcer.pingAcceptable()) {
    ByteBuf debugData = ByteBufUtil.writeAscii(ctx.alloc(), "too_many_pings");
    goAway(ctx, connection().remote().lastStreamCreated(), Http2Error.ENHANCE_YOUR_CALM.code(),
        debugData, ctx.newPromise());
    Status status = Status.RESOURCE_EXHAUSTED.withDescription("Too many pings from client");
    try {
      forcefulClose(ctx, new ForcefulCloseCommand(status), ctx.newPromise());
    } catch (Exception ex) {
      onError(ctx, ex);
    }
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:NettyServerHandler.java

示例12: forcefulClose

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
    ChannelPromise promise) throws Exception {
  // close() already called by NettyClientTransport, so just need to clean up streams
  connection().forEachActiveStream(new Http2StreamVisitor() {
    @Override
    public boolean visit(Http2Stream stream) throws Http2Exception {
      NettyClientStream.TransportState clientStream = clientStream(stream);
      if (clientStream != null) {
        clientStream.transportReportStatus(msg.getStatus(), true, new Metadata());
        resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
      }
      stream.close();
      return true;
    }
  });
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:NettyClientHandler.java

示例13: goingAway

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
/**
 * Handler for a GOAWAY being either sent or received. Fails any streams created after the
 * last known stream.
 */
private void goingAway(Status status) {
  lifecycleManager.notifyShutdown(status);
  final Status goAwayStatus = lifecycleManager.getShutdownStatus();
  final int lastKnownStream = connection().local().lastStreamKnownByPeer();
  try {
    connection().forEachActiveStream(new Http2StreamVisitor() {
      @Override
      public boolean visit(Http2Stream stream) throws Http2Exception {
        if (stream.id() > lastKnownStream) {
          NettyClientStream.TransportState clientStream = clientStream(stream);
          if (clientStream != null) {
            clientStream.transportReportStatus(goAwayStatus, false, new Metadata());
          }
          stream.close();
        }
        return true;
      }
    });
  } catch (Http2Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:27,代码来源:NettyClientHandler.java

示例14: onPingAckRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Override
public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
  Http2Ping p = ping;
  if (data.getLong(data.readerIndex()) == flowControlPing().payload()) {
    flowControlPing().updateWindow();
    if (logger.isLoggable(Level.FINE)) {
      logger.log(Level.FINE, String.format("Window: %d",
          decoder().flowController().initialWindowSize(connection().connectionStream())));
    }
  } else if (p != null) {
    long ackPayload = data.readLong();
    if (p.payload() == ackPayload) {
      p.complete();
      ping = null;
    } else {
      logger.log(Level.WARNING, String.format(
          "Received unexpected ping ack. Expecting %d, got %d", p.payload(), ackPayload));
    }
  } else {
    logger.warning("Received unexpected ping ack. No ping outstanding");
  }
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:NettyClientHandler.java

示例15: updateWindow

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
public void updateWindow() throws Http2Exception {
  if (!autoTuneFlowControlOn) {
    return;
  }
  pingReturn++;
  long elapsedTime = (System.nanoTime() - lastPingTime);
  if (elapsedTime == 0) {
    elapsedTime = 1;
  }
  long bandwidth = (getDataSincePing() * TimeUnit.SECONDS.toNanos(1)) / elapsedTime;
  Http2LocalFlowController fc = decoder().flowController();
  // Calculate new window size by doubling the observed BDP, but cap at max window
  int targetWindow = Math.min(getDataSincePing() * 2, MAX_WINDOW_SIZE);
  setPinging(false);
  int currentWindow = fc.initialWindowSize(connection().connectionStream());
  if (targetWindow > currentWindow && bandwidth > lastBandwidth) {
    lastBandwidth = bandwidth;
    int increase = targetWindow - currentWindow;
    fc.incrementWindowSize(connection().connectionStream(), increase);
    fc.initialWindowSize(targetWindow);
    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(targetWindow);
    frameWriter().writeSettings(ctx(), settings, ctx().newPromise());
  }

}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:27,代码来源:AbstractNettyHandler.java


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