-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from evasiba-ericsson/master
made publish handle any json and not only json arrays
- Loading branch information
Showing
12 changed files
with
426 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 37 additions & 33 deletions
70
src/main/java/com/ericsson/eiffel/remrem/publish/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
package com.ericsson.eiffel.remrem.publish; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import java.util.List; | ||
|
||
import org.springframework.boot.Banner; | ||
import org.springframework.boot.DefaultApplicationArguments; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.web.SpringBootServletInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import com.ericsson.eiffel.remrem.publish.cli.CLI; | ||
import org.springframework.boot.web.support.SpringBootServletInitializer; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.ComponentScan; | ||
|
||
import java.util.Arrays; | ||
import com.ericsson.eiffel.remrem.publish.cli.CliOptions; | ||
import com.ericsson.eiffel.remrem.publish.config.SpringLoggingInitializer; | ||
|
||
@SpringBootApplication | ||
@Slf4j | ||
@SpringBootApplication | ||
@ComponentScan("com.ericsson.eiffel.remrem") | ||
public class App extends SpringBootServletInitializer { | ||
public static void main(String[] args) { | ||
|
||
// CLI class checks if arguments are passed to application | ||
// and if so we do not start the service but act based on | ||
// passed arguments. If no arguments are passed the server | ||
// will be started | ||
CLI cli = new CLI(); | ||
boolean needsStartService = cli.parse(args); | ||
|
||
if (needsStartService) { | ||
startService(args); | ||
} | ||
} | ||
|
||
private static void startService(String[] args) { | ||
ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args); | ||
|
||
log.info("Let's inspect the beans provided by Spring Boot:"); | ||
|
||
String[] beanNames = ctx.getBeanDefinitionNames(); | ||
Arrays.sort(beanNames); | ||
for (String beanName : beanNames) { | ||
log.info(beanName); | ||
} | ||
} | ||
public static void main(String[] args) { | ||
startService(args); | ||
} | ||
|
||
private static void startService(String[] args) { | ||
handleArgs(args); | ||
SpringApplication application = new SpringApplication(App.class); | ||
application.addInitializers(new SpringLoggingInitializer()); | ||
application.setBannerMode(Banner.Mode.OFF); | ||
application.setLogStartupInfo(false); | ||
// We do not start web service if any CLI arguments are passed | ||
if (CliOptions.hasParsedOptions()) | ||
application.setWebEnvironment(false); | ||
ApplicationContext ctx = application.run(args); | ||
} | ||
|
||
private static void handleArgs(String[] args) { | ||
//We sort out Spring specific arguments and send the others to CLI parser | ||
DefaultApplicationArguments springARgs = new DefaultApplicationArguments(args); | ||
List<String> nonOptions = springARgs.getNonOptionArgs(); | ||
String[] nonSpringArgs = nonOptions.toArray(new String[0]); | ||
// We need to parse the cLI options before Spring starts since we need the available when | ||
// Spring instantiate autowired components needing argument values | ||
if (nonSpringArgs.length > 0) | ||
CliOptions.parse(nonSpringArgs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.