Search in sources :

Example 1 with ObjectListParameter

use of com.pspace.ifs.ksan.gw.identity.ObjectListParameter in project ksan by infinistor.

the class ListObject method initParameters.

private void initParameters(DataRepository dbm, String bucketName, String delimiter, String marker, String versionIdMarker, String continuationToken, int maxKeys, String prefix) {
    this.dbm = dbm;
    this.bucketName = bucketName;
    this.delimiter = delimiter;
    this.marker = marker;
    this.maxKeys = maxKeys;
    this.prefix = prefix;
    this.versionIdMarker = versionIdMarker;
    this.continuationToken = continuationToken;
    objectListParameter = new ObjectListParameter();
    mongoQuery = null;
    bBucketListParameterPrefix = false;
    bMarker = false;
    bDelimiter = false;
    bDelForceGte = false;
    bDelimiterMarker = false;
    bContinuationToken = false;
    bDelimitertoken = false;
    bVersionIdMarker = false;
    query = "";
    delmarker = "";
    if (!Strings.isNullOrEmpty(prefix)) {
        bBucketListParameterPrefix = true;
    }
    if (!Strings.isNullOrEmpty(marker)) {
        bMarker = true;
    }
    if (!Strings.isNullOrEmpty(continuationToken)) {
        bContinuationToken = true;
    }
    if (!Strings.isNullOrEmpty(delimiter)) {
        bDelimiter = true;
    }
    if (!Strings.isNullOrEmpty(versionIdMarker)) {
        bVersionIdMarker = true;
    }
    if (bMarker && bDelimiter) {
        if (marker.substring(marker.length() - delimiter.length(), marker.length()).compareTo(delimiter) == 0) {
            StringBuilder delimiterp2 = new StringBuilder();
            delimiterp2.append(marker.substring(0, marker.length() - 1));
            delimiterp2.append(Character.getNumericValue(marker.charAt(marker.length() - 1)) + 1);
            this.marker = delimiterp2.toString();
            bDelimiterMarker = true;
        }
    }
    if (bContinuationToken && bDelimiter) {
        if (continuationToken.substring(continuationToken.length() - delimiter.length(), continuationToken.length()).compareTo(delimiter) == 0) {
            StringBuilder delimiterp2 = new StringBuilder();
            delimiterp2.append(continuationToken.substring(0, continuationToken.length() - 1));
            delimiterp2.append(Character.getNumericValue(continuationToken.charAt(continuationToken.length() - 1)) + 1);
            this.continuationToken = delimiterp2.toString();
            bDelimitertoken = true;
        }
    }
}
Also used : ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter)

Example 2 with ObjectListParameter

use of com.pspace.ifs.ksan.gw.identity.ObjectListParameter in project ksan by infinistor.

