Package com.cloud.bridge.service.core.s3

Examples of com.cloud.bridge.service.core.s3.S3ConditionalHeaders


                xmlDeleteResponse = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                        "<DeleteResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">");

                String bucket = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);

                S3DeleteObjectRequest engineRequest = new S3DeleteObjectRequest();
                engineRequest.setBucketName( bucket );
                is.close();

                doc.getDocumentElement().normalize();
                NodeList qList = doc.getElementsByTagName("Quiet");

                if (qList.getLength() == 1 ) {
                    Node qNode= qList.item(0);
                    if ( qNode.getFirstChild().getNodeValue().equalsIgnoreCase("true") == false )
                        quite = false;

                    logger.debug("Quite value  :" + qNode.getFirstChild().getNodeValue());
                }

                NodeList objList = doc.getElementsByTagName("Object");

                for (int i = 0; i < objList.getLength(); i++) {

                    Node key = objList.item(i);
                    NodeList key_data = key.getChildNodes();

                    if (key.getNodeType() == Node.ELEMENT_NODE) {
                        Element eElement = (Element) key;
                        String key_name = getTagValue(elements[0], eElement);
                        engineRequest.setBucketName(bucket);
                        engineRequest.setKey(key_name);

                        if (key_data.getLength() == 2) {
                            versionID = getTagValue(elements[1], eElement);
                            engineRequest.setVersion(versionID);
                        }

                        S3Response engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );
                        int resultCode = engineResponse.getResultCode();
                        String resutlDesc = engineResponse.getResultDescription();
                        if(resultCode == 204) {
                            if (quite) { // show response depending on quite/verbose
                                xmlDeleteResponse.append("<Deleted><Key>"+key_name+"</Key>");
                                if (resutlDesc != null)
                                    xmlDeleteResponse.append(resutlDesc);
                                xmlDeleteResponse.append("</Deleted>");
                            }
                        }
                        else {
                            logger.debug("Error in delete ::" + key_name + " eng response:: " + engineResponse.getResultDescription());
                            xmlDeleteResponse.append("<Error><Key>"+key_name+"</Key>" );
                            if (resutlDesc != null)
                                xmlDeleteResponse.append(resutlDesc);
                            xmlDeleteResponse.append("</Error>");
                        }


                    }
                }

                String version = engineRequest.getVersion();
                if (null != version) response.addHeader( "x-amz-version-id", version );


            } catch (IOException e) {
                logger.error("Unable to read request data due to " + e.getMessage(), e);
View Full Code Here


    private void executeDeleteObject(HttpServletRequest request, HttpServletResponse response) throws IOException
    {
        String   bucket    = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
        String   key       = (String) request.getAttribute(S3Constants.OBJECT_ATTR_KEY);

        S3DeleteObjectRequest engineRequest = new S3DeleteObjectRequest();
        engineRequest.setBucketName(bucket);
        engineRequest.setKey(key);

        // -> is this a request for a specific version of the object?  look for "versionId=" in the query string
        String queryString = request.getQueryString();
        if (null != queryString) engineRequest.setVersion( returnParameter( queryString, "versionId=" ));

        S3Response engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );

        response.setStatus( engineResponse.getResultCode())
        String version = engineRequest.getVersion();
        if (null != version) response.addHeader( "x-amz-version-id", version );   
    }
