Examples of DirectMemoryResponse


Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

    public DirectMemoryResponse retrieve( DirectMemoryRequest directMemoryRequest )
        throws DirectMemoryException, IOException, ClassNotFoundException, InstantiationException,
        IllegalAccessException
    {
        verifyPerRequestParameters( directMemoryRequest );
        DirectMemoryResponse response = this.directMemoryHttpClient.get( directMemoryRequest );
        if ( response.isFound() && response.getCacheContent() != null && response.getCacheContent().length > 0 )
        {
            Serializer serializer = directMemoryRequest.getSerializer();
            if ( serializer == null )
            {
                serializer = clientConfiguration.getSerializer();
            }
            response.setResponse(
                serializer.deserialize( response.getCacheContent(), directMemoryRequest.getObjectClass() ) );
        }
        return response;
    }
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

    @Override
    public byte[] handleGet( DirectMemoryRequest request, byte[] cacheResponseContent, HttpServletResponse resp,
                             HttpServletRequest req )
        throws DirectMemoryException, IOException
    {
        DirectMemoryResponse response =
            new DirectMemoryResponse().setKey( request.getKey() ).setCacheContent( cacheResponseContent );
        String json = writer.generateJsonResponse( response );
        resp.setContentType( MediaType.APPLICATION_JSON );
        return json.getBytes();
    }
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

            case JSON:
                return DirectMemoryParser.instance().buildResponse( inputStream );
            case JAVA_SERIALIZED_OBJECT:
                try
                {
                    DirectMemoryResponse response = new DirectMemoryResponse();
                    response.setResponse( request.getSerializer().deserialize( IOUtils.toByteArray( inputStream ),
                                                                               request.getObjectClass() ) );
                    return response;

                }
                catch ( IOException e )
                {
                    throw new DirectMemoryException( e.getMessage(), e );
                }
                catch ( ClassNotFoundException e )
                {
                    throw new DirectMemoryException( e.getMessage(), e );
                }
                catch ( IllegalAccessException e )
                {
                    throw new DirectMemoryException( e.getMessage(), e );
                }
                catch ( InstantiationException e )
                {
                    throw new DirectMemoryException( e.getMessage(), e );
                }
            case TEXT_PLAIN:
                try
                {
                    DirectMemoryResponse<String> response = new DirectMemoryResponse<String>();
                    response.setResponse( IOUtils.toString( inputStream ) );
                    return response;
                }
                catch ( IOException e )
                {
                    throw new DirectMemoryException( e.getMessage(), e );
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

            switch ( statusLine.getStatusCode() )
            {
                case 200:
                    Header header = response.getFirstHeader( DirectMemoryHttpConstants.EXPIRES_SERIALIZE_SIZE );
                    int storedSize = header == null ? -1 : Integer.valueOf( header.getValue() );
                    return new DirectMemoryResponse().setStored( Boolean.TRUE ).setStoredSize( storedSize );
                case 204:
                    return new DirectMemoryResponse().setStored( Boolean.FALSE );
                default:
                    throw new DirectMemoryException(
                        "put cache content return http code:'" + statusLine.getStatusCode() + "', reasonPhrase:"
                            + statusLine.getReasonPhrase() );
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

            // handle no content response
            StatusLine statusLine = httpResponse.getStatusLine();
            if ( statusLine.getStatusCode() == 204 )
            {
                return new DirectMemoryResponse().setFound( false );
            }

            if ( request.isDeleteRequest() )
            {
                return new DirectMemoryResponse().setFound( true ).setDeleted( true );
            }

            return buildResponse( httpResponse.getEntity().getContent(), request ).setFound( true );
        }
        catch ( IOException e )
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

            // handle no content response
            StatusLine statusLine = httpResponse.getStatusLine();
            if ( statusLine.getStatusCode() == 204 )
            {
                return new DirectMemoryResponse().setFound( false ).setDeleted( false );
            }

            return new DirectMemoryResponse().setFound( true ).setDeleted( true );

        }
        catch ( IOException e )
        {
            throw new DirectMemoryException( e.getMessage(), e );
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

        switch ( statusCode )
        {
            case 200:
                String headerValue = response.getHeader( DirectMemoryHttpConstants.EXPIRES_SERIALIZE_SIZE );
                int storedSize = headerValue == null ? -1 : Integer.valueOf( headerValue );
                return new DirectMemoryResponse().setStored( Boolean.TRUE ).setStoredSize( storedSize );
            case 204:
                return new DirectMemoryResponse().setStored( Boolean.FALSE );
            default:
                throw new DirectMemoryException(
                    "put cache content return http code:'" + statusCode + "', reasonPhrase:"
                        + response.getStatusText() );
        }
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

        // handle no content response

        if ( statusCode == 204 )
        {
            return new DirectMemoryResponse().setFound( false );
        }

        if ( request.isDeleteRequest() )
        {
            return new DirectMemoryResponse().setFound( true ).setDeleted( true );
        }

        return AbstractDirectMemoryHttpClient.
            buildResponse( response.getResponseBodyAsStream(), request ).setFound( true );
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

        int statusCode = response.getStatusCode();

        // handle no content response

        return statusCode == 204
            ? new DirectMemoryResponse().setFound( false ).setDeleted( false )
            : new DirectMemoryResponse().setFound( true ).setDeleted( true );
    }
View Full Code Here

Examples of org.apache.directmemory.server.commons.DirectMemoryResponse

            client.retrieve( new DirectMemoryRequest( "bordeaux", "very great wine" ) );

        assertTrue( response.isFound() );
        assertEquals( "very great wine", response.getResponse() );

        DirectMemoryResponse deleteResponse = client.delete( new DirectMemoryRequest<Wine>( "bordeaux" ) );
        assertTrue( deleteResponse.isDeleted() );

        response = client.retrieve( new DirectMemoryRequest<String>( "bordeaux", String.class ) );

        assertFalse( response.isFound() );
        String res = response.getResponse();
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.