<?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>Matt's Blog &#187; woolly thoughts</title>
	<atom:link href="http://blog.rueedlinger.ch/category/woolly-thoughts/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rueedlinger.ch</link>
	<description>Software Engineering and Java</description>
	<lastBuildDate>Tue, 07 Sep 2010 17:38:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>.Net (C#) and SOAP with Attachments</title>
		<link>http://blog.rueedlinger.ch/2009/01/net-c-and-soap-with-attachments/</link>
		<comments>http://blog.rueedlinger.ch/2009/01/net-c-and-soap-with-attachments/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 14:24:48 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[woolly thoughts]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=40</guid>
		<description><![CDATA[In our project we offer a web service to our customers and to simplify the use of the web service we have implemented web service clients as examples in different frameworks. So we have the usual suspects for Java (JAX-WS, Apache CXF and Axis).
I was asked if I’m interested in program a web service client [...]]]></description>
			<content:encoded><![CDATA[<p>In our project we offer a web service to our customers and to simplify the use of the web service we have implemented web service clients as examples in different frameworks. So we have the usual suspects for Java (JAX-WS, Apache CXF and Axis).</p>
<p>I was asked if I’m interested in program a web service client for the .Net framework. I had already some little experience with C# and ASP.Net and so I thought it would be nice to see what .Net has to offer.</p>
<p>So first the goal was to implement a web service client for a contract first document / literal / wrapped web service which is WS-I Attachments Profile conform.</p>
<p>The big problem is that .Net does not support SwA (SOAP Messages with Attachments). There are three approaches which could work for you when you have the same problem.</p>
<ul>
<li>Use the open source library <a href="http://www.pocketsoap.com/">PocketSOAP </a></li>
<li>Use the commercial library from <a href="http://www.alotsoft.com/view/product.jsf">Alotsoft.com</a></li>
<li>Create your own web service stub</li>
</ul>
<p>In this post I will show you how you could send a SOAP request manually, receive the SOAP response and parse the MIME attachments with the open source library <a href="http://anmar.eu.org/projects/sharpmimetools/">SharpMimeTools</a>.</p>
<p>So keep in mind that I&#8217;m a Java developer and not a C# developer. I also wrote these pieces of code only to show that there is also a simple way to receive a SOAP response with MIME attachments when your were forced to write a web service stub manually in C#.</p>
<h3>Data contract</h3>
<p>So first we create our Data contract with the <strong>xsd.exe</strong>. After that we can serialize or deserialize XML with the <strong>System.Xml.XMLSerializer</strong> from the .Net framework. You will find a reference to a XSD schema in your WSDL file from your web service for which you want to create a web service client.</p>
<pre class="code">Xsd.exe data_contract.xsd /c /o:c:\out</pre>
<h3>Send SOAP request</h3>
<p>With <strong>System.Net.HttpWebRequest</strong> you can send a SOAP request manually to your endpoint. We serialize our XML with the <strong>XMLSerializer </strong>and add the SOAP Envelope, SOAP Header and SOAP Body.</p>
<p>The followng example show how you could use the <strong>XMLSerializer </strong>and the <strong>HttpWebRequest </strong>to create a SOAP request and send it to a web service endpoint.</p>
<pre class="code">FileStream fs = new FileStream(“C:\data.xml”, FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(MyData));
MyData myData = (MyData) serializerReq.Deserialize(fs);

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.OmitXmlDeclaration = true;
StringWriter stringWriter = new StringWriter();

using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter,
	writerSettings))
      {
                serializerReq.Serialize(xmlWriter, myData);
      }

string xmlText = stringWriter.ToString();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.ContentType = @"text/xml;charset=""utf-8""";
req.Accept = "text.xml";
req.Method = "POST";

// create soap message (with SOAP Header, Body and Envelope)
String msg = START_MSG + xmlText + END_MSG;
byte[] reqBytes = System.Text.Encoding.UTF8.GetBytes(msg);
req.ContentLength = reqBytes.Length;
Stream reqStream = req.GetRequestStream();

// send soap request
reqStream.Write(reqBytes, 0, reqBytes.Length); reqStream.Close();

reqStream.Close();</pre>
<h3>Receive SOAP response</h3>
<p>We will use the <a href="http://anmar.eu.org/projects/sharpmimetools/">SharpMimeTools </a>to parse MIME attachments. So for that we have to make our response stream MIME multipart conform.</p>
<p>The example show how you can create a stream which can be parsed from the SharpMimeTool library. You have to copy the HTTP headers <strong>Date</strong>, <strong>Content-Type</strong>, <strong>Content-Length</strong> and the content of the HttpWebReponse stream to a memory stream. The new memeory stream can then be parsed by the SharpMimeTool library.</p>
<pre class="code">HttpWebResponse res = …;
MemoryStream httpStream = …;
MemoryStream mimeStream = …;
Encoding utf8 = Encoding.UTF8;
TextReader readerReq = new StreamReader(httpStream, utf8);
TextWriter writer = new StreamWriter(mimeStream, utf8);

// create a correct mime stream form the HttpResponseStream
// add http headers which were required for a correct mime
// format
writer.WriteLine("Date: " + res.GetResponseHeader("Date"));
writer.WriteLine("Content-Type: " + res.ContentType);
writer.WriteLine("Content-Length: " + res.ContentLength);
writer.WriteLine(Environment.NewLine);

// copy rest of the stream
while (true)
{
      string line = readerReq.ReadLine();
      if (line == null)
      {
                break;
      }
      writer.WriteLine(line);
}
writer.Flush();
mimeStream.Position = 0;

// parse  the stream for mime attachments
SharpMessage message = new SharpMessage(mimeStream,
   SharpDecodeOptions.Default | SharpDecodeOptions.DecodeTnef |
   SharpDecodeOptions.UuDecode);</pre>
<h3>Parse MIME attachments from the SOAP response</h3>
<p>With the SharpMessage from the <a href="http://anmar.eu.org/projects/sharpmimetools/">SharpMimeTools </a>we can access the SOAP response and also the MIME attachments.</p>
<pre class="code">SharpMessage message = …;
if (message.Attachments != null)
{
  foreach (attachment in message.Attachments)
  {
    Stream stream = attachment.Stream;
    …
  }</pre>
<h3>Finally&#8230;</h3>
<p>To access the soap payload you could retrieve it with XPath and then deserialize it with the XMLSerializer.</p>
<p>&#8230; I hope this post and line of codes gave you a hint how you could parse a SOAP response with MIME attachments manually in C#.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2009/01/net-c-and-soap-with-attachments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>I wanted to buy an apache wicket book but I got stuck on stripes</title>
		<link>http://blog.rueedlinger.ch/2008/12/i-wanted-to-buy-an-apache-wicket-book-but-i-got-stuck-on-stripes/</link>
		<comments>http://blog.rueedlinger.ch/2008/12/i-wanted-to-buy-an-apache-wicket-book-but-i-got-stuck-on-stripes/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 22:29:13 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[woolly thoughts]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=39</guid>
		<description><![CDATA[So today I wanted to buy an apache wicket book, because I try to create a simple example which shows how you could use apache activemq as embedded JMS broker in a web application with spring and hibernate to process data asynchronously.
I have already written the whole business layer (spring, hibernate and JMS) but for [...]]]></description>
			<content:encoded><![CDATA[<p>So today I wanted to buy an <a href="http://manning.com/dashorst/">apache wicket book</a>, because I try to create a simple example which shows how you could use <a href="http://activemq.apache.org/">apache activemq</a> as embedded JMS broker in a web application with spring and hibernate to process data asynchronously.</p>
<p>I have already written the whole business layer (spring, hibernate and JMS) but for a simple demonstration I need a web ui framework.</p>
<p>I didn&#8217;t want to write the ui in JSF, so I thought this is a good way to learn <a href="http://wicket.apache.org/">Apache wicket</a>. I went to my locale bookstore but they didn&#8217;t had the &#8220;<a href="http://manning.com/dashorst/">wicket in action</a>&#8221; book. </p>
<p>But an other book got my attention. <a href="http://www.pragprog.com/titles/fdstr/stripes">Stripes &#8230;and Java Web Development is fun again</a>.</p>
<p><em>Stripes is an open source web application framework based on the model-view-controller pattern. It aims to be a more lightweight framework than Struts by using Java technologies such as annotations and generics that were introduced in Java 1.5, to achieve &#8220;convention over configuration&#8221;.  [<a href="http://en.wikipedia.org/wiki/Stripes_(framework)">Wikipedia</a>]</em></p>
<p>As fare as I can tell <a href="http://www.stripesframework.org/">Stripes</a> looks quite interesting. I&#8217;m not yet finished with reading, but I must say after few chapters I already have a glue how to implement the ui layer. The book covers also a chapter how you could integrate hibernate and spring annotations.  </p>
<p>So I&#8217;m looking forward to see how stripes fits in with spring and hibernate. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/12/i-wanted-to-buy-an-apache-wicket-book-but-i-got-stuck-on-stripes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thanks Head First Servlet and JSP</title>
		<link>http://blog.rueedlinger.ch/2008/12/thanks-head-first-servlet-and-jsp/</link>
		<comments>http://blog.rueedlinger.ch/2008/12/thanks-head-first-servlet-and-jsp/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 20:25:53 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[woolly thoughts]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=37</guid>
		<description><![CDATA[&#8230;. I am now a Sun Certified Web Component Developer (SCWCD). The Oreilly Book Head First Servlet and JSP gives you a quick overview about what you should know. One advantages of the Book is it&#8217;s very &#8220;brain friendly&#8221;. But I got some tough  questions on the exam which were not covered in the Book.
When [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;. I am now a Sun Certified Web Component Developer (SCWCD). The <a href="http://www.amazon.com/Head-First-Servlets-JSP-Brain-Friendly/dp/0596516681/">Oreilly Book Head First Servlet and JSP</a> gives you a quick overview about what you should know. One advantages of the Book is it&#8217;s very &#8220;brain friendly&#8221;. But I got some tough  questions on the exam which were not covered in the Book.</p>
<p>When you want a Book which covers almost everything and when your are interested in a Book which you can keep after the exam as reference book the I recommend you the <a href="http://www.amazon.com/Certified-Component-Developer-310-081-310-082/dp/0072258810">Book from David Bridgewater.</a></p>
<p>Also a good source to prepare yourself on a Sun certificate is the <a href="http://www.javaranch.com/">javaranch webiste</a>.</p>
<p>I also got asked why should I take the exam. One statement I mostly heard was they only test you on &#8220;old technologies&#8221; like JSP and Servlets&#8221; and why should I take the exam when JSF is not part of the exam.</p>
<p>But most of the Java web frameworks use JSP and Servlets as the fundamentals. So with the SCWCD exam you will be forced to learn the fundamentals. You get a glue how JSF could be realized. Honestly there are a lot of things you will never use but I think when you prepare yourself seriously then it gives you a great benefit.</p>
<p><cite>Steve</cite> which works in the same company as I took recently the Sun Certified Business Component Developer and he created some nice <a href="http://blog.stefanjaeger.ch/2008/11/14/sun-certified-business-component-developer/">fact sheets</a> which you can use to prepare yourself for the Sun Certified Business Component Developer exam.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/12/thanks-head-first-servlet-and-jsp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Is Linux the better choice for Java developers?</title>
		<link>http://blog.rueedlinger.ch/2008/11/is-linux-the-better-choice-for-java-developers/</link>
		<comments>http://blog.rueedlinger.ch/2008/11/is-linux-the-better-choice-for-java-developers/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 12:55:45 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[woolly thoughts]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=16</guid>
		<description><![CDATA[Last week I had a discussion with some colleges from work, if it would be better when we used Linux instead of Windows. I don&#8217;t want to start a flame war with my blog. I personally use Linux because when I was a student I couldn&#8217;t effort the licenses cost :-) and since then I [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I had a discussion with some colleges from work, if it would be better when we used Linux instead of Windows. I don&#8217;t want to start a flame war with my blog. I personally use Linux because when I was a student I couldn&#8217;t effort the licenses cost :-) and since then I pretty happy with my choice. But I must say that I don&#8217;t&#8217; have a problem to work with Windows, but sometimes I think it would be easier for me to work with Linux. But thats my personal opinion. I really miss a package manager (apt-get, emerge, etc.) under Windows and the shell (bash, etc).</p>
<p>I started to think about this topic when they did a update of the antivirus software last week. Suddenly the build of our Java application took longer, because the antivirus software scanned during the build all jar&#8217;s, war&#8217;s, ear&#8217;s and class files. It took about a day and the problem was fixed from the IT support! Now the problem is solved but there are still some points which could be improved, like to exclude XML files from the scan.</p>
<p>A big company mostly have a Java development crew and they have to customize the workstations for them. For example when you are lucky you have local administration rights and you can install a JDK. So would it be better to give them Linux workstations (or a MacBook Air&#8230;;-)  with a Windows Terminal Server client to access the MS applications?</p>
<p>A interesting post is from Cay Horstmann about why Java developers should switch to Linux.<br />
<a href="http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/why_java_develo.html ">http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/why_java_develo.html<br />
</a><br />
And naturally a blog from Eitan Suez about Mac and Java.<br />
<a href="http://weblogs.java.net/blog/eitan/archive/2004/11/java_developmen_1.html">http://weblogs.java.net/blog/eitan/archive/2004/11/java_developmen_1.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/11/is-linux-the-better-choice-for-java-developers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