the class ListObjectVersions method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_LIST_OBJECT_VERSIONS_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);
    }
    checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    DataListObjectVersions dataListObjectVersions = new DataListObjectVersions(s3Parameter);
    dataListObjectVersions.extract();
    String delimiter = dataListObjectVersions.getDelimiter();
    String encodingType = dataListObjectVersions.getEncodingType();
    String keyMarker = dataListObjectVersions.getKeyMarker();
    String maxKeys = dataListObjectVersions.getMaxKeys();
    String prefix = dataListObjectVersions.getPrefix();
    String versionIdMarker = dataListObjectVersions.getVersionIdMarker();
    S3ObjectList s3ObjectList = new S3ObjectList();
    s3ObjectList.setDelimiter(delimiter);
    s3ObjectList.setEncodingType(encodingType);
    s3ObjectList.setKeyMarker(keyMarker);
    s3ObjectList.setMaxKeys(maxKeys);
    if (Strings.isNullOrEmpty(s3ObjectList.getMaxKeys())) {
        s3ObjectList.setMaxKeys(GWConstants.DEFAULT_MAX_KEYS);
    }
    logger.debug(GWConstants.LOG_LIST_OBJECT_VERSIONS_MAXKEYS, s3ObjectList.getMaxKeys());
    if (Integer.valueOf(s3ObjectList.getMaxKeys()) < 0) {
        throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
    }
    s3ObjectList.setPrefix(prefix);
    s3ObjectList.setVersionIdMarker(versionIdMarker);
    s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    ObjectListParameter objectListParameter = listObjectVersions(bucket, s3ObjectList);
    try (Writer writer = s3Parameter.getResponse().getWriter()) {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.LIST_VERSIONS_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_NAME, bucket);
        if (prefix == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_PREFIX);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeBlob(encodingType, prefix));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_MAX_KEYS, String.valueOf(s3ObjectList.getMaxKeys()));
        if (keyMarker == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_KEY_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_KEY_MARKER, GWUtils.encodeBlob(encodingType, keyMarker));
        }
        if (versionIdMarker == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_VERSIONID_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_VERSIONID_MARKER, GWUtils.encodeBlob(encodingType, versionIdMarker));
        }
        logger.debug(GWConstants.LOG_LIST_OBJECT_VERSIONS_PARAMETER_INFO, objectListParameter, objectListParameter.getObjects());
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_KEY_COUNT, String.valueOf(objectListParameter.getObjects().size()));
        if (delimiter != null) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_DELIMITER, GWUtils.encodeBlob(encodingType, delimiter));
        }
        if (encodingType != null && encodingType.equals(GWConstants.URL)) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_ENCODING_TYPE, encodingType);
        }
        if (objectListParameter.isTruncated()) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_KEY_MARKER, GWUtils.encodeBlob(encodingType, objectListParameter.getNextMarker()));
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_VERSIONID_MARKER, GWUtils.encodeBlob(encodingType, objectListParameter.getNextVersion()));
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
        }
        for (S3Metadata s3Metadata : objectListParameter.getObjects()) {
            if (s3Metadata != null) {
                if (s3Metadata.getDeleteMarker() != null) {
                    if (s3Metadata.getDeleteMarker().compareTo(GWConstants.OBJECT_TYPE_MARK) == 0) {
                        xmlStreamWriter.writeStartElement(GWConstants.XML_DELETE_MARKER);
                    } else {
                        xmlStreamWriter.writeStartElement(GWConstants.VERSION);
                    }
                    writeSimpleElement(xmlStreamWriter, GWConstants.KEY, GWUtils.encodeBlob(encodingType, s3Metadata.getName()));
                    if (s3Metadata.getLastModified() != null) {
                        writeSimpleElement(xmlStreamWriter, GWConstants.LAST_MODIFIED, formatDate(s3Metadata.getLastModified()));
                    }
                    if (s3Metadata.getETag() != null) {
                        writeSimpleElement(xmlStreamWriter, GWConstants.ETAG, GWUtils.maybeQuoteETag(s3Metadata.getETag()));
                    }
                    writeSimpleElement(xmlStreamWriter, GWConstants.XML_SIZE, s3Metadata.getSize().toString());
                    writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, s3Metadata.getTier());
                    writeSimpleElement(xmlStreamWriter, GWConstants.VERSIONID, s3Metadata.getVersionId());
                    writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_LATEST, s3Metadata.getIsLatest());
                    writeOwnerInfini(xmlStreamWriter, s3Metadata.getOwnerId(), s3Metadata.getOwnerName());
                    xmlStreamWriter.writeEndElement();
                    logger.debug(GWConstants.LOG_LIST_OBJECT_VERSIONS_INFO, s3Metadata.getName(), s3Metadata.getVersionId());
                }
            }
        }
        for (Entry<String, String> entry : objectListParameter.getCommonPrefixes().entrySet()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_COMMON_PREFIXES);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeBlob(encodingType, entry.getValue()));
            xmlStreamWriter.writeEndElement();
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.flush();
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } catch (XMLStreamException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DataListObjectVersions(com.pspace.ifs.ksan.gw.data.DataListObjectVersions) IOException(java.io.IOException) S3ObjectList(com.pspace.ifs.ksan.gw.identity.S3ObjectList) ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 3 with ObjectListParameter

use of com.pspace.ifs.ksan.gw.identity.ObjectListParameter in project ksan by infinistor.

the class ListObjects method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_LIST_OBJECT_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);
    }
    checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    DataListBuckets dataListBuckets = new DataListBuckets(s3Parameter);
    dataListBuckets.extract();
    S3ObjectList s3ObjectList = new S3ObjectList();
    if (!Strings.isNullOrEmpty(dataListBuckets.getMaxkeys())) {
        if (Integer.valueOf(dataListBuckets.getMaxkeys()) < 0) {
            throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
        }
        s3ObjectList.setMaxKeys(dataListBuckets.getMaxkeys());
    } else {
        s3ObjectList.setMaxKeys(GWConstants.DEFAULT_MAX_KEYS);
    }
    s3ObjectList.setDelimiter(dataListBuckets.getDelimiter());
    s3ObjectList.setEncodingType(dataListBuckets.getEncodingType());
    s3ObjectList.setMarker(dataListBuckets.getMarker());
    s3ObjectList.setPrefix(dataListBuckets.getPrefix());
    logger.debug("delimiter : {}", dataListBuckets.getDelimiter());
    logger.debug("marker : {}", dataListBuckets.getMarker());
    logger.debug("prefix : {}", dataListBuckets.getPrefix());
    logger.debug("maxKeys : {}", dataListBuckets.getMaxkeys());
    s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    ObjectListParameter objectListParameter = listObject(bucket, s3ObjectList);
    try (Writer writer = s3Parameter.getResponse().getWriter()) {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.LIST_BUCKET_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_NAME, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), bucket));
        if (s3ObjectList.getPrefix() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_PREFIX);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3ObjectList.getPrefix()));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_MAX_KEYS, String.valueOf(s3ObjectList.getMaxKeys()));
        if (s3ObjectList.getMarker() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_MARKER, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3ObjectList.getMarker()));
        }
        if (s3ObjectList.getDelimiter() != null) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_DELIMITER, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3ObjectList.getDelimiter()));
        }
        if (s3ObjectList.getEncodingType() != null && s3ObjectList.getEncodingType().equals(GWConstants.URL)) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_ENCODING_TYPE, s3ObjectList.getEncodingType());
        }
        if (objectListParameter.isTruncated()) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_MARKER, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), objectListParameter.getNextMarker()));
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
        }
        for (S3Metadata s3Metadata : objectListParameter.getObjects()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_CONTENTS);
            logger.debug(s3Metadata.getName());
            writeSimpleElement(xmlStreamWriter, GWConstants.KEY, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3Metadata.getName()));
            if (s3Metadata.getLastModified() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.LAST_MODIFIED, formatDate(s3Metadata.getLastModified()));
            }
            if (s3Metadata.getETag() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.ETAG, GWUtils.maybeQuoteETag(s3Metadata.getETag()));
            }
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_SIZE, s3Metadata.getSize().toString());
            writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, s3Metadata.getTier());
            writeOwnerInfini(xmlStreamWriter, s3Metadata.getOwnerId(), s3Metadata.getOwnerName());
            xmlStreamWriter.writeEndElement();
        }
        for (Entry<String, String> prefix : objectListParameter.getCommonPrefixes().entrySet()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_COMMON_PREFIXES);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), prefix.getValue()));
            xmlStreamWriter.writeEndElement();
            logger.debug(GWConstants.LOG_LIST_OBJECT_PREFIX_ENCODING, s3ObjectList.getEncodingType(), prefix.getValue());
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.flush();
    } catch (IOException | XMLStreamException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) IOException(java.io.IOException) S3ObjectList(com.pspace.ifs.ksan.gw.identity.S3ObjectList) DataListBuckets(com.pspace.ifs.ksan.gw.data.DataListBuckets) ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 4 with ObjectListParameter

use of com.pspace.ifs.ksan.gw.identity.ObjectListParameter in project ksan by infinistor.

the class S3Request method listObject.

protected ObjectListParameter listObject(String bucket, S3ObjectList s3ObjectList) throws GWException {
    ObjectListParameter objectListParameter = null;
    try {
        setObjManager();
        objectListParameter = objManager.listObject(bucket, s3ObjectList);
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    return objectListParameter;
}
Also used : ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) GWException(com.pspace.ifs.ksan.gw.exception.GWException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 5 with ObjectListParameter

use of com.pspace.ifs.ksan.gw.identity.ObjectListParameter in project ksan by infinistor.

the class ListObjectsV2 method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_LIST_OBJECT_V2_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);
    }
    checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    DataListObjectV2 dataListObjectV2 = new DataListObjectV2(s3Parameter);
    dataListObjectV2.extract();
    // read header
    S3ObjectList s3ObjectList = new S3ObjectList();
    if (!Strings.isNullOrEmpty(dataListObjectV2.getMaxKeys())) {
        if (Integer.valueOf(dataListObjectV2.getMaxKeys()) < 0) {
            throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
        }
        s3ObjectList.setMaxKeys(dataListObjectV2.getMaxKeys());
    } else {
        s3ObjectList.setMaxKeys(GWConstants.DEFAULT_MAX_KEYS);
    }
    s3ObjectList.setContinuationToken(dataListObjectV2.getContinuationToken());
    s3ObjectList.setDelimiter(dataListObjectV2.getDelimiter());
    s3ObjectList.setEncodingType(dataListObjectV2.getEncodingType());
    s3ObjectList.setPrefix(dataListObjectV2.getPrefix());
    s3ObjectList.setStartAfter(dataListObjectV2.getStartAfter());
    s3ObjectList.setFetchOwner(dataListObjectV2.getFetchOwner());
    s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    ObjectListParameter objectListParameter = listObjectV2(bucket, s3ObjectList);
    try (Writer writer = s3Parameter.getResponse().getWriter()) {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.LIST_BUCKET_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_NAME, bucket);
        String encodingType = s3ObjectList.getEncodingType();
        String prefix = s3ObjectList.getPrefix();
        if (prefix == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_PREFIX);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(encodingType, prefix));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_MAX_KEYS, String.valueOf(s3ObjectList.getMaxKeys()));
        if (s3ObjectList.getStartAfter() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_START_AFTER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_START_AFTER, GWUtils.encodeObjectName(encodingType, s3ObjectList.getStartAfter()));
        }
        if (s3ObjectList.getContinuationToken() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_CONTINUEATION_TOKEN);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_CONTINUEATION_TOKEN, GWUtils.encodeObjectName(encodingType, s3ObjectList.getContinuationToken()));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_KEY_COUNT, String.valueOf(objectListParameter.getObjects().size()));
        if (s3ObjectList.getDelimiter() != null) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_DELIMITER, GWUtils.encodeObjectName(encodingType, s3ObjectList.getDelimiter()));
        }
        if (encodingType != null && encodingType.equals(GWConstants.URL)) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_ENCODING_TYPE, encodingType);
        }
        if (objectListParameter.isTruncated()) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_CONTINUATION_TOKEN, GWUtils.encodeObjectName(encodingType, objectListParameter.getNextMarker()));
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
        }
        for (S3Metadata s3Metadata : objectListParameter.getObjects()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_CONTENTS);
            writeSimpleElement(xmlStreamWriter, GWConstants.KEY, GWUtils.encodeObjectName(encodingType, s3Metadata.getName()));
            if (s3Metadata.getLastModified() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.LAST_MODIFIED, formatDate(s3Metadata.getLastModified()));
            }
            if (s3Metadata.getETag() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.ETAG, GWUtils.maybeQuoteETag(s3Metadata.getETag()));
            }
            if (!Strings.isNullOrEmpty(s3ObjectList.getFetchOwner()) && s3ObjectList.getFetchOwner().equals(GWConstants.XML_TRUE)) {
                writeOwnerInfini(xmlStreamWriter, s3Metadata.getOwnerId(), s3Metadata.getOwnerName());
            }
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_SIZE, s3Metadata.getContentLength().toString());
            writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, s3Metadata.getTier());
            xmlStreamWriter.writeEndElement();
        }
        for (Entry<String, String> entry : objectListParameter.getCommonPrefixes().entrySet()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_COMMON_PREFIXES);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(encodingType, entry.getValue()));
            xmlStreamWriter.writeEndElement();
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.flush();
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } catch (XMLStreamException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) IOException(java.io.IOException) S3ObjectList(com.pspace.ifs.ksan.gw.identity.S3ObjectList) DataListObjectV2(com.pspace.ifs.ksan.gw.data.DataListObjectV2) ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Aggregations

ObjectListParameter (com.pspace.ifs.ksan.gw.identity.ObjectListParameter)8 GWException (com.pspace.ifs.ksan.gw.exception.GWException)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 S3ObjectList (com.pspace.ifs.ksan.gw.identity.S3ObjectList)4 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)4 ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)4 IOException (java.io.IOException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)3 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)3 Writer (java.io.Writer)3 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)3 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)3 DataListBuckets (com.pspace.ifs.ksan.gw.data.DataListBuckets)1 DataListObjectV2 (com.pspace.ifs.ksan.gw.data.DataListObjectV2)1 DataListObjectVersions (com.pspace.ifs.ksan.gw.data.DataListObjectVersions)1 AllServiceOfflineException (com.pspace.ifs.ksan.objmanager.ObjManagerException.AllServiceOfflineException)1 InvalidParameterException (java.security.InvalidParameterException)1 SQLException (java.sql.SQLException)1