Skip to content

Commit

Permalink
Fixed issue of success status being returned in case of invalid excha…
Browse files Browse the repository at this point in the history
…nge.

Improved with a property to create exchange if not existing.
Application terminates when exchange does not exist, creation property is not selected.
  • Loading branch information
ZVADHEM authored and xvinosi-github committed May 28, 2019
1 parent d0ce9c1 commit 268b75d
Show file tree
Hide file tree
Showing 22 changed files with 561 additions and 188 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1
- Fix for Invalid exchange return success. Added a createExchangeIfNotExisting property to create an exchange.
- For CLI Added a option create_exchange or ce to create Exchange.
- Upgraded eiffel-remrem-semantics version from 2.0.3 to 2.0.4.

## 2.0.0
- Upgraded eiffel-remrem-semantics version from 1.0.1 to 2.0.3
- Modified test cases as per agen version and tested with proper data
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<version>2.0.0</version>
</parent>
<properties>
<eiffel-remrem-publish.version>2.0.0</eiffel-remrem-publish.version>
<eiffel-remrem-publish.version>2.0.1</eiffel-remrem-publish.version>
<eiffel-remrem-shared.version>2.0.0</eiffel-remrem-shared.version>
<eiffel-remrem-semantics.version>2.0.3</eiffel-remrem-semantics.version>
<eiffel-remrem-semantics.version>2.0.4</eiffel-remrem-semantics.version>
</properties>
<artifactId>eiffel-remrem-publish</artifactId>
<version>${eiffel-remrem-publish.version}</version>
Expand Down
12 changes: 12 additions & 0 deletions publish-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.ericsson.eiffel.remrem.publish.service.MessageService;
import com.ericsson.eiffel.remrem.publish.service.PublishResultItem;
import com.ericsson.eiffel.remrem.publish.service.SendResult;
import com.ericsson.eiffel.remrem.publish.exception.RemRemPublishException;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;

Expand All @@ -58,53 +59,56 @@
@SpringBootApplication
@ComponentScan(basePackages = "com.ericsson.eiffel.remrem")
public class CLI implements CommandLineRunner{

@Autowired @Qualifier("messageServiceRMQImpl") MessageService messageService;
@Autowired

@Autowired
@Qualifier("messageServiceRMQImpl")
MessageService messageService;

@Autowired
private MsgService[] msgServices;

@Autowired
RMQHelper rmqHelper;
Logger log = (Logger) LoggerFactory.getLogger(CLI.class);


Logger log = (Logger) LoggerFactory.getLogger(CLI.class);

/**
* Delegates actions depending on the passed arguments
* @param commandLine command line arguments
*/
private void handleOptions() {
CommandLine commandLine = CliOptions.getCommandLine();
if (commandLine.hasOption("h")) {
System.out.println("You passed help flag.");
CliOptions.help(0);
} else if (commandLine.hasOption("f")) {
CommandLine commandLine = CliOptions.getCommandLine();
if (commandLine.hasOption("h")) {
System.out.println("You passed help flag.");
CliOptions.help(0);
} else if (commandLine.hasOption("f")) {
String filePath = commandLine.getOptionValue("f");
handleContentFile(filePath);
} else if (commandLine.hasOption("json")) {
String content = getJsonString(commandLine);
handleContent(content);
} else {
System.out.println("Missing arguments, please review your arguments" +
" and check if any mandatory argument is missing");
CliOptions.help(CLIExitCodes.CLI_MISSING_OPTION_EXCEPTION);
System.out.println("Missing arguments, please review your arguments" +
" and check if any mandatory argument is missing");
CliOptions.help(CLIExitCodes.CLI_MISSING_OPTION_EXCEPTION);
}
}

private String getJsonString(CommandLine commandLine) {
String jsonContent = commandLine.getOptionValue("json");

if (jsonContent.equals("-")) {
try {
InputStreamReader isReader = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isReader);
jsonContent = bufReader.readLine();
} catch (Exception e) {
e.printStackTrace();
CliOptions.exit(CLIExitCodes.READ_JSON_FROM_CONSOLE_FAILED);
}

}
return jsonContent;
String jsonContent = commandLine.getOptionValue("json");
if (jsonContent.equals("-")) {
try {
InputStreamReader isReader = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isReader);
jsonContent = bufReader.readLine();
} catch (Exception e) {
e.printStackTrace();
CliOptions.exit(CLIExitCodes.READ_JSON_FROM_CONSOLE_FAILED);
}
}
return jsonContent;
}

/**
* Handle event from file
* @param filePath the path of the file where the messages reside
Expand All @@ -123,12 +127,13 @@ public void handleContentFile(String filePath) {
CliOptions.exit(CLIExitCodes.HANDLE_CONTENT_FILE_COULD_NOT_READ_FAILED);
}
}

/**
* Handle event from file
* @param filePath the path of the file where the messages reside
*/
public void handleContent(String content) {
String exchangeName = CliOptions.getCommandLine().getOptionValue("en");
try {
String msgProtocol = CliOptions.getCommandLine().getOptionValue("mp");
MsgService msgService = PublishUtils.getMessageService(msgProtocol, msgServices);
Expand All @@ -146,29 +151,36 @@ public void handleContent(String content) {
} else {
throw new Exception();
}
}catch (RemRemPublishException e) {
JsonArray errorResponse = new JsonArray();
PublishResultItem result = new PublishResultItem(null, 404,
null,e.getMessage());
errorResponse.add(result.toJsonObject());
System.err.println(new GsonBuilder().setPrettyPrinting().create().toJson(errorResponse));
CliOptions.exit(CLIExitCodes.HANDLE_CONTENT_FAILED);
} catch (Exception e) {
log.debug("Exception: ", e);
System.err.println("Exception: " + e.getMessage());
CliOptions.exit(CLIExitCodes.HANDLE_CONTENT_FAILED);
}
}

@Override
public void run(String... args) throws Exception {
if (CliOptions.hasParsedOptions())
handleOptions();
boolean cliMode = Boolean.getBoolean(PropertiesConfig.CLI_MODE);
@Override
public void run(String... args) throws Exception {
if (CliOptions.hasParsedOptions())
handleOptions();
boolean cliMode = Boolean.getBoolean(PropertiesConfig.CLI_MODE);
if (cliMode)
CliOptions.help(CLIExitCodes.CLI_MISSING_OPTION_EXCEPTION);
}
public static void main(String args[]) {
SpringApplication application = new SpringApplication(CLI.class);
application.addInitializers(new SpringLoggingInitializer());
application.setBannerMode(Banner.Mode.OFF);
application.setLogStartupInfo(false);
application.setWebEnvironment(false);
CliOptions.parse(args);
application.run(args);
}
CliOptions.help(CLIExitCodes.CLI_MISSING_OPTION_EXCEPTION);
}

public static void main(String args[]) {
SpringApplication application = new SpringApplication(CLI.class);
application.addInitializers(new SpringLoggingInitializer());
application.setBannerMode(Banner.Mode.OFF);
application.setLogStartupInfo(false);
application.setWebEnvironment(false);
CliOptions.parse(args);
application.run(args);
}
}
Loading

0 comments on commit 268b75d

Please sign in to comment.