diff options
Diffstat (limited to 'client/client-full')
4 files changed, 37 insertions, 21 deletions
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java index c6460d2c9..774cfc632 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java @@ -59,14 +59,14 @@ public class ApexServicesRest { // Create a resource configuration that scans for JAX-RS resources and providers // in org.onap.policy.apex.client.full.rest package - final ResourceConfig rc = new ResourceConfig().packages(parameters.getRESTPackages()); + final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages()); // Add MultiPartFeature class for jersey-media-multipart rc.register(MultiPartFeature.class); // create and start a new instance of grizzly http server // exposing the Jersey application at BASE_URI - server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseURI(), rc); + server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc); // Add static content server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler( diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java index a2fb0ac73..c89fcf473 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java @@ -22,11 +22,20 @@ package org.onap.policy.apex.client.full.rest; import java.io.PrintStream; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + /** * This class is the main class that is used to launch the Apex editor from the command line. * */ public class ApexServicesRestMain { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServicesRestMain.class); + + // Recurring string constants + private static final String REST_ENDPOINT_PREFIX = "Apex Editor REST endpoint ("; + /** * The Enum EditorState holds the current state of the editor. */ @@ -65,7 +74,7 @@ public class ApexServicesRestMain { final ApexServicesRestMain editorMain = new ApexServicesRestMain(args, System.out); editorMain.init(); } catch (final Exception e) { - System.err.println(e.getMessage()); + LOGGER.error(e.getMessage()); } } @@ -87,7 +96,7 @@ public class ApexServicesRestMain { parameters = parser.parse(args); } catch (final ApexServicesRestParameterException e) { throw new ApexServicesRestParameterException( - "Apex Editor REST endpoint (" + this.toString() + ") parameter error, " + e.getMessage() + '\n' + REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); } @@ -99,7 +108,7 @@ public class ApexServicesRestMain { final String validationMessage = parameters.validate(); if (validationMessage.length() > 0) { throw new ApexServicesRestParameterException( - "Apex Editor REST endpoint (" + this.toString() + ") parameters invalid, " + validationMessage + REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); } @@ -110,8 +119,8 @@ public class ApexServicesRestMain { * Initialize the Apex editor. */ public void init() { - outStream.println("Apex Editor REST endpoint (" + this.toString() + ") starting at " - + parameters.getBaseURI().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + + parameters.getBaseUri().toString() + " . . ."); try { state = EditorState.INITIALIZING; @@ -125,10 +134,10 @@ public class ApexServicesRestMain { state = EditorState.RUNNING; if (parameters.getTimeToLive() == ApexServicesRestParameters.INFINITY_TIME_TO_LIVE) { - outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started at " - + parameters.getBaseURI().toString()); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " + + parameters.getBaseUri().toString()); } else { - outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started"); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } // Find out how long is left to wait @@ -144,7 +153,7 @@ public class ApexServicesRestMain { } } catch (final Exception e) { outStream.println( - "Apex Editor REST endpoint (" + this.toString() + ") failed at with error: " + e.getMessage()); + REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage()); } finally { if (apexServices != null) { apexServices.shutdown(); @@ -181,11 +190,11 @@ public class ApexServicesRestMain { */ public void shutdown() { if (apexServices != null) { - outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shutting down"); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down"); apexServices.shutdown(); } state = EditorState.STOPPED; - outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shut down"); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down"); } /** diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java index 8a90aa633..bb27943d6 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java @@ -81,7 +81,7 @@ public class ApexServicesRestParameterParser { } try { if (commandLine.hasOption('p')) { - parameters.setRESTPort(((Number) commandLine.getParsedOptionValue("port")).intValue()); + parameters.setRestPort(((Number) commandLine.getParsedOptionValue("port")).intValue()); } } catch (final ParseException e) { throw new ApexServicesRestParameterException("error parsing argument \"port\" :" + e.getMessage(), e); diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java index 52ad885fd..f5f9d4c35 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java @@ -37,14 +37,21 @@ public class ApexServicesRestParameters { private static final String DEFAULT_STATIC_PATH = "/"; // Package that will field REST requests - private static final String[] DEFAULT_PACKAGES = new String[] { "org.onap.policy.apex.client.deployment.rest", - "org.onap.policy.apex.client.editor.rest", "org.onap.policy.apex.client.monitoring.rest" }; + private static final String[] DEFAULT_PACKAGES = new String[] { + "org.onap.policy.apex.client.deployment.rest", + "org.onap.policy.apex.client.editor.rest", + "org.onap.policy.apex.client.monitoring.rest" + }; // The services parameters private boolean helpSet = false; private int restPort = DEFAULT_REST_PORT; private long timeToLive = INFINITY_TIME_TO_LIVE; + /** + * Validate the parameters. + * @return the result of the validation + */ public String validate() { String validationMessage = ""; validationMessage += validatePort(); @@ -53,11 +60,11 @@ public class ApexServicesRestParameters { return validationMessage; } - public URI getBaseURI() { + public URI getBaseUri() { return URI.create(DEFAULT_SERVER_URI_ROOT + restPort + DEFAULT_REST_PATH); } - public String[] getRESTPackages() { + public String[] getRestPackages() { return DEFAULT_PACKAGES; } @@ -89,11 +96,11 @@ public class ApexServicesRestParameters { this.helpSet = helpSet; } - public int getRESTPort() { + public int getRestPort() { return restPort; } - public void setRESTPort(final int restPort) { + public void setRestPort(final int restPort) { this.restPort = restPort; } @@ -108,7 +115,7 @@ public class ApexServicesRestParameters { @Override public String toString() { final StringBuilder ret = new StringBuilder(); - ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseURI()).append(", TTL=") + ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=") .append(this.getTimeToLive()).append("sec"); return ret.toString(); } |