/*
 * Copyright 2015 yihtserns.
 *
 * Licensed 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 com.github.yihtserns.test.camel.spring.remoting;

import com.github.yihtserns.test.camel.spring.remoting.testutil.Service;
import com.github.yihtserns.test.camel.spring.remoting.testutil.Request;
import com.github.yihtserns.test.camel.spring.remoting.testutil.Response;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.Test;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
import org.springframework.remoting.support.RemoteInvocationResult;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.After;
import org.springframework.remoting.support.RemoteInvocation;

/**
 * @author yihtserns
 */
public class CamelSpringRemotingTest {

    private DefaultCamelContext camelContext = new DefaultCamelContext();

    @After
    public void stopCamelContext() throws Exception {
        if (camelContext.isStarted()) {
            camelContext.stop();
        }
    }

    @Test
    public void canServeSpringRemotingCallerUsingCamelJetty() throws Exception {
        final String url = "http://localhost:8088/trigger";

        camelContext.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("jetty:" + url)
                        .process(new Processor() {

                            @Override
                            public void process(Exchange exchange) throws Exception {
                                RemoteInvocation remoteInvocation = exchange.getIn().getBody(RemoteInvocation.class);
                                Request req = (Request) remoteInvocation.getArguments()[0];
                                String reply = req.message + " Bye!";

                                exchange.getIn().setBody(new RemoteInvocationResult(new Response(reply)));
                            }
                        });
            }
        });
        camelContext.start();

        HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
        factoryBean.setServiceInterface(Service.class);
        factoryBean.setServiceUrl(url);
        factoryBean.afterPropertiesSet();
        Service service = (Service) factoryBean.getObject();

        Response response = service.service(new Request("Hi!"));
        assertThat(response, is(notNullValue()));
        assertThat(response.message, is("Hi! Bye!"));
    }
}

@@ -1031,16 +1031,67 @@
 ontext;%0A
+import org.apache.camel.support.ExpressionAdapter;%0A
 import o
@@ -2076,28 +2076,38 @@
    .
-process(new Processo
+transform(new ExpressionAdapte
 r() 
@@ -2186,20 +2186,23 @@
 lic 
-void process
+Object evaluate
 (Exc
@@ -2216,33 +2216,16 @@
 xchange)
- throws Exception
  %7B%0A     
@@ -2329,32 +2329,33 @@
 ocation.class);%0A
+%0A
                 
@@ -2374,31 +2374,14 @@
     
-Request req = (Request)
+return
  rem
@@ -2445,30 +2445,360 @@
     
-    String reply = req
+%7D%0A                        %7D)%0A                        .transform(new ExpressionAdapter() %7B%0A%0A                            @Override%0A                            public Object evaluate(Exchange exchange) %7B%0A                                Request request = exchange.getIn().getBody(Request.class);%0A%0A                                return new Response(request
 .mes
@@ -2811,18 +2811,48 @@
  %22 Bye!%22
+)
 ;%0A
+                            %7D
 %0A       
@@ -2853,32 +2853,42 @@
                 
+       %7D)%0A
                e
@@ -2890,33 +2890,204 @@
     
-exchange.getIn().setBody(
+         .transform(new ExpressionAdapter() %7B%0A%0A                            @Override%0A                            public Object evaluate(Exchange exchange) %7B%0A                                return 
 new 
@@ -3113,27 +3113,33 @@
 ult(
-new Response(reply)
+exchange.getIn().getBody(
 ));%0A

Split operations into three different transformers.