<?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>Stuff and Junk</title>
	<atom:link href="http://www.stuffandjunk.net/main/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stuffandjunk.net/main</link>
	<description>Programming and Philosophy</description>
	<lastBuildDate>Wed, 25 Apr 2012 18:37:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>XPath and C#</title>
		<link>http://www.stuffandjunk.net/main/2012/04/25/xpath-and-cshar/</link>
		<comments>http://www.stuffandjunk.net/main/2012/04/25/xpath-and-cshar/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 18:37:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[New (to me)]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=55</guid>
		<description><![CDATA[Our C# application needs to retrieve data from a Java SOAP source. And, anyone who has dealt with SOAP for any time knows that standards aren&#8217;t. In our case, the null dates in the data were being passed back with &#8230; <a href="http://www.stuffandjunk.net/main/2012/04/25/xpath-and-cshar/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Our C# application needs to retrieve data from a Java SOAP source. And, anyone who has dealt with SOAP for any time knows that standards aren&#8217;t. In our case, the null dates in the data were being passed back with a date that the Java system, I supposed, considered &#8216;null&#8217;: 1899-01-01 00:00:00. But our C# system parsed the incoming XML and saw a &#8216;Date Format Exception&#8217;. </p>
<p>This all happened when we used Visual Studio&#8217;s automagic object creator (Add Service Reference/Advanced/Add Web Reference). When we switched to used the &#8216;standard&#8217; Add Service Reference, this error disappeared. But we then saw a Number Format Exception error. We couldn&#8217;t figure out where this one was coming from, so we started seeking other options.</p>
<p>The Java SOAP services are being created using Axis 2, which permits the user to also make REST calls. So I changed my code to use an <strong>XPathDocument</strong> to make a REST call for the data. The data returned is still in XML format. But this allows me to walk through the elements myself and either ignore the elements if I don&#8217;t need them, or handle a single element&#8217;s value if it causes issues.</p>
<p>I found about 5 different ways of accomplishing this exercise before settling on the <strong>XPathDocument</strong> method I found in <a href="http://developer.yahoo.com/dotnet/howto-xml_cs.html" title="Using Returned XML with C#" target="_blank">Using Returned XML with C#</a>. The one &#8216;gotcha&#8217; that I had to contend with was remembering to use the <strong>XMLNamespaceManager</strong> once I created it. Using it is optional when searching for nodes. </p>
<p>The one &#8216;gotcha&#8217; I ran into was remembering to include *all* the namespaces used within the document, and to use the optional namespace argument when searching for nodes. Without it, I ran into expected &#8211; and unexpected &#8211; errors:</p>
<p>1) The obvious one &#8211; it complained about the fact I was using &#8216;:&#8217; within the node name but not declaring namespaces.<br />
2) I ran into one error &#8211; I can&#8217;t reproduce it now &#8211; but it complained about the &#8216;:&#8217; and only told me that was an illegal character to use within a node name, without telling me why.<br />
3) I put one namespace in, but not both that were used in the document and ran into problems with that as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2012/04/25/xpath-and-cshar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ and Dynamic Queries</title>
		<link>http://www.stuffandjunk.net/main/2012/04/10/linq-and-dynamic-queries/</link>
		<comments>http://www.stuffandjunk.net/main/2012/04/10/linq-and-dynamic-queries/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 17:34:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Notes to Myself]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[intersect]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[sets]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=49</guid>
		<description><![CDATA[Our users need to filter through a list of groups from one list to bring in the groups that should have access on another. The one list is overwhelming, since a group may be created on the fly for special &#8230; <a href="http://www.stuffandjunk.net/main/2012/04/10/linq-and-dynamic-queries/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Our users need to filter through a list of groups from one list to bring in the groups that should have access on another. The one list is overwhelming, since a group may be created on the fly for special purposes at any time. But the list of groups needed for this secondary application may be quite small in comparison.</p>
<p>But each users&#8217; organization will have a different beginning and ending group list. So filtering criteria will be different for each. Hence, to provide that capability, I need to be able to create filters for these lists dynamically.</p>
<p>Looking for a solution, I ran across <a href="http://blog.bvsoftware.com/post/2008/02/27/How-to-create-a-Dynamic-LINQ-Query-Programmatically.aspx" title="Dynamic LINQ Queries">this article</a> that I thought would work. But it broke down when I tried to use more than one &#8216;where&#8217; statement. </p>
<p>The solution I did use may not be elegant. And I&#8217;m hoping it can be made more so, yet more flexible, in the future. But it works. So I wanted to pass it on, in case someone else could use it:</p>
<pre>
public static List<RoleDTO> GetFilteredRoles(List<GroupFilterCLR> roleFilterList) {
   EntityObject context = new EntityObject();
   IQueryable<Role> matches = context.Roles;
   List<String> integers = new List<String>();

   IEnumerable<Role> filterSet = from r in context.Roles
                                 select r;

// now figure out a filter

   foreach (GroupFilterCLR filter in roleFilterList) {
      String strTmp = filter.Regex;
      List<Role> tmp = new List<Role>();
      if (filter.Status == FilterStatus.INCLUDE) {
         if (filter.Relation == FilterRelation.CONTAINS) {
            tmp = (from r in context.Roles
                   where r.Name.Contains(strTmp)
                   select r).ToList<Role>();

          } else if (filter.Relation == FilterRelation.STARTS_WITH) {
               tmp = (from r in context.Roles
                     where r.Name.StartsWith(strTmp)
                     select r).ToList<Role>();

          } else if (filter.Relation == FilterRelation.ENDS_WITH) {
                tmp = (from r in context.Roles
                       where r.Name.EndsWith(strTmp)
                       select r).ToList<Role>();
          }

      } else {
         if (filter.Relation == FilterRelation.CONTAINS) {
            tmp = (from r in context.Roles
                   where !r.Name.Contains(strTmp)
                   select r).ToList<Role>();
          } else if (filter.Relation == FilterRelation.STARTS_WITH) {
                     tmp = (from r in context.Roles
                            where !r.Name.StartsWith(strTmp)
                            select r).ToList<Role>();
          } else if (filter.Relation == FilterRelation.ENDS_WITH) {
                      tmp = (from r in context.Roles
                             where !r.Name.EndsWith(strTmp)
                             select r).ToList<Role>();
           }
        }
           filterSet = filterSet.Intersect(tmp);
      }
   return Mapper.Map&lt;List&lt;Role&gt;, List&lt;RoleDTO&gt;&gt;(filterSet.ToList<Role>());

}
</pre>
<p>Notice, too, that it shows how to negate an expression.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2012/04/10/linq-and-dynamic-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NUnit Testing and Connection Errors</title>
		<link>http://www.stuffandjunk.net/main/2012/04/09/nunit-testing-and-connection-errors/</link>
		<comments>http://www.stuffandjunk.net/main/2012/04/09/nunit-testing-and-connection-errors/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 02:46:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Notes to Myself]]></category>
		<category><![CDATA[app.config]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[nunit]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=40</guid>
		<description><![CDATA[I&#8217;ve moved into the C#/.NET world for a bit. I&#8217;m working on a project that offers a simplified interface into a system. Part of that system requires providing a filtered view of data from the original database. I&#8217;m not doing &#8230; <a href="http://www.stuffandjunk.net/main/2012/04/09/nunit-testing-and-connection-errors/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve moved into the C#/.NET world for a bit. I&#8217;m working on a project that offers a simplified interface into a system. Part of that system requires providing a filtered view of data from the original database. I&#8217;m not doing test-first development. But I am writing unit tests frequently to confirm concepts before completing a module.</p>
<p>Since this is the .NET world, I&#8217;m using NUnit as my unit test framework. But I was getting headaches trying to figure out why I couldn&#8217;t set up my test system to use a different database than the debug or production systems. I&#8217;m trying to keep the database in a known state for testing, meaning that I delete the records and re-add them before running unit tests. I couldn&#8217;t get DBUnit, with IKVM to work, as recommended in http://stackoverflow.com/questions/780614/dbunit-net-alternatives. Nor could I get NDBUnit or tdunit, also recommended in the same query to work. In each case, I was apparently connecting to the database. But at the point I tried to read the xml data I&#8217;d created, everything seemed to break down. Since the latter two have had no update in about 3 &#8211; 4 years, and the IKVM solution combined so many different technologies, I wasn&#8217;t sure where to find an answer, I moved back to trying to use LINQ, as we were using in the rest of the project. </p>
<p>But LINQ was giving me headaches, too:</p>
<blockquote><p>
<em>The specified named connection is either not found in the configuration, not intended to be used with the EntityClient Provider, not valid.</em>
</p></blockquote>
<p>I had an app.config file. It contained the correct connection string entry. I even went as far as to copy and past the connection string from our .edmx file, to ensure I had it right. I did find one person who suggested making sure that it was being correctly read by querying the connectionstring(s) and printing them out during debug:</p>
<pre>
ConnectionStringSettingsCollection settings = ConfigurationManager.ConnectionStrings;
if (settings != null) {
   foreach(ConnectionStringSettings cs in settings) {
      Console.WriteLine(cs.Name);
      Console.WriteLine(cs.ProviderName);
      Console.WriteLine(cs.ConnectionString);
   }
}
</pre>
<p>Rather than finding my named connection string, I found one named <em>LocalSqlServer</em>. I search all the files in our solution and couldn&#8217;t find that anywhere. I then looked in the machine.config and lo and behold! I found it!</p>
<p>So the system wasn&#8217;t even reading my app.config file. </p>
<p>As we all know, many times, finding the answer means finding the right set of keywords to search. Hopefully, I&#8217;ve filled in enough detail in this article that someone else won&#8217;t have that problem. I finally found the right answer when looking for a solution for &#8216;<em>nunit reading app.config&#8217;</em>. Some <a href="http://blog.coryfoy.com/2005/08/nunit-app-config-files-its-all-about-the-nunit-file/" title="Nunit and App.config files" target="_blank">other poor soul</a> had had the same issue. His solution:</p>
<ol>
<li>Make sure that your .nunit file has the same name as your project. That is, if your project is MyProject, then your .nunit file needs to be called MyProject.nunit.</li>
<li>Your configuration file needs to have the same prefix as well. Rather than being called <em>app.config</em>, you need to name it MyProject.config.</li>
<li>Both of the aforementioned files need to be in the same directory.</li>
</ol>
<p>It worked for me. Hopefully, someone else can find this solution as well.</p>
<p>Next problem to solve: dynamic &#8216;where&#8217; clauses for LINQ.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2012/04/09/nunit-testing-and-connection-errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Threading in Spring</title>
		<link>http://www.stuffandjunk.net/main/2010/08/10/threading-in-spring/</link>
		<comments>http://www.stuffandjunk.net/main/2010/08/10/threading-in-spring/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 15:05:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[New (to me)]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=14</guid>
		<description><![CDATA[In order to know when a user requests a tarot reading, I needed to set up an email client to send a message to me. The joys of SMTP are that sending email is very straightforward, no matter what your &#8230; <a href="http://www.stuffandjunk.net/main/2010/08/10/threading-in-spring/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In order to know when a user requests a tarot reading, I needed to set up an email client to send a message to me. The joys of SMTP are that sending email is very straightforward, no matter what your programming language. Java is no different. So I created code to send out the message. Problem was, the email was slow to send, slowing the web page response time down too much. I needed to create a second thread to handle it, in order to avoid the slowdown.</p>
<p>I didn&#8217;t take the time to read the Spring MVC model documentation first regarding threads. I just moved my email to a class that implemented Runnable and tried to be done with it. Unfortunately, the Spring MVC (or any other servlet for that matter, I&#8217;m guessing) requires that all the threads be tied up in pretty bows before proceeding. So using this method to send the email didn&#8217;t help my timing issue &#8211; it still required the email thread to finish before sending the response page to the user.</p>
<p>A bit more research brought me to Apache&#8217;s Active MQ. That was what I needed. It took care of all the heavy lifting for my producer/consumer pieces. I only need to write those classes and call the Active MQ libraries to put it in place.</p>
<p>The one issue I had with the process, after my first foray into it, was that it required a place to write to my file system. It took a bit of digging to figure out how to change the default location to one that my server would allow.</p>
<p>I see that there&#8217;s also a way of using my database. That will be another refactoring later.</p>
<p>Here&#8217;s the links you need to use this library:</p>
<p>ActiveMQ home page: http://activemq.apache.org</p>
<p>Setup Information for Spring: http://activemq.apache.org/spring-support.html<br />
Tutorial site. A bit out of date (version 3, current version is 5), but it will help you get started:</p>
<p>http://javaboutique.internet.com/tutorials/activemq/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2010/08/10/threading-in-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Up to Speed Again</title>
		<link>http://www.stuffandjunk.net/main/2010/07/03/getting-up-to-speed-again/</link>
		<comments>http://www.stuffandjunk.net/main/2010/07/03/getting-up-to-speed-again/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 15:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Notes to Myself]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=9</guid>
		<description><![CDATA[I&#8217;ve found myself with a bit of extra time on my hands. To keep my skills fresh &#8211; or to refreshen them, I&#8217;m going to attempt to put together a new web site using CoreServlet&#8217;s slides. I then pulled the &#8230; <a href="http://www.stuffandjunk.net/main/2010/07/03/getting-up-to-speed-again/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found myself with a bit of extra time on my hands. To keep my skills fresh &#8211; or to refreshen them, I&#8217;m going to attempt to put together a new web site using <a href="http://jabsorb.org/Manual>JSON-RPC</a>, Spring MVC, and Yahoo&#8217;s UI Library. I&#8217;m still a bit fuzzy on any specific framework for the user facing pieces, but I&#8217;m leaning towards JSF. We&#8217;ll see how that goes.</p>
<p>I&#8217;ve come up with my set of requirements, done a few UML diagrams so I can be sure of where I&#8217;m heading, and I&#8217;m beginning development now.</p>
<p>It&#8217;s a tarot reading site, with all sorts of whistles and buzzers. Users can request a reading, view past readings that have been done for them, and respond to surveys regarding the accuracy of their readings. The owner of the site will be able to query card meanings, enter the readings into the site, and enter the interpretations. The owner will be able to see the full reading, the user will be able to see the interpretations. The user will be able to view the analysis of the surveys &#8211; this part I&#8217;m still not quite sure how to present the data. But since it&#8217;ll take awhile to get some good values in, I&#8217;m not too worried about it at this point.</p>
<p>So far, I&#8217;ve put together the first parts of the query page. And I&#8217;m very impressed with the JSON-RPC libraries. They&#8217;re very easy to use! I followed the directions for creating my classes based on the notes in <a href=">CoreServlet&#8217;s</a> slides. I then pulled the data also following the same directions. Then a bit of Javascript magic anc voila! The data appeared.</p>
<p>More details to follow as I proceed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2010/07/03/getting-up-to-speed-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Time Projects</title>
		<link>http://www.stuffandjunk.net/main/2010/01/30/on-time-projects/</link>
		<comments>http://www.stuffandjunk.net/main/2010/01/30/on-time-projects/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 17:57:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Philosophy]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=34</guid>
		<description><![CDATA[I find myself oftentimes trying to get developers to understand why it&#8217;s important to give a client a realistic date upon which to expect a release. I have heard the words that make me cringe: &#8220;But it will be ready &#8230; <a href="http://www.stuffandjunk.net/main/2010/01/30/on-time-projects/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I find myself oftentimes trying to get developers to understand why it&#8217;s important to give a client a realistic date upon which to expect a release.  I have heard the words that make me cringe: &#8220;But it will be ready when it&#8217;s ready.  This is new stuff and we can&#8217;t predict what might happen along the way.&#8221;  Try telling that to your client for whom your software is a necessary piece for their own software.</p>
<p>I think I&#8217;ve finally figured out a way to explain it&#8230;&#8230;</p>
<p>I think every area of the country has the &#8216;backyard&#8217; auto mechanic.  The guy with several cars sitting around that haven&#8217;t been repaired since before you were  born.  But often those folks know more about cars than you can shake a stick at.  In my area of the country, we have some of those that are actual businesses.  And a few have been recommended to me as the best place to take my not-so-new cars.</p>
<p>When you take your car to a mechanic, it doesn&#8217;t halt your need for a vehicle.  Especially in areas with poor public transportation.  That means either having to rely on someone else to drive you places, or drive with you places, or it means renting a car.</p>
<p>Now the dilemma with the &#8216;backyard&#8217; mechanic.  They may be good.  They may be less expensive than the other guy.  But many times you don&#8217;t know when your car will be finished.</p>
<p>So you take the car in for what you hope is a straightforward repair.  You ask the mechanic when it&#8217;ll be done and you get a general handwaving.  So you make arrangements to hitch a ride, or, worse, you rent a car, to tide you over until your car is ready.  </p>
<p>A week passes.  Your car isn&#8217;t ready yet.  Your told the parts have finally arrived, and you&#8217;ve moved up the priority list, so they should be working on your car again soon.</p>
<p>Another week passes.  Your car isn&#8217;t ready yet.  Something else came it that was more important than getting your car done.</p>
<p>Another week passes.  You finally get your car back.  Mind you, when you get it, it runs better than when you left it, because they&#8217;ve tweaked a few other things that had been annoying you that you hadn&#8217;t even mentioned.</p>
<p>But the fact remains that you were 3 weeks without your car, you were inconvenienced much longer than you expected to be, and you may, if you did end up renting a car, be out more than if you&#8217;d taken it to the &#8216;other guy&#8217;.</p>
<p>Now think about a software project.  The developers tell you that, with design, development, code review, and testing, the project will take 8 weeks.  6 weeks rolls around and the coding isn&#8217;t done.  They say it&#8217;ll be at least another week added on.  8 weeks passes and the coding is finally done and reviewed.  But it&#8217;s not tested yet.  Add another two weeks.  11 weeks passes. The software is finally delivered.  It works great.  But in the meantime, you&#8217;ve had your team sitting on their thumbs waiting for that functionality so they could get their part done.  And your clients, to whom you&#8217;ve promised an end product, will now have to be told that it needs to come a month later.  So your clients go somewhere else.</p>
<p>Kinda makes sense, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2010/01/30/on-time-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merging Redmine Databases</title>
		<link>http://www.stuffandjunk.net/main/2009/10/22/merging-redmine-databases/</link>
		<comments>http://www.stuffandjunk.net/main/2009/10/22/merging-redmine-databases/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 15:25:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Notes to Myself]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=24</guid>
		<description><![CDATA[Many plug-ins have been written to allow a person to migrate from other issue tracking systems to Redmine. In these casese, the assumption is that the company is discarding an old issue tracking system and starting with a new Redmine &#8230; <a href="http://www.stuffandjunk.net/main/2009/10/22/merging-redmine-databases/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Many plug-ins have been written to allow a person to migrate from other issue tracking systems to Redmine. In these casese, the assumption is that the company is discarding an old issue tracking system and starting with a new Redmine installation. Ours is a different scenario. Our group is already using Rackspace. And we were merging with a group that had their own installation of the software. So what I needed to be able to do was merge the two databases together.</p>
<p>The &#8216;new&#8217; team had two projects in their system, only one of which was of interest to us. That project already existed in our system. A number of users overlapped in the two systems. And the &#8216;new&#8217; team&#8217;s system included some Redmine plugins that we weren&#8217;t using. The last one proved to be the most difficult to deal with.</p>
<p>The integration of the wiki into ours was very straightforward. What proved to be difficult was the issues. Using the existing &#8216;merge&#8217; plug-ins as templates, as well as my knowledge from having created a limited interface (for our clients to see their issues, but not everything in the system), I was able to figure out most of the entries that needed to be moved over.</p>
<p>The easiest method of combining the issues into our system proved to be getting a csv extract from the &#8216;new&#8217; system, parsing that, and adding it in. Unfortunately, doing it that way, we missed out on any attachments as well as any update history for the issues.</p>
<p><a href="/Downloads/RedmineMigration.zip">Scripts for migration</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2009/10/22/merging-redmine-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a CXF Client Application</title>
		<link>http://www.stuffandjunk.net/main/2009/06/16/creating-a-cxf-client-application/</link>
		<comments>http://www.stuffandjunk.net/main/2009/06/16/creating-a-cxf-client-application/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 15:10:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Notes to Myself]]></category>

		<guid isPermaLink="false">http://www.stuffandjunk.net/main/?p=20</guid>
		<description><![CDATA[I&#8217;m creating a client that accesses our in-house SOAP web services. Our code base uses Spring, so I need to incorporate that. The SOAP service has security, so I need to get that working. We use maven as our build &#8230; <a href="http://www.stuffandjunk.net/main/2009/06/16/creating-a-cxf-client-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m creating a client that accesses our in-house SOAP web services. Our code base uses <em>Spring</em>, so I need to incorporate that. The SOAP service has security, so I need to get that working. We use <em>maven</em> as our build tool, so I need to get that in here as well. Here&#8217;s the steps I&#8217;m following to get it to work. I&#8217;ll edit these as I go.</p>
<ol>
<li>Download and install <a href="http://cxf.apache.org/">Apache CXF</a>.</li>
<li>Install the security certificate on your system using <a href="http://blogs.sun.com/andreas/entry/no_more_unable_to_find">Install Cert</a>. If that code ever goes missing, we&#8217;re all in trouble!</li>
<ul>
<li>compile the code</li>
<li>run the instructions as written</li>
<li>move the jsscacert file to your /jre/lib/security folder for the JRE you&#8217;re using for your system</li>
</ul>
<li>Create a generic <em>maven</em> jar project (#5) using <em>maven arechetype:generate</em>.</li>
<li>Add the <a href="http://cwiki.apache.org/CXF20DOC/maven-integration-and-plugin.html">CXF maven entries</a> to your pom.xml.</li>
<li>Run <a href="http://cwiki.apache.org/CXF20DOC/wsdl-to-java.html">WSDL2JAVA</a>to generate your base code.</li>
<li>Create a password callback class
<pre>import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import org.apache.ws.security.WSPasswordCallback;

public class ClientPasswordCallback implements CallbackHandler {

	private String system;
	public ClientPasswordCallback() {
		// TODO Auto-generated constructor stub
	}

	public void handle(Callback[] callbacks) throws IOException,
			UnsupportedCallbackException {
		WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

		pc.setPassword("My password");

	}
	public void setSystem(String pVal)
	{
		system = pVal;
	}</pre>
</li>
<li>Add the security and bean information to your applicationContext.xml file:
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"&gt;
&lt;jaxws:client id="[port bean id]"
                  serviceClass="[my port class]"
                  address="[https://mywsdl]"&gt;
   &lt;jaxws:outInterceptors&gt;
     &lt;bean class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor"/&gt;
     &lt;ref bean="wss4jOutConfiguration"/&gt;
   &lt;/jaxws:outInterceptors&gt;
&lt;/jaxws:client&gt;

&lt;bean id="wss4jOutConfiguration" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor"&gt;
  &lt;constructor-arg&gt;
    &lt;map&gt;
       &lt;entry key="action" value="UsernameToken"/&gt;
       &lt;entry key="passwordType" value="PasswordText"/&gt;
       &lt;entry key="user" value="[my login]"/&gt;
       &lt;entry key="passwordCallbackRef"&gt;
         &lt;ref bean="passwordCallback"/&gt;
       &lt;/entry&gt;
    &lt;/map&gt;
  &lt;/constructor-arg&gt;
&lt;/bean&gt;

&lt;bean id="passwordCallback" class="[my callback class]"&gt;
   &lt;property name="system" value="test"/&gt;
&lt;/bean&gt;
&lt;/beans&gt;</pre>
</li>
<li>Modify the test case to use your beans:
<pre>ApplicationContext context = new ClassPathXmlApplicationContext(
		"/applicationContext.xml");
    	port = ([port class]) context.getBean("[beanid]");

        ObjectFactory factory = new ObjectFactory();

        [request class] myRequest = factory.create[request class]</pre>
</li>
<li>Delete the [beanname]Service.java class. You don&#8217;t need it when you use the Spring stuff.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.stuffandjunk.net/main/2009/06/16/creating-a-cxf-client-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

