Search in sources :

Example 1 with DataGetObjectTagging

use of com.pspace.ifs.ksan.gw.data.DataGetObjectTagging in project ksan by infinistor.

the class GetObjectTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_OBJECT_TAGGING_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    S3Bucket s3Bucket = new S3Bucket();
    s3Bucket.setCors(getBucketInfo().getCors());
    s3Bucket.setAccess(getBucketInfo().getAccess());
    s3Parameter.setBucket(s3Bucket);
    GWUtils.checkCors(s3Parameter);
    if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
        throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
    }
    DataGetObjectTagging dataGetObjectTagging = new DataGetObjectTagging(s3Parameter);
    dataGetObjectTagging.extract();
    String object = s3Parameter.getObjectName();
    String versionId = dataGetObjectTagging.getVersionId();
    Metadata objMeta = null;
    if (Strings.isNullOrEmpty(versionId)) {
        objMeta = open(bucket, object);
    } else {
        objMeta = open(bucket, object, versionId);
    }
    objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
    checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    String taggingInfo = objMeta.getTag();
    logger.info(GWConstants.LOG_TAGGING, taggingInfo);
    if (Strings.isNullOrEmpty(taggingInfo)) {
        XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
        javax.xml.stream.XMLStreamWriter xml;
        try {
            xml = xmlOutputFactory.createXMLStreamWriter(s3Parameter.getResponse().getOutputStream());
            xml.writeStartDocument();
            xml.writeStartElement(GWConstants.TAGGING);
            xml.writeDefaultNamespace(GWConstants.AWS_XMLNS);
            xml.writeStartElement(GWConstants.TAG_SET);
            xml.writeEndElement();
            xml.writeEndElement();
            xml.flush();
        } catch (XMLStreamException e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        } catch (IOException e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    } else {
        try {
            if (!Strings.isNullOrEmpty(taggingInfo)) {
                s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
                s3Parameter.getResponse().getOutputStream().write(taggingInfo.getBytes());
            }
        } catch (IOException e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) DataGetObjectTagging(com.pspace.ifs.ksan.gw.data.DataGetObjectTagging) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Aggregations

DataGetObjectTagging (com.pspace.ifs.ksan.gw.data.DataGetObjectTagging)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)1 IOException (java.io.IOException)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1