From 00526352dab37f7e6638176fb431dee82795eddd Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 16 Oct 2019 16:31:22 +0530 Subject: [PATCH] Fix MsSQL and Oracle syntax issues --- .../application/OracleApplicationDAOImpl.java | 2 +- .../SQLServerApplicationDAOImpl.java | 2 +- .../dao/impl/review/OracleReviewDAOImpl.java | 6 +++--- .../impl/review/SQLServerReviewDAOImpl.java | 6 +++--- .../GenericSubscriptionDAOImpl.java | 4 ++-- .../OracleSubscriptionDAOImpl.java | 10 ++++----- .../SQLServerSubscriptionDAOImpl.java | 10 ++++----- .../ApplicationManagementPublisherAPI.java | 2 +- ...pplicationManagementPublisherAdminAPI.java | 4 ++-- ...ApplicationManagementPublisherAPIImpl.java | 5 ++--- ...cationManagementPublisherAdminAPIImpl.java | 7 +++++-- .../request/interceptor/InvokerHandler.java | 21 +++++++++---------- .../ui/request/interceptor/UserHandler.java | 3 +++ 13 files changed, 43 insertions(+), 39 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java index 1ed3ae0ec5f..249dea33969 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java @@ -81,7 +81,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { + "FROM AP_APP " + "INNER JOIN AP_APP_RELEASE ON " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " - + "INNER JOIN (SELECT ID FROM AP_APP OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID " + + "INNER JOIN (SELECT ID FROM AP_APP ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID " + "WHERE AP_APP.TENANT_ID = ?"; if (filter == null) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java index 6ed7ca72cea..3b247d886aa 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java @@ -79,7 +79,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { + "FROM AP_APP " + "INNER JOIN AP_APP_RELEASE ON " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " - + "INNER JOIN (SELECT ID FROM AP_APP OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID " + + "INNER JOIN (SELECT ID FROM AP_APP ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID " + "WHERE AP_APP.TENANT_ID = ?"; if (filter == null) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/OracleReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/OracleReviewDAOImpl.java index f24aac96ca4..7abec2ecc88 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/OracleReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/OracleReviewDAOImpl.java @@ -63,7 +63,7 @@ public class OracleReviewDAOImpl extends GenericReviewDAOImpl { + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND " + "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + "AP_APP_REVIEW.TENANT_ID = ? " - + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try { Connection conn = this.getDBConnection(); try (PreparedStatement statement = conn.prepareStatement(sql)) { @@ -114,7 +114,7 @@ public class OracleReviewDAOImpl extends GenericReviewDAOImpl { ") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + "AP_APP_REVIEW.TENANT_ID = ? " - + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + + "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); releaseIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { @@ -169,7 +169,7 @@ public class OracleReviewDAOImpl extends GenericReviewDAOImpl { + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + "AP_APP_REVIEW.USERNAME = ? AND " + "AP_APP_REVIEW.TENANT_ID = ? " - + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + + "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); releaseIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/SQLServerReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/SQLServerReviewDAOImpl.java index ccad696597b..4949e7f23a7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/SQLServerReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/SQLServerReviewDAOImpl.java @@ -63,7 +63,7 @@ public class SQLServerReviewDAOImpl extends GenericReviewDAOImpl { + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND " + "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + "AP_APP_REVIEW.TENANT_ID = ? " - + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try { Connection conn = this.getDBConnection(); try (PreparedStatement statement = conn.prepareStatement(sql)) { @@ -114,7 +114,7 @@ public class SQLServerReviewDAOImpl extends GenericReviewDAOImpl { ") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + "AP_APP_REVIEW.TENANT_ID = ? " - + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + + "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); releaseIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { @@ -169,7 +169,7 @@ public class SQLServerReviewDAOImpl extends GenericReviewDAOImpl { + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + "AP_APP_REVIEW.USERNAME = ? AND " + "AP_APP_REVIEW.TENANT_ID = ? " - + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + + "ORDER BY AP_APP_REVIEW.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); releaseIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 5b137b6253e..c7fc46fd362 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -971,8 +971,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc Connection conn = this.getDBConnection(); List subscribedRoles = new ArrayList<>(); String sql = "SELECT " - + "US.ROLE_NAME AS ROLE " - + "FROM AP_ROLE_SUBSCRIPTION US " + + "RS.ROLE_NAME AS ROLE " + + "FROM AP_ROLE_SUBSCRIPTION RS " + "WHERE " + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?"; try (PreparedStatement ps = conn.prepareStatement(sql)) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java index 439fdbf1177..b7932d9f9c8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java @@ -51,7 +51,7 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { + "US.USER_NAME AS USER " + "FROM AP_USER_SUBSCRIPTION US " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, appReleaseId); stmt.setInt(2, tenantId); @@ -88,10 +88,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { Connection conn = this.getDBConnection(); List subscribedRoles = new ArrayList<>(); String sql = "SELECT " - + "US.ROLE_NAME AS ROLE " - + "FROM AP_ROLE_SUBSCRIPTION US " + + "RS.ROLE_NAME AS ROLE " + + "FROM AP_ROLE_SUBSCRIPTION RS " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, appReleaseId); ps.setInt(2, tenantId); @@ -131,7 +131,7 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { + "GS.GROUP_NAME AS GROUPS " + "FROM AP_GROUP_SUBSCRIPTION GS " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, appReleaseId); ps.setInt(2, tenantId); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java index b3a93749e64..ea4ff20962b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java @@ -51,7 +51,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { + "US.USER_NAME AS USER " + "FROM AP_USER_SUBSCRIPTION US " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, appReleaseId); stmt.setInt(2, tenantId); @@ -88,10 +88,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { Connection conn = this.getDBConnection(); List subscribedRoles = new ArrayList<>(); String sql = "SELECT " - + "US.ROLE_NAME AS ROLE " - + "FROM AP_ROLE_SUBSCRIPTION US " + + "RS.ROLE_NAME AS ROLE " + + "FROM AP_ROLE_SUBSCRIPTION RS " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, appReleaseId); ps.setInt(2, tenantId); @@ -131,7 +131,7 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { + "GS.GROUP_NAME AS GROUPS " + "FROM AP_GROUP_SUBSCRIPTION GS " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, appReleaseId); ps.setInt(2, tenantId); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index a89aeb37660..d157c01a112 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -1276,7 +1276,7 @@ public interface ApplicationManagementPublisherAPI { ); @PUT - @Path("/tags/{oldTagName}") + @Path("/tags/rename") @Produces(MediaType.APPLICATION_JSON) @ApiOperation( consumes = MediaType.APPLICATION_JSON, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java index d536528af9f..83a719092f4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java @@ -230,12 +230,12 @@ public interface ApplicationManagementPublisherAdminAPI { ); @PUT - @Path("/tags/{tagName}") + @Path("/categories/rename") @Produces(MediaType.APPLICATION_JSON) @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", + httpMethod = "PUT", value = "Update application category", notes = "This will update application category.", tags = "Application Management", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index 163ddc84a13..499b59815b9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -48,7 +48,6 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; -import java.beans.Customizer; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -748,7 +747,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @DELETE @Override - @Consumes("application/json") + @Consumes(MediaType.WILDCARD) @Path("/{appId}/tags/{tagName}") public Response deleteApplicationTag( @PathParam("appId") int appId, @@ -775,7 +774,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @DELETE @Override - @Consumes("application/json") + @Consumes(MediaType.WILDCARD) @Path("/tags/{tagName}") public Response deleteUnusedTag( @PathParam("tagName") String tagName) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java index 4f6287e21f7..58a48a0f16b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java @@ -36,6 +36,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -49,6 +50,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa private static Log log = LogFactory.getLog(ApplicationManagementPublisherAdminAPIImpl.class); @DELETE + @Consumes(MediaType.WILDCARD) @Path("/release/{uuid}") public Response deleteApplicationRelease( @PathParam("uuid") String releaseUuid) { @@ -76,6 +78,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa } @DELETE + @Consumes(MediaType.WILDCARD) @Path("/{appId}") public Response deleteApplication( @PathParam("appId") int applicationId) { @@ -102,7 +105,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa @DELETE @Override - @Consumes("application/json") + @Consumes(MediaType.WILDCARD) @Path("/tags/{tagName}") public Response deleteTag( @PathParam("tagName") String tagName) { @@ -168,7 +171,7 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa @DELETE @Override - @Consumes("application/json") + @Consumes(MediaType.WILDCARD) @Path("/categories/{categoryName}") public Response deleteCategory( @PathParam("categoryName") String categoryName) { diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java index 1ec7b0e51ac..0ef489c9ba4 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java @@ -70,10 +70,9 @@ import java.util.List; public class InvokerHandler extends HttpServlet { private static final Log log = LogFactory.getLog(InvokerHandler.class); private static final long serialVersionUID = -6508020875358160165L; - private AuthData authData; - private String apiEndpoint; - private String serverUrl; - private String platform; + private static AuthData authData; + private static String serverUrl; + private static String platform; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) { @@ -229,7 +228,7 @@ public class InvokerHandler extends HttpServlet { */ private String generateBackendRequestURL(HttpServletRequest req) { StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append(serverUrl).append(HandlerConstants.API_COMMON_CONTEXT).append(apiEndpoint); + urlBuilder.append(serverUrl).append(HandlerConstants.API_COMMON_CONTEXT).append(req.getPathInfo()); if (StringUtils.isNotEmpty(req.getQueryString())) { urlBuilder.append("?").append(req.getQueryString()); } @@ -269,10 +268,9 @@ public class InvokerHandler extends HttpServlet { * @return If request is a valid one, returns TRUE, otherwise return FALSE * @throws IOException If and error occurs while witting error response to client side */ - private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) + private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException { serverUrl = req.getScheme() + "://" + req.getServerName() + ":" + System.getProperty("iot.gateway.https.port"); - apiEndpoint = req.getPathInfo(); HttpSession session = req.getSession(false); if (session == null) { @@ -289,8 +287,8 @@ public class InvokerHandler extends HttpServlet { return false; } - if (apiEndpoint == null || req.getMethod() == null) { - log.error("Bad Request, Either destination api-endpoint or method is empty"); + if (req.getMethod() == null) { + log.error("Bad Request, Request method is empty"); handleError(req, resp, HttpStatus.SC_BAD_REQUEST); return false; } @@ -322,13 +320,14 @@ public class InvokerHandler extends HttpServlet { } /*** + * This method is responsible to get the refresh token * * @param req {@link HttpServletRequest} * @param resp {@link HttpServletResponse} * @return If successfully renew tokens, returns TRUE otherwise return FALSE * @throws IOException If an error occurs while witting error response to client side or invoke token renewal API */ - private boolean refreshToken(HttpServletRequest req, HttpServletResponse resp) + private static boolean refreshToken(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (log.isDebugEnabled()) { log.debug("refreshing the token"); @@ -391,7 +390,7 @@ public class InvokerHandler extends HttpServlet { * @param errorCode HTTP error status code * @throws IOException If error occurred when trying to send the error response. */ - private void handleError(HttpServletRequest req, HttpServletResponse resp, int errorCode) + private static void handleError(HttpServletRequest req, HttpServletResponse resp, int errorCode) throws IOException { ProxyResponse proxyResponse = new ProxyResponse(); proxyResponse.setCode(errorCode); diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java index 5268160689b..81041d9e9cc 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java @@ -115,6 +115,7 @@ public class UserHandler extends HttpServlet { /** * Send UnAuthorized Response to the user + * * @param req HttpServletRequest object * @param resp HttpServletResponse object * @param serverUrl Url of the server @@ -124,6 +125,8 @@ public class UserHandler extends HttpServlet { throws IOException { ProxyResponse proxyResponse = new ProxyResponse(); proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED); + proxyResponse.setExecutorResponse( + HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil.getStatusKey(HttpStatus.SC_UNAUTHORIZED)); HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse); } }