Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.ozone.s3.exception;

import javax.inject.Inject;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
Expand Down Expand Up @@ -45,6 +46,7 @@ public Response toResponse(OS3Exception exception) {
}
exception.setRequestId(requestIdentifier.getRequestId());
return Response.status(exception.getHttpCode())
.type(MediaType.APPLICATION_XML_TYPE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change is correct, but I noticed that the exact reproduction of HDDS-16189 follows the authentication-error path, which bypasses OS3ExceptionMapper. Should we also set MediaType.APPLICATION_XML_TYPE in S3Utils.wrapOS3Exception() and add a test for that?

public static WebApplicationException wrapOS3Exception(OS3Exception ex) {
return new WebApplicationException(ex.getErrorMessage(), ex,
Response.status(ex.getHttpCode())
.entity(ex.toXml())
.build());
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I missed that the curl request stops at AuthorizationFilter and never reaches OS3ExceptionMapper.
Thanks a lot for catching this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated S3Utils.wrapOS3Exception() and added a test.

.entity(exception.toXml()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,30 @@
package org.apache.hadoop.ozone.s3.exception;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.hadoop.ozone.s3.RequestIdentifier;
import org.apache.hadoop.ozone.web.utils.OzoneUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* This class tests OS3Exception class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This class now also tests OS3ExceptionMapper. Could we update the class Javadoc accordingly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks.

*/
@ExtendWith(MockitoExtension.class)
public class TestOS3Exceptions {

@Mock
private RequestIdentifier requestIdentifier;

@InjectMocks
private OS3ExceptionMapper exceptionMapper;

@Test
public void testOS3Exceptions() {
OS3Exception ex = S3ErrorTable.newError(S3ErrorTable.ACCESS_DENIED, "bucket");
Expand All @@ -44,4 +59,15 @@ public void testOS3Exceptions() {
ex.getRequestId());
assertEquals(expected, val);
}

@Test
public void testResponseContentType() {
when(requestIdentifier.getRequestId()).thenReturn("request-id");
OS3Exception exception = S3ErrorTable.newError(
S3ErrorTable.ACCESS_DENIED, "bucket");

Response response = exceptionMapper.toResponse(exception);

assertEquals(MediaType.APPLICATION_XML_TYPE, response.getMediaType());
}
}