コード例 #1
0
ファイル: PerMessageDeflate.java プロジェクト: sqtds/tomcat7
  @Override
  public Extension getExtensionResponse() {
    Extension result = new WsExtension(NAME);

    List<Extension.Parameter> params = result.getParameters();

    if (!serverContextTakeover) {
      params.add(new WsExtensionParameter(SERVER_NO_CONTEXT_TAKEOVER, null));
    }
    if (serverMaxWindowBits != -1) {
      params.add(
          new WsExtensionParameter(SERVER_MAX_WINDOW_BITS, Integer.toString(serverMaxWindowBits)));
    }
    if (!clientContextTakeover) {
      params.add(new WsExtensionParameter(CLIENT_NO_CONTEXT_TAKEOVER, null));
    }
    if (clientMaxWindowBits != -1) {
      params.add(
          new WsExtensionParameter(CLIENT_MAX_WINDOW_BITS, Integer.toString(clientMaxWindowBits)));
    }

    return result;
  }
コード例 #2
0
    @Override
    public void handle(ByteBuffer data) {
      try {
        if (data != null && data.hasRemaining()) {

          if (buffer != null) {
            data = Utils.appendBuffers(buffer, data, incomingBufferSize, BUFFER_STEP_SIZE);
          } else {
            int newSize = data.remaining();
            if (newSize > incomingBufferSize) {
              throw new IllegalArgumentException("Buffer overflow.");
            } else {
              final int roundedSize =
                  (newSize % BUFFER_STEP_SIZE) > 0
                      ? ((newSize / BUFFER_STEP_SIZE) + 1) * BUFFER_STEP_SIZE
                      : newSize;
              final ByteBuffer result =
                  ByteBuffer.allocate(roundedSize > incomingBufferSize ? newSize : roundedSize);
              result.flip();
              data = Utils.appendBuffers(result, data, incomingBufferSize, BUFFER_STEP_SIZE);
            }
          }

          do {
            final Frame incomingFrame = protocolHandler.unframe(data);

            if (incomingFrame == null) {
              buffer = data;
              break;
            } else {
              Frame frame = incomingFrame;

              for (Extension extension : negotiatedExtensions) {
                if (extension instanceof ExtendedExtension) {
                  try {
                    frame =
                        ((ExtendedExtension) extension).processIncoming(extensionContext, frame);
                  } catch (Throwable t) {
                    LOGGER.log(
                        Level.FINE,
                        String.format(
                            "Extension '%s' threw an exception during processIncoming method invocation: \"%s\".",
                            extension.getName(), t.getMessage()),
                        t);
                  }
                }
              }

              protocolHandler.process(frame, socket);
            }
          } while (true);
        }
      } catch (FramingException e) {
        LOGGER.log(Level.FINE, e.getMessage(), e);
        socket.onClose(
            new CloseFrame(
                new CloseReason(
                    CloseReason.CloseCodes.getCloseCode(e.getClosingCode()), e.getMessage())));
      } catch (Exception e) {
        LOGGER.log(Level.FINE, e.getMessage(), e);
        if (endpoint.onError(socket, e)) {
          socket.onClose(
              new CloseFrame(
                  new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, e.getMessage())));
        }
      }
    }
コード例 #3
0
 public JsrExtensionConfig(Extension ext) {
   super(ext.getName());
   for (Extension.Parameter param : ext.getParameters()) {
     this.setParameter(param.getName(), param.getValue());
   }
 }