/**
 * 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.netty4.http;

import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.junit.Test;

public class NettyHttp500ErrorTest extends BaseNettyTest {

    @Test
    public void testHttp500Error() throws Exception {
        getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");

        try {
            template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
            fail("Should have failed");
        } catch (CamelExecutionException e) {
            NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
            assertEquals(500, cause.getStatusCode());
            assertEquals("Camel cannot do this", context.getTypeConverter().convertTo(String.class, cause.getHttpContent().content()));
        }

        assertMockEndpointsSatisfied();
    }

    @Test
    public void testHttp500ErrorDisabled() throws Exception {
        getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");

        String body = template.requestBody("netty4-http:http://localhost:{{port}}/foo?throwExceptionOnFailure=false", "Hello World", String.class);
        assertEquals("Camel cannot do this", body);

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("netty4-http:http://0.0.0.0:{{port}}/foo")
                    .to("mock:input")
                    // trigger failure by setting error code to 500
                    .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
                    .setBody().constant("Camel cannot do this");
            }
        };
    }

}

@@ -929,16 +929,51 @@
 change;%0A
+import org.apache.camel.Processor;%0A
 import o
@@ -2215,24 +2215,749 @@
 d();%0A    %7D%0A%0A
+    @Test%0A    public void testHttp500ErrorDisabledStatusCode() throws Exception %7B%0A        getMockEndpoint(%22mock:input%22).expectedBodiesReceived(%22Hello World%22);%0A%0A        Exchange out = template.request(%22netty4-http:http://localhost:%7B%7Bport%7D%7D/foo?throwExceptionOnFailure=false%22, new Processor() %7B%0A            @Override%0A            public void process(Exchange exchange) throws Exception %7B%0A                exchange.getIn().setBody(%22Hello World%22);%0A            %7D%0A        %7D);%0A        assertNotNull(out);%0A%0A        assertEquals(500, out.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));%0A        assertEquals(%22Internal Server Error%22, out.getOut().getHeader(Exchange.HTTP_RESPONSE_TEXT));%0A%0A        assertMockEndpointsSatisfied();%0A    %7D%0A%0A
     @Overrid

Add test based on user forum trouble