Package org.java_websocket.exceptions

Examples of org.java_websocket.exceptions.InvalidHandshakeException


  private static byte[] getPart( String key ) throws InvalidHandshakeException {
    try {
      long keyNumber = Long.parseLong( key.replaceAll( "[^0-9]", "" ) );
      long keySpace = key.split( "\u0020" ).length - 1;
      if( keySpace == 0 ) {
        throw new InvalidHandshakeException( "invalid Sec-WebSocket-Key (/key2/)" );
      }
      long part = new Long( keyNumber / keySpace );
      return new byte[]{ (byte) ( part >> 24 ), (byte) ( ( part << 8 ) >> 24 ), (byte) ( ( part << 16 ) >> 24 ), (byte) ( ( part << 24 ) >> 24 ) };
    } catch ( NumberFormatException e ) {
      throw new InvalidHandshakeException( "invalid Sec-WebSocket-Key (/key1/ or /key2/)" );
    }
  }
View Full Code Here


    response.put( "Sec-WebSocket-Location", location );
    String key1 = request.getFieldValue( "Sec-WebSocket-Key1" );
    String key2 = request.getFieldValue( "Sec-WebSocket-Key2" );
    byte[] key3 = request.getContent();
    if( key1 == null || key2 == null || key3 == null || key3.length != 8 ) {
      throw new InvalidHandshakeException( "Bad keys" );
    }
    response.setContent( createChallenge( key1, key2, key3 ) );
    return response;
  }
View Full Code Here

   */
  @Override
  public String getFlashPolicy( WebSocket conn ) throws InvalidDataException {
    InetSocketAddress adr = conn.getLocalSocketAddress();
    if(null == adr){
      throw new InvalidHandshakeException( "socket not bound" );
    }
   
    StringBuffer sb = new StringBuffer( 90 );
    sb.append( "<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"" );
    sb.append(adr.getPort());
View Full Code Here

    if( line == null )
      throw new IncompleteHandshakeException( buf.capacity() + 128 );

    String[] firstLineTokens = line.split( " ", 3 );// eg. HTTP/1.1 101 Switching the Protocols
    if( firstLineTokens.length != 3 ) {
      throw new InvalidHandshakeException();
    }

    if( role == Role.CLIENT ) {
      // translating/parsing the response from the SERVER
      handshake = new HandshakeImpl1Server();
      ServerHandshakeBuilder serverhandshake = (ServerHandshakeBuilder) handshake;
      serverhandshake.setHttpStatus( Short.parseShort( firstLineTokens[ 1 ] ) );
      serverhandshake.setHttpStatusMessage( firstLineTokens[ 2 ] );
    } else {
      // translating/parsing the request from the CLIENT
      ClientHandshakeBuilder clienthandshake = new HandshakeImpl1Client();
      clienthandshake.setResourceDescriptor( firstLineTokens[ 1 ] );
      handshake = clienthandshake;
    }

    line = readStringLine( buf );
    while ( line != null && line.length() > 0 ) {
      String[] pair = line.split( ":", 2 );
      if( pair.length != 2 )
        throw new InvalidHandshakeException( "not an http header" );
      handshake.put( pair[ 0 ], pair[ 1 ].replaceFirst( "^ +", "" ) );
      line = readStringLine( buf );
    }
    if( line == null )
      throw new IncompleteHandshakeException();
View Full Code Here

    response.put( "Upgrade", "websocket" );
    response.put( "Connection", request.getFieldValue( "Connection" ) ); // to respond to a Connection keep alives
    response.setHttpStatusMessage( "Switching Protocols" );
    String seckey = request.getFieldValue( "Sec-WebSocket-Key" );
    if( seckey == null )
      throw new InvalidHandshakeException( "missing Sec-WebSocket-Key" );
    response.put( "Sec-WebSocket-Accept", generateFinalKey( seckey ) );
    return response;
  }
View Full Code Here

    // Notify Listener
    try {
      wsl.onWebsocketHandshakeSentAsClient( this, this.handshakerequest );
    } catch ( InvalidDataException e ) {
      // Stop if the client code throws an exception
      throw new InvalidHandshakeException( "Handshake data rejected by client." );
    } catch ( RuntimeException e ) {
      wsl.onWebsocketError( this, e );
      throw new InvalidHandshakeException( "rejected because of" + e );
    }

    // Send
    write( draft.createHandshake( this.handshakerequest, role ) );
  }
View Full Code Here

TOP

Related Classes of org.java_websocket.exceptions.InvalidHandshakeException

Copyright © 2018 www.massapicom. 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.