Hi Charles,

I think you can add the endpoint in your Camel bean like this
@EndpointInject(uri = "sql://xxx")
protected Endpoint sql;
and use template.sendBody(endpoint, body) to send the message.

or use call template.sendBody("sql:xxx", body) to send the request.

Willem

On 3/23/11 2:11 PM, Charles Moulliard wrote:
Hi Willem,

The producer has been defined like that :

1) Spring XML

<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="reportdb"/>
</bean>

<bean id="reportdb"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:hsql://localhost/reportdb"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>

2) Camel bean

private ProducerTemplate template;

public void insertRecord(@Body String ref) {

StringBuilder query = new StringBuilder();
query.append("INSERT INTO REPORT.T_INCIDENT (INCIDENT_REF,\n" +
"
INCIDENT_DATE,GIVEN_NAME,FAMILY_NAME,SUMMARY,DETAILS,EMAIL,PHONE)\n" +
" VALUES (");
query.append("'" + ref + "'");
query.append("'2011-03-21','Charles','Moulliard','Incident
Webinar','This is a\n" +
" report incident for
webinar-001','[email protected]
<mailto:[email protected]>','+111 10 20 300'");

template.sendBody("sql", query.toString());


}

Should I define an endpoint ?

Regards,

Charles


On 23/03/11 05:52, Willem Jiang wrote:
Hi Charles,

How did you setup the default endpoint of the producerTemplate?
It looks the query is used be resolved as an CamelEndpoint, that could
explain why this line of code is called.
at
org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:57)


Willem

On 3/23/11 1:05 AM, Charles Moulliard wrote:
I use a ProducerTemplate to create the SQL query send to sql endpoint.
When I launch camel, I get this error :

Caused by: java.net.URISyntaxException: Illegal character in opaque
part at index 54:
sql:INSERT%20INTO%20REPORT.T_INCIDENT%20(INCIDENT_REF,
%20%20%20%20%20%20%20INCIDENT_DATE,GIVEN_NAME,FAMILY_NAME,SUMMARY,DETAILS,EMAIL,PHONE)

%20%20%20%20%20%20%20VALUES%20('099','2011-03-21','Charles','Moulliard','Incident%20Webinar','This%20is%20a

%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20report%20incident%20for%20webinar-001','[email protected]','+111%2010%2020%20300'

at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.parse(URI.java:3019)
at java.net.URI.<init>(URI.java:578)
at
org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:57)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

Is there a way to avoid that ?

Here is the code :

public void insertRecord(@Body String ref) {

StringBuilder query = new StringBuilder();
query.append("sql:INSERT INTO REPORT.T_INCIDENT (INCIDENT_REF,\n" +
"
INCIDENT_DATE,GIVEN_NAME,FAMILY_NAME,SUMMARY,DETAILS,EMAIL,PHONE)\n" +
" VALUES (");
query.append("'" + ref + "'");
query.append("'2011-03-21','Charles','Moulliard','Incident
Webinar','This is a\n" +
" report incident for
webinar-001','[email protected]','+111 10 20 300'");

template.sendBody(query.toString());


}

Regards,


Charles Moulliard

Sr. Principal Solution Architect - FuseSource
Apache Committer

Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard






--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Reply via email to