Skip to content

Commit

Permalink
CAMEL-21300: camel-platform-http - Consumer should have option to con…
Browse files Browse the repository at this point in the history
…trol if writing response failing should cause Exchange to fail
  • Loading branch information
davsclaus committed Oct 2, 2024
1 parent 8a04e3e commit 07c5ad3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
},
"componentProperties": {
"bridgeErrorHandler": { "index": 0, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored." },
"autowiredEnabled": { "index": 1, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." },
"engine": { "index": 2, "kind": "property", "displayName": "Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.platform.http.spi.PlatformHttpEngine", "deprecated": false, "autowired": false, "secret": false, "description": "An HTTP Server engine implementation to serve the requests" },
"headerFilterStrategy": { "index": 3, "kind": "property", "displayName": "Header Filter Strategy", "group": "filter", "label": "filter", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message." }
"handleWriteResponseError": { "index": 1, "kind": "property", "displayName": "Handle Write Response Error", "group": "consumer", "label": "advanced,consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "When Camel is complete processing the message, and the HTTP server is writing response. This option controls whether Camel should catch any failure during writing response and store this on the Exchange, which allows onCompletion\/UnitOfWork to regard the Exchange as failed and have access to the caused exception from the HTTP server." },
"autowiredEnabled": { "index": 2, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." },
"engine": { "index": 3, "kind": "property", "displayName": "Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.platform.http.spi.PlatformHttpEngine", "deprecated": false, "autowired": false, "secret": false, "description": "An HTTP Server engine implementation to serve the requests" },
"headerFilterStrategy": { "index": 4, "kind": "property", "displayName": "Header Filter Strategy", "group": "filter", "label": "filter", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message." }
},
"properties": {
"path": { "index": 0, "kind": "path", "displayName": "Path", "group": "consumer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The path under which this endpoint serves the HTTP requests, for proxy use 'proxy'" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "bridgeerrorhandler":
case "bridgeErrorHandler": target.setBridgeErrorHandler(property(camelContext, boolean.class, value)); return true;
case "engine": target.setEngine(property(camelContext, org.apache.camel.component.platform.http.spi.PlatformHttpEngine.class, value)); return true;
case "handlewriteresponseerror":
case "handleWriteResponseError": target.setHandleWriteResponseError(property(camelContext, boolean.class, value)); return true;
case "headerfilterstrategy":
case "headerFilterStrategy": target.setHeaderFilterStrategy(property(camelContext, org.apache.camel.spi.HeaderFilterStrategy.class, value)); return true;
default: return false;
Expand All @@ -42,6 +44,8 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "bridgeerrorhandler":
case "bridgeErrorHandler": return boolean.class;
case "engine": return org.apache.camel.component.platform.http.spi.PlatformHttpEngine.class;
case "handlewriteresponseerror":
case "handleWriteResponseError": return boolean.class;
case "headerfilterstrategy":
case "headerFilterStrategy": return org.apache.camel.spi.HeaderFilterStrategy.class;
default: return null;
Expand All @@ -57,6 +61,8 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "bridgeerrorhandler":
case "bridgeErrorHandler": return target.isBridgeErrorHandler();
case "engine": return target.getEngine();
case "handlewriteresponseerror":
case "handleWriteResponseError": return target.isHandleWriteResponseError();
case "headerfilterstrategy":
case "headerFilterStrategy": return target.getHeaderFilterStrategy();
default: return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
},
"componentProperties": {
"bridgeErrorHandler": { "index": 0, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored." },
"autowiredEnabled": { "index": 1, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." },
"engine": { "index": 2, "kind": "property", "displayName": "Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.platform.http.spi.PlatformHttpEngine", "deprecated": false, "autowired": false, "secret": false, "description": "An HTTP Server engine implementation to serve the requests" },
"headerFilterStrategy": { "index": 3, "kind": "property", "displayName": "Header Filter Strategy", "group": "filter", "label": "filter", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message." }
"handleWriteResponseError": { "index": 1, "kind": "property", "displayName": "Handle Write Response Error", "group": "consumer", "label": "advanced,consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "When Camel is complete processing the message, and the HTTP server is writing response. This option controls whether Camel should catch any failure during writing response and store this on the Exchange, which allows onCompletion\/UnitOfWork to regard the Exchange as failed and have access to the caused exception from the HTTP server." },
"autowiredEnabled": { "index": 2, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." },
"engine": { "index": 3, "kind": "property", "displayName": "Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.platform.http.spi.PlatformHttpEngine", "deprecated": false, "autowired": false, "secret": false, "description": "An HTTP Server engine implementation to serve the requests" },
"headerFilterStrategy": { "index": 4, "kind": "property", "displayName": "Header Filter Strategy", "group": "filter", "label": "filter", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message." }
},
"properties": {
"path": { "index": 0, "kind": "path", "displayName": "Path", "group": "consumer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The path under which this endpoint serves the HTTP requests, for proxy use 'proxy'" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ public class PlatformHttpComponent extends HeaderFilterStrategyComponent

@Metadata(label = "advanced", description = "An HTTP Server engine implementation to serve the requests")
private volatile PlatformHttpEngine engine;
@Metadata(label = "advanced,consumer", defaultValue = "false",
description = "When Camel is complete processing the message, and the HTTP server is writing response. This option controls whether Camel"
+ " should catch any failure during writing response and store this on the Exchange, which allows onCompletion/UnitOfWork to"
+ " regard the Exchange as failed and have access to the caused exception from the HTTP server.")
private boolean handleWriteResponseError;

private final Set<HttpEndpointModel> httpEndpoints = new TreeSet<>();

private final List<PlatformHttpListener> listeners = new ArrayList<>();

private volatile boolean localEngine;

private final Object lock = new Object();

public PlatformHttpComponent() {
Expand All @@ -77,6 +79,7 @@ public PlatformHttpComponent(CamelContext context) {
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
PlatformHttpEndpoint endpoint = new PlatformHttpEndpoint(uri, remaining, this);
endpoint.setPlatformHttpEngine(engine);
endpoint.setHandleWriteResponseError(handleWriteResponseError);
setEndpointHeaderFilterStrategy(endpoint);
setProperties(endpoint, parameters);
return endpoint;
Expand Down Expand Up @@ -194,6 +197,14 @@ public void setEngine(PlatformHttpEngine engine) {
this.engine = engine;
}

public boolean isHandleWriteResponseError() {
return handleWriteResponseError;
}

public void setHandleWriteResponseError(boolean handleWriteResponseError) {
this.handleWriteResponseError = handleWriteResponseError;
}

private Consumer doCreateConsumer(
CamelContext camelContext, Processor processor, String verb, String basePath,
String uriTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ default PlatformHttpComponentBuilder bridgeErrorHandler(boolean bridgeErrorHandl
}


/**
* When Camel is complete processing the message, and the HTTP server is
* writing response. This option controls whether Camel should catch any
* failure during writing response and store this on the Exchange, which
* allows onCompletion/UnitOfWork to regard the Exchange as failed and
* have access to the caused exception from the HTTP server.
*
* The option is a: &lt;code&gt;boolean&lt;/code&gt; type.
*
* Default: false
* Group: consumer
*
* @param handleWriteResponseError the value to set
* @return the dsl builder
*/
default PlatformHttpComponentBuilder handleWriteResponseError(boolean handleWriteResponseError) {
doSetProperty("handleWriteResponseError", handleWriteResponseError);
return this;
}


/**
* Whether autowiring is enabled. This is used for automatic autowiring
* options (the option must be marked as autowired) by looking up in the
Expand Down Expand Up @@ -151,6 +172,7 @@ protected boolean setPropertyOnComponent(
Object value) {
switch (name) {
case "bridgeErrorHandler": ((PlatformHttpComponent) component).setBridgeErrorHandler((boolean) value); return true;
case "handleWriteResponseError": ((PlatformHttpComponent) component).setHandleWriteResponseError((boolean) value); return true;
case "autowiredEnabled": ((PlatformHttpComponent) component).setAutowiredEnabled((boolean) value); return true;
case "engine": ((PlatformHttpComponent) component).setEngine((org.apache.camel.component.platform.http.spi.PlatformHttpEngine) value); return true;
case "headerFilterStrategy": ((PlatformHttpComponent) component).setHeaderFilterStrategy((org.apache.camel.spi.HeaderFilterStrategy) value); return true;
Expand Down

0 comments on commit 07c5ad3

Please sign in to comment.