mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
f8719c6dc4
@ -27,8 +27,10 @@ import org.apache.commons.lang.StringUtils;
|
||||
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.ContentType;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.io.entity.StringEntity;
|
||||
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
|
||||
|
||||
import javax.servlet.annotation.MultipartConfig;
|
||||
@ -37,6 +39,7 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
@MultipartConfig
|
||||
@ -183,9 +186,24 @@ public class InvokerHandler extends HttpServlet {
|
||||
@Override
|
||||
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
String jsonPayload = null;
|
||||
if (req.getContentLength() > 0) {
|
||||
StringBuilder jsonBuilder = new StringBuilder();
|
||||
String line;
|
||||
try (BufferedReader reader = req.getReader()) {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
jsonBuilder.append(line);
|
||||
}
|
||||
}
|
||||
jsonPayload = jsonBuilder.toString();
|
||||
}
|
||||
if (validateRequest(req, resp)) {
|
||||
ClassicHttpRequest deleteRequest = ClassicRequestBuilder.delete(HandlerUtil.generateBackendRequestURL(req,
|
||||
apiEndpoint)).build();
|
||||
if (jsonPayload != null && !jsonPayload.isEmpty()) {
|
||||
StringEntity entity = new StringEntity(jsonPayload, ContentType.APPLICATION_JSON);
|
||||
deleteRequest.setEntity(entity);
|
||||
}
|
||||
HandlerUtil.copyRequestHeaders(req, deleteRequest, false);
|
||||
deleteRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
|
||||
ProxyResponse proxyResponse = HandlerUtil.execute(deleteRequest);
|
||||
|
||||
@ -104,6 +104,13 @@ public class HandlerUtil {
|
||||
final HttpEntity responseEntity = response.getEntity();
|
||||
ProxyResponse handlerResponse = new ProxyResponse();
|
||||
int statusCode = response.getCode();
|
||||
if (statusCode == 204) {
|
||||
handlerResponse.setCode(statusCode);
|
||||
handlerResponse.setStatus(ProxyResponse.Status.SUCCESS);
|
||||
handlerResponse.setExecutorResponse("SUCCESS");
|
||||
handlerResponse.setHeaders(response.getHeaders());
|
||||
return handlerResponse;
|
||||
}
|
||||
if (responseEntity == null) {
|
||||
log.error("Received null response for http request : " + httpRequest.getMethod() + " " + httpRequest.getRequestUri());
|
||||
handlerResponse.setCode(HandlerConstants.INTERNAL_ERROR_CODE);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user