-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KOGITO-7453: Extend error handling example to show usage of error code (
#1341) * KOGITO-7453: Extend error handling example to show usage of error code * KOGITO-7453: Replace FQCN in error code with error message * KOGITO-7453: Apply QE review changes * Update PublishRestService.java * Update application.properties * Create application.properties * Delete serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/resources/application.properties * Create application.properties * Delete serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/resources/application.properties * Update application.properties * Update ErrorRestIT.java --------- Co-authored-by: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com>
- Loading branch information
1 parent
a51112c
commit 49d8870
Showing
6 changed files
with
127 additions
and
27 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
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
60 changes: 60 additions & 0 deletions
60
...less-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/PublishRestService.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2020 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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. | ||
*/ | ||
package org.kie.kogito.examples; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.core.Response.Status; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@Path("/publish") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class PublishRestService { | ||
|
||
private ObjectMapper objectMapper; | ||
private static final Logger logger = LoggerFactory.getLogger(PublishRestService.class); | ||
|
||
@PostConstruct | ||
void init() { | ||
objectMapper = new ObjectMapper(); | ||
} | ||
|
||
@Path("/{type}/{number}") | ||
@POST | ||
public Response publishEvenNumber(@PathParam("type") String type, @PathParam("number") int number) { | ||
logger.info("Publish type " + type + " number " + number); | ||
// check if the input number is even | ||
if (!"even".equals(type)) { | ||
return Response.status(Status.BAD_REQUEST).entity(objectMapper.createObjectNode().put("error", "Perfect square assessment not supported for odd numbers by this service")).build(); | ||
} | ||
return Response.ok().entity(objectMapper.createObjectNode().put("perfect", isPerfectSquare(number))).build(); | ||
} | ||
|
||
private boolean isPerfectSquare(int number) { | ||
double sqrt = Math.sqrt(number); | ||
return (sqrt == Math.round(sqrt)); | ||
} | ||
|
||
} |
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
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
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