You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "richie.riviere@gmail.com" <ri...@gmail.com> on 2013/10/11 13:22:08 UTC

Help to re-write route

Hi guys,

I was wondering if someone could give me some help out how to re-write this
camel test into a proper camel program. The issue is I know how to write a
simple route and then execute it. But after the route is executed and I want
to grab the parsed xml in a fashion similar to testStaxExpression how would
I do this in a real Camel application. I know the configure method in the
route is not the right place to do it.

Where is the right place. Sorry for the easy questions. I am a beginner.



package org.apache.camel.component.stax;

import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.stax.model.Record;
import org.apache.camel.component.stax.model.RecordsUtil;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.apache.camel.component.stax.StAXBuilder.stax;

public class StAXJAXBIteratorExpressionTest extends CamelTestSupport {
    @EndpointInject(uri = "mock:records")
    private MockEndpoint recordsEndpoint;

    @BeforeClass
    public static void initRouteExample() {
        RecordsUtil.createXMLFile();
    }

    @Override
    public RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
            	log.info("Doing route");
                // START SNIPPET: e1
                from("file:target/in")
                    // split the file using StAX (the stax method is from
StAXBuilder)
                    // and use streaming mode in the splitter
                    .split(stax(Record.class)).streaming()
                        .to("mock:records");
                // END SNIPPET: e1
            }
        };
    }

    @Test
    public void testStaxExpression() throws InterruptedException {
        recordsEndpoint.expectedMessageCount(10);
        recordsEndpoint.allMessages().body().isInstanceOf(Record.class);

        recordsEndpoint.assertIsSatisfied();

        Record five =
recordsEndpoint.getReceivedExchanges().get(4).getIn().getBody(Record.class);
        assertEquals("4", five.getKey());
        assertEquals("#4", five.getValue());
    }
}




--
View this message in context: http://camel.465427.n5.nabble.com/Help-to-re-write-route-tp5741339.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help to re-write route

Posted by "richie.riviere@gmail.com" <ri...@gmail.com>.
No quite. I know that If I want to create a separate class for the route i
can do this...

public class MyRouteBuilder extends RouteBuilder {	
	@Override
	public void configure() throws Exception {
		from("file:src/data?noop=true")		
        .split(stax(Record.class)).streaming()
		.to("mock:records");
	}    
}

And then I can call it from a Main...

public class MainApp {
    public static void main(String... args) throws Exception {
        Main main = new Main();
        main.enableHangupSupport();
        main.addRouteBuilder(new MyRouteBuilder());
        main.run(args);
    }
}

But what I am confused about is where would I place the bit where the
endpoint is injected in etc...
	@EndpointInject(uri = "mock:records")
	public static MockEndpoint recordsEndpoint;

and then...

        recordsEndpoint.expectedMessageCount(10);
        recordsEndpoint.allMessages().body().isInstanceOf(Record.class);
        recordsEndpoint.assertIsSatisfied();
        Record five =
recordsEndpoint.getReceivedExchanges().get(4).getIn().getBody(Record.class);

I'm asking because everywhere I put that code I can't get it to work. Yet in
the unit test it works perfectly!

appreciate your advice.






--
View this message in context: http://camel.465427.n5.nabble.com/Help-to-re-write-route-tp5741339p5741381.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help to re-write route

Posted by Andreas Gies <an...@wayofquality.de>.
Aehm....Are you asking how to get your route into its own class
so that you could use it in a container ?

Andreas

