Skip to content

Commit

Permalink
Merge pull request #85 from wjonassen/bugfix-lib-updates
Browse files Browse the repository at this point in the history
Bug Fixes on start script for rest api jetty.
  • Loading branch information
wjonassen authored Jan 17, 2024
2 parents 58c7122 + ac8d90c commit 687d018
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 221 deletions.
30 changes: 16 additions & 14 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
[versions]
opendcs = "7.0.10"
opendcs = "7.0.11"

jetty = "9.4.53.v20231009"
servlet-api = "3.1.0"
slf4j = "2.0.0"
jetty-jsp = "9.2.30.v20200428"
javax-servlet-jsp = "2.3.0"
servlet-api = "4.0.1" #Updating this further will require a change to the jakarta namespace.
slf4j = "2.0.10"
jersey = "2.40"
postgresql = "42.6.0"
swagger = "2.2.15"
swagger-ui = "5.9.0"
postgresql = "42.7.1"
swagger = "2.2.19"
glassfish-jaxb = "2.3.3"
websocket = "1.1"

javax-validation = "2.0.1.Final"
#Test Dependencies
junit = "5.10.1"
mockito = "3.12.4"

[libraries]
opendcs = { module = "org.opendcs:opendcs", version.ref = "opendcs" }

jetty-jsp = { module = "org.eclipse.jetty:jetty-jsp", version.ref = "jetty-jsp" }
jetty-annotations = { module = "org.eclipse.jetty:jetty-annotations", version.ref = "jetty" }
jetty-server = { module = "org.eclipse.jetty:jetty-server", version.ref = "jetty" }
jetty-servlets = { module = "org.eclipse.jetty:jetty-servlets", version.ref = "jetty" }
jetty-servlet = { module = "org.eclipse.jetty:jetty-servlet", version.ref = "jetty" }
jetty-webapp = { module = "org.eclipse.jetty:jetty-webapp", version.ref = "jetty" }

javax-validation = { module = "javax.validation:validation-api", version.ref = "javax-validation" }

