You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lassesvestergaard <la...@gmail.com> on 2013/08/21 13:18:03 UTC
Exception when trying to create a route including jdbc:sqlserver
Hi all.
I'm having a problem when trying to create a route where I get data from a
microsoft sql server. My problem seems to be that the route want an other
bean than I provide ( Found bean
com.microsoft.sqlserver.jdbc.SQLServerConnection expected type was:
interface javax.sql.DataSource). The stacktrace is:
Exception in thread "main" org.apache.camel.FailedToCreateRouteException:
Failed to create route route1 at: >>> To[jdbc:affaldVarme] <<< in route:
Route(route1)[[From[timer://foo?period=10000]] -> [SetBody[{... because of
Failed to resolve endpoint: jdbc://affaldVarme due to: Found bean:
affaldVarme in SimpleRegistry: {affaldVarme=ConnectionID:1
ClientConnectionId: 7a67cbe0-9cc8-4ae6-82c9-518d1c0471a3} of type:
com.microsoft.sqlserver.jdbc.SQLServerConnection expected type was:
interface javax.sql.DataSource
at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:883)
at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:176)
at
org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:750)
at
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1829)
at
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1609)
at
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1478)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1446)
at org.apache.camel.main.Main.doStart(Main.java:109)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:148)
at dk.alexandra.harvestertesting.App.boot(App.java:40)
at dk.alexandra.harvestertesting.App.main(App.java:18)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
resolve endpoint: jdbc://affaldVarme due to: Found bean: affaldVarme in
SimpleRegistry: {affaldVarme=ConnectionID:1 ClientConnectionId:
7a67cbe0-9cc8-4ae6-82c9-518d1c0471a3} of type:
com.microsoft.sqlserver.jdbc.SQLServerConnection expected type was:
interface javax.sql.DataSource
at
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:508)
at
org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:62)
at
org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:191)
at
org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:108)
at
org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:114)
at
org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:61)
at
org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:55)
at
org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:479)
at
org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:197)
at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:880)
... 12 more
Caused by: org.apache.camel.NoSuchBeanException: Found bean: affaldVarme in
SimpleRegistry: {affaldVarme=ConnectionID:1 ClientConnectionId:
7a67cbe0-9cc8-4ae6-82c9-518d1c0471a3} of type:
com.microsoft.sqlserver.jdbc.SQLServerConnection expected type was:
interface javax.sql.DataSource
at
org.apache.camel.impl.SimpleRegistry.lookupByNameAndType(SimpleRegistry.java:51)
at
org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookupByNameAndType(PropertyPlaceholderDelegateRegistry.java:63)
at
org.apache.camel.util.CamelContextHelper.lookup(CamelContextHelper.java:120)
at
org.apache.camel.util.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:140)
at
org.apache.camel.component.jdbc.JdbcComponent.createEndpoint(JdbcComponent.java:49)
at
org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:119)
at
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:488)
... 21 more
Caused by: java.lang.ClassCastException: Cannot cast
com.microsoft.sqlserver.jdbc.SQLServerConnection to javax.sql.DataSource
at java.lang.Class.cast(Class.java:3084)
at
org.apache.camel.impl.SimpleRegistry.lookupByNameAndType(SimpleRegistry.java:47)
My overall setup is that I have a main class that looks like this (I use the
stand alone instance of camel):
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
import java.sql.Connection;
import java.sql.DriverManager;
import org.apache.camel.main.Main;
public class App
{
private Main main;
public static void main(String[] args) throws Exception {
App example = new App();
example.boot();
}
public void boot() throws Exception {
// create a Main instance
main = new Main();
String connURL =
"jdbc:sqlserver://10.225.16.34;databaseName=Renomatic;username=some_username;password=some_password";
DriverManager.registerDriver(new SQLServerDriver());
Connection connection = DriverManager.getConnection(connURL);
main.bind("affaldVarme", connection);
// enable hangup support so you can press ctrl + c to terminate the
JVM
main.enableHangupSupport();
// add routes
main.addRouteBuilder(new AffaldVarme());
// run until you terminate the JVM
main.run();
}
}
My concrete routebuilder:
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
public class AffaldVarme extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer://foo?period=10000").setBody(constant("select * from
dbo.Container_Vejning_V")).to("jdbc:affaldVarme").process(
new Processor() {
public void process(Exchange exchange) throws
Exception {
System.out.println("noget");
String payload =
exchange.getIn().getBody(String.class);
System.out.println(payload);
}
});
}
}
Any suggestions on how to get past this?
An aditional question is; is it possible to put the sql connection in the
RouteBuilder class, and from there register it in the Camelcontext's
registry?
Best regards
Lasse Vestergaard
--
View this message in context: http://camel.465427.n5.nabble.com/Exception-when-trying-to-create-a-route-including-jdbc-sqlserver-tp5737657.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Exception when trying to create a route including
jdbc:sqlserver
Posted by lassesvestergaard <la...@gmail.com>.
Great! That worked, thanks.
--
View this message in context: http://camel.465427.n5.nabble.com/Exception-when-trying-to-create-a-route-including-jdbc-sqlserver-tp5737657p5737749.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Exception when trying to create a route including jdbc:sqlserver
Posted by Dale King <da...@gmail.com>.
You are providing a connection object, but it needs a DataSource object.
See here for an example of using DataSource with SQLServer and bind to the
data source instead of the connection:
http://technet.microsoft.com/en-us/library/aa342342.aspx