/*
 * Copyright 2008 the original author or authors.
 * 
 * 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 org.openehealth.ipf.platform.camel.lbs.mina.builder;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.spring.SpringRouteBuilder;

/**
 * @author Jens Riemschneider
 */
public class LbsMinaRouteBuilder extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {
        errorHandler(defaultErrorHandler().maximumRedeliveries(2).redeliveryDelay(0));
        
        from("mina:tcp://localhost:6123?textline=true&sync=true")
            .to("mock:mock");

        from("mina:tcp://localhost:6124?textline=true&sync=true")
            .unmarshal().hl7()
            .to("mock:mock");
        
        from("mina:tcp://localhost:6125?sync=true&codec=#mllpStoreCodec")
            .process(new MyProcessor(1))
            .to("mock:mock");

        from("mina:tcp://localhost:6126?sync=true&codec=#mllpStoreCodec")
            .process(new MyProcessor(2))
            .unmarshal().hl7()
            .process(new MyProcessor(3))
            .to("mock:mock");
        
        from("mina:tcp://localhost:6127?sync=true&codec=#mllpStoreCodec")
            .process(new MyProcessor(4))
            .unmarshal().hl7()
            .process(new MyProcessor(5))
            .marshal().hl7()
            .process(new MyProcessor(6))
            .to("mina:tcp://localhost:6126?sync=true&codec=#mllpStoreCodec");

        from("mina:tcp://localhost:6128?sync=true&codec=#mllpStoreCodec")
            .process(new MyProcessor(7))
            .to("mina:tcp://localhost:6126?sync=true&codec=#mllpStoreCodec");
    }


    private static class MyProcessor implements Processor {
        final int x;

        private MyProcessor(int x) {
            this.x = x;
        }

        @Override
        public void process(Exchange exchange) throws Exception {
             System.out.println(x);
        }
    }
}

@@ -697,79 +697,8 @@
 %0D%0A%0D%0A
-import org.apache.camel.Exchange;%0D%0Aimport org.apache.camel.Processor;%0D%0A
 impo
@@ -1341,54 +1341,9 @@
     
-    .process(new MyProcessor(1))%0D%0A            
+%09
 .to(
@@ -1451,412 +1451,202 @@
    .
-process(new MyProcessor(2))%0D%0A            .unmarshal().hl7()%0D%0A            .process(new MyProcessor(3))%0D%0A            .to(%22mock:mock%22);%0D%0A        %0D%0A        from(%22mina:tcp://localhost:6127?sync=true&codec=#mllpStoreCodec%22)%0D%0A            .process(new MyProcessor(4))%0D%0A            .unmarshal().hl7()%0D%0A            .process(new MyProcessor(5))%0D%0A            .marshal().hl7()%0D%0A            .process(new MyProcessor(6)
+unmarshal().hl7()%0D%0A            .to(%22mock:mock%22);%0D%0A        %0D%0A        from(%22mina:tcp://localhost:6127?sync=true&codec=#mllpStoreCodec%22)%0D%0A            .unmarshal().hl7()%0D%0A            .marshal().hl7(
 )%0D%0A 
@@ -1804,50 +1804,8 @@
 %22)%0D%0A
-            .process(new MyProcessor(7))%0D%0A
     
@@ -1890,313 +1890,7 @@
  %7D%0D%0A
-%0D%0A%0D%0A    private static class MyProcessor implements Processor %7B%0D%0A        final int x;%0D%0A%0D%0A        private MyProcessor(int x) %7B%0D%0A            this.x = x;%0D%0A        %7D%0D%0A%0D%0A        @Override%0D%0A        public void process(Exchange exchange) throws Exception %7B%0D%0A             System.out.println(x);%0D%0A        %7D%0D%0A    %7D%0D%0A
 %7D%0D%0A

Rollback wrongly committed file