diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java index 3252767cb..5956df8dd 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java @@ -38,7 +38,9 @@ public class ContentNegotiator { private final static Logger LOG = LoggerFactory.getLogger(ContentNegotiator.class); - private List + private ContentNegotiator() {} + + private static List getDefaultSupportedContentTypes(final Class processorClass) { List defaults = new ArrayList(); @@ -51,7 +53,7 @@ public class ContentNegotiator { return defaults; } - private List getSupportedContentTypes(final Processor processor, + private static List getSupportedContentTypes(final Processor processor, final Class processorClass) { List 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 processorClass) { String requestedContentType = null; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java index 419b04712..fdb47a2dc 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java @@ -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 { diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java index fd7fcaa96..66db64ad5 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java @@ -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);