• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Http2Exception类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: decode_responseHeaders

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
@Test
public void decode_responseHeaders() throws Http2Exception {
  Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
  Http2HeadersEncoder encoder =
      new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);

  Http2Headers headers = new DefaultHttp2Headers(false);
  headers.add(of(":status"), of("200")).add(of("custom"), of("header"));
  encodedHeaders = Unpooled.buffer();
  encoder.encodeHeaders(1 /* randomly chosen */, headers, encodedHeaders);

  Http2Headers decodedHeaders = decoder.decodeHeaders(3 /* randomly chosen */, encodedHeaders);
  assertEquals(headers.get(of(":status")), decodedHeaders.get(of(":status")));
  assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
  assertEquals(headers.size(), decodedHeaders.size());

  String toString = decodedHeaders.toString();
  assertContainsKeyAndValue(toString, ":status", decodedHeaders.get(of(":status")));
  assertContainsKeyAndValue(toString, "custom", decodedHeaders.get(of("custom")));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:GrpcHttp2HeadersUtilsTest.java


示例17: 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 {
    RequestResponder responder = mResponderMap.get(streamId);
    if (endOfStream) {
        mResponderMap.remove(streamId);
    }
    return responder.onDataRead(ctx, streamId, data, padding, endOfStream);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:10,代码来源:Http2TestHandler.java


示例18: 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 {
  encoder.writeHeaders(ctx, streamId,
    new DefaultHttp2Headers().status(HttpResponseStatus.OK.codeAsText()), 0,
    false, ctx.newPromise());
  encoder.writeData(
    ctx,
    streamId,
    ctx.alloc().buffer()
        .writeBytes("HTTP/2 DTP".getBytes(StandardCharsets.UTF_8)), 0, true,
    ctx.newPromise());
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:15,代码来源:DtpHttp2FrameListener.java


示例19: onDataRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
/**
 * If receive a frame with end-of-stream set, send a pre-canned response.
 */
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
        boolean endOfStream) throws Http2Exception {
    int processed = data.readableBytes() + padding;
    if (endOfStream) {
        sendResponse(ctx, streamId, data.retain());
    }
    return processed;
}
 
开发者ID:duchien85,项目名称:netty-cookbook,代码行数:13,代码来源:HelloWorldHttp2Handler.java


示例20: onHeadersRead

import io.netty.handler.codec.http2.Http2Exception; //导入依赖的package包/类
/**
 * If receive a frame with end-of-stream set, send a pre-canned response.
 */
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId,
        Http2Headers headers, int streamDependency, short weight,
        boolean exclusive, int padding, boolean endStream) throws Http2Exception {
	System.out.println("aaa");
    if (endStream) {
        sendResponse(ctx, streamId, RESPONSE_BYTES.duplicate());
    }
}
 
开发者ID:duchien85,项目名称:netty-cookbook,代码行数:13,代码来源:HelloWorldHttp2Handler.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ParseResult类代码示例发布时间:2022-05-22
下一篇:
Java LogHandlerEventType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap