Package com.dottydingo.hyperion.service.pipeline

Examples of com.dottydingo.hyperion.service.pipeline.UriRequestResult


            throw new ServiceUnavailableException("Service not available");

        HyperionRequest request = phaseContext.getEndpointRequest();
        HyperionResponse response = phaseContext.getEndpointResponse();

        UriRequestResult uriRequestResult = uriParser.parseRequestUri(request.getResourceUri());

        if(uriRequestResult == null)
            throw new NotFoundException(String.format("%s is not recognized.",request.getResourceUri()));

        String entityName = uriRequestResult.getEndpoint();

        EntityPlugin plugin = serviceRegistry.getPluginForName(entityName);
        if(plugin == null)
            throw new NotFoundException(String.format("%s is not a valid entity.",entityName));

        phaseContext.setEntityPlugin(plugin);

        phaseContext.setRequestMethod(getHttpMethod(request.getRequestMethod()));
        String requestMethod = getEffectiveMethod(request);
        HttpMethod httpMethod = getHttpMethod(requestMethod);

        if(!plugin.isMethodAllowed(httpMethod))
            throw new NotAllowedException(String.format("%s is not allowed.",httpMethod));

        if(serviceStatus.getReadOnly() && httpMethod.isWriteOperation())
            throw new NotAllowedException("Service is in read only mode.");

        phaseContext.setEffectiveMethod(httpMethod);

        // special case where version is in the URI
        String version = uriRequestResult.getVersion();

        if(version == null || version.length() == 0)
        {
            version = request.getFirstParameter(hyperionEndpointConfiguration.getVersionParameterName());
            if(version == null || version.length() == 0)
                version = request.getFirstHeader(hyperionEndpointConfiguration.getVersionHeaderName());

            if(hyperionEndpointConfiguration.isRequireVersion() && httpMethod != HttpMethod.DELETE &&
                    (version == null || version.length()==0))
                throw new BadRequestException(String.format("The %s parameter must be specified",
                        hyperionEndpointConfiguration.getVersionParameterName()));
        }


        if(version != null)
        {
            try
            {
                phaseContext.setVersion(Integer.parseInt(version));
            }
            catch(NumberFormatException e)
            {
                throw new BadRequestException(String.format("%s is not a valid value for version.",version));
            }
        }

        if(!validateMethod(httpMethod,uriRequestResult))
            throw new HyperionException(405,"Not allowed.");

        if(uriRequestResult.getId() != null)
            phaseContext.setId(URLDecoder.decode(uriRequestResult.getId()));
        phaseContext.setHistory(uriRequestResult.isHistory());

        ApiVersionPlugin versionPlugin = plugin.getApiVersionRegistry().getPluginForVersion(phaseContext.getVersion());
        phaseContext.setVersionPlugin(versionPlugin);

        logRequestInformation(phaseContext);
View Full Code Here


    protected void executePhase(HyperionContext phaseContext) throws Exception
    {
        HyperionRequest request = phaseContext.getEndpointRequest();
        HyperionResponse response = phaseContext.getEndpointResponse();

        UriRequestResult uriRequestResult = uriParser.parseRequestUri(request.getResourceUri());

        if(uriRequestResult == null)
            throw new NotFoundException(String.format("%s is not recognized.",request.getResourceUri()));

        String entityName = uriRequestResult.getEndpoint();

        EntityPlugin plugin = serviceRegistry.getPluginForName(entityName);
        if(plugin == null)
            throw new NotFoundException(String.format("%s is not a valid entity.",entityName));

        phaseContext.setEntityPlugin(plugin);

        phaseContext.setRequestMethod(getHttpMethod(request.getRequestMethod()));
        String requestMethod = getEffectiveMethod(request);
        HttpMethod httpMethod = getHttpMethod(requestMethod);

        if(!plugin.isMethodAllowed(httpMethod))
            throw new HyperionException(405,String.format("%s is not allowed.",httpMethod));

        phaseContext.setEffectiveMethod(httpMethod);

        // special case where version is in the URI
        String version = uriRequestResult.getVersion();

        if(version == null || version.length() == 0)
        {
            version = request.getFirstParameter(hyperionEndpointConfiguration.getVersionParameterName());
            if(version == null || version.length() == 0)
                version = request.getFirstHeader(hyperionEndpointConfiguration.getVersionHeaderName());

            if(hyperionEndpointConfiguration.isRequireVersion() && httpMethod != HttpMethod.DELETE &&
                    (version == null || version.length()==0))
                throw new BadRequestException(String.format("The %s parameter must be specified",hyperionEndpointConfiguration.getVersionParameterName()));
        }


        if(version != null)
        {
            try
            {
                phaseContext.setVersion(Integer.parseInt(version));
            }
            catch(NumberFormatException e)
            {
                throw new BadRequestException(String.format("%s is not a valid value for version.",version));
            }
        }

        if(!validateMethod(httpMethod,uriRequestResult))
            throw new HyperionException(405,"Not allowed.");

        if(uriRequestResult.getId() != null)
            phaseContext.setId(URLDecoder.decode(uriRequestResult.getId()));
        phaseContext.setHistory(uriRequestResult.isHistory());

        ApiVersionPlugin versionPlugin = plugin.getApiVersionRegistry().getPluginForVersion(phaseContext.getVersion());
        phaseContext.setVersionPlugin(versionPlugin);

        logRequestInformation(phaseContext);
View Full Code Here

TOP

Related Classes of com.dottydingo.hyperion.service.pipeline.UriRequestResult

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.