View Full Code Here

    private void processDimeRequest(HttpServletRequest request, HttpServletResponse response) {
        S3PutObjectRequest  putRequest  = null;
        S3PutObjectResponse putResponse = null;
        int                 bytesRead   = 0;

        S3Engine engine = new S3Engine();

        try {  
            logRequest(request);

            MultiPartDimeInputStream ds = new MultiPartDimeInputStream( request.getInputStream());

            // -> the first stream MUST be the SOAP party
            if (ds.nextInputStream())
            {
                //logger.debug( "DIME msg [" + ds.getStreamType() + "," + ds.getStreamTypeFormat() + "," + ds.getStreamId() + "]" );
                byte[] buffer = new byte[8192];
                bytesRead = ds.read( buffer, 0, 8192 );
                //logger.debug( "DIME SOAP Bytes read: " + bytesRead );
                ByteArrayInputStream bis = new ByteArrayInputStream( buffer, 0, bytesRead );
                putRequest = toEnginePutObjectRequest( bis );
            }

            // -> we only need to support a DIME message with two bodyparts
            if (null != putRequest && ds.nextInputStream())
            {
                InputStream is = ds.getInputStream();
                putRequest.setData( is );
            }

            // -> need to do SOAP level auth here, on failure return the SOAP fault
            StringBuffer xml = new StringBuffer();
            String AWSAccessKey = putRequest.getAccessKey();
            UserInfo info = ServiceProvider.getInstance().getUserInfo(AWSAccessKey);
            try
            {   S3SoapAuth.verifySignature( putRequest.getSignature(), "PutObject", putRequest.getRawTimestamp(), AWSAccessKey, info.getSecretKey());    

            } catch( AxisFault e ) {
                String reason = e.toString();
                int start = reason.indexOf( ".AxisFault:" );
                if (-1 != start) reason = reason.substring( start+11 );

                xml.append( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" );
                xml.append( "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >\n" );
                xml.append( "<soap:Body>\n" );              
                xml.append( "<soap:Fault>\n" );
                xml.append( "<faultcode>" ).append( e.getFaultCode().toString()).append( "</faultcode>\n" );
                xml.append( "<faultstring>" ).append( reason ).append( "</faultstring>\n" );
                xml.append( "</soap:Fault>\n" );
                xml.append( "</soap:Body></soap:Envelope>" );

                endResponse(response, xml.toString());
                return;
            }

            // -> PutObject S3 Bucket Policy would be done in the engine.handleRequest() call
            UserContext.current().initContext( AWSAccessKey, info.getSecretKey(), AWSAccessKey, "S3 DIME request", request );
            putResponse = engine.handleRequest( putRequest );

            xml.append( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" );
            xml.append( "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"http://s3.amazonaws.com/doc/2006-03-01/\">" );
            xml.append( "<soap:Body>" );
            xml.append( "<tns:PutObjectResponse>" );
View Full Code Here

      toEngineGetBucketAccessControlPolicyRequest(getBucketAccessControlPolicy)));
    }
 
  private S3GetBucketAccessControlPolicyRequest toEngineGetBucketAccessControlPolicyRequest(
    GetBucketAccessControlPolicy getBucketAccessControlPolicy) {
    S3GetBucketAccessControlPolicyRequest request = new S3GetBucketAccessControlPolicyRequest();
   
    request.setAccessKey(getBucketAccessControlPolicy.getAWSAccessKeyId());
    request.setRequestTimestamp(getBucketAccessControlPolicy.getTimestamp());
    request.setSignature(getBucketAccessControlPolicy.getSignature());
    request.setBucketName(getBucketAccessControlPolicy.getBucket());
    return request;
  }
View Full Code Here

            }

    public void executeGetBucketAcl(HttpServletRequest request, HttpServletResponse response)
            throws IOException, XMLStreamException
            {
        S3GetBucketAccessControlPolicyRequest engineRequest = new S3GetBucketAccessControlPolicyRequest();
        Calendar cal = Calendar.getInstance();
        cal.set( 1970, 1, 1 );
        engineRequest.setAccessKey(UserContext.current().getAccessKey());
        engineRequest.setRequestTimestamp( cal );
        engineRequest.setSignature( "" );   // TODO - Consider providing signature in a future release which allows additional user description
        engineRequest.setBucketName((String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY));

        S3AccessControlPolicy engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest(engineRequest);

        // To allow the bucket acl policy result to be serialized via Axiom classes
        GetBucketAccessControlPolicyResponse onePolicy = S3SerializableServiceImplementation.toGetBucketAccessControlPolicyResponse( engineResponse );
View Full Code Here

      toEngineGetObjectAccessControlPolicyRequest(getObjectAccessControlPolicy)));
    }
 
  private S3GetObjectAccessControlPolicyRequest toEngineGetObjectAccessControlPolicyRequest(
    GetObjectAccessControlPolicy getObjectAccessControlPolicy) {
    S3GetObjectAccessControlPolicyRequest request = new S3GetObjectAccessControlPolicyRequest();
   
    request.setAccessKey(getObjectAccessControlPolicy.getAWSAccessKeyId());
    request.setRequestTimestamp(getObjectAccessControlPolicy.getTimestamp());
    request.setSignature(getObjectAccessControlPolicy.getSignature());
    request.setBucketName(getObjectAccessControlPolicy.getBucket());
    request.setKey(getObjectAccessControlPolicy.getKey());
    return request;
  }
