Package org.pereni.dina.server

Examples of org.pereni.dina.server.ServerRuntimeException


     *
     * @param requestURI
     */
    public void setRequestURI(URI requestURI){
        if( requestURI == null || !requestURI.getPath().startsWith("/")) {
            throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
        }
        processQueryParameters( requestURI.getQuery());
        this.requestURI = requestURI;
    }
View Full Code Here


     *
     * @param method
     */
    public void setMethod(Http.Method method) {
        if( method == null ) {
            throw new ServerRuntimeException( HttpResponse.SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
        }
        this.method = method;
    }
View Full Code Here

     *
     * @param version
     */
    public void setVersion(Http.Version version) {
        if( version == null || Http.Version.HTTP_0_9.equals( version ) ){
            throw new ServerRuntimeException( HttpResponse.SC_HTTP_VERSION_NOT_SUPPORTED, "HTTP Version Not Supported");
        }
        this.version = version;
    }
View Full Code Here

                            if( elements.length < 3 ) {
                                LOG.warning("Request line has " + elements.length
                                        + " elements, expected 3. Value is "
                                        + lexerCurretToken.Value.toString() );
                                throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
                            }

                            Http.Method method = Http.Method.valueOf(elements[0]);
                            context.request.setMethod(method);

                            URI uri = new URI(elements[1]);
                            context.request.setRequestURI(uri);

                            LOG.finer("New request on " + uri.getPath() + " of type " + method.name());

                            Http.Version version = Http.Version.valueOf(
                                    elements[2].replace('/', '_').replace('.', '_'));
                            context.request.setVersion( version);

                        } else {
                            // it does not start with a potential request line, not valid http request
                            LOG.warning("Unable to understand request it is of type " + lexerCurretToken.Type.name()
                                        + "  and value starts with " + lexerCurretToken.Value.toString());
                            throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
                        }
                    }

                    // we've got the request line now we need to find the EOL so we can move to the headers
                    if( httpLexer.hasNext() ) {

                        lexerCurretToken = httpLexer.next();

                        if( HttpLexer.TokenType.EOL.equals( lexerCurretToken.Type) ) {
                            context.requestHandler.setCurrentStateHandler(new ProcessingHeadersStateHandler());
                            context.requestHandler.getCurrentStateHandler().handleState(context);
                        } else {
                            LOG.warning("Unable to understand request it does not end properly, expecting EOL found  "
                                    + lexerCurretToken.Value.toString());
                            throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
                        }
                        return;
                    }


                    inputBuffer.clear();    // make buffer empty
                    count = context.inputChannel.read( inputBuffer);
                }

            } catch (IOException ex) {
                LOG.log(Level.SEVERE, "Unable to process request input", ex);
            } catch (URISyntaxException e) {
                LOG.log(Level.SEVERE, "Unable to process request input", e);
                throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad Request");
            }
        }
View Full Code Here

                                context.request.getHeaders().put( headerName.trim().toLowerCase(), headerValue.trim());
                                LOG.finer("Found header " + headerName + " / " + headerValue);
                            } else {
                                LOG.warning("End of line parsing the headers yet missing the complete key value pair"
                                + " key is " + headerName + " value is " + headerValue);
                                throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
                            }

                            headerName = null;
                            headerValue = null;
                            isHeaderName = true;
                            break;

                        case EOF:
                            if( headerName != null && headerValue != null ) {
                                context.request.getHeaders().put( headerName.trim().toLowerCase(), headerValue.trim());
                                LOG.finer("Found header " + headerName + " / " + headerValue);
                            } else {
                                LOG.warning("End of line parsing the headeers yet missing the complete key value pair"
                                        + " key is " + headerName + " value is " + headerValue);
                                throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
                            }

                            LOG.finer("End of headers found, mooving to body");
                            context.requestHandler.setCurrentStateHandler(new ProcessingBodyStateHandler());
                            context.requestHandler.getCurrentStateHandler().handleState(context);
View Full Code Here

            ByteBuffer tempBuffer = ByteBuffer.wrap( tempOutput.toByteArray());
            try {
                this.outputByteChannel.write(tempBuffer);
                LOG.finer("Wrote " + tempOutput.size() + " bytes to output channel");
            } catch (IOException e) {
                throw new ServerRuntimeException("Unable to empty temporary output buffer");
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.pereni.dina.server.ServerRuntimeException

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.