javax-servlet-jsp = { module = "javax.servlet.jsp:javax.servlet.jsp-api", version.ref= "javax-servlet-jsp" }
servlet-api = { module = "javax.servlet:javax.servlet-api", version.ref = "servlet-api" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
jersey-client = { module = "org.glassfish.jersey.core:jersey-client", version.ref = "jersey" }
jersey-server = { module = "org.glassfish.jersey.core:jersey-server", version.ref = "jersey" }
slf4j-jdk = { module = "org.slf4j:slf4j-jdk14", version.ref = "slf4j" }

json-jackson = { module = "org.glassfish.jersey.media:jersey-media-json-jackson", version.ref = "jersey" }
jersey-common = { module = "org.glassfish.jersey.core:jersey-common", version.ref = "jersey" }
jersey-container-servlet = { module = "org.glassfish.jersey.containers:jersey-container-servlet", version.ref = "jersey" }
jersey-hk2 = { module = "org.glassfish.jersey.inject:jersey-hk2", version.ref = "jersey" }
postgresql = { module = "org.postgresql:postgresql", version.ref = "postgresql" }
swagger-jaxrs2 = { module = "io.swagger.core.v3:swagger-jaxrs2", version.ref = "swagger" }
swagger-ui = { module = "org.webjars:swagger-ui", version.ref = "swagger-ui" }
swagger-jaxrs2 = { module = "io.swagger.core.v3:swagger-jaxrs2-jakarta", version.ref = "swagger" }
jaxb-runtime = { module = "org.glassfish.jaxb:jaxb-runtime", version.ref = "glassfish-jaxb" }
websocket = { module = "javax.websocket:javax.websocket-api", version.ref = "websocket" }

Expand Down
32 changes: 24 additions & 8 deletions opendcs-rest-api-jetty/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id "opendcs-rest-api.java-conventions"
id "opendcs-rest-api.deps-conventions"
Expand All @@ -14,6 +12,8 @@ dependencies {
implementation(libs.jersey.container.servlet)
implementation(libs.postgresql)
implementation(libs.swagger.jaxrs2)
implementation(libs.javax.validation)
implementation(libs.slf4j.jdk)
}

jar {
Expand Down Expand Up @@ -46,24 +46,40 @@ task startJetty(type: JavaExec) { ->
"-s")
}

task prepareStartScript(type: Copy) {
from './bin/start.sh'
into "${buildDir}/odcsapi-jetty-standalone/bin/"
filter(ReplaceTokens, tokens: ['jarName': jar.archiveFileName.get()])
task createStartScript() {
doLast {

//Make bin directory if it does not exist already. buildDir is now deprecated.
File buildDir = project.layout.getBuildDirectory().get().getAsFile();
File binDir = new File(buildDir.toString(), "bin");
project.mkdir(binDir);

//Make the start.sh file.
new File(binDir, "start.sh").text = """
#!/bin/bash
cd `dirname \$0`/..
java -Djava.util.logging.config.file=config/logging.properties \$JAVA_OPTS -jar libs/${project.name}-${project.version}.jar \$JAVA_ARGS
"""
}
}

task bundle(type: Tar) {
dependsOn jar
dependsOn prepareStartScript
dependsOn createStartScript

compression Compression.GZIP
archiveExtension = 'tar.gz'

into('config') {
from project.file("config/logging.properties")
}
into('libs') {
from configurations.runtimeClasspath
}
into('libs') {
from jar
}
into('bin') {
from "${buildDir}/odcsapi-jetty-standalone/bin/start.sh"
from new File(project.layout.getBuildDirectory().get().getAsFile(), "bin/start.sh");
}
}
77 changes: 77 additions & 0 deletions opendcs-rest-api-jetty/config/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Copyright 2024 OpenDCS Consortium
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

############################################################
# Default Logging Configuration File
#
# You can use a different file by specifying a filename
# with the java.util.logging.config.file system property.
# For example java -Djava.util.logging.config.file=myfile
# or: -Djava.util.logging.config.file=./config/properties/logging.properties
############################################################

############################################################
# Global properties
############################################################

# "handlers" specifies a comma separated list of log Handler
# classes. These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# Additional handlers can be added to the list
handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler

# Default global logging level.
# This specifies which kinds of events are logged across
# all loggers. For any given facility this global level
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level= CONFIG

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

# Individual handlers filter messages by level.
# Messages at or above this level get output by the handler being configured.

# Setting this level = CONFIG causes CONFIG, INFO, WARNING, and SEVERE messages to be
# output by this handler.
java.util.logging.ConsoleHandler.level = CONFIG
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# The following special tokens can be used in the FileHandler pattern property
# which specifies the location and name of the log file.
# / - standard path separator
# %t - system temporary directory
# %h - value of the user.home system property
# %g - generation number for rotating logs
# %u - unique number to avoid conflicts
# FileHandler writes to %h/demo0.log by default.
java.util.logging.FileHandler.pattern = %t/opendcs_rest_logging_%g.log
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

# Formats the messages with a timestamp at the beginning.
java.util.logging.SimpleFormatter.format=[%1$tc] %4$s: %5$s %n

############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################

# Specify logging levels for specific namespaces.
# org.opendcs.odcsapi.level = FINEST
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ public class ApiCmdLineArgs
private int httpsPort = -1;
private String keyStorePath;
private String keyStorePassword;

private String decodesPropFile = "$DCSTOOL_USERDIR/user.properties";
private boolean secureMode = false;
private String corsFile = "$DCSTOOL_HOME/opendcs_api_cors.cfg";

private enum State { IDLE, EXPECT_CONTEXT, EXPECT_HTTPPORT, EXPECT_HTTPSPORT, EXPECT_KEYSTOREPATH, EXPECT_KEYSTOREPASSWORD, EXPECT_PROPFILE, EXPECT_CORS };
private enum State
{
IDLE, EXPECT_CONTEXT, EXPECT_HTTPPORT, EXPECT_HTTPSPORT, EXPECT_KEYSTOREPATH, EXPECT_KEYSTOREPASSWORD, EXPECT_PROPFILE, EXPECT_CORS
}
private State state = State.IDLE;
private String splitArg = null;

Expand All @@ -43,15 +46,11 @@ public void parseArgs(String[] args)
{
state = State.IDLE;
splitArg = null;
System.out.println("ALL Args: " + args.toString());
for(String arg : args)
{
System.out.println("First Arg: " + arg);
parseArg(arg);
System.out.println("Arg after parse: " + arg);
if (splitArg != null)
{
System.out.println("Split Arg Before Parse: " + splitArg);
parseArg(splitArg);
splitArg = null;
}
Expand All @@ -66,24 +65,17 @@ private void parseArg(String arg)
switch(state)
{
case IDLE:
System.out.println("IDLE: Arg: " + arg);
if (arg.startsWith("-cors"))
{
System.out.println("-cors argument found.");
state = State.EXPECT_CORS;
System.out.println("Arg: " + arg);
if (arg.length() > 5)
splitArg = arg.substring(5);
System.out.println("Split Arg: " + splitArg);
}
else if (arg.startsWith("-c"))
{
System.out.println("-c argument found.");
state = State.EXPECT_CONTEXT;
System.out.println("Arg: " + arg);
if (arg.length() > 2)
splitArg = arg.substring(2);
System.out.println("Split Arg: " + splitArg);
}
else if (arg.startsWith("-p"))
{
Expand Down Expand Up @@ -172,11 +164,7 @@ else if (arg.startsWith("-s"))
state = State.IDLE;
break;
case EXPECT_CORS:
System.out.println("Cors File!!!");
System.out.println("Whole Arg: " + arg);
System.out.println("Split Arg: " + splitArg);
corsFile = arg.trim();
System.out.println("Cors File: " + corsFile);
Path corsPath = Paths.get(corsFile);
boolean fExists = Files.exists(corsPath);
if (!fExists)
Expand Down Expand Up @@ -244,7 +232,7 @@ public void setKeyStorePassword(String keyStorePassword)
{
this.keyStorePassword = keyStorePassword;
}

public String getDecodesPropFile()
{
return decodesPropFile;
Expand Down
Loading

0 comments on commit 687d018

Please sign in to comment.