On 10/11/2013 01:22 PM, richie.riviere@gmail.com wrote:
> Hi guys,
>
> I was wondering if someone could give me some help out how to re-write this
> camel test into a proper camel program. The issue is I know how to write a
> simple route and then execute it. But after the route is executed and I want
> to grab the parsed xml in a fashion similar to testStaxExpression how would
> I do this in a real Camel application. I know the configure method in the
> route is not the right place to do it.
>
> Where is the right place. Sorry for the easy questions. I am a beginner.
>
>
>
> package org.apache.camel.component.stax;
>
> import org.apache.camel.EndpointInject;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.component.stax.model.Record;
> import org.apache.camel.component.stax.model.RecordsUtil;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.BeforeClass;
> import org.junit.Test;
>
> import static org.apache.camel.component.stax.StAXBuilder.stax;
>
> public class StAXJAXBIteratorExpressionTest extends CamelTestSupport {
>      @EndpointInject(uri = "mock:records")
>      private MockEndpoint recordsEndpoint;
>
>      @BeforeClass
>      public static void initRouteExample() {
>          RecordsUtil.createXMLFile();
>      }
>
>      @Override
>      public RouteBuilder createRouteBuilder() {
>          return new RouteBuilder() {
>              @Override
>              public void configure() throws Exception {
>              	log.info("Doing route");
>                  // START SNIPPET: e1
>                  from("file:target/in")
>                      // split the file using StAX (the stax method is from
> StAXBuilder)
>                      // and use streaming mode in the splitter
>                      .split(stax(Record.class)).streaming()
>                          .to("mock:records");
>                  // END SNIPPET: e1
>              }
>          };
>      }
>
>      @Test
>      public void testStaxExpression() throws InterruptedException {
>          recordsEndpoint.expectedMessageCount(10);
>          recordsEndpoint.allMessages().body().isInstanceOf(Record.class);
>
>          recordsEndpoint.assertIsSatisfied();
>
>          Record five =
> recordsEndpoint.getReceivedExchanges().get(4).getIn().getBody(Record.class);
>          assertEquals("4", five.getKey());
>          assertEquals("#4", five.getValue());
>      }
> }
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Help-to-re-write-route-tp5741339.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

-- 


    Andreas Gies

WoQ -- Way of Quality UG

Geschäftsführer & CTO

/eMail:/andreas@wayofquality.de <ma...@wayofquality.de>

/Tel:/ +49 151 23470823

/Fax:/ +49 1805 006534 2114

/Twitter:/ andreasgies /Skype:/ giessonic

/LinkedIn:/ <http://de.linkedin.com/pub/andreas-gies/0/594/aa5/> 
(http://de.linkedin.com/pub/andreas-gies/0/594/aa5/)

/Xing:/ <http://www.xing.com/profile/Andreas_Gies> 
(http://www.xing.com/profile/Andreas_Gies)

/Blog:/ <http://www.wayofquality.de/index.php/en/blog> 
(http://www.wayofquality.de/index.php/en/blog)

/Github:/ <https://github.com/atooni> (https://github.com/atooni)

/Amtsgericht Landshut:/HRB 8352//

//

/Ust.-Id.:/ DE274771254


      Haftungsausschluss

Diese Email kann vertrauliche und/oder rechtlich geschützte 
Informationen enthalten und ist ausschließlich für den/die benannten 
Adressaten bestimmt. Sollten Sie nicht der beabsichtigte Empfänger sein 
oder diese Email irrtümlich erhalten haben, ist es Ihnen nicht gestattet 
diese Mail oder einen Teil davon ohne unsere Erlaubnis zu verbreiten, zu 
kopieren, unbefugt weiterzuleiten oder zu behalten. Informieren Sie 
bitte sofort den Absender telefonisch oder per Email und löschen Sie 
diese Email und alle Kopien aus Ihrem System. Wir haften nicht für die 
Unversehrtheit von Emails, nachdem sie unseren Einflussbereich verlassen 
haben.


      Disclaimer

This email may contain confidential and/or privileged information and is 
intended solely for the attention and use of the named addressee(s). If 
you are not the intended recipient, or a person responsible for 
delivering it to the intended recipient, you are not authorized to and 
must not disclose, copy, distribute, or retain this message or any part 
of it without our authority. Please contact the sender by call or reply 
email immediately and destroy all copies and the original message. We 
are not responsible for the integrity of emails after they have left our 
sphere of control.

//

Re: Help to re-write route

Posted by "richie.riviere@gmail.com" <ri...@gmail.com>.
scrap this question. I'm following the camel-example-etl code from the camel
examples instead.

thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Help-to-re-write-route-tp5741339p5741389.html
Sent from the Camel - Users mailing list archive at Nabble.com.