View Full Code Here

    private void executeGetObjectAcl(HttpServletRequest request, HttpServletResponse response) throws IOException, XMLStreamException
    {
        String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
        String key        = (String)request.getAttribute(S3Constants.OBJECT_ATTR_KEY);

        S3GetObjectAccessControlPolicyRequest engineRequest = new S3GetObjectAccessControlPolicyRequest();
        engineRequest.setBucketName( bucketName );
        engineRequest.setKey( key );

        // -> is this a request for a specific version of the object?  look for "versionId=" in the query string
        String queryString = request.getQueryString();
        if (null != queryString) engineRequest.setVersion( returnParameter( queryString, "versionId=" ));

        S3AccessControlPolicy engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest(engineRequest);
        int resultCode = engineResponse.getResultCode();
        if (200 != resultCode) {
            response.setStatus( resultCode );
View Full Code Here

    return toGetObjectExtendedResponse(engine.handleRequest(toEngineGetObjectRequest(getObjectExtended)));
    }
 
  private S3GetObjectRequest toEngineGetObjectRequest(GetObject getObject)
  {
    S3GetObjectRequest request = new S3GetObjectRequest();
   
    request.setAccessKey(getObject.getAWSAccessKeyId());
    request.setRequestTimestamp(getObject.getTimestamp());
    request.setSignature(getObject.getSignature());
    request.setBucketName(getObject.getBucket());
    request.setKey(getObject.getKey());
    request.setReturnData(getObject.getGetData());
    request.setReturnMetadata(getObject.getGetMetadata());
    request.setInlineData(getObject.getInlineData());
    return request;
  }
View Full Code Here

    request.setInlineData(getObject.getInlineData());
    return request;
  }
 
  private S3GetObjectRequest toEngineGetObjectRequest(GetObjectExtended getObjectExtended) {
    S3GetObjectRequest request = new S3GetObjectRequest();
    request.setAccessKey(getObjectExtended.getAWSAccessKeyId());
    request.setRequestTimestamp(getObjectExtended.getTimestamp());
    request.setSignature(getObjectExtended.getSignature());
    request.setBucketName(getObjectExtended.getBucket());
    request.setKey(getObjectExtended.getKey());
    request.setReturnData(getObjectExtended.getGetData());
    request.setReturnMetadata(getObjectExtended.getGetMetadata());
    request.setInlineData(getObjectExtended.getInlineData());
   
    S3ConditionalHeaders conds = new S3ConditionalHeaders();
    conds.setModifiedSince(getObjectExtended.getIfModifiedSince());
    conds.setUnModifiedSince(getObjectExtended.getIfUnmodifiedSince());
    conds.setMatch(getObjectExtended.getIfMatch());
    conds.setNoneMatch(getObjectExtended.getIfNoneMatch());
    request.setConditions(conds);

    request.setByteRangeStart(getObjectExtended.getByteRangeStart());
    request.setByteRangeEnd(getObjectExtended.getByteRangeEnd());
    request.setReturnCompleteObjectOnConditionFailure(getObjectExtended.getReturnCompleteObjectOnConditionFailure());
    return request;
  }
View Full Code Here

    {
        String   bucket    = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
        String   key       = (String) request.getAttribute(S3Constants.OBJECT_ATTR_KEY);


        S3GetObjectRequest engineRequest = new S3GetObjectRequest();
        engineRequest.setBucketName(bucket);
        engineRequest.setKey(key);
        engineRequest.setInlineData(true);
        engineRequest.setReturnData(true)
        //engineRequest.setReturnMetadata(true);
        engineRequest = setRequestByteRange( request, engineRequest );

        // -> is this a request for a specific version of the object?  look for "versionId=" in the query string
        String queryString = request.getQueryString();
        if (null != queryString) engineRequest.setVersion( returnParameter( queryString, "versionId=" ));

        S3GetObjectResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );     
        response.setStatus( engineResponse.getResultCode());

        if (engineResponse.getResultCode()  >=400 ) {
View Full Code Here

TOP

Related Classes of com.cloud.bridge.service.core.s3.S3ConditionalHeaders

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.