Running on JBoss EAP
Christina Lin
<profiles>
<profile>
<id>jboss-repos</id>
<repositories>
<repository>
<id>jboss-ga-repository</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jboss-earlyaccess-repository</id>
<url>http://maven.repository.redhat.com/earlyaccess/all/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-earlyaccess-plugin-repository</id>
<url>http://maven.repository.redhat.com/earlyaccess/all/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>jboss-ga-plugin-repository</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>fuse-repos</id>
<repositories>
<repository>
<id>fusesource-release-repository</id>
<url>https://repo.fusesource.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>fusesource-earlyaccess-repository</id>
<url>https://repo.fusesource.com/nexus/content/groups/ea</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>fusesource-release-plugin-repository</id>
<url>https://repo.fusesource.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>fusesource-earlyaccess-plugin-repository</id>
<url>https://repo.fusesource.com/nexus/content/groups/ea</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jboss-repos</activeProfile>
<activeProfile>fuse-repos</activeProfile>
</activeProfiles>
Run jboss-eap-6.4.0-installer.jar to start install JBoss EAP
Run fuse-eap-installer-6.2.1.redhat-xxx.jar to start setup Fuse libraries and configuration in EAP
java -jar fuse-eap-installer-6.2.1.redhat-xxx.jar your_eap_installpath
And your EAP is now ready!
Start the EAP by running to eap_installpath/bin/standalone.sh
Select H2 as JDBC driver for this datasource
Enter
Connection URL: jdbc:h2:file:~/h2/fuseoneap;AUTO_SERVER=TRUE
Username: sa
Password:
Change the min and max pool size to 1 and 10. And then enable the MyCamelDS datasource.
In JBoss Developer Studio, create an new maven project
Select wildfly-camel-archetype-cdi
Uncheck "Show the last version on Archetype only" checkbox and select version 2.3.0-redhat-621084
Group Id: com.redhat
Artifact Id: currencylab
Delete two java files under com.redhat.currencylab
MyServlet.java
MyBean.java
Create a Producer class that lookup the JNDI resource and register it in CDI context
DatasourceProducer
public class DatasourceProducer { @Resource(lookup= "java:jboss/datasources/MyCamelDS") DataSource dataSource; @Produces @Named("MyCamelDS") public DataSource getDataSource() { return dataSource; } }
Go to MyRouteBuilder.java under com.redhat.currencylab
from("direct:getCurrencies").routeId("allcurrencies") .to("sql:select * from currencyexchange?dataSource=MyCamelDS") .marshal() .json(JsonLibrary.Jackson);
Create Java Bean class that does the actual calculation of currency.
CurrencyConvertor
Enter the following content to bean
@Named("currencyconvertor")
public class CurrencyConvertor {
public double convertUSD(double amt, ArrayList<Map<String, Object>> data){
Double rate = (Double)data.get(0).get("rate");
return amt*rate;
}
}
Go to MyRouteBuilder.java under com.redhat.currencylab
from("direct:getCurrency").routeId("covertcurrency")
.log("Got currency: ${headers.amt} and amt${headers.currency} ")
.choice()
.when()
.header("currency")
.to("sql:select * from currencyexchange where currencycode = :#currency?dataSource=MyCamelDS")
.log("exchange rate ====> ${body[0][rate]}")
.to("bean:currencyconvertor?method=convertUSD(${headers.amt},${body})")
.otherwise()
.log("nothing to lookup")
.transform().constant("nothing to lookup");
Generate web.xml by right click on Deployment Descriptor -> Generate Deployment Descriptor Stub
Add following servlet setting in the web.xml file.
<servlet> <servlet-name>camel</servlet-name> <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>camel</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>
Go to MyRouteBuilder.java under com.redhat.currencylab
from("servlet:///currencies?servletName=camel&matchOnUriPrefix=true") .routeId("servletCurrencies") .to("direct:getCurrencies"); from("servlet:///currency?servletName=camel&matchOnUriPrefix=true") .routeId("servletCurrency") .to("direct:getCurrency");
In MyRouteBuilder.java under com.redhat.currencylab
restConfiguration().component("servlet") .contextPath("/camel").port(8080).bindingMode(RestBindingMode.json); rest("/currenciesrest") .get() .produces(MediaType.APPLICATION_JSON) .to("direct:getCurrencies");
<dependency> <groupId>org.jboss.spec.javax.ws.rs</groupId> <artifactId>jboss-jaxrs-api_1.1_spec</artifactId> <scope>provided</scope> </dependency>
pom.xml
Add index.html under webapp folder
Download the web file
Build Fuse Application by right click on application, Run As, Maven Build
Logon to EAP admin console. http://localhost:9990 under runtime, click on "add" button, to add the war file to deploy
Enable the application by clicking on En/Disable button