<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Schabby&#039;s Blog</title>
	<atom:link href="http://schabby.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://schabby.de</link>
	<description>computer science and binary watches, there isnt probably much more that matters in the known part of the universe</description>
	<lastBuildDate>Thu, 04 Mar 2010 10:24:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Keine Sessions in Tomcat / JSP</title>
		<link>http://schabby.de/keine-sessions-in-tomcat-jsp/</link>
		<comments>http://schabby.de/keine-sessions-in-tomcat-jsp/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 19:27:41 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=827</guid>
		<description><![CDATA[Ab einem gewissen Trafficvolumumen beginnt die Sessionstabelle die der Tomcat auf der Platte hält stetig zu wachsen und täglich größere Ausmaße anzunehmen. Da der Tomcat einen großen Teil der serialisierten Sessiontabelle im Speicher hält, kann das zu einem akkuten Crashrisiko werden, wenn der Tomcat bis zum Limit wächst (oder das OS zu swappen beginnt). Ausserdem [...]]]></description>
			<content:encoded><![CDATA[<p>Ab einem gewissen Trafficvolumumen beginnt die Sessionstabelle die der Tomcat auf der Platte hält stetig zu wachsen und täglich größere Ausmaße anzunehmen. Da der Tomcat einen großen Teil der serialisierten Sessiontabelle im Speicher hält, kann das zu einem akkuten Crashrisiko werden, wenn der Tomcat bis zum Limit wächst (oder das OS zu swappen beginnt). <span id="more-827"></span>Ausserdem ist es ineffizient für jede css-, JavaScript oder Bilddatei einen Sessionstempel im Header mitzusenden. Das gilt inbesondere für Seiten die stark und regelmäßig von Bots gecrawled werden, da Bots naturgemäß keine Session halten und der Tomcat bei jedem Zugriff des Bots von einem neuen User ausgehen muss und eine neue Session anlegt.</p>
<p>Es stellt sich also folgende Frage:</p>
<ul>
<li>Session unterdrücken in Tomcat / JSP</li>
<li>Tomcat keine Sessions</li>
<li>JSP / Tomcat ohne Sessions</li>
</ul>
<p>Im Prinzip ist die Lösung sehr einfach. Man muss nur zwei einfache Regeln befolgen.</p>
<ol>
<li>Mache nur nur <tt>request.getSession()</tt> calls wenn Du wirklich eine neue oder die bestehende Session brauchst (Login, etc.). Überlege Dir auch, ob nicht <tt>request.getSession(false)</tt> reicht (= nur eine bereits bestehende Session zurückgeben, aber keine neue Anlegen falls noch keine existiert).</li>
<li>Setze in allen JSPs die Direktive <tt><%@ page session="false" %></tt> um das automatische Erzeugen einer Session im JSP-Code zu unterbinden. Wenn Du die Session doch in einer JSP brauchen solltest, erstelle sie vorher in einem Controller.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/keine-sessions-in-tomcat-jsp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BufferedReader &#8211; kurz Erklärt</title>
		<link>http://schabby.de/bufferedreader-kurz-erklart/</link>
		<comments>http://schabby.de/bufferedreader-kurz-erklart/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 23:53:37 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=825</guid>
		<description><![CDATA[Der BufferedReader bereitet so manchem Java-Experten noch Kopfschmerzen. In diesem Artikel wird kurz und knapp der BufferedReader mit einem Beispiel erläutert sowie seine Funktionsweise erklärt.]]></description>
			<content:encoded><![CDATA[<p>Moin, moin! Heute nun eine kurze Einweisung in die richtige Verwendung von BufferedReaders und den Grund warum der BufferedReader so populär ist. Im Grunde gibt es zwei Gründe:<span id="more-825"></span></p>
<ol>
<li>BufferedReader verbessert die Lesegeschwindigkeit aus anderen Readern (z.B. FileReader um von der Festplatte zu lesen) drastisch,</li>
<li>BufferedReader hat praktischer Weise eine readLine() Methode, mit deren Hilfe man ganze Zeilen lesen kann.</li>
</ol>
<p>In Prinzip ist der BufferedReader auch nur ein Reader. Das heisst er hat die typischen read(&#8230;) Methoden. Intern aber, arbeitet der BufferedReader auf einem Speicherbereich (dem Buffer), den er erst füllt, bevor seine read(&#8230;) Methoden darauf arbeiten können. Das heisst, dass der BufferedReader größere Datenblöcke auf einmal lesen kann und die dann nach und nach an den äußeren Reader weiterleiten kann. Das ist insbesondere sinnvoll bei Readern die von wiederum von Low-Level Readern lesen, die jeweils bei größeren Datenblöcken performant sind, wie typischer Weise von der Festplatte oder vom Socket.</p>
<p>Ein typischer Gebrauch eines BufferedReaders sieht so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">InputStreamReader</span> inputStreamReader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileInputStream</span> <span style="color: #009900;">&#40;</span>textFile<span style="color: #009900;">&#41;</span>, encoding <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">BufferedReader</span> bufferedReader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span> <span style="color: #009900;">&#40;</span>inputStreamReader<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://schabby.de/bufferedreader-kurz-erklart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java JDK Download</title>
		<link>http://schabby.de/java-jdk-download/</link>
		<comments>http://schabby.de/java-jdk-download/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 23:07:19 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=820</guid>
		<description><![CDATA[Kurze, klare Erklaerung welcher Java JDK der richtige zum herunterladen ist und was SE, EE und ME bedeutet. Der offizielle Download des Java JDKs gibt es naemlich nur an einer Stelle.]]></description>
			<content:encoded><![CDATA[<p>Seltsamer Weise scheinen viele meiner freundlichen Mitmenschen sich zu fragen, wo die richtige Quelle zum downloaden des Java JDKs bzw. des Java SDKs ist. Nun, da gibt es eine einfache Antwort: offiziell bei <span id="more-820"></span><a href="http://java.sun.com/">SUN</a> <img src='http://schabby.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ok, neuerdings Oracle, da Oracle SUN mitsamt MySQL gekauft hat, aber das steht auf einem anderen Blatt.</p>
<p>Uebrigens, JDK heisst Java Development Kit, und SDK Software Development Kit. Es nimmt sich aber defacto nichts.</p>
<p>Ist man nun bei SUN gelandet, gibt es drei Varianten zum downloaden.</p>
<ul>
<li>Java SE: steht fuer Standard Edition ist ziemlich sicher das was Du suchst wenn Du das klassische Javapaket fuer den Deskop runterladen willst (JRE und JDK)</li>
<li>Java ME: steht fuer Mobile Edition und beinhaltet eine auf fuer Handies zugeschnittene Java Plattform (mit Compiler) mit reduzierten Bibliotheken</li>
<li>Java EE: steht fuer Enterprise Edition und ist deutlich umfangreicher als die Standard Edition und enthaelt zusaetzliche, business nahe Tools wie den Glassfish Application Server</li>
</ul>
<p>Ich hoffe das hilft.</p>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/java-jdk-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven Tests Ignorieren</title>
		<link>http://schabby.de/maven-tests-ignorieren/</link>
		<comments>http://schabby.de/maven-tests-ignorieren/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 09:02:47 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=816</guid>
		<description><![CDATA[Es kommt auch in den besten Familien vor, dass mal ein unit test nicht läuft. Da muss sich nicht schämen, nur ein bisschen ärgern. Ähnliche Probleme sind

Maven tests ausschalten
mvn ignoriere test fehler


Wenn man trotzdem seinen maven snapshot bauen möchte, müssen aber die tests failures ignoriert werden. Das wird mittels einer Property direkt auf der Kommandezeile [...]]]></description>
			<content:encoded><![CDATA[<p>Es kommt auch in den besten Familien vor, dass mal ein unit test nicht läuft. Da muss sich nicht schämen, nur ein bisschen ärgern. Ähnliche Probleme sind</p>
<ul>
<li>Maven tests ausschalten</li>
<li>mvn ignoriere test fehler</li>
</ul>
<p><span id="more-816"></span><br />
Wenn man trotzdem seinen maven snapshot bauen möchte, müssen aber die tests failures ignoriert werden. Das wird mittels einer Property direkt auf der Kommandezeile bewerkstelligt. Da ich dieses Property andauernd vergesse, möchte ich es mir hier selbst und der Allgemeinheit nochmals vor Augen führen:</p>
<p><tt><br />
mvn -Dmaven.test.failure.ignore=true install<br />
</tt></p>
<p>Hope that helps&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/maven-tests-ignorieren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Neues Star Trek Online Forum gestartet</title>
		<link>http://schabby.de/star-trek-online-forum/</link>
		<comments>http://schabby.de/star-trek-online-forum/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 14:53:27 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Dies Und Das]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=811</guid>
		<description><![CDATA[Vor ein paar Tagen ist ein deutsches STO Forum gestartet. STO ist zwar selbst noch nicht in Deutschland live gegangen, aber man kann sich bereits ein pre-order sichern und damit die Beta version testen. Und das lohnt sich. Ein In-Game Bug Tracker hilft dabei, ständige Verbesserungen und Fehler an die Entwickler hautnah und mit Screenshot [...]]]></description>
			<content:encoded><![CDATA[<p>Vor ein paar Tagen ist ein deutsches <a href="http://www.forum-startrekonline.de/">STO Forum</a> gestartet. <a href="http://www.startrekonline.com/">STO</a> ist zwar selbst noch nicht in Deutschland live gegangen, aber man kann sich bereits ein pre-order sichern und damit die Beta version testen. Und das lohnt sich. <span id="more-811"></span>Ein In-Game Bug Tracker hilft dabei, ständige Verbesserungen und Fehler an die Entwickler hautnah und mit Screenshot zu schicken. Dabei ist eine ganz neue Variante des Testens möglich, die es so in herkömmlichen Spielen noch nicht gibt. Ich kann empfehlen mal reinzuschnuppern. Man muss sich ja nicht gleich eine Life Time Subscription kaufen. Erste Fragen und Anregungen kann man sich auf jeden Fall schonmal im <a href="http://www.forum-startrekonline.de/">Star Trek Online Forum</a> holen.</p>
<p>Insgesammt ist das Spiel sehr ähnlich wie WoW. Es gib Charakerklassen innerhalb einer Reihe von Spezies die sich wieder zu Verbänden zusammengeschlossen haben. Neu ist allerdings, dass man im Weltraum, wie auch auf Bodenmissionen tätig werden kann. Dabei wird man tatkräftig von drei Bodenoffizieren unterstützt die einem zur Seite stehen.</p>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/star-trek-online-forum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cassandra Installation and Configuration</title>
		<link>http://schabby.de/cassandra-installation-configuration/</link>
		<comments>http://schabby.de/cassandra-installation-configuration/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 16:44:42 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Cassandra]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=786</guid>
		<description><![CDATA[This is the second post on my little &#8220;Cassandra &#8211; Getting Started&#8221; series covering the installation and basic configuration of Cassandra. Cassandra is extremely easy to set up, especially compared to HBase. All you got to do is to download, extract, edit a single XML-file and run. But let us take it step by step.

You [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second post on my little &#8220;Cassandra &#8211; Getting Started&#8221; series covering the installation and basic configuration of Cassandra. Cassandra is extremely easy to set up, especially compared to <a href="http://hadoop.apache.org/hbase/">HBase</a>. All you got to do is to download, extract, edit a single XML-file and run. But let us take it step by step.<br />
<span id="more-786"></span><br />
You can <a href="http://incubator.apache.org/cassandra/">download Cassandra</a> directly from it&#8217;s (her?) website. At the time of the submission of this post, version 0.4.1 was the most recent stable. Note that you need <a href="http://java.sun.com/javase/downloads/index.jsp">Java 6</a> installed to run Cassandra which I assume here as properly installed. </p>
<p>After extracting Cassandra to some folder (on my Windows box I placed it directly in <tt>D:\cassandra</tt>), the only file you need to edit is <tt>conf/storage-conf.xml</tt>. While Cassandra is engineered to run on a large number of machines in a network, we start it here as a single node with the default parameter set, so that most of the settings are ok for now. </p>
<p>If your are <b>not</b> on a Unix-like system, you need to update the folders where Cassandra is supposed to store the data. If your using Windows (like me), then find the following lines in <tt>conf/storage-conf.xml</tt> and change the paths to something sensible</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CommitLogDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/var/lib/cassandra/commitlog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CommitLogDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataFileDirectories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/var/lib/cassandra/data<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataFileDirectories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CalloutLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/var/lib/cassandra/callouts<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CalloutLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;BootstrapFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/var/lib/cassandra/bootstrap<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/BootstrapFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StagingFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/var/lib/cassandra/staging<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StagingFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>like for example my settings:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CommitLogDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>D:/cassandra/data/commitlog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CommitLogDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataFileDirectories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>D:/cassandra/data/data<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DataFileDirectories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CalloutLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>D:/cassandra/data/callouts<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CalloutLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;BootstrapFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>D:/cassandra/data/bootstrap<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/BootstrapFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StagingFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>D:/cassandra/data/staging<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StagingFileDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Let&#8217;s take Cassandra for a spin and check if she starts up correctly. For Mac OS, Linux, etc. users, simply change to the <tt>bin</tt> directory of Cassandra and run <tt>./cassandra</tt>. As an aside for the impatient, I start Cassanda with <tt>sudo</tt> to avoid trouble with the Cassandras <tt>system.log</tt>.</p>
<p>Windows users, however, that use the command line (meaning not <a href="http://www.cygwin.com/">Cygwin</a>) cannot start it just like that. The <tt>cassandra.bat</tt> didnt work for me on my Vista box if executed with <tt>bin</tt> being the current working directory (probably due to the CASSANDRA_HOME environment variable that get&#8217;s incorrectly set in the batch file). BUT it works perfect if you call <tt>bin\cassandra.bat</tt> from Cassandra&#8217;s main directory above <tt>bin</tt>. So if you are on Windows, change to the directory where you extracted Cassandra and execute <tt>bin\cassandra.bat</tt>.</p>
<p>Cassandras output on startup will look similar to this (here on Mac OS):</p>
<pre style="font-size:10px">
Schabbys-MacBook-Pro:bin johannes$ sudo ./cassandra
Schabbys-MacBook-Pro:bin johannes$ Listening for transport dt_socket at address: 8888
DEBUG - Loading settings from ./../conf/storage-conf.xml
DEBUG - Syncing log with a period of 1000
DEBUG - opening keyspace Keyspace1
DEBUG - adding Super1 as 0
DEBUG - adding Standard2 as 1
DEBUG - adding Standard1 as 2
DEBUG - adding StandardByUUID1 as 3
DEBUG - adding LocationInfo as 4
DEBUG - adding HintsColumnFamily as 5
DEBUG - opening keyspace system
DEBUG - INDEX LOAD TIME for /Users/johannes/cassandra/data/system/LocationInfo-1-Data.db: 0 ms.
DEBUG - INDEX LOAD TIME for /Users/johannes/cassandra/data/system/LocationInfo-2-Data.db: 0 ms.
DEBUG - INDEX LOAD TIME for /Users/johannes/cassandra/data/system/LocationInfo-3-Data.db: 0 ms.
INFO - Replaying /Users/johannes/cassandra/commitlog/CommitLog-1257980407451.log
DEBUG - Replaying /Users/johannes/cassandra/commitlog/CommitLog-1257980407451.log starting at 117
DEBUG - Reading mutation at 117
DEBUG - replaying mutation for system.L: {ColumnFamily(LocationInfo [Generation,])}
INFO - Flushing Memtable(LocationInfo)@228828460
DEBUG - Submitting LocationInfo for compaction
INFO - Completed flushing Memtable(LocationInfo)@228828460
INFO - Compacting [/Users/johannes/cassandra/data/system/LocationInfo-1-Data.db,/Users/johannes/cassandra/data/system/LocationInfo-2-Data.db,/Users/johannes/cassandra/data/system/LocationInfo-3-Data.db,/Users/johannes/cassandra/data/system/LocationInfo-4-Data.db]
DEBUG - index size for bloom filter calc for file  : /Users/johannes/cassandra/data/system/LocationInfo-1-Data.db   : 256
DEBUG - index size for bloom filter calc for file  : /Users/johannes/cassandra/data/system/LocationInfo-2-Data.db   : 512
DEBUG - index size for bloom filter calc for file  : /Users/johannes/cassandra/data/system/LocationInfo-3-Data.db   : 768
DEBUG - index size for bloom filter calc for file  : /Users/johannes/cassandra/data/system/LocationInfo-4-Data.db   : 1024
DEBUG - Expected bloom filter size : 1024
INFO - Compacted to /Users/johannes/cassandra/data/system/LocationInfo-5-Data.db.  0/255 bytes for 0/1 keys read/written.  Time: 150ms.
DEBUG - collecting Generation:false:4@3
DEBUG - collecting Token:false:16@0
INFO - Saved Token found: 160533723849634883377008460059010504450
DEBUG - Starting to listen on 127.0.0.1:7001
DEBUG - Binding thrift service to localhost:9160
</pre>
<p>I think that&#8217;s it. Leave a comment if you run in trouble or check the nice <a href="http://wiki.apache.org/cassandra/GettingStarted#if_something_goes_wrong">If Something Goes Wrong</a> page in the Cassandra Wiki.</p>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/cassandra-installation-configuration/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cassandra &#8211; Getting Started</title>
		<link>http://schabby.de/cassandra-getting-started/</link>
		<comments>http://schabby.de/cassandra-getting-started/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 13:58:11 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Cassandra]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=733</guid>
		<description><![CDATA[This post addresses Java developers who want to get their feet wet with Cassandra. This is the first post in a series of three in which I describe Cassandras data model as seen from the angle of a typical Java developer. By contributing a javaish view on the data model, I try to extend the [...]]]></description>
			<content:encoded><![CDATA[<p>This post addresses Java developers who want to get their feet wet with Cassandra. This is the first post in a series of three in which I describe Cassandras data model as seen from the angle of a typical Java developer. By contributing a javaish view on the data model, I try to extend the set of existing data model descriptions.<br />
<span id="more-733"></span><br />
The second post in this series will briefly describe how to install and configure Cassandra. The third post will provide several hands-on examples for Cassandra with Java.</p>
<p>I have been toying around with <a href="http://incubator.apache.org/cassandra/">Cassandra </a>for quite some time now. From all NOSQL databases I have seen (and there are <a href="http://blog.oskarsson.nu/2009/06/nosql-debrief.html">quite a few</a> already as <a href="http://www.franzkowiak.org/">Michael</a> pointed out to me earlier), Cassandra seems to be the most promising one to me for reasons that are definitely worth discussing, but are here be beyond the scope of this post.</p>
<h2>Data Model</h2>
<p>Cassandras data model has been described <a href="http://wiki.apache.org/cassandra/DataModel">more</a> <a href="http://arin.me/code/wtf-is-a-supercolumn-cassandra-data-model">than</a> <a href="http://blog.evanweaver.com/articles/2009/07/06/up-and-running-with-cassandra/">once</a>. In contrast to the descriptions above, I will try to follow a more javaish view which I find easiest and most powerful to work with. I thereby start describing Cassandras data model as nested hash maps. </p>
<p>The way in which data get&#8217;s stored in key/value based databases like Cassandra strongly resembles the use of ordinary hash maps. To recall, hash maps store data for a (unique) key. The key is also later used to retrieve the data from the hash map. For example, in order to map string keys to byte arrays you would write in Java</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Map<span style="color: #339933;">&lt;</span>String, <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span> map <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This principle stays the same with Cassandra. However, in Cassandra you do not have a single hash map but up to three layers of nested hash maps! What does the mean? Imagine you dont store your values in a single byte array for each key, but again in a hash map, like</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Map<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;&gt;</span> map <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This way you would partition the data you want to store as key/value pairs that are first filled in the data hash map. The data hash map then gets inserted in the higher-order hash map for a given key string. Similarly, to retrieve a value, you would provide the key string and get the data hash map from which you would extract the value you are interested in. </p>
<p>Let us further assume that we dont want to store the key/value pairs as two individual values, but coupled in a class called &#8220;Column&#8221; so that our data model would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Map<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, Column<span style="color: #339933;">&gt;&gt;</span> map <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, Column<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Where <tt>Column</tt> is defined as:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Column <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> name<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> value<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">long</span> timestamp<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Column<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> name, <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">timestamp</span> <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is already pretty close to what is called a <em>Column Family</em> in Cassandra. You need to restrain yourself from deriving something from the name &#8220;Column&#8221;. Also ignore <tt>timestamp</tt> which is used by Cassandra to avoid data inconsistency and which shall not bother us here.  </p>
<p>Before we go on, let us have a look on a concrete example on how you would need to work with this kind of data structure. Let us assume we want to store the profile data of a single user for some imaginary social networking website.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* data model to store user profiles */</span>
Map<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, Column<span style="color: #339933;">&gt;&gt;</span> user <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, Column<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* create a user 'schabby' */</span>
user.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, Column<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* fill in some profile data for user 'schabby' */</span>
Column age <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;age&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span> 27b <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
user.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>age.<span style="color: #006633;">name</span>, age<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Column realName <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;real name&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;Johannes Schaback&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
user.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>realName.<span style="color: #006633;">name</span>, realName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Column nationality <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nationality&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;German&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
user.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>nationality.<span style="color: #006633;">name</span>, nationality<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Again, do not get confused by the use of the byte arrays where normal string would make more sense. This is to resemble the Cassandra data model as close as possible. You will later realize that it&#8217;s actually quite nifty to keep the inner hash map byte based for the price of manually converting everything to byte arrays.</p>
<p>If we want to retrieve values from our data structure, we would need to do as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">byte</span> age <span style="color: #339933;">=</span> user.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;age&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">value</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> realName  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>user.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;real name&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> nationality<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>user.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nationality&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And this is it. There is not much more conceptual stuff to understand in order to use Cassandra. So we are now ready to project this structure to Cassanda terminology.</p>
<h3>Column Family</h3>
<p>Cassandra structures its data model in <em>keyspaces</em>, <em>Column Families</em> (CF), <em>Columns</em> and <em>SuperColumns</em>.</p>
<p>A keyspace is a namespace to group Column Families and can be compared to a <em>schema</em> or single <em>database</em> in the SQL world. A keyspace contains one or more Column Families.</p>
<p>A Column Family can be seen as a multidimensional hash map like the one in our example above. In the SQL analogy, you may see a Column Family as a single table that belongs to a schema, however this comparison will not take you far. It is really more a dynamically growing and shrinking hash map rather than a table with fixed columns. Still, in Cassandras terminology you speak of <em>rows</em> when you refer to the hash map that you get for a key string. </p>
<p>Rows are accessed by string keys and each row &#8211; which can be seen as a &#8220;data hash map&#8221; &#8211; has several <em>columns</em>. Each column within a row is a bundled pair of a byte array key (a.k.a <tt>name</tt>) and its byte array data field (a.k.a. <tt>value</tt>) very similar to our example.</p>
<p>Depending on your configuration, you can let Cassandra apply a sorting scheme to impose an order over your columns in a row. This enables to query ranges over columns. For example, imagine a telephone book from which you want to retrieve all names starting with &#8220;Smi&#8221;. In Java terms, this could be compared to using <tt>SortedMap</tt> instead of <tt>Map</tt>. But we sticked to <tt>Map</tt> for simplicity here.</p>
<h3>SuperColumns</h3>
<p>The cool thing about Cassandra is its support for an additional hash map layer. This additional layer is added to the Column layer and enables you to store and access your data as a hash map in a hash map in a hash map, or in other words, as a three dimensional hash map. This additional hash map is called a SuperColumn (SC) </p>
<p>In our Java-like example, a Column Family with SuperColumns look like</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Map<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, SuperColumn<span style="color: #339933;">&gt;&gt;</span> superColumn 
     <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, SuperColumn<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>where <tt>SuperColumn</tt> is again a hash map over columns like</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> SuperColumn <span style="color: #000000; font-weight: bold;">extends</span> HashMap<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, Column<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Again, I want to point out that the actual SuperColumn definition in Cassandra is different and that this explanatory definition is not too accurate, but nicely serves the illustration purpose.</p>
<p>Similar to normal Columns, the values within a SuperColumn are also stored in an order depending on your configuration, enabling to cut out slices from your SuperColumns.</p>
<p>To continue our social networking site example, let us have a look on how SuperColumns are used to store the friend and relations of the user &#8217;schabby&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* create ColumnFamily with SuperColumns */</span>
Map<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, SuperColumn<span style="color: #339933;">&gt;&gt;</span> columnFamily <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Map<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, SuperColumn<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* prepare a SuperColumn for 'schabby' */</span>
columnFamily.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, SuperColumn<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* create SC to store friend info */</span>
SuperColumn friends <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SuperColumn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* fill in some friends */</span>
Column friend1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;friend_1&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;Merry&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
friends.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>friend1.<span style="color: #006633;">name</span>, friend1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Column friend2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;friend_2&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;Robert&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
friends.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>friend2.<span style="color: #006633;">name</span>, friend2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Column friend3 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;friend_3&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;Susan&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
friends.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>friend3.<span style="color: #006633;">name</span>, friend3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* finally store SC in Colunm Family */</span>
columnFamily.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;friends&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, friends<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We are free to create another SuperColumn in the same Column Family to store other list-like data for &#8217;schabby&#8217;, for example his inbox.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* ... continued example */</span>
&nbsp;
SuperColumn inbox <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SuperColumn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* add two mails to inbox */</span>
Column mail1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hi Schabby&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;I hope you are well! Cheers, Nick&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
inbox.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>mail1.<span style="color: #006633;">name</span>, mail1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Column mail2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Column<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Welcome&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;some message body&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
inbox.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>mail2.<span style="color: #006633;">name</span>, mail2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
columnFamily.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;inbox&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, inbox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Retrieving the mails from the inbox is straight forward:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* continued example */</span>
&nbsp;
SuperColumn inbox <span style="color: #339933;">=</span> columnFamily.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;schabby&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;inbox&quot;</span>.<span style="color: #006633;">toBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> subject<span style="color: #339933;">:</span> inbox.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #003399;">String</span> body <span style="color: #339933;">=</span> inbox.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #666666; font-style: italic;">// do something with subject/body</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And this is it. I hope this enlightened your understanding of Cassandras data model. It&#8217;s not that difficult all in all, especially when you start using it.</p>
<p>Please leave some comments for corrections and feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/cassandra-getting-started/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Zanox SOAP API Java</title>
		<link>http://schabby.de/zanox-soap-api/</link>
		<comments>http://schabby.de/zanox-soap-api/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 13:26:15 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=693</guid>
		<description><![CDATA[In this post I am going to provide some example code to connect to Zanox revised API via Java and SOAP. 
The updated API got more coherent and consistent. Its changes mainly address the new authentication model and the application store in which you can feature your own applications based on Zanox data.

Now for the [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I am going to provide some example code to connect to Zanox revised API via Java and SOAP. </p>
<p>The updated API got more coherent and consistent. Its changes mainly address the new authentication model and the application store in which you can feature your own applications based on Zanox data.<br />
<span id="more-693"></span><br />
Now for the purpose of this post, I sum up how to connect to Zanox SOAP API using Java. There are several steps to do, mostly administrative in nature.</p>
<h2>Get the keys</h2>
<p>Zanox implements a shared key authentication model. Therefore, you need to get yourself the right keys (public and private) to get started. <a href="http://wiki.zanox.com/en/Zanox_Connect_Authentification_Model">Here&#8217;s the page that describes how to get them</a>. Once you created your own application, you will receive the following keys that are necessary prerequisites for your code</p>
<ul>
<li>zanox Application ID</li>
<li>Connect ID</li>
<li>Public key</li>
<li>zanox secret key (aka. private key)</li>
</ul>
<h2>Generate Zanox SOAP Beans From WSDL</h2>
<p>Once you have the keys, you need to generate the classes from the WSDL. For the purpose of this post, we used the (currently latest) WSDL on </p>
<pre>
http://api.zanox.com/wsdl/2009-07-01
</pre>
<p>with the endpoint at</p>
<pre>
http://api.zanox.com/soap/2009-07-01
</pre>
<p>We used <tt>wsimport</tt> to generate the classes as follows</p>
<pre>
wsimport -d bin -s src -p com.zanox.api.namespace._2009_07_01 http://api.zanox.com/wsdl/2009-07-01
</pre>
<p>This should generate you a bunch of class in in the src folder.</p>
<h2>Example Code to Connect to Zanox SOAP API</h2>
<p>In order to run our example code, you need to setup your classpath with the following libraries (actually I am not sure if they are really all necessary)</p>
<ul>
<li>XmlSchema-1.4.3.jar</li>
<li>asm-2.2.3.jar</li>
<li>cxf-2.1.4.jar</li>
<li>geronimo-activation_1.1_spec-1.0.2.jar</li>
<li>geronimo-annotation_1.0_spec-1.1.1.jar</li>
<li>geronimo-jaxws_2.1_spec-1.0.jar</li>
<li>geronimo-stax-api_1.0_spec-1.0.1.jar</li>
<li>geronimo-ws-metadata_2.0_spec-1.1.2.jar</li>
<li>jaxb-api-2.1.jar</li>
<li>jaxb-impl-2.1.9.jar</li>
<li>jaxb-xjc-2.1.9.jar</li>
<li>saaj-api-1.3.jar</li>
<li>saaj-impl-1.3.2.jar</li>
<li>wsdl4j-1.6.2.jar</li>
<li>wstx-asl-3.2.6.jar</li>
<li>xml-resolver-1.2.jar</li>
</ul>
<p>Alrighty, we got all we need to fill in the last bricks. The example code conncets to the API and retrieves the sales of the specified date. The API holds far more methods for different purposes, but they are quit similar in use and once you got the sale-example working (even though you might not generate any sales yet) you can easily infere the correct usage and parameter sets for all other methods. </p>
<p>Create two classes: <tt>ZanoxAuthenticationDto</tt> and <tt>SoapZanoxFacade</tt>. The first DTO is just to hold the authentication data and looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ZanoxAuthenticationDto
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> applicationId<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> connectId<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> sharedKey<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> privateKey<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// ... according getter and setter methods</span>
 <span style="color: #666666; font-style: italic;">//  are left out for simplicity reasons</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the SoapZanoxFacade class we do the actual work and contain all following code snippets. </p>
<p>We first define a couple of helper methods. The most important one is certainly the one to compute the correct signature that is sent to Zanox for every request.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> createSoapSignature<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> serviceName, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> serviceMethod, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> timestamp, <span style="color: #003399;">String</span> nonce, <span style="color: #003399;">String</span> secreyKey<span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> HMAC_SHA1_ALGORITHM <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;HmacSHA1&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Acquire an HMAC/SHA1 from the raw key bytes.</span>
        SecretKeySpec signingKey <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SecretKeySpec<span style="color: #009900;">&#40;</span>secreyKey.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, HMAC_SHA1_ALGORITHM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Acquire the MAC instance and initialize with the signing key.</span>
        Mac mac <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> 
        <span style="color: #009900;">&#123;</span>
            mac <span style="color: #339933;">=</span> Mac.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>HMAC_SHA1_ALGORITHM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            mac.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>signingKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> 
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;trouble while initiating/signing&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003399;">String</span> input <span style="color: #339933;">=</span> serviceName.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> serviceMethod.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> timestamp <span style="color: #339933;">+</span> nonce<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Compute the HMAC on the digest, and set it.</span>
        <span style="color: #003399;">String</span> signature <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BASE64Encoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span>mac.<span style="color: #006633;">doFinal</span><span style="color: #009900;">&#40;</span>input.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> signature<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Another one to format the timestamp</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> createSoapTimestamp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> fmt <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;yyyy-MM-dd'T'HH:mm:ss.000'Z'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">SimpleDateFormat</span> df <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span>fmt, <span style="color: #003399;">Locale</span>.<span style="color: #006633;">US</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        df.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> date <span style="color: #339933;">=</span> df.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> date<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>one to converte java.util.Calendar to XmlGregorianCalendar</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> XMLGregorianCalendar toXmlGregorianCalendar<span style="color: #009900;">&#40;</span><span style="color: #003399;">Calendar</span> c<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>c <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">GregorianCalendar</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
    		<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ZanoxWsException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Calendar instance must be of type GregorianCalendar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> DatatypeFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">newXMLGregorianCalendar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">GregorianCalendar</span><span style="color: #009900;">&#41;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> 
    	<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>DatatypeConfigurationException e<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
    		<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ZanoxWsException<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>    	
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>and the last one to generate a random string of specified length (aka. nonce)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> createNonce<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> length<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> CHARS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;01234567890abcdefghijkmlmnopqrstuvwxyz&quot;</span><span style="color: #339933;">;</span>
    	StringBuilder sb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> length<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    		sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>CHARS.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>CHARS.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The final code snipped finally retrieves the sales:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Retrieve the first 10K sales for day &lt;code&gt;calTime&lt;/code&gt;. 
	 * Paging is hard-wired to first page (in other words: no paging)
	 */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getSales<span style="color: #009900;">&#40;</span><span style="color: #003399;">Calendar</span> calTime, ZanoxAuthenticationDto auth<span style="color: #009900;">&#41;</span>  
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> timestamp <span style="color: #339933;">=</span> createSoapTimestamp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> nonce     <span style="color: #339933;">=</span> createNonce<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> signature <span style="color: #339933;">=</span> createSoapSignature<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PublisherService&quot;</span>, <span style="color: #0000ff;">&quot;GetSales&quot;</span>, timestamp, nonce, auth.<span style="color: #006633;">getPrivateKey</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        XMLGregorianCalendar date <span style="color: #339933;">=</span> toXmlGregorianCalendar<span style="color: #009900;">&#40;</span>calTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        GetSalesRequest getSalesRequest <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GetSalesRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        getSalesRequest.<span style="color: #006633;">setConnectId</span><span style="color: #009900;">&#40;</span>auth.<span style="color: #006633;">getConnectId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        getSalesRequest.<span style="color: #006633;">setDate</span><span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        getSalesRequest.<span style="color: #006633;">setTimestamp</span><span style="color: #009900;">&#40;</span>timestamp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        getSalesRequest.<span style="color: #006633;">setPage</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        getSalesRequest.<span style="color: #006633;">setItems</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        getSalesRequest.<span style="color: #006633;">setSignature</span><span style="color: #009900;">&#40;</span>signature<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        getSalesRequest.<span style="color: #006633;">setNonce</span><span style="color: #009900;">&#40;</span>nonce<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        GetSalesResponse response <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span> 
        <span style="color: #009900;">&#123;</span>
            response <span style="color: #339933;">=</span> getPublisher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSales</span><span style="color: #009900;">&#40;</span>getSalesRequest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ZanoxWsException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error while fetching sales from Zanox SOAP API&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> 
&nbsp;
        <span style="color: #666666; font-style: italic;">// TODO: do something sensible with the data...</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> SaleItem item<span style="color: #339933;">:</span> response.<span style="color: #006633;">getSaleItems</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSaleItem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>item.<span style="color: #006633;">getProgram</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span> &quot;</span><span style="color: #339933;">+</span>item.<span style="color: #006633;">getSubPublisher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">+</span>item.<span style="color: #006633;">getClickId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">+</span>item.<span style="color: #006633;">getAmount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">+</span>item.<span style="color: #006633;">getLptId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">+</span>item.<span style="color: #006633;">getCommission</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> PublisherSoapPortType getPublisher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> PublisherService pubs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PublisherService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> pubs.<span style="color: #006633;">getPublisherSoapPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>To run the code, create a main methode where you set up you authentication data and call getSales on SoapZanoxFacade.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>
    	ZanoxAuthenticationDto dto <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ZanoxAuthenticationDto<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	dto.<span style="color: #006633;">setConnectId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ASL22DKAS223SKD55KAgD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	dto.<span style="color: #006633;">setSharedKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;JY89AFLLA(RKJZZ&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	dto.<span style="color: #006633;">setPrivateKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;asdkljah893qisdnfsyniweoi8ynw893nw&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	dto.<span style="color: #006633;">setApplicationId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sdfs4w9p4uao8oadf9fusm9d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #003399;">Calendar</span> c <span style="color: #339933;">=</span> <span style="color: #003399;">Calendar</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	c.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2009</span>, <span style="color: #cc66cc;">9</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	SoapZanoxFacade l <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapZanoxFacade<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	l.<span style="color: #006633;">getSales</span><span style="color: #009900;">&#40;</span>c, dto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This should get you going with the API. All other SOAP requests are built in a similar fashion. </p>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/zanox-soap-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>connection refused</title>
		<link>http://schabby.de/connection-refused/</link>
		<comments>http://schabby.de/connection-refused/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 07:57:33 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=721</guid>
		<description><![CDATA[Was tun bei einer "connection refused" Exception? "Connection Refused" Probleme können durch meist abarbeiten der beschriebenen Checklist leicht gelöst werden.]]></description>
			<content:encoded><![CDATA[<p>Die Fehlermeldung &#8220;connection refused&#8221; (z.B. beim Tomcat) bedeutet, dass Java ein Problem beim Verbindungsaufbau besteht. In der Regel wird &#8220;connection refused&#8221; von einer unterliegenden, fehlgeschlagenen Socketverbindung geworfen da der Zielhost auf dem angesprochenen Port nicht reagiert. Checklist:<br />
<span id="more-721"></span></p>
<ul>
<li>kann der Zielhost angepingt werden? (Befehl <tt>ping</tt> auf Kommandozeile)</li>
<li>Stimmt der angesprochene Port?</li>
<li>läuft der angesprochene Serverdienst? Gerne blockieren sich zwei Dienste auf dem selben Port (z.B. Tomcat)</li>
<li>Sind Firewalls installiert, die ein Ansprechen des Zielhostes verhindern?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/connection-refused/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google hilft der FDP</title>
		<link>http://schabby.de/google-doodle-wahlsonntag/</link>
		<comments>http://schabby.de/google-doodle-wahlsonntag/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 08:41:05 +0000</pubDate>
		<dc:creator>schabby</dc:creator>
				<category><![CDATA[Dies Und Das]]></category>

		<guid isPermaLink="false">http://schabby.de/?p=677</guid>
		<description><![CDATA[Die FDP wird der relative Gewinner der Bundestagswahl 2009 werden. Und ich weiss auch wieso:
Google hat ja bekanntlich das nette Feature, zu großen Ereignissen oder wichtigen Feiertagen das Logo auf der Startseite abzuwanden. Das abgeänderte Logo wird Google Doodle genannt. Zur Bundestagswahl 2009 hat Google auch ein Doodle gemalt, das wie folgt aussieht: 

Das Kreuz [...]]]></description>
			<content:encoded><![CDATA[<p>Die FDP wird der relative Gewinner der Bundestagswahl 2009 werden. Und ich weiss auch wieso:</p>
<p>Google hat ja bekanntlich das nette Feature, zu großen Ereignissen oder wichtigen Feiertagen das Logo auf der Startseite abzuwanden. Das abgeänderte Logo wird Google Doodle genannt. Zur Bundestagswahl 2009 hat Google auch ein Doodle gemalt, das wie folgt aussieht: </p>
<p><div id="attachment_679" class="wp-caption aligncenter" style="width: 286px"><img src="http://schabby.de/wp-content/uploads/2009/09/germanelections09.gif" alt="Google Doodle Bundestagswahl 2009" title="Google Doodle Bundestagswahl 2009" width="276" height="110" class="size-full wp-image-679" /><p class="wp-caption-text">Google Doodle Bundestagswahl 2009</p></div><br />
<span id="more-677"></span><br />
Das Kreuz wurde beim <strong>gelben</strong> &#8220;o&#8221; gemacht und nicht beim <strong>roten</strong>. Allen Wähler die sich in letzter Sekunde nochmal per Google informieren wollen, wird damit subversiv vorgeschlagen das Kreuzchen bei der FDP zu machen.</p>
]]></content:encoded>
			<wfw:commentRss>http://schabby.de/google-doodle-wahlsonntag/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
