This is an automated email from the ASF dual-hosted git repository. imesha pushed a commit to branch development in repository https://gitbox.apache.org/repos/asf/oodt.git
commit 52ef20b591872aafd4c28b9cd3ff2fded29dbeb0 Author: Imesha Sudasingha <[email protected]> AuthorDate: Sat Sep 21 13:50:31 2019 +0530 [OODT-1026] Code formatting changes and moved several test classes to fmprod/test/java directory. --- .../BadRequestExceptionMapper.java | 4 +- .../CasProductExceptionMapper.java | 4 +- .../InternalServerErrorExceptionMapper.java | 4 +- .../exceptionmappers/NotFoundExceptionMapper.java | 2 +- .../oodt/cas/product/jaxrs/filters/CORSFilter.java | 9 +- .../jaxrs/servlets/CasProductJaxrsServlet.java | 166 ++++++++------------- .../product/handlers/ofsn/util/OFSNUtilsTest.java | 0 .../xmlquery/ChunkedProductInputStreamTest.java | 0 .../org/apache/oodt/xmlquery/LargeResultTest.java | 0 9 files changed, 70 insertions(+), 119 deletions(-) diff --git a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/BadRequestExceptionMapper.java b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/BadRequestExceptionMapper.java index b6b1f23..f6f3ac6 100644 --- a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/BadRequestExceptionMapper.java +++ b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/BadRequestExceptionMapper.java @@ -37,14 +37,14 @@ public class BadRequestExceptionMapper implements ExceptionMapper<BadRequestExce @Override public Response toResponse(BadRequestException exception) { - /** Initialising ErrorMessage Entity for Mapping to Response */ + /* Initialising ErrorMessage Entity for Mapping to Response */ ErrorMessage errorMessageEntity = new ErrorMessage( Response.Status.BAD_REQUEST.getStatusCode(), ErrorType.BAD_REQUEST_EXCEPTION.getErrorType(), exception.getMessage()); - /** Maps Error Status 400 to Response */ + /* Maps Error Status 400 to Response */ return Response.status(Response.Status.BAD_REQUEST) .entity(errorMessageEntity) .type(MediaType.APPLICATION_JSON) diff --git a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/CasProductExceptionMapper.java b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/CasProductExceptionMapper.java index ea8f329..f9fe52a 100644 --- a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/CasProductExceptionMapper.java +++ b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/CasProductExceptionMapper.java @@ -36,12 +36,12 @@ public class CasProductExceptionMapper implements ExceptionMapper<CasProductExce @Override public Response toResponse(CasProductException exception) { - /** Initialising ErrorMessage Entity for Mapping to Response */ + /* Initialising ErrorMessage Entity for Mapping to Response */ ErrorMessage errorMessageEntity = new ErrorMessage( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), exception.getMessage()); - /** Maps Error Status 500 to Response */ + /* Maps Error Status 500 to Response */ return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity(errorMessageEntity) .type(MediaType.APPLICATION_JSON) diff --git a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/InternalServerErrorExceptionMapper.java b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/InternalServerErrorExceptionMapper.java index fd29437..4baa40c 100644 --- a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/InternalServerErrorExceptionMapper.java +++ b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/InternalServerErrorExceptionMapper.java @@ -37,12 +37,12 @@ public class InternalServerErrorExceptionMapper @Override public Response toResponse(InternalServerErrorException exception) { - /** Initialising ErrorMessage Entity for Mapping to Response */ + /* Initialising ErrorMessage Entity for Mapping to Response */ ErrorMessage errorMessageEntity = new ErrorMessage( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), exception.getMessage()); - /** Maps Error Status 500 to Response */ + /* Maps Error Status 500 to Response */ return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity(errorMessageEntity) .type(MediaType.APPLICATION_JSON) diff --git a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/NotFoundExceptionMapper.java b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/NotFoundExceptionMapper.java index e90360a..291f123 100644 --- a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/NotFoundExceptionMapper.java +++ b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/exceptionmappers/NotFoundExceptionMapper.java @@ -33,7 +33,7 @@ import org.apache.oodt.cas.product.jaxrs.exceptions.NotFoundException; @Provider public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> { - /* Maps NotFoundException to HTTP Response */ + /** Maps NotFoundException to HTTP Response */ @Override public Response toResponse(NotFoundException exception) { diff --git a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/filters/CORSFilter.java b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/filters/CORSFilter.java index 6682ed3..1185822 100644 --- a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/filters/CORSFilter.java +++ b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/filters/CORSFilter.java @@ -58,13 +58,12 @@ public class CORSFilter implements Filter { HttpServletRequest request = (HttpServletRequest) servletRequest; logger.debug("CORSFilter HTTP Request: {}", request.getMethod()); - // Authorize (allow) all domains to consume the content - ((HttpServletResponse) servletResponse).addHeader("Access-Control-Allow-Origin", "*"); - ((HttpServletResponse) servletResponse) - .addHeader("Access-Control-Allow-Methods", "GET, OPTIONS, HEAD, PUT, POST"); - HttpServletResponse resp = (HttpServletResponse) servletResponse; + // Authorize (allow) all domains to consume the content + resp.addHeader("Access-Control-Allow-Origin", "*"); + resp.addHeader("Access-Control-Allow-Methods", "GET, OPTIONS, HEAD, PUT, POST"); + // For HTTP OPTIONS verb/method reply with ACCEPTED status code -- per CORS handshake if (request.getMethod().equals("OPTIONS")) { resp.setStatus(HttpServletResponse.SC_ACCEPTED); diff --git a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/servlets/CasProductJaxrsServlet.java b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/servlets/CasProductJaxrsServlet.java index 25f6d84..11bf959 100755 --- a/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/servlets/CasProductJaxrsServlet.java +++ b/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/jaxrs/servlets/CasProductJaxrsServlet.java @@ -13,7 +13,7 @@ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -*/ + */ package org.apache.oodt.cas.product.jaxrs.servlets; @@ -22,14 +22,11 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; -import java.util.concurrent.ConcurrentHashMap; import java.util.Map; -import java.util.logging.Level; - +import java.util.concurrent.ConcurrentHashMap; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; - import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet; import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException; import org.apache.oodt.cas.filemgr.system.FileManagerClient; @@ -42,13 +39,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Provides a single place to initialize items such as the file manager client, - * working directory and configurations when the web application is started up. + * Provides a single place to initialize items such as the file manager client, working directory + * and configurations when the web application is started up. + * * @author rlaidlaw * @version $Revision$ */ -public class CasProductJaxrsServlet extends CXFNonSpringJaxrsServlet -{ +public class CasProductJaxrsServlet extends CXFNonSpringJaxrsServlet { // Auto-generated ID for serialization. private static final long serialVersionUID = -1835790185000773396L; @@ -58,10 +55,8 @@ public class CasProductJaxrsServlet extends CXFNonSpringJaxrsServlet private static final int CONFIG_PARAM_FORMAT = 1; private static final int CONFIG_PARAM_NAME = 2; - @Override - public void init(ServletConfig configuration) throws ServletException - { + public void init(ServletConfig configuration) throws ServletException { super.init(configuration); ServletContext context = configuration.getServletContext(); initializeClient(context); @@ -69,29 +64,22 @@ public class CasProductJaxrsServlet extends CXFNonSpringJaxrsServlet initializeConfigurations(context); } - - /** - * Initializes the file manager client and stores it as a "client" context - * attribute by retrieving a value for the file manager URL from the servlet - * context. + * Initializes the file manager client and stores it as a "client" context attribute by retrieving + * a value for the file manager URL from the servlet context. + * * @param context the servlet context - * @throws ServletException if the servlet context parameter for the file - * manager working directory path cannot be found + * @throws ServletException if the servlet context parameter for the file manager working + * directory path cannot be found */ - private void initializeClient(ServletContext context) throws ServletException - { - try - { + private void initializeClient(ServletContext context) throws ServletException { + try { URL url; String urlParameter = context.getInitParameter("filemgr.url"); - if (urlParameter != null) - { + if (urlParameter != null) { // Get the file manager URL from the context parameter. url = new URL(PathUtils.replaceEnvVariables(urlParameter)); - } - else - { + } else { // Try the default URL for the file manager. logger.debug( "WARNING Exception Thrown: {}", @@ -104,126 +92,90 @@ public class CasProductJaxrsServlet extends CXFNonSpringJaxrsServlet // store the client as a context attribute for other objects to access. FileManagerClient client = RpcCommunicationFactory.createClient(url); context.setAttribute("client", client); - } - catch (MalformedURLException e) - { + } catch (MalformedURLException e) { String message = "Encountered a malformed URL for the file manager."; - logger.debug( - "Exception Thrown: {}", - message,e); + logger.error("Exception Thrown: {}", message, e); throw new ServletException(message); - } - catch (ConnectionException e) - { - String message = - "Client could not establish a connection to the file manager."; - logger.debug( - "Exception Thrown: {}", - message,e); + } catch (ConnectionException e) { + String message = "Client could not establish a connection to the file manager."; + logger.error("Exception Thrown: {}", message, e); throw new ServletException(message); } } - - /** - * Initializes the file manager working directory path and stores it as a - * "workingDir" context attribute by retrieving a value from the servlet - * context. + * Initializes the file manager working directory path and stores it as a "workingDir" context + * attribute by retrieving a value from the servlet context. + * * @param context the servlet context - * @throws ServletException if the servlet context parameter for the file - * manager working directory path cannot be found + * @throws ServletException if the servlet context parameter for the file manager working + * directory path cannot be found */ - private void initializeWorkingDir(ServletContext context) - throws ServletException - { + private void initializeWorkingDir(ServletContext context) throws ServletException { String workingDirPath = context.getInitParameter("filemgr.working.dir"); - if (workingDirPath != null) - { + if (workingDirPath != null) { // Validate the path. File workingDir = new File(PathUtils.replaceEnvVariables(workingDirPath)); - if (workingDir.exists() && workingDir.isDirectory()) - { + if (workingDir.exists() && workingDir.isDirectory()) { context.setAttribute("workingDir", workingDir); logger.debug( - "Exception Thrown: {}", - "The file manager's working directory has been " - + "set up as " + workingDir.getAbsolutePath()); - } - else - { + "The file manager's working directory has been set up as {}", + workingDir.getAbsolutePath()); + } else { logger.debug( - "Exception Thrown: {}", - "Unable to locate the working directory for " - + "the file manager."); + "Unable to locate the working directory for the file manager: {}", + workingDir.getAbsolutePath()); } - } - else - { - String message = "Unable to find a servlet context parameter for the file" - + " manager working directory path."; - logger.debug( - "Exception Thrown: {}",message); + } else { + String message = + "Unable to find a servlet context parameter for the file manager working directory path."; + logger.debug(message); throw new ServletException(message); } } - - /** - * Initializes the output configurations for various different formats and - * stores them in "configurations" attributes by retrieving values from the - * servlet context. + * Initializes the output configurations for various different formats and stores them in + * "configurations" attributes by retrieving values from the servlet context. + * * @param context the servlet context * @throws IOException if the specified file cannot be found or read */ - public void initializeConfigurations(ServletContext context) - { + public void initializeConfigurations(ServletContext context) { Map<String, RdfConfiguration> rdfConfigurations = - new ConcurrentHashMap<String, RdfConfiguration>(); + new ConcurrentHashMap<String, RdfConfiguration>(); Map<String, RssConfiguration> rssConfigurations = - new ConcurrentHashMap<String, RssConfiguration>(); + new ConcurrentHashMap<String, RssConfiguration>(); Enumeration<String> enumeration = context.getInitParameterNames(); - while (enumeration.hasMoreElements()) - { + while (enumeration.hasMoreElements()) { String parameterName = enumeration.nextElement(); - if(parameterName.startsWith("configuration")) - { + if (parameterName.startsWith("configuration")) { String[] values = parameterName.split("\\."); - if (values.length == CONFIG_PARAM_LENGTH) - { + if (values.length == CONFIG_PARAM_LENGTH) { String format = values[CONFIG_PARAM_FORMAT]; String name = values[CONFIG_PARAM_NAME]; - String value = PathUtils.replaceEnvVariables( - context.getInitParameter(parameterName)); + String value = PathUtils.replaceEnvVariables(context.getInitParameter(parameterName)); - try - { - if ("rdf".equals(format)) - { + try { + if ("rdf".equals(format)) { RdfConfiguration configuration = new RdfConfiguration(); configuration.initialize(new File(value)); rdfConfigurations.put(name, configuration); - } - else if ("rss".equals(format)) - { + } else if ("rss".equals(format)) { RssConfiguration configuration = new RssConfiguration(); configuration.initialize(new File(value)); rssConfigurations.put(name, configuration); } + } catch (IOException e) { + logger.error( + "Exception Thrown: The configuration '{}' could not be initialized (value: {}).", + parameterName, + value, + e); } - catch (IOException e) - { - logger.debug( - "WARNING Exception Thrown: {}","The configuration '" + parameterName - + "'could not be initialized (value: " + value + ").", e); - } - } - else - { - logger.debug( - "Exception Thrown: {}","Configuration context parameter could not be parsed."); + } else { + logger.debug("Exception Thrown: Configuration context parameter could not be parsed."); } } } diff --git a/webapp/fmprod/src/test/org/apache/oodt/product/handlers/ofsn/util/OFSNUtilsTest.java b/webapp/fmprod/src/test/java/org/apache/oodt/product/handlers/ofsn/util/OFSNUtilsTest.java similarity index 100% rename from webapp/fmprod/src/test/org/apache/oodt/product/handlers/ofsn/util/OFSNUtilsTest.java rename to webapp/fmprod/src/test/java/org/apache/oodt/product/handlers/ofsn/util/OFSNUtilsTest.java diff --git a/webapp/fmprod/src/test/org/apache/oodt/xmlquery/ChunkedProductInputStreamTest.java b/webapp/fmprod/src/test/java/org/apache/oodt/xmlquery/ChunkedProductInputStreamTest.java similarity index 100% rename from webapp/fmprod/src/test/org/apache/oodt/xmlquery/ChunkedProductInputStreamTest.java rename to webapp/fmprod/src/test/java/org/apache/oodt/xmlquery/ChunkedProductInputStreamTest.java diff --git a/webapp/fmprod/src/test/org/apache/oodt/xmlquery/LargeResultTest.java b/webapp/fmprod/src/test/java/org/apache/oodt/xmlquery/LargeResultTest.java similarity index 100% rename from webapp/fmprod/src/test/org/apache/oodt/xmlquery/LargeResultTest.java rename to webapp/fmprod/src/test/java/org/apache/oodt/xmlquery/LargeResultTest.java
