Repository: camel Updated Branches: refs/heads/master 5e0c8dea8 -> 08d60c0c1
CAMEL-11748 - Camel-Undertow: transferException option doesn't work Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/08d60c0c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/08d60c0c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/08d60c0c Branch: refs/heads/master Commit: 08d60c0c142766a198e95cf12b46d926e36a6d12 Parents: 5e0c8de Author: Andrea Cosentino <anco...@gmail.com> Authored: Tue Sep 5 15:46:47 2017 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Tue Sep 5 15:53:38 2017 +0200 ---------------------------------------------------------------------- .../undertow/DefaultUndertowHttpBinding.java | 3 +- .../undertow/UndertowTransferExceptionTest.java | 55 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/08d60c0c/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java index 7fb22ce..7d64433 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java @@ -311,7 +311,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { // we failed due an exception, and transfer it as java serialized object ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(exception.getCause()); + oos.writeObject(exception); oos.flush(); IOHelper.close(oos, bos); @@ -342,7 +342,6 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding { httpExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, contentType); LOG.trace("Content-Type: {}", contentType); } - return body; } http://git-wip-us.apache.org/repos/asf/camel/blob/08d60c0c/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java new file mode 100644 index 0000000..6e693c6 --- /dev/null +++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.component.undertow; + +import java.io.IOException; +import java.io.ObjectInputStream; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.Assert; +import org.junit.Test; + +public class UndertowTransferExceptionTest extends BaseUndertowTest { + + @Test + public void getSerializedExceptionTest() throws IOException, ClassNotFoundException { + HttpClient client = new HttpClient(); + GetMethod get = new GetMethod("http://localhost:" + getPort() + "/test/transfer"); + get.setRequestHeader("Accept", "application/x-java-serialized-object"); + client.executeMethod(get); + ObjectInputStream in = new ObjectInputStream(get.getResponseBodyAsStream()); + IllegalArgumentException e = (IllegalArgumentException)in.readObject(); + Assert.assertNotNull(e); + Assert.assertEquals(500, get.getStatusCode()); + Assert.assertEquals("Camel cannot do this", e.getMessage()); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + + public void configure() { + + from("undertow:http://localhost:" + getPort() + "/test/transfer?transferException=true").to("mock:input") + .throwException(new IllegalArgumentException("Camel cannot do this")); + } + }; + } + +}