-->

Thursday, August 18, 2011

Deploying a Camel OSGi Bundle to ServiceMix

start servicemix

features:install webconsole

change to working directory


mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-camel-osgi-bundle -DgroupId=com.blogspot.aliasmrchips -DartifactId=example -Dversion=0.0.1-SNAPSHOT


Run mvn install to build the bundle.

Deploy to servicemix using "install/update..." functionality in web console.

If the bundle is deployed correctly, you will see log output in the servicemix command console.

Use the webconsole to stop the bundle.

Now, to make this a little more interesting, let's add a jetty endpoint to our camel route.

Add camel-jetty dependency to example/pom.xml



org.apache.camel
camel-jetty
${camel.version}



Edit src/main/resources/META_INF/spring/camel-context.xml and change the from endpoint to use jetty...









Build and redeploy the bundle to servicemix. At this point, you should get an error:


Failed to resolve endpoint: jetty://http://localhost/example due to: No component found with scheme: jetty



Saturday, August 06, 2011

Eclipse Software Update Proxy Settings

Set up the proxy settings in the preferences and then tell eclipse to actually use the proxy settings by adding the following to your eclipse.ini

-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient

Adding SyntaxHighlighter to your Blog

First add the CSS to your template using the Template Designer. Copy and paste this CSS snippet to "Advanced -> Add CSS"


<style>
.syntaxhighlighter .toolbar
{
top: -33px !important;
}
code {
background-color: #FFFFCC;
font-family: Consolas,Monaco,"Bitstream Vera Sans Mono","Courier New",Courier,monospace;
}
</style>


Next, you will need to add some additional CSS and scripts by editing the template html. I put mine in the head just after the title.


<link href='http://alexgorbatchev.com/pub/sh/2.0.296/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/2.0.296/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shCore.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushJava.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushCpp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushXml.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushSql.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushJScript.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushGroovy.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushBash.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/2.0.296/scripts/shBrushCSharp.js' type='text/javascript'></script>
<script type='text/javascript'>
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.0.296/scripts/clipboard.swf';
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.defaults['auto-links'] = false;
SyntaxHighlighter.all();
</script>


Then use the "pre" block with appropriate "brush" class to create your code block. For example:


<pre class="brush:xml">
<style>
.syntaxhighlighter .toolbar
{
top: -33px !important;
}
code {
background-color: #FFFFCC;
font-family: Consolas,Monaco,"Bitstream Vera Sans Mono","Courier New",Courier,monospace;
}
</style>
</pre>

Friday, August 05, 2011

Bulk Inserts with Postgres JDBC COPY

The COPY command is a much faster way to do bulk inserts into a postgres database. The postgres JDBC driver supports this as well.

Here is a simple example of a command line tool to COPY the contents of a text file to a table. Each line becomes a row in the database.


import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;

import org.postgresql.copy.CopyManager;
import org.postgresql.core.BaseConnection;

public class PgSqlJdbcCopyStreamsExample {

public static void main(String[] args) throws Exception {

if(args.length!=4) {
System.out.println("usage: [url] [user] [password] [file]");
} else {

System.err.println("Loading driver");
Class.forName("org.postgresql.Driver");

System.err.println("Connecting to " + args[0]);
Connection con = DriverManager.getConnection(args[0],args[1],args[2]);

System.err.println("Copying text data rows from stdin");

CopyManager copyManager = new CopyManager((BaseConnection) con);

FileReader fileReader = new FileReader(args[3]);
copyManager.copyIn("COPY t FROM STDIN", fileReader );

System.err.println("Done.");
}
}
}