All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.robothy.s3.rest.handler.GetBucketAclController Maven / Gradle / Ivy

package com.robothy.s3.rest.handler;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.robothy.netty.http.HttpRequest;
import com.robothy.netty.http.HttpRequestHandler;
import com.robothy.netty.http.HttpResponse;
import com.robothy.s3.core.service.BucketAclService;
import com.robothy.s3.core.service.BucketService;
import com.robothy.s3.datatypes.AccessControlPolicy;
import com.robothy.s3.rest.assertions.RequestAssertions;
import com.robothy.s3.rest.service.ServiceFactory;
import com.robothy.s3.rest.utils.ResponseUtils;
import io.netty.handler.codec.http.HttpResponseStatus;

/**
 * Handle GetBucketAcl.
 * Get access control of a specified bucket.
 */
class GetBucketAclController implements HttpRequestHandler {

  private final BucketAclService aclService;

  private final XmlMapper xmlMapper;

  GetBucketAclController(ServiceFactory serviceFactory) {
    this.aclService = serviceFactory.getInstance(BucketService.class);
    this.xmlMapper = serviceFactory.getInstance(XmlMapper.class);
  }

  @Override
  public void handle(HttpRequest request, HttpResponse response) throws Exception {
    String bucketName = RequestAssertions.assertBucketNameProvided(request);
    AccessControlPolicy acl = aclService.getBucketAcl(bucketName);
    response.status(HttpResponseStatus.OK)
        .write(xmlMapper.writeValueAsString(acl));
    ResponseUtils.addAmzRequestId(response);
    ResponseUtils.addServerHeader(response);
    ResponseUtils.addDateHeader(response);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy