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 (#15802)

* CAMEL-21300: camel-platform-http - Consumer should have option to control if writing response failing should cause Exchange to fail
  • Loading branch information
davsclaus authored Oct 2, 2024
1 parent d079c85 commit 6bbb9db
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 42 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class VertxPlatformHttpConsumer extends DefaultConsumer
private final List<Handler<RoutingContext>> handlers;
private final String fileNameExtWhitelist;
private final boolean muteExceptions;
private final boolean handleWriteResponseError;
private Set<Method> methods;
private String path;
private Route route;
Expand All @@ -92,6 +93,7 @@ public VertxPlatformHttpConsumer(PlatformHttpEndpoint endpoint,
this.fileNameExtWhitelist
= endpoint.getFileNameExtWhitelist() == null ? null : endpoint.getFileNameExtWhitelist().toLowerCase(Locale.US);
this.muteExceptions = endpoint.isMuteException();
this.handleWriteResponseError = endpoint.isHandleWriteResponseError();
}

@Override
Expand Down Expand Up @@ -238,6 +240,14 @@ private void handleFailure(Exchange exchange, RoutingContext ctx, Throwable fail
"Failed handling platform-http endpoint " + getEndpoint().getPath(),
failure);
ctx.fail(failure);
if (handleWriteResponseError && failure != null) {
Exception existing = exchange.getException();
if (existing != null) {
failure.addSuppressed(existing);
}
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, failure);
exchange.setException(failure);
}
handleExchangeComplete(exchange);
}

Expand Down Expand Up @@ -351,7 +361,7 @@ protected void populateAttachments(List<FileUpload> uploads, Message message) {

class VertxCookieHandler implements CookieHandler {

private RoutingContext routingContext;
private final RoutingContext routingContext;

VertxCookieHandler(RoutingContext routingContext) {
this.routingContext = routingContext;
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 @@ -44,6 +44,8 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "exchangePattern": target.setExchangePattern(property(camelContext, org.apache.camel.ExchangePattern.class, value)); return true;
case "filenameextwhitelist":
case "fileNameExtWhitelist": target.setFileNameExtWhitelist(property(camelContext, java.lang.String.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;
case "httpmethodrestrict":
Expand Down Expand Up @@ -89,6 +91,8 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "exchangePattern": return org.apache.camel.ExchangePattern.class;
case "filenameextwhitelist":
case "fileNameExtWhitelist": return java.lang.String.class;
case "handlewriteresponseerror":
case "handleWriteResponseError": return boolean.class;
case "headerfilterstrategy":
case "headerFilterStrategy": return org.apache.camel.spi.HeaderFilterStrategy.class;
case "httpmethodrestrict":
Expand Down Expand Up @@ -135,6 +139,8 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "exchangePattern": return target.getExchangePattern();
case "filenameextwhitelist":
case "fileNameExtWhitelist": return target.getFileNameExtWhitelist();
case "handlewriteresponseerror":
case "handleWriteResponseError": return target.isHandleWriteResponseError();
case "headerfilterstrategy":
case "headerFilterStrategy": return target.getHeaderFilterStrategy();
case "httpmethodrestrict":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PlatformHttpEndpointUriFactory extends org.apache.camel.support.com
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
Set<String> props = new HashSet<>(21);
Set<String> props = new HashSet<>(22);
props.add("bridgeErrorHandler");
props.add("consumes");
props.add("cookieDomain");
Expand All @@ -35,6 +35,7 @@ public class PlatformHttpEndpointUriFactory extends org.apache.camel.support.com
props.add("exceptionHandler");
props.add("exchangePattern");
props.add("fileNameExtWhitelist");
props.add("handleWriteResponseError");
props.add("headerFilterStrategy");
props.add("httpMethodRestrict");
props.add("matchOnUriPrefix");
Expand Down
Loading

0 comments on commit 6bbb9db

Please sign in to comment.