Fix invoker handler

remotes/1728937285237262521/master
tcdlpds 10 months ago
parent 7007558623
commit 8bf027f2b3

@ -30,6 +30,8 @@ import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerUtil;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
@ -68,7 +70,7 @@ public class GrafanaHandler extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
HttpGet grafanaRequest = new HttpGet();
ClassicHttpRequest grafanaRequest = ClassicRequestBuilder.get().build();
HandlerUtil.copyRequestHeaders(req, grafanaRequest, true);
if (!GrafanaUtil.isGrafanaAPI(req.getRequestURI())) {
proxyPassGrafanaRequest(grafanaRequest, resp, req);
@ -112,7 +114,7 @@ public class GrafanaHandler extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
HttpPost grafanaRequest = new HttpPost();
ClassicHttpRequest grafanaRequest = ClassicRequestBuilder.post().build();
HandlerUtil.generateRequestEntity(req, grafanaRequest);
HandlerUtil.copyRequestHeaders(req, grafanaRequest, true);
if (!GrafanaUtil.isGrafanaAPI(req.getRequestURI())) {

@ -26,9 +26,10 @@ import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.*;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
@ -58,7 +59,7 @@ public class InvokerHandler extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
HttpPost postRequest = new HttpPost(HandlerUtil.generateBackendRequestURL(req, apiEndpoint));
ClassicHttpRequest postRequest = ClassicRequestBuilder.post(HandlerUtil.generateBackendRequestURL(req, apiEndpoint)).build();
HandlerUtil.generateRequestEntity(req, postRequest);
postRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(postRequest);
@ -88,7 +89,8 @@ public class InvokerHandler extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
HttpGet getRequest = new HttpGet(HandlerUtil.generateBackendRequestURL(req, apiEndpoint));
ClassicHttpRequest getRequest = ClassicRequestBuilder.get(HandlerUtil.generateBackendRequestURL(req,
apiEndpoint)).build();
HandlerUtil.copyRequestHeaders(req, getRequest, false);
getRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(getRequest);
@ -123,7 +125,8 @@ public class InvokerHandler extends HttpServlet {
protected void doHead(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
HttpHead headRequest = new HttpHead(HandlerUtil.generateBackendRequestURL(req, apiEndpoint));
ClassicHttpRequest headRequest = ClassicRequestBuilder.head(HandlerUtil.generateBackendRequestURL(req,
apiEndpoint)).build();
HandlerUtil.copyRequestHeaders(req, headRequest, false);
headRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(headRequest);
@ -150,7 +153,8 @@ public class InvokerHandler extends HttpServlet {
protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
HttpPut putRequest = new HttpPut(HandlerUtil.generateBackendRequestURL(req, apiEndpoint));
ClassicHttpRequest putRequest = ClassicRequestBuilder.put(HandlerUtil.generateBackendRequestURL(req,
apiEndpoint)).build();
HandlerUtil.generateRequestEntity(req, putRequest);
putRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(putRequest);
@ -180,7 +184,8 @@ public class InvokerHandler extends HttpServlet {
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
HttpDelete deleteRequest = new HttpDelete(HandlerUtil.generateBackendRequestURL(req, apiEndpoint));
ClassicHttpRequest deleteRequest = ClassicRequestBuilder.delete(HandlerUtil.generateBackendRequestURL(req,
apiEndpoint)).build();
HandlerUtil.copyRequestHeaders(req, deleteRequest, false);
deleteRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
ProxyResponse proxyResponse = HandlerUtil.execute(deleteRequest);

@ -52,7 +52,6 @@ public class OTPInvokerHandler extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
// HttpPost postRequest = new HttpPost(HandlerUtil.generateBackendRequestURL(req, apiEndpoint));
ClassicHttpRequest postRequest = ClassicRequestBuilder.post(HandlerUtil.generateBackendRequestURL(req
, apiEndpoint)).build();
HandlerUtil.generateRequestEntity(req, postRequest);
@ -76,7 +75,7 @@ public class OTPInvokerHandler extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
ClassicHttpRequest getRequest = ClassicRequestBuilder.post(HandlerUtil.generateBackendRequestURL(req
ClassicHttpRequest getRequest = ClassicRequestBuilder.get(HandlerUtil.generateBackendRequestURL(req
, apiEndpoint)).build();
HandlerUtil.copyRequestHeaders(req, getRequest, false);
ProxyResponse proxyResponse = HandlerUtil.execute(getRequest);
@ -97,7 +96,7 @@ public class OTPInvokerHandler extends HttpServlet {
protected void doHead(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
ClassicHttpRequest headRequest = ClassicRequestBuilder.post(HandlerUtil.generateBackendRequestURL(req
ClassicHttpRequest headRequest = ClassicRequestBuilder.head(HandlerUtil.generateBackendRequestURL(req
, apiEndpoint)).build();
HandlerUtil.copyRequestHeaders(req, headRequest, false);
ProxyResponse proxyResponse = HandlerUtil.execute(headRequest);
@ -118,7 +117,7 @@ public class OTPInvokerHandler extends HttpServlet {
protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
ClassicHttpRequest putRequest = ClassicRequestBuilder.post(HandlerUtil.generateBackendRequestURL(req
ClassicHttpRequest putRequest = ClassicRequestBuilder.put(HandlerUtil.generateBackendRequestURL(req
, apiEndpoint)).build();
HandlerUtil.generateRequestEntity(req, putRequest);
ProxyResponse proxyResponse = HandlerUtil.execute(putRequest);
@ -141,7 +140,7 @@ public class OTPInvokerHandler extends HttpServlet {
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
try {
if (validateRequest(req, resp)) {
ClassicHttpRequest deleteRequest = ClassicRequestBuilder.post(HandlerUtil.generateBackendRequestURL(req
ClassicHttpRequest deleteRequest = ClassicRequestBuilder.delete(HandlerUtil.generateBackendRequestURL(req
, apiEndpoint)).build();
HandlerUtil.copyRequestHeaders(req, deleteRequest, false);
ProxyResponse proxyResponse = HandlerUtil.execute(deleteRequest);

Loading…
Cancel
Save