Examples of ProtocolException


Examples of org.httpkit.ProtocolException

                    finalFlag = (b & 0x80) != 0;

                    int tmpOp = b & 0x0F;
                    if (opcode != -1 && tmpOp != opcode) {
                        // TODO ping frame in fragmented text frame
                        throw new ProtocolException("opcode mismatch: pre: " + opcode + ", now: "
                                + tmpOp);
                    }
                    opcode = tmpOp;
                    state = State.READ_LENGTH;
                    break;
                case READ_LENGTH:
                    b = buffer.get(); // MASK, PAYLOAD LEN 1
                    boolean masked = (b & 0x80) != 0;
                    if (!masked) {
                        throw new ProtocolException("unmasked client to server frame");
                    }
                    payloadLength = b & 0x7F;
                    if (payloadLength == 126) {
                        state = State.READ_2_LENGTH;
                    } else if (payloadLength == 127) {
                        state = State.READ_8_LENGTH;
                    } else {
                        state = State.MASKING_KEY;
                    }
                    break;
                case READ_2_LENGTH:
                    if (isAvailable(buffer, 2)) {
                        payloadLength = tmpBuffer.getShort() & 0xFFFF;
                        tmpBuffer.clear();
                        if (payloadLength < 126) {
                            throw new ProtocolException(
                                    "invalid data frame length (not using minimal length encoding)");
                        }
                        state = State.MASKING_KEY;
                    }
                    break;
                case READ_8_LENGTH:
                    if (isAvailable(buffer, 8)) {
                        long length = tmpBuffer.getLong();
                        tmpBuffer.clear();
                        // if negative, that too big, drop it.
                        if (length < 65536) {
                            throw new ProtocolException("invalid data frame length. max payload length 4M");
                        }
                        abortIfTooLarge(length);
                        payloadLength = (int) length;
                        state = State.MASKING_KEY;
                    }
                    break; // wait for more data from TCP
                case MASKING_KEY:
                    if (isAvailable(buffer, 4)) {
                        maskingKey = tmpBuffer.getInt();
                        tmpBuffer.clear();
                        if (content == null) {
                            content = new byte[payloadLength];
                        } else if (payloadLength > 0) {
                            abortIfTooLarge(content.length + payloadLength);
                            /*
                             * TODO if an attacker sent many fragmented frames, only one
                             * byte of data per frame, server end up reallocate many
                             * times. may not be a problem
                             */
                            // resize
                            content = Arrays.copyOf(content, content.length + payloadLength);
                        }
                        framePayloadIndex = 0; // reset
                        state = State.PAYLOAD;
                        // No break. since payloadLength can be 0
                    } else {
                        break; // wait for more data from TCP
                    }
                case PAYLOAD:
                    int read = Math.min(buffer.remaining(), payloadLength - payloadRead);
                    if (read > 0) {
                        buffer.get(content, idx, read);

                        byte[] mask = ByteBuffer.allocate(4).putInt(maskingKey).array();
                        for (int i = 0; i < read; i++) {
                            content[i + idx] = (byte) (content[i + idx] ^ mask[(framePayloadIndex + i) % 4]);
                        }

                        payloadRead += read;
                        idx += read;
                    }
                    framePayloadIndex += read;

                    // all read (this frame)
                    if (payloadRead == payloadLength) {
                        if (finalFlag) {
                            switch (opcode) {
                                case OPCODE_TEXT:
                                    return new Frame.TextFrame(content);
                                case OPCODE_BINARY:
                                    return new Frame.BinaryFrame(content);
                                case OPCODE_PING:
                                    return new Frame.PingFrame(content);
                                case OPCODE_PONG:
                                    return new Frame.PongFrame(content);
                                case OPCODE_CLOSE:
                                    return new Frame.CloseFrame(content);
                                default:
                                    throw new ProtocolException("not impl for opcode: " + opcode);
                            }
                        } else {
                            state = State.FRAME_START;
                            payloadRead = 0;
                        }
View Full Code Here

Examples of org.jtestserver.common.protocol.ProtocolException

        try {
            LOGGER.log(Level.INFO, "xml report: " + report);
           
            return parser.parse(sr);
        } catch (XMLParseException e) {
            throw new ProtocolException("invalid XML answer", e);
        } catch (IOException e) {
            throw new ProtocolException("I/O error", e);
        }
    }
View Full Code Here

Examples of org.jwall.web.http.ProtocolException

     */
    public HttpHeader readHeader() throws TimeOutException, IOException, ProtocolException {
        log.debug("Entering HttpRequestStream.readHeader()");
       
        if( state == STATE_READING_BODY )
            throw new ProtocolException("Last header indicated a message-body - need to read that first!");

        String line = in.readLine();

        if( line == null ){
            //
View Full Code Here

Examples of org.red5.server.net.protocol.ProtocolException

      }
    } catch (ProtocolException pe) {
      // raise to caller unmodified
      throw pe;
    } catch (RuntimeException e) {
      throw new ProtocolException("Error during decoding", e);
    } finally {
      if (log.isTraceEnabled()) {
        log.trace("Decoding finished for {}", conn.getSessionId());
      }
    }
View Full Code Here

Examples of org.w3c.tools.resources.ProtocolException

    return reply;
      }
  }
  // Create a lookup state, and a lookup result:

  ProtocolException error = null;
  LookupState   ls = null;
  LookupResult  lr = null;
  // Run the lookup algorithm of root resource:
  // catch exception to get error (FIXME)
  try {
      lr = new LookupResult(root.getResourceReference());
      ls = new LookupState(request);

      if ( root.lookup(ls, lr) ) {
    if (lr.hasReply())
        return lr.getReply();
      }
  } catch (ProtocolException ex) {
      error = ex;
  } catch (Exception ex) {
      /*
       * We have a problem here, the error can be a configuration
       * or resource/extension problem, and it should be a
       * 5xx error, or it is a client side error and it should be
       * a 4xx error, ex, try with "Authorization:" and it fails.
       * For now we will reply with a 400, but with a FIXME
       */
      Reply err = request.makeReply(HTTP.BAD_REQUEST);
      err.setContent("<html><head><title>Bad Request</title></head>\n"
         + "<body><p>The server was not able to "
         + "understand this request</p></body></html>");
      error = new ProtocolException(err);
  }
  // Let the target resource perform the method
  ResourceReference  target = lr.getTarget();
  Reply              reply  = null;

  ResourceFilter filters[]  = lr.getFilters();
  int            infilter   = 0;

  if (error == null) {
      //call the ingoing filters:
      try {
    // temporary target resource !!! WARNING
    request.setTargetResource(target);
    if ( filters != null ) {
        for ( ; infilter < filters.length ; infilter++ ) {
      if ( filters[infilter] == null )
          continue;
      reply = (Reply)filters[infilter].
                                     ingoingFilter(request,
                     filters,
                     infilter);
      if ( reply != null ) {
          return reply;
      }
        }
    }
      } catch (ProtocolException ex) {
    error = ex;
      }
      //perform the request:
      if ((error == null) && (target != null)) {
    request.setFilters(filters, infilter);
    request.setTargetResource(target);
    try {
        FramedResource res = (FramedResource)target.lock();
        reply = (Reply) res.perform(request);
        if (reply == null) {
      reply = request.makeReply(HTTP.NOT_FOUND);
      if (uri_error) {
          reply.setContent("<html><head><title>Not Found" +
               "</title></head>\n"+
               "<body><h1>Invalid" +
               " URL</h1><p>The URL <b>"+
               request.getURL()+
               "</b> that you requested is not" +
               " available "+
               " for this protocol.</body>\n"
               +"</html>");
      } else {
          reply.setContent("<html><head><title>Not Found" +
               "</title></head>\n"+
               "<body><h1>Invalid" +
               " URL</h1><p>The URL" +
               "</b> that you requested is not" +
               " available "+
               " for this protocol.</body>\n"
               +"</html>");
      }
      reply.setContentType(org.w3c.www.mime.MimeType.
               TEXT_HTML);
        }
    } catch (InvalidResourceException ex) {
        //FIXME
        reply = request.makeReply(HTTP.NOT_FOUND);
        if (uri_error) {
      reply.setContent("<html><head><title>Not"+
           " Found</title>"+
           "</head><body><b>The URL <b>"+
           request.getURL()+
           "</b> that you requested is not " +
           "available, "+
           " probably deleted.</body></html>");
        } else {
      reply.setContent("<html><head><title>Not"+
           " Found</title>"+
           "</head><body><b>The URL"+
           " that you requested is not " +
           "available, "+
           " probably deleted.</body></html>");
        }
        reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
    } finally {
        target.unlock();
    }
      } else {
    reply = request.makeReply(HTTP.NOT_FOUND);
    if (uri_error) {
        reply.setContent("<html><head>\n"+
             "<title>Not Found</title></head>"+
             "<body><h1>Invalid URL</h1><p>The URL"+
             " <b>"+ request.getURL()+
             "</b> that you requested is not"+
             " available "+
             " on that server.</body></html>");
    } else {
        reply.setContent("<html><head>\n"+
             "<title>Not Found</title></head>"+
             "<body><h1>Invalid URL</h1><p>The URL"+
             " that you requested is not"+
             " available "+
             " on that server.</body></html>");
    }
    reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
      }
  }
  // call the outgoing filters:
  if ((reply == null) || (reply.getStatus() != HTTP.DONE)) {
      if ( error == null ) {
    for (int i = infilter ; --i >= 0 ; ) {
        if ( filters[i] == null )
      continue;
        Reply fr = (Reply)filters[i].outgoingFilter(request,
                reply,
                filters,
                i);
        if ( fr != null )
      return fr;
    }
      } else {
    // Make sure we always invoke appropriate filters:
    if (filters != null) {
        for (int i = filters.length ; --i >= 0 ; ) {
      if ( filters[i] == null ) {
          continue;
      }
      Reply fr = (Reply)filters[i].exceptionFilter(request,
                 error,
                 filters,
                 i);
      if ( fr != null ){
          return fr;
      }
        }
    }
    reply = (Reply)error.getReply() ;
    if (reply == null) {
        reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
        if (uri_error) {
      reply.setContent("<html><head>\n"+
           "<title>Server Error</title>"+
View Full Code Here

Examples of org.xlightweb.ProtocolException

                    isBufferIsActivated = false;
                    inMemorySink.destroy();
                }
               
            } else if (is100ContinueReceived && isRedirectResponse(getRequestHeader(), response.getResponseHeader())) {
                onException(new ProtocolException("Response order error. Got a redirect response after a 100-continue response", response.getResponseHeader()));
            }

            super.onResponse(response);
        }
View Full Code Here

Examples of org.xlightweb.ProtocolException

                    isBufferIsActivated = false;
                    inMemorySink.destroy();
                }
               
            } else if (is100ContinueReceived && isRedirectResponse(getRequestHeader(), response.getResponseHeader())) {
                onException(new ProtocolException("Response order error. Got a redirect response after a 100-continue response", response.getResponseHeader()));
            }

            super.onResponse(response);
        }
View Full Code Here

Examples of org.xlightweb.ProtocolException

                    isBufferIsActivated = false;
                    inMemorySink.destroy();
                }
               
            } else if (is100ContinueReceived && isRedirectResponse(getRequestHeader(), response.getResponseHeader())) {
                onException(new ProtocolException("Response order error. Got a redirect response after a 100-continue response", response.getResponseHeader()));
            }

            super.onResponse(response);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.