Loading .classpath +18 −4 Changes for .classpath: 18 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -13,7 +13,12 @@ <attribute name="optional" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" output="target/classes" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> Loading @@ -21,7 +26,6 @@ </classpathentry> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> <attributes> <attribute name="module" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> Loading @@ -36,14 +40,24 @@ <attribute name="optional" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" path="target/generated-sources/annotations"> <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations"> <attributes> <attribute name="test" value="true"/> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> <attribute name="ignore_optional_problems" value="true"/> <attribute name="m2e-apt" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations"> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> <attribute name="test" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" path="target/generated-sources/annotations"> <attributes> <attribute name="optional" value="true"/> </attributes> </classpathentry> Loading pom.xml +8 −8 Changes for pom.xml: 8 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -223,6 +223,11 @@ </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-service-starter</artifactId> Loading Loading @@ -326,6 +331,9 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot-version}</version> <configuration> <classifier>exec</classifier> </configuration> <executions> <execution> <goals> Loading @@ -334,14 +342,6 @@ </execution> </executions> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot-version}</version> <configuration> <classifier>exec</classifier> </configuration> </plugin> </plugins> </build> Loading src/main/java/org/etsi/osl/mcp/server/CatalogErrorException.java +29 Changes for src/main/java/org/etsi/osl/mcp/server/CatalogErrorException.java: 29 added lines, 0 removed lines. Original line number Diff line number Diff line package org.etsi.osl.mcp.server; /** * Thrown when the catalog service answers a request with an error reply * ({@code {"error":"<ExceptionClass>","message":"..."}}) or with a body that cannot be * understood. Unlike a timeout, retrying the same request will not help, so the message * is meant to be shown to the caller. */ public class CatalogErrorException extends RuntimeException { private static final long serialVersionUID = 1L; private final String error; public CatalogErrorException(String error, String message) { super(message); this.error = error; } public CatalogErrorException(String error, String message, Throwable cause) { super(message, cause); this.error = error; } /** The error type reported by the catalog, e.g. the exception class name. */ public String getError() { return error; } } src/main/java/org/etsi/osl/mcp/server/ProductCatalogQClient.java +45 −17 Changes for src/main/java/org/etsi/osl/mcp/server/ProductCatalogQClient.java: 45 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; Loading Loading @@ -136,43 +137,70 @@ public class ProductCatalogQClient extends RouteBuilder { return sor; }catch (Exception e) { logger.error("Cannot retrieve Product Specification details from catalog. " + e.toString()); logger.error("Cannot retrieve Product Offering details from catalog. productOfferingId=" + productOfferingId, e); } return null; } /** * Create a product order via bus. * * @return the created order, or {@code null} when the catalog did not answer (e.g. the * request timed out), so the caller may retry later * @throws CatalogErrorException when the catalog rejected the order or replied with a body * that is not a product order; retrying the same request will not help */ public ProductOrder createProductOrder(ProductOrderCreate productOrderCreate) { logger.info("will create Product Order "); try { Object response; try { Object response = template.requestBody(CATALOG_ADD_PRODUCTORDER, toJsonString(productOrderCreate)); response = template.requestBody(CATALOG_ADD_PRODUCTORDER, toJsonString(productOrderCreate)); } catch (Exception e) { logger.error("Cannot createProductOrder to catalog.", e); return null; } if (!(response instanceof String)) { logger.error("Product Order object is wrong."); logger.error("createProductOrder: unexpected response from catalog: {}", response); return null; } logger.debug("createProductOrder response is: " + response); ProductOrder sor = toJsonObj((String) response, ProductOrder.class); return sor; } catch (Exception e) { logger.error("Cannot createProductOrder details to catalog. " + e.toString()); return parseCatalogReply((String) response, ProductOrder.class); } return null; /** * Parse a catalog reply, detecting the {@code {"error":"...","message":"..."}} body that * the catalog sends when a request fails. * * @throws CatalogErrorException for an error reply or a body that cannot be parsed */ static <T> T parseCatalogReply(String response, Class<T> valueType) { ObjectMapper mapper = new ObjectMapper(); JsonNode node; try { node = mapper.readTree(response); } catch (IOException e) { logger.error("Catalog reply is not valid JSON: " + response, e); throw new CatalogErrorException("InvalidResponse", "the catalog service returned an invalid response", e); } } catch (Exception e) { logger.error("Cannot createProductOrder to catalog. " + e.toString()); if (node != null && node.isObject() && node.has("error")) { String error = node.path("error").asText(null); String message = node.hasNonNull("message") ? node.get("message").asText() : error; logger.error("Catalog rejected the request: {}: {}", error, message); throw new CatalogErrorException(error, message); } return null; try { return mapper.treeToValue(node, valueType); } catch (IOException e) { logger.error("Cannot parse catalog reply as " + valueType.getSimpleName() + ": " + response, e); throw new CatalogErrorException("InvalidResponse", "the catalog service returned an unexpected response", e); } } /** Loading src/main/java/org/etsi/osl/mcp/server/ProductCatalogTools.java +11 −1 Changes for src/main/java/org/etsi/osl/mcp/server/ProductCatalogTools.java: 11 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -253,6 +253,10 @@ public class ProductCatalogTools { poi.action(OrderItemActionType.ADD); ProductOffering productOffering = aCatalogClient.retrieveProductOffering(productOfferingId); if (productOffering == null) { logger.warn("createProductOrder: product offering not found: {}", productOfferingId); return "Product Order submission failed: Product offering not found: " + productOfferingId; } ProductOfferingRef prodOffRef = new ProductOfferingRef(); prodOffRef.setId(productOfferingId); Loading Loading @@ -282,7 +286,13 @@ public class ProductCatalogTools { ponew.getProductOrderItem().add(poi); } ProductOrder po = aCatalogClient.createProductOrder(ponew); ProductOrder po; try { po = aCatalogClient.createProductOrder(ponew); } catch (CatalogErrorException e) { logger.error("createProductOrder rejected by catalog service: {}: {}", e.getError(), e.getMessage()); return "Product Order submission failed: " + e.getMessage(); } if (po == null) { logger.error("createProductOrder returned null - catalog service may be unavailable"); Loading Loading
.classpath +18 −4 Changes for .classpath: 18 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -13,7 +13,12 @@ <attribute name="optional" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" output="target/classes" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> Loading @@ -21,7 +26,6 @@ </classpathentry> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> <attributes> <attribute name="module" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> Loading @@ -36,14 +40,24 @@ <attribute name="optional" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" path="target/generated-sources/annotations"> <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations"> <attributes> <attribute name="test" value="true"/> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> <attribute name="ignore_optional_problems" value="true"/> <attribute name="m2e-apt" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations"> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> <attribute name="test" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" path="target/generated-sources/annotations"> <attributes> <attribute name="optional" value="true"/> </attributes> </classpathentry> Loading
pom.xml +8 −8 Changes for pom.xml: 8 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -223,6 +223,11 @@ </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-service-starter</artifactId> Loading Loading @@ -326,6 +331,9 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot-version}</version> <configuration> <classifier>exec</classifier> </configuration> <executions> <execution> <goals> Loading @@ -334,14 +342,6 @@ </execution> </executions> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot-version}</version> <configuration> <classifier>exec</classifier> </configuration> </plugin> </plugins> </build> Loading
src/main/java/org/etsi/osl/mcp/server/CatalogErrorException.java +29 Changes for src/main/java/org/etsi/osl/mcp/server/CatalogErrorException.java: 29 added lines, 0 removed lines. Original line number Diff line number Diff line package org.etsi.osl.mcp.server; /** * Thrown when the catalog service answers a request with an error reply * ({@code {"error":"<ExceptionClass>","message":"..."}}) or with a body that cannot be * understood. Unlike a timeout, retrying the same request will not help, so the message * is meant to be shown to the caller. */ public class CatalogErrorException extends RuntimeException { private static final long serialVersionUID = 1L; private final String error; public CatalogErrorException(String error, String message) { super(message); this.error = error; } public CatalogErrorException(String error, String message, Throwable cause) { super(message, cause); this.error = error; } /** The error type reported by the catalog, e.g. the exception class name. */ public String getError() { return error; } }
src/main/java/org/etsi/osl/mcp/server/ProductCatalogQClient.java +45 −17 Changes for src/main/java/org/etsi/osl/mcp/server/ProductCatalogQClient.java: 45 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; Loading Loading @@ -136,43 +137,70 @@ public class ProductCatalogQClient extends RouteBuilder { return sor; }catch (Exception e) { logger.error("Cannot retrieve Product Specification details from catalog. " + e.toString()); logger.error("Cannot retrieve Product Offering details from catalog. productOfferingId=" + productOfferingId, e); } return null; } /** * Create a product order via bus. * * @return the created order, or {@code null} when the catalog did not answer (e.g. the * request timed out), so the caller may retry later * @throws CatalogErrorException when the catalog rejected the order or replied with a body * that is not a product order; retrying the same request will not help */ public ProductOrder createProductOrder(ProductOrderCreate productOrderCreate) { logger.info("will create Product Order "); try { Object response; try { Object response = template.requestBody(CATALOG_ADD_PRODUCTORDER, toJsonString(productOrderCreate)); response = template.requestBody(CATALOG_ADD_PRODUCTORDER, toJsonString(productOrderCreate)); } catch (Exception e) { logger.error("Cannot createProductOrder to catalog.", e); return null; } if (!(response instanceof String)) { logger.error("Product Order object is wrong."); logger.error("createProductOrder: unexpected response from catalog: {}", response); return null; } logger.debug("createProductOrder response is: " + response); ProductOrder sor = toJsonObj((String) response, ProductOrder.class); return sor; } catch (Exception e) { logger.error("Cannot createProductOrder details to catalog. " + e.toString()); return parseCatalogReply((String) response, ProductOrder.class); } return null; /** * Parse a catalog reply, detecting the {@code {"error":"...","message":"..."}} body that * the catalog sends when a request fails. * * @throws CatalogErrorException for an error reply or a body that cannot be parsed */ static <T> T parseCatalogReply(String response, Class<T> valueType) { ObjectMapper mapper = new ObjectMapper(); JsonNode node; try { node = mapper.readTree(response); } catch (IOException e) { logger.error("Catalog reply is not valid JSON: " + response, e); throw new CatalogErrorException("InvalidResponse", "the catalog service returned an invalid response", e); } } catch (Exception e) { logger.error("Cannot createProductOrder to catalog. " + e.toString()); if (node != null && node.isObject() && node.has("error")) { String error = node.path("error").asText(null); String message = node.hasNonNull("message") ? node.get("message").asText() : error; logger.error("Catalog rejected the request: {}: {}", error, message); throw new CatalogErrorException(error, message); } return null; try { return mapper.treeToValue(node, valueType); } catch (IOException e) { logger.error("Cannot parse catalog reply as " + valueType.getSimpleName() + ": " + response, e); throw new CatalogErrorException("InvalidResponse", "the catalog service returned an unexpected response", e); } } /** Loading
src/main/java/org/etsi/osl/mcp/server/ProductCatalogTools.java +11 −1 Changes for src/main/java/org/etsi/osl/mcp/server/ProductCatalogTools.java: 11 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -253,6 +253,10 @@ public class ProductCatalogTools { poi.action(OrderItemActionType.ADD); ProductOffering productOffering = aCatalogClient.retrieveProductOffering(productOfferingId); if (productOffering == null) { logger.warn("createProductOrder: product offering not found: {}", productOfferingId); return "Product Order submission failed: Product offering not found: " + productOfferingId; } ProductOfferingRef prodOffRef = new ProductOfferingRef(); prodOffRef.setId(productOfferingId); Loading Loading @@ -282,7 +286,13 @@ public class ProductCatalogTools { ponew.getProductOrderItem().add(poi); } ProductOrder po = aCatalogClient.createProductOrder(ponew); ProductOrder po; try { po = aCatalogClient.createProductOrder(ponew); } catch (CatalogErrorException e) { logger.error("createProductOrder rejected by catalog service: {}: {}", e.getError(), e.getMessage()); return "Product Order submission failed: " + e.getMessage(); } if (po == null) { logger.error("createProductOrder returned null - catalog service may be unavailable"); Loading