[OLINGO-328] refactoring
This commit is contained in:
parent
b97226b059
commit
a51146a46f
|
@ -38,7 +38,9 @@ public class ContentNegotiator {
|
|||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(ContentNegotiator.class);
|
||||
|
||||
private List<FormatContentTypeMapping>
|
||||
private ContentNegotiator() {}
|
||||
|
||||
private static List<FormatContentTypeMapping>
|
||||
getDefaultSupportedContentTypes(final Class<? extends Processor> processorClass) {
|
||||
List<FormatContentTypeMapping> defaults = new ArrayList<FormatContentTypeMapping>();
|
||||
|
||||
|
@ -51,7 +53,7 @@ public class ContentNegotiator {
|
|||
return defaults;
|
||||
}
|
||||
|
||||
private List<FormatContentTypeMapping> getSupportedContentTypes(final Processor processor,
|
||||
private static List<FormatContentTypeMapping> getSupportedContentTypes(final Processor processor,
|
||||
final Class<? extends Processor> processorClass) {
|
||||
|
||||
List<FormatContentTypeMapping> supportedContentTypes = getDefaultSupportedContentTypes(processorClass);
|
||||
|
@ -64,7 +66,7 @@ public class ContentNegotiator {
|
|||
return supportedContentTypes;
|
||||
}
|
||||
|
||||
public String doContentNegotiation(final FormatOption formatOption, final ODataRequest request,
|
||||
public static String doContentNegotiation(final FormatOption formatOption, final ODataRequest request,
|
||||
final Processor processor, final Class<? extends Processor> processorClass) {
|
||||
String requestedContentType = null;
|
||||
|
||||
|
|
|
@ -75,15 +75,13 @@ public class ODataHandler {
|
|||
UriValidator validator = new UriValidator();
|
||||
validator.validate(uriInfo, request.getMethod());
|
||||
|
||||
ContentNegotiator contentNegotiator = new ContentNegotiator();
|
||||
|
||||
String requestedContentType = null;
|
||||
switch (uriInfo.getKind()) {
|
||||
case metadata:
|
||||
MetadataProcessor mp = selectProcessor(MetadataProcessor.class);
|
||||
|
||||
requestedContentType =
|
||||
contentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, mp, MetadataProcessor.class);
|
||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, mp, MetadataProcessor.class);
|
||||
|
||||
mp.readMetadata(request, response, uriInfo, requestedContentType);
|
||||
break;
|
||||
|
@ -95,7 +93,7 @@ public class ODataHandler {
|
|||
ServiceDocumentProcessor sdp = selectProcessor(ServiceDocumentProcessor.class);
|
||||
|
||||
requestedContentType =
|
||||
contentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, sdp,
|
||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, sdp,
|
||||
ServiceDocumentProcessor.class);
|
||||
|
||||
sdp.readServiceDocument(request, response, uriInfo, requestedContentType);
|
||||
|
@ -120,7 +118,6 @@ public class ODataHandler {
|
|||
int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
|
||||
UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
|
||||
String requestedContentType = null;
|
||||
ContentNegotiator contentNegotiator = new ContentNegotiator();
|
||||
|
||||
switch (lastPathSegment.getKind()) {
|
||||
case entitySet:
|
||||
|
@ -129,7 +126,7 @@ public class ODataHandler {
|
|||
CollectionProcessor cp = selectProcessor(CollectionProcessor.class);
|
||||
|
||||
requestedContentType =
|
||||
contentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp, CollectionProcessor.class);
|
||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp, CollectionProcessor.class);
|
||||
|
||||
cp.readCollection(request, response, uriInfo, requestedContentType);
|
||||
} else {
|
||||
|
@ -140,7 +137,7 @@ public class ODataHandler {
|
|||
EntityProcessor ep = selectProcessor(EntityProcessor.class);
|
||||
|
||||
requestedContentType =
|
||||
contentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
||||
|
||||
ep.readEntity(request, response, uriInfo, requestedContentType);
|
||||
} else {
|
||||
|
@ -154,7 +151,7 @@ public class ODataHandler {
|
|||
CollectionProcessor cp = selectProcessor(CollectionProcessor.class);
|
||||
|
||||
requestedContentType =
|
||||
contentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp, CollectionProcessor.class);
|
||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp, CollectionProcessor.class);
|
||||
|
||||
cp.readCollection(request, response, uriInfo, requestedContentType);
|
||||
} else {
|
||||
|
@ -165,7 +162,7 @@ public class ODataHandler {
|
|||
EntityProcessor ep = selectProcessor(EntityProcessor.class);
|
||||
|
||||
requestedContentType =
|
||||
contentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
||||
|
||||
ep.readEntity(request, response, uriInfo, requestedContentType);
|
||||
} else {
|
||||
|
|
|
@ -144,8 +144,6 @@ public class ContentNegotiatorTest {
|
|||
request.setMethod(HttpMethod.GET);
|
||||
request.setRawODataPath("/" + (useCase[1] == null ? "" : "?$format=" + useCase[1]));
|
||||
|
||||
ContentNegotiator cn = new ContentNegotiator();
|
||||
|
||||
ProcessorStub p = new ProcessorStub(createCustomContentTypeMapping(useCase[3], useCase[4]));
|
||||
|
||||
FormatOption fo = null;
|
||||
|
@ -158,7 +156,7 @@ public class ContentNegotiatorTest {
|
|||
request.addHeader(HttpHeader.ACCEPT, Arrays.asList(useCase[2]));
|
||||
}
|
||||
|
||||
String requestedContentType = cn.doContentNegotiation(fo, request, p, processorClass);
|
||||
String requestedContentType = ContentNegotiator.doContentNegotiation(fo, request, p, processorClass);
|
||||
|
||||
assertNotNull(requestedContentType);
|
||||
assertEquals(useCase[0], requestedContentType);
|
||||
|
|
Loading…
Reference in New Issue