Skip to content

Commit

Permalink
Not getting error responseBody in remrem-publish, (#173)
Browse files Browse the repository at this point in the history
if statusCode is not OK

Implemented code changes to handle error ResponseBody in
/generateAndPublish endpoint
  • Loading branch information
zburswa authored and Raja Maragani committed Nov 7, 2019
1 parent 28fecbf commit 68ac333
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 58 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.0.9
- Implemented code changes to handle error ResponseBody in /generateAndPublish endpoint.

## 2.0.8
- Code to handle the lookup towards ER when generating events using REMReM.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>2.0.2</version>
</parent>
<properties>
<eiffel-remrem-publish.version>2.0.8</eiffel-remrem-publish.version>
<eiffel-remrem-publish.version>2.0.9</eiffel-remrem-publish.version>
<eiffel-remrem-shared.version>2.0.2</eiffel-remrem-shared.version>
<eiffel-remrem-semantics.version>2.0.6</eiffel-remrem-semantics.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package com.ericsson.eiffel.remrem.publish.config;

import com.ericsson.eiffel.remrem.publish.constants.RemremPublishServiceConstants;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -52,7 +51,7 @@ private ApiInfo metaData() {
final StringBuilder remremDescription = new StringBuilder();
remremDescription.append("REMReM (REST Mailbox for Registered Messages) Publish "
+ "for publish validated Eiffel messages on a RabbitMQ message bus. ");
remremDescription.append("<a href= " + RemremPublishServiceConstants.DOCUMENTATION_URL + ">REMReM Publish documentation</a>");
remremDescription.append("<a href= https://eiffel-community.github.io/eiffel-remrem-publish/index.html>REMReM Publish documentation</a>");

return new ApiInfoBuilder()
.title("Eiffel REMReM Publish Service")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.ericsson.eiffel.remrem.publish.controller;

import java.util.EnumSet;
import java.util.Map;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,6 +30,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;

import com.ericsson.eiffel.remrem.protocol.MsgService;
Expand All @@ -38,7 +40,6 @@
import com.ericsson.eiffel.remrem.publish.service.MessageService;
import com.ericsson.eiffel.remrem.publish.service.SendResult;
import com.ericsson.eiffel.remrem.shared.VersionService;
import com.ericsson.eiffel.remrem.publish.constants.RemremPublishServiceConstants;
import com.ericsson.eiffel.remrem.publish.service.GenerateURLTemplate;
import com.ericsson.eiffel.remrem.publish.exception.RemRemPublishException;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -170,6 +171,7 @@ public ResponseEntity generateAndPublish(@ApiParam(value = "message protocol", r
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>(bodyJsonOut, headers);
EnumSet<HttpStatus> getStatus = EnumSet.of(HttpStatus.SERVICE_UNAVAILABLE, HttpStatus.UNAUTHORIZED, HttpStatus.NOT_ACCEPTABLE, HttpStatus.EXPECTATION_FAILED, HttpStatus.INTERNAL_SERVER_ERROR);

try {
String generateUrl=generateURLTemplate.getUrl()+"&failIfMultipleFound="+failIfMultipleFound+"&failIfNoneFound="+failIfNoneFound;
Expand Down Expand Up @@ -198,22 +200,12 @@ public ResponseEntity generateAndPublish(@ApiParam(value = "message protocol", r
catch (RemRemPublishException e) {
return new ResponseEntity(e.getMessage(), HttpStatus.NOT_FOUND);
}
catch (Exception e) {
log.info("The result from REMReM Generate is not OK and have value: " + e.getMessage());
if (e.getMessage().startsWith(Integer.toString(HttpStatus.BAD_REQUEST.value()))) {
return new ResponseEntity(parser.parse(RemremPublishServiceConstants.GENERATE_BAD_REQUEST), HttpStatus.BAD_REQUEST);
} else if (e.getMessage().startsWith(Integer.toString(HttpStatus.SERVICE_UNAVAILABLE.value()))) {
return new ResponseEntity(parser.parse(RemremPublishServiceConstants.GENERATE_NO_SERVICE_ERROR), HttpStatus.SERVICE_UNAVAILABLE);
} else if (e.getMessage().startsWith(Integer.toString(HttpStatus.UNAUTHORIZED.value()))) {
return new ResponseEntity(parser.parse(RemremPublishServiceConstants.GENERATE_UNAUTHORIZED), HttpStatus.UNAUTHORIZED);
}else if (e.getMessage().startsWith(Integer.toString(HttpStatus.NOT_ACCEPTABLE.value()))) {
return new ResponseEntity(parser.parse(RemremPublishServiceConstants.ERLOOKUP_NONEFOUND), HttpStatus.NOT_ACCEPTABLE);
}else if (e.getMessage().startsWith(Integer.toString(HttpStatus.EXPECTATION_FAILED.value()))) {
return new ResponseEntity(parser.parse(RemremPublishServiceConstants.ERLOOKUP_MULTIPLEFOUND), HttpStatus.EXPECTATION_FAILED);
}
else {
return new ResponseEntity(parser.parse(RemremPublishServiceConstants.GENERATE_INTERNAL_ERROR), HttpStatus.INTERNAL_SERVER_ERROR);
catch (HttpStatusCodeException e) {
HttpStatus result = HttpStatus.BAD_REQUEST;
if (getStatus.contains(e.getStatusCode())) {
result = e.getStatusCode();
}
return new ResponseEntity(parser.parse(e.getResponseBodyAsString()), result);
}
}

Expand Down

0 comments on commit 68ac333

Please sign in to comment.