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