<?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>Svens Blog &#187; Entwicklung</title>
	<atom:link href="http://blog.borkert.net/category/devel/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.borkert.net</link>
	<description></description>
	<lastBuildDate>Tue, 17 May 2011 09:28:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>HessianProtocolException: listRecent: expected int at 0x7a (z)</title>
		<link>http://blog.borkert.net/2010/12/22/hessianprotocolexception-listrecent-expected-int-at-0x7a-z/</link>
		<comments>http://blog.borkert.net/2010/12/22/hessianprotocolexception-listrecent-expected-int-at-0x7a-z/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 20:36:08 +0000</pubDate>
		<dc:creator>Sven Borkert</dc:creator>
				<category><![CDATA[Entwicklung]]></category>
		<category><![CDATA[Hessian]]></category>
		<category><![CDATA[HessianProtocolException]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Webservice]]></category>

		<guid isPermaLink="false">http://blog.borkert.net/?p=367</guid>
		<description><![CDATA[<a href="http://blog.borkert.net/2010/12/22/hessianprotocolexception-listrecent-expected-int-at-0x7a-z/" title="HessianProtocolException: listRecent: expected int at 0x7a (z)"></a>When working with the Java Hessian Webservice library (resin-hessian-4.0.7.jar) I encountered the following problem: Calling the method: public List&#60;EventView&#62; listRecent(String node, int limit); via the webservice works fine. Another very similar method on the same service fails with an exception: &#8230;<p class="read-more"><a href="http://blog.borkert.net/2010/12/22/hessianprotocolexception-listrecent-expected-int-at-0x7a-z/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://blog.borkert.net/2010/12/22/hessianprotocolexception-listrecent-expected-int-at-0x7a-z/" title="HessianProtocolException: listRecent: expected int at 0x7a (z)"></a><p>When working with the Java Hessian Webservice library (resin-hessian-4.0.7.jar) I encountered the following problem:</p>
<p>Calling the method:</p>
<p><em>public List&lt;EventView&gt; listRecent(String node, int limit);</em></p>
<p>via the webservice works fine. Another very similar method on the same service fails with an exception:</p>
<p><em>public List&lt;EventView&gt; listRecent(int limit);</em></p>
<p><code>WARN  [btpool0-1] 2010-12-22 21:08:16,441 log: Nested in org.springframework.web.util.NestedServletException: Hessian skeleton invocation failed; nested exception is com.caucho.hessian.io.HessianProtocolException: listRecent: expected int at 0x7a (z):<br />
com.caucho.hessian.io.HessianProtocolException: listRecent: expected int at 0x7a (z)<br />
at com.caucho.hessian.io.HessianInput.error(HessianInput.java:1695)<br />
at com.caucho.hessian.io.HessianInput.expect(HessianInput.java:1681)<br />
at com.caucho.hessian.io.HessianInput.readInt(HessianInput.java:538)<br />
at com.caucho.hessian.io.BasicDeserializer.readObject(BasicDeserializer.java:169)</code></p>
<p>I exported the webservice via the Spring HessianServiceExporter (org.springframework.remoting.caucho.HessianServiceExporter, Spring 3.0.5). <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#remoting-caucho-protocols">See documentation.</a></p>
<p>Calling the webservice works very simple:</p>
<p><code>HessianProxyFactory factory = new HessianProxyFactory();<br />
EventService eventService = (EventService) factory.create(EventService.class, urlString);</code></p>
<p>I found out, that the problem is related to the version of the Hessian Protocol thats beeing used. Telling the HessianProxyFactory to use version 2 of the protocol resolves the problem:</p>
<p><code> HessianProxyFactory factory = new HessianProxyFactory();<br />
factory.setHessian2Request(true);<br />
factory.setHessian2Reply(true);<br />
</code></p>
<p>Hope this information can help anyone else with the same problem, took me some time searching to find out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.borkert.net/2010/12/22/hessianprotocolexception-listrecent-expected-int-at-0x7a-z/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate Blobs und Input Streams</title>
		<link>http://blog.borkert.net/2010/06/03/hibernate-blobs-und-input-streams/</link>
		<comments>http://blog.borkert.net/2010/06/03/hibernate-blobs-und-input-streams/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 10:13:00 +0000</pubDate>
		<dc:creator>Sven Borkert</dc:creator>
				<category><![CDATA[Entwicklung]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[empty blob]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[inputstream]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://blog.borkert.net/?p=343</guid>
		<description><![CDATA[<a href="http://blog.borkert.net/2010/06/03/hibernate-blobs-und-input-streams/" title="Hibernate Blobs und Input Streams"></a>Nach einigen Tests mit der Blob Unterstützung in Hibernate musste ich leider feststellen, dass sich Hibernate nicht dazu eignet Blobs aus einem InputStream einzulesen, wenn die Gesamtgrösse der einzulesenden Daten nicht bekannt ist und man die Daten nicht alle im &#8230;<p class="read-more"><a href="http://blog.borkert.net/2010/06/03/hibernate-blobs-und-input-streams/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://blog.borkert.net/2010/06/03/hibernate-blobs-und-input-streams/" title="Hibernate Blobs und Input Streams"></a><p>Nach einigen Tests mit der Blob Unterstützung in Hibernate musste ich leider feststellen, dass sich Hibernate nicht dazu eignet Blobs aus einem InputStream einzulesen, wenn die Gesamtgrösse der einzulesenden Daten nicht bekannt ist und man die Daten nicht alle im Speicher halten will.</p>
<p>Auf das Problem wurde ich aufmerksam als ich feststellte, dass Blobs aus einigen InputStreams nicht korrekt eingelesen wurden. Zum Einsatz kam Hibernate 3.3.2, ein Blick in die Quellen offenbart einen Fehler in dieser Version:</p>
<blockquote><p>public static Blob createBlob(InputStream stream) throws IOException {<br />
return new SerializableBlob( new BlobImpl( stream, stream.available() ) );<br />
}</p></blockquote>
<p>Hier wird eine Methode angesprochen, die die Länge der einzulesenden Daten erwartet. Fälschlicherweise wird hier .available() des Streams verwendet. Dieser Wert gibt allerdings nur die Anzahl an Bytes zurück, die garantiert gelesen werden können, bevor der Stream das nächste Mal blockiert. Der Wert hat also keine Aussagekraft bzgl. der Gesamtgrösse der Daten des Streams.</p>
<p><a href="http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#available%28%29">http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#available%28%29</a></p>
<p>Der Fehler ist bekannt:</p>
<p><a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-4095?page=com.atlassian.jirafisheyeplugin:fisheye-issuepanel">http://opensource.atlassian.com/projects/hibernate/browse/HHH-4095?page=com.atlassian.jirafisheyeplugin:fisheye-issuepanel</a></p>
<p>In den aktuellen Versionen von Hibernate wurde dieser Fehler behoben, allerdings wird jetzt der ganze Stream in einen Puffer gezogen, damit Hibernate die Gesamtgröße kennt:</p>
<blockquote><p>public static Blob createBlob(InputStream stream) throws IOException {<br />
ByteArrayOutputStream buffer = new ByteArrayOutputStream( stream.available() );<br />
StreamUtils.copy( stream, buffer );<br />
return createBlob( buffer.toByteArray() );<br />
}</p></blockquote>
<p>So etwas ist natürlich völlig inakzeptabel, wenn man sauber mit größeren Datenmengen arbeiten will.</p>
<p>Ich werde nun auf die native PostgreSQL Blob API umsteigen, das nimmt mir zwar den Hibernate Komfort, ermöglicht aber mehr Kontrolle über den Speicherverbrauch.</p>
<p><a href="http://www.postgresql.org/files/documentation/books/pghandbuch/html/jdbc-binary-data.html">http://www.postgresql.org/files/documentation/books/pghandbuch/html/jdbc-binary-data.html</a></p>
<p>Eine weitere Alternative wäre es, Daten aus einem InputStream zuerst in eine temporäre Datei zu schrieben, und sie erst anschließend in die Datenbank einzulesen, da dann ja die Gesamtgröße bekannt ist. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.borkert.net/2010/06/03/hibernate-blobs-und-input-streams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

