2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
4 * ===============================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6 * in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
14 * ============LICENSE_END========================================================================
16 package org.onap.dcaegen2.collectors.datafile.service.producer;
20 import org.apache.http.HttpRequest;
21 import org.apache.http.HttpResponse;
22 import org.apache.http.ProtocolException;
23 import org.apache.http.annotation.Contract;
24 import org.apache.http.annotation.ThreadingBehavior;
25 import org.apache.http.client.methods.HttpDelete;
26 import org.apache.http.client.methods.HttpGet;
27 import org.apache.http.client.methods.HttpHead;
28 import org.apache.http.client.methods.HttpPost;
29 import org.apache.http.client.methods.HttpPut;
30 import org.apache.http.client.methods.HttpUriRequest;
31 import org.apache.http.client.methods.RequestBuilder;
32 import org.apache.http.impl.client.DefaultRedirectStrategy;
33 import org.apache.http.protocol.HttpContext;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * PublishRedirectStrategy implementation
39 * that automatically redirects all HEAD, GET, POST, PUT, and DELETE requests.
40 * This strategy relaxes restrictions on automatic redirection of
41 * POST methods imposed by the HTTP specification.
44 @Contract(threading = ThreadingBehavior.IMMUTABLE)
45 public class PublishRedirectStrategy extends DefaultRedirectStrategy {
47 public static final PublishRedirectStrategy INSTANCE = new PublishRedirectStrategy();
48 private final Logger logger = LoggerFactory.getLogger(this.getClass());
51 * Redirectable methods.
53 private static final String[] REDIRECT_METHODS = new String[] {
58 HttpDelete.METHOD_NAME
62 protected boolean isRedirectable(final String method) {
63 for (final String m: REDIRECT_METHODS) {
64 if (m.equalsIgnoreCase(method)) {
72 public HttpUriRequest getRedirect(
73 final HttpRequest request,
74 final HttpResponse response,
75 final HttpContext context) throws ProtocolException {
76 final URI uri = getLocationURI(request, response, context);
77 logger.trace("getRedirect...: {}", request.toString());
78 return RequestBuilder.copy(request).setUri(uri).build();