<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1022147621335552644</id><updated>2011-07-07T16:03:41.546-07:00</updated><category term='Alfresco CapTech JBoss Portal XForms Mock'/><category term='CapTech'/><category term='JBoss Portal'/><category term='XSLT'/><category term='ANT'/><category term='java json commons httpclient xstream'/><category term='JAXB'/><category term='XML'/><category term='Alfresco'/><category term='Alfresco CapTech JBoss Portal GSA Google Search Appliance XML'/><category term='XML Beans'/><category term='JBoss Rules Engine'/><category term='SOA'/><category term='Google Search Appliance'/><category term='Alfresco JSF Faces Spring Chiba CapTech JBoss Portal XForms Mock'/><category term='Castor'/><category term='GSA'/><title type='text'>Ron DiFrango on Software Development</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rdifrango.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://rdifrango.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ron DiFrango</name><uri>http://www.blogger.com/profile/17489618571530887897</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_ClnrVvpnHaY/SbAdjjEiizI/AAAAAAAABYQ/UJPx1LjL-LU/S220/IMG_0740.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1022147621335552644.post-7851596055893365862</id><published>2009-10-20T05:56:00.001-07:00</published><updated>2009-10-20T06:00:41.041-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Alfresco'/><category scheme='http://www.blogger.com/atom/ns#' term='CapTech'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='GSA'/><category scheme='http://www.blogger.com/atom/ns#' term='JBoss Portal'/><category scheme='http://www.blogger.com/atom/ns#' term='XSLT'/><category scheme='http://www.blogger.com/atom/ns#' term='Google Search Appliance'/><title type='text'>Google Search Appliance (GSA) Sorting in Portal</title><content type='html'>&lt;p class="MsoNormal"&gt;At several of our clients, we have integrated the Google Search appliance into a Portal.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;In order to accomplish this integration we could take 1 of 2 approaches:&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l2 level1 lfo1"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;1.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Utilize GSA’s built-in ability to format the presentation logic via a &lt;span class="MsoHyperlink"&gt;&lt;a href="http://code.google.com/apis/searchappliance/documentation/50/admin_searchexp/ce_understanding.html"&gt;XLST&lt;/a&gt;&lt;/span&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l2 level1 lfo1"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;2.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Utilize GSA’s ability to return straight &lt;a href="http://code.google.com/apis/searchappliance/documentation/50/xml_reference.html"&gt;XML&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Both approaches work well and can suit the needs of a portal.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;Option 1 though will not work if you need to sort the entire result set prior to displaying it to the users.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;The reasons for this is as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l1 level1 lfo2"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;1.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;GSA does not provide the ability to retrieve more than 100 results at a time &lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l1 level1 lfo2"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;2.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;GSA’s built in sorting only sorts the first 100 results.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l1 level1 lfo2"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;3.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Sorting on things other than Date or Relevance [e.g. Meta Data] requires some XSLT work and it is still bound by the limitations of only sorting the 100 records at a time.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Option 2 still has the limitation of fetching 100 records at a time, but you can sort it client side as requirements dictate.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;Our approach to accomplishing this typically involves the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l0 level1 lfo3"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;1.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Creating client side code that dynamically fetches the entire result from GSA by fetching blocks of 100 results at a time up to the maximum available.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l0 level1 lfo3"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;2.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Store the resulting composite XML in a cached region for a predetermined amount of time.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;The caching algorithm for the key and time should be configurable so that it can be adjusted as needed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left:.5in;text-indent:-.25in;mso-list:l0 level1 lfo3"&gt;&lt;span style="mso-fareast-font-family:Arial;mso-bidi-font-family:Arial;"&gt;&lt;span style="mso-list:Ignore"&gt;3.&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;After fetching and storing the results, sort them based upon the client input.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;h2&gt;Conclusion&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;  &lt;p class="MsoNormal"&gt;Overall Option 2 &lt;span style="mso-spacerun: yes"&gt; &lt;/span&gt;worked very well for us when the sorting requirements exceed those available to you by the built-in mechanisms provided by GSA.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;The one challenge to keep in mind is the memory requirements needed for caching and the time required to fetch the results in chunks.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;In both cases, we found that the memory requirements rarely had an adverse impact on our portal and the fetch time was only incurred by the first requestor and was rarely noticeable.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;!--EndFragment--&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1022147621335552644-7851596055893365862?l=rdifrango.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rdifrango.blogspot.com/feeds/7851596055893365862/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rdifrango.blogspot.com/2009/10/google-search-appliance-gsa-sorting-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/7851596055893365862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/7851596055893365862'/><link rel='alternate' type='text/html' href='http://rdifrango.blogspot.com/2009/10/google-search-appliance-gsa-sorting-in.html' title='Google Search Appliance (GSA) Sorting in Portal'/><author><name>Ron DiFrango</name><uri>http://www.blogger.com/profile/17489618571530887897</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_ClnrVvpnHaY/SbAdjjEiizI/AAAAAAAABYQ/UJPx1LjL-LU/S220/IMG_0740.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1022147621335552644.post-3344693705320884170</id><published>2009-09-16T10:37:00.000-07:00</published><updated>2009-09-17T13:27:20.633-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Alfresco CapTech JBoss Portal GSA Google Search Appliance XML'/><title type='text'>Alfresco Integration with GSA</title><content type='html'>&lt;h1&gt;&lt;a name="_Toc113698902"&gt;Alfresco Integration with GSA&lt;/a&gt;&lt;/h1&gt;  &lt;p class="MsoNormal"&gt;In order to provide searching within the portal a strategy had to be defined with how to integrate Alfresco with GSA.  There were two approaches considered:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;1.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-weight: normal;"&gt;&lt;span style="font-size:78%;"&gt;     &lt;/span&gt;&lt;/span&gt;Utilize the traditional approach and have GSA crawl Alfresco through either a webscript mechanism or via CIFS.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;2.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-weight: normal;"&gt;&lt;span style="font-size:78%;"&gt;     &lt;/span&gt;&lt;/span&gt;Utilize the GSA Feed based approach.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;After careful review we decided upon the feed base approach for the following reasons:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;1.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-weight: normal;"&gt;&lt;span style="font-size:78%;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;b&gt;Meta Data:&lt;/b&gt; In order to support the Faceted searching, we need to find a way to attach metadata to each content item.  Given that our HTML code is just snippets and does not contain a header with this information and that we are indexing documents, the only way to reliably accomplish this was via the feed.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;2.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-weight: normal;"&gt;&lt;span style="font-size:78%;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;b&gt;Portal Page:&lt;/b&gt;  For each of the Content portlets, we need to determine a way to identify the underlying portal page that a given content item lives on. The only way to reliably accomplish this was via the feed.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;3.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-weight: normal;"&gt;&lt;span style="font-size:78%;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;b&gt;Security:&lt;/b&gt;  GSA does have support for a late binding approach to security whereby on a search request a security check would be performed against the underlying system to see if a user had access.  In order to support this we would have had to pass along the security credentials to GSA and setup GSA to access Active Directory.  Furthermore, we determined that the processing overhead associated with this check would slow down the search results.  Therefore, we add security metadata to the feed and just add that to the query string. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;Please refer to the GSA documentation for the documentation on how to develop a feed:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;a href="http://code.google.com/apis/searchappliance/documentation/50/feedsguide.html"&gt;http://code.google.com/apis/searchappliance/documentation/50/feedsguide.html&lt;/a&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;a href="http://code.google.com/apis/searchappliance/documentation/50/metadata.html"&gt;http://code.google.com/apis/searchappliance/documentation/50/metadata.html&lt;/a&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;The following sections will describe in some detail how this is accomplished for each both the Alfresco DM and WCM&lt;a name="_Toc113698903"&gt; content stores.&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;GSA Metadata&lt;/h2&gt;  &lt;p class="MsoNormal"&gt;In order to support the faceted searching, we needed to add our own custom Metadata to a given content item.  This was in part accomplished by defining a custom content model. Below are some references that we utilized to create our own custom content model:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Step-By-Step:_Creating_A_Custom_Model"&gt;http://wiki.alfresco.com/wiki/Step-By-Step:_Creating_A_Custom_Model&lt;/a&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;a href="http://ecmarchitect.com/archives/2007/06/09/756"&gt;http://ecmarchitect.com/archives/2007/06/09/756&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&lt;a name="_Toc113698904"&gt;Alfresco DM&lt;/a&gt;&lt;/h2&gt;  &lt;p class="MsoNormal"&gt;Our feed from DM was straightforward, we just created an &lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;Alfresco webscript&lt;/a&gt; that traversed the repository and created the XML in the format required by GSA.  In addition to traversing the standard repository, the &lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;Alfresco webscript&lt;/a&gt; traversed the archive store to obtain a list of files that should be deleted from the index.  The output of the &lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;webscript&lt;/a&gt; was the XML format required by GSA.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;On the portal side, we utilized &lt;a href="http://www.opensymphony.com/quartz/"&gt;Quartz&lt;/a&gt; to created a scheduled process that executed this webscript, obtained the XML and passed it along to GSA via the Feed URL.&lt;/p&gt;  &lt;h2&gt;&lt;a name="_Toc113698905"&gt;Alfresco WCM&lt;/a&gt;&lt;/h2&gt;  &lt;p class="MsoNormal"&gt;Our feed from WCM was nearly the same.  We created an &lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;Alfresco webscript&lt;/a&gt; that traversed the repository and created the XML in the format required by GSA.  &lt;/p&gt;  &lt;p class="MsoNormal"&gt;On the portal side, we utilized &lt;a href="http://www.opensymphony.com/quartz/"&gt;Quartz&lt;/a&gt; to create a scheduled process that executed this &lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;webscript&lt;/a&gt;. Once the response is returned from the &lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;webscript&lt;/a&gt;, we traverse each record within the results set and attempt to determine if the given content item has been mapped to a page within the portal.  If it has been matched to one or more portal pages, then the custom metadata attribute pageId is set to the Portal Page ID.  This allows the search client to generate the appropriate portal URL for display to the client.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Then we post the modified XML to GSA via the Feed URL.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Please note, one limitation of WCM versus DM is that it does not have a mechanism to determine if a file has been removed.  If this occurs, then you will have to manually construct a delete feed and push it to GSA.&lt;/p&gt;  &lt;h2&gt;Conclusion&lt;/h2&gt;  &lt;p class="MsoNormal"&gt;Overall this approached worked very well for us. The only issue we ran into was the query string limitations of 2048 characters inherent in GSA.  The reason our query was long because we had so many custom fields that needed to query against when searching.  In order to account for this, we only sending along those fields that are required.  In the end, this solution met the client’s business requirements and provided an effective search experience&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1022147621335552644-3344693705320884170?l=rdifrango.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rdifrango.blogspot.com/feeds/3344693705320884170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rdifrango.blogspot.com/2009/09/alfresco-integration-with-gsa.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/3344693705320884170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/3344693705320884170'/><link rel='alternate' type='text/html' href='http://rdifrango.blogspot.com/2009/09/alfresco-integration-with-gsa.html' title='Alfresco Integration with GSA'/><author><name>Ron DiFrango</name><uri>http://www.blogger.com/profile/17489618571530887897</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_ClnrVvpnHaY/SbAdjjEiizI/AAAAAAAABYQ/UJPx1LjL-LU/S220/IMG_0740.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1022147621335552644.post-2752922787627011269</id><published>2009-08-18T05:02:00.000-07:00</published><updated>2009-08-18T07:34:07.520-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Alfresco CapTech JBoss Portal XForms Mock'/><title type='text'>Alfresco Impersonation</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;On my current project, we are using &lt;span style="color: rgb(18, 0, 238);"&gt;&lt;a href="http://www.alfresco.com/"&gt;Alfresco&lt;/a&gt;&lt;/span&gt; and working on an integration with &lt;span style="color: rgb(18, 0, 238);"&gt;&lt;a href="http://jboss.org/jbossportal"&gt;JBoss Portal&lt;/a&gt;&lt;/span&gt;. In this case we were building a component that allowed for the browsing, uploading, moving, renaming, and deleting of files.  We had built all the &lt;span style="color: rgb(18, 0, 238);"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;Alfresco Web Scripts&lt;/a&gt;&lt;/span&gt; to support these operations.  In order to ensure the proper auditing of the changes, we needed to implement a  &lt;span style="color: rgb(18, 0, 238);"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;WebScripts&lt;/a&gt;&lt;/span&gt; component that performed impersonation of the user that was executing the action.  After some Google searching, we found the following common solution to the problem:&lt;br /&gt;&lt;br /&gt;   public String impersonate(String username) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        String currentUser = AuthenticationUtil.getCurrentUserName();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        if (currentUser == null || !currentUser.equals(username)) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;            AuthenticationUtil.setCurrentUser(username);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        return currentUser;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;With this code the owner is set correctly, but the creator and modifier fields are not being set to the username we are impersonating.  Furthermore, the permission checks (via hasPermission) were behaving correctly in that we were authenticating for the impersonated user.  After some searching through the Alfresco API we had to change our impersonation code as follows:&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;    public String impersonate(String username) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        if (currentUser == null || !currentUser.equals(username)) {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;            AuthenticationUtil.setRunAsUser(username);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;            AuthenticationUtil.setFullyAuthenticatedUser(username);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;        return currentUser;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;The reason the original solution did not work for us is because the Alfresco engine runs background processes on the content item to apply any rules that may be defined on the workspace.  If you do not ensure that those background processes run in the impersonated user’s context, then they will run as the system account.  Reading the new API calls is what made the light bulb go off in my head.  The API &lt;/span&gt;&lt;b style="font-family: arial;"&gt;setRunAsUser&lt;/b&gt;&lt;span style="font-family: arial;"&gt; says that it switches to the given user for all authenticated operations and the API &lt;/span&gt;&lt;b style="font-family: arial;"&gt;setFullyAuthenticatedUser&lt;/b&gt;&lt;span style="font-family: arial;"&gt; places the guarantees that the given users are set for all operations.  Therefore the combination of these two API calls guarantees that all operations will be run in the context of this user. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1022147621335552644-2752922787627011269?l=rdifrango.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rdifrango.blogspot.com/feeds/2752922787627011269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rdifrango.blogspot.com/2009/08/alfresco-impersonation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/2752922787627011269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/2752922787627011269'/><link rel='alternate' type='text/html' href='http://rdifrango.blogspot.com/2009/08/alfresco-impersonation.html' title='Alfresco Impersonation'/><author><name>Ron DiFrango</name><uri>http://www.blogger.com/profile/17489618571530887897</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_ClnrVvpnHaY/SbAdjjEiizI/AAAAAAAABYQ/UJPx1LjL-LU/S220/IMG_0740.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1022147621335552644.post-7755193026395089154</id><published>2009-02-27T05:48:00.000-08:00</published><updated>2009-03-04T10:03:20.950-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Alfresco JSF Faces Spring Chiba CapTech JBoss Portal XForms Mock'/><title type='text'>Alfresco Web Forms Integration - Mock JSF Faces Context</title><content type='html'>&lt;span class="Apple-style-span"   style="font-family:Arial;font-size:7;"&gt;&lt;span class="Apple-style-span"  style="font-size:48px;"&gt;&lt;span class="Apple-style-span"   style="  ;font-family:Times;font-size:16px;"&gt;&lt;div style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; width: auto; font: normal normal normal 100%/normal Georgia, serif; text-align: left; "&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;On my current project, we are using &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://www.alfresco.com/"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Alfresco&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; and working on an integration with &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://jboss.org/jbossportal"&gt;JBoss Portal&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;. In particular, we were creating our own version of &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Forms_Developer_Guide"&gt;Alfresco&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Forms_Developer_Guide"&gt; &lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Forms_Developer_Guide"&gt;WebForms&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; editor that is built into their web client. We had built all the &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Web_Scripts"&gt;Alfresco Web Scripts&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; to fetch the appropriate &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://wiki.alfresco.com/wiki/Forms_Developer_Guide"&gt;WebForm&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; for a given content item and a college of mine had built all the Portal magic to render and save the form in a fashion similar to &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://chiba.sourceforge.net/"&gt;Chiba&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;. The last component I needed to build was the Webscript to generate the renditions of the web forms within &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://www.alfresco.com/"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Alfresco&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;. I found the magic component with &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://www.alfresco.com/"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Alfresco&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; that did this in &lt;a href="http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/web-client/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java"&gt;AVMEditBean&lt;/a&gt;. But in order to utilize it, I had to cut and paste the following lines:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;if&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; (&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0F00C2;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;services&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;.getAVMService().hasAspect(nodeRef.getVersion(), nodeRef.getPath(), WCMAppModel.&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0F00C2;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;ASPECT_FORM_INSTANCE_DATA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;)) {&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;.regenerateRenditions(nodeRef);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; regenerateRenditions(AVMNode node)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;throws&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; FormNotFoundException {&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;final&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; String avmPath = node.getPath();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;final&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; FormInstanceData fid = &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0F00C2;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;formsService&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;.getFormInstanceData(-1, avmPath);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;final&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; List result = fid.regenerateRenditions();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;for&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; (FormInstanceData.RegenerateResult rr : result) {&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;if&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; (rr.getException() != &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;) {&lt;br /&gt;Utils.addErrorMessage(&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#2A00FF;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;"error regenerating rendition using "&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;+ rr.getRenderingEngineTemplate().getName() + &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#2A00FF;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;": "&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;+ rr.getException().getMessage(), rr.getException());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;The trouble, I ran into was all the utility classes that were called by this blurb of code required a static instances of the current &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://www.alfresco.com/"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Alfresco&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#55188B;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://java.sun.com/javaee/javaserverfaces/1.0/docs/api/javax/faces/context/FacesContext.html"&gt;FacesContext&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;. My first instinct was to start pulling apart each of these utility classes that were called and removing their dependence upon the &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#55188B;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a href="http://java.sun.com/javaee/javaserverfaces/1.0/docs/api/javax/faces/context/FacesContext.html"&gt;FacesContext&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;. I had done this effectively in the past when I was mimicking the Submit All functionality, but this time it was not going as well. I seem to keep digging myself a bigger and bigger hole of code that following the &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://en.wikipedia.org/wiki/Copy_and_paste_programming"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Cut And Paste Anti-Pattern&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;. I was talking with my &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;colleague &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Phil Kedy and he suggested that we create a &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#55188B;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Mock&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; version of the &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#55188B;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://java.sun.com/javaee/javaserverfaces/1.0/docs/api/javax/faces/context/FacesContext.html"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;FacesContext&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; and just initialize it with the things that the Alfresco utility classes needed, mainly the Spring WebContext. He got to work on building the Mock class and I figured out to wire in &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://www.springsource.com/"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Spring&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; context. Wiring in the &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://www.springsource.com/"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Spring&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;context was fairly easy because all &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#1200EE;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://www.alfresco.com/"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Alfresco&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; Webscripts are declared in a Spring context file so I just had my Webscript implement the Spring interface &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#55188B;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/context/ApplicationContextAware.html"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;ApplicationContextAware&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; and we would be set.  Mr. Kedy figured out how to create the mock class and now all I had to add in was the following:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; width: auto; font: normal normal normal 100%/normal Georgia, serif; text-align: left; "&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;MockFacesContext faces = &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#7F0355;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; MockFacesContext((WebApplicationContext) &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0F00C2;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;ctx&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Now in conjunction with the MockFacesContext, he had to create 2 supporting classes a MockApplication class that implemented the method createValueBinding. This was necessary in order to process the el syntax that Alfresco used to locate the Alfresco Services. And in conjunction with that he had to implement a MockValueBinding object to handle the location of the services. And finally, we had to load in the message bundles to handle the word substitution.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Once all of this was done, we had a working version of the Web Forms upload and rendition generation that worked within the JBoss Portal.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1022147621335552644-7755193026395089154?l=rdifrango.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rdifrango.blogspot.com/feeds/7755193026395089154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rdifrango.blogspot.com/2009/02/alfresco-web-forms-integration-mock-jsf.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/7755193026395089154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/7755193026395089154'/><link rel='alternate' type='text/html' href='http://rdifrango.blogspot.com/2009/02/alfresco-web-forms-integration-mock-jsf.html' title='Alfresco Web Forms Integration - Mock JSF Faces Context'/><author><name>Ron DiFrango</name><uri>http://www.blogger.com/profile/17489618571530887897</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_ClnrVvpnHaY/SbAdjjEiizI/AAAAAAAABYQ/UJPx1LjL-LU/S220/IMG_0740.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1022147621335552644.post-8840043213614885767</id><published>2009-02-22T17:45:00.000-08:00</published><updated>2009-02-23T10:10:53.758-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java json commons httpclient xstream'/><title type='text'>Posting JSON with Commons HTTPClient and XStream</title><content type='html'>I recently had an occasion where I had to perform an HTTP POST with JSON data from a Java service class as oppose to Javascript. No amount of Google searches turned up the answer I was after.   Here are the steps I took to do so:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;STEP 1 - Handle HTTP Post&lt;/span&gt;&lt;br /&gt;The project I am working we were already using &lt;a href="http://hc.apache.org/httpclient-3.x/"&gt;Commons HTTPClient&lt;/a&gt; which has a PostMethod class that peforms an HTTP Post.  Here is the code to setup the post:&lt;br /&gt;&lt;br /&gt;HttpClient  clientService = new HttpClient();&lt;br /&gt;PostMethod post = new PostMethod();&lt;br /&gt;post.setURI(new URI("http://yoururl" false));&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 2 - Find JSON Converter&lt;/span&gt;&lt;br /&gt;The best tool kit I found for handling JSON is a combination of &lt;a href="http://xstream.codehaus.org/json-tutorial.html"&gt;XStream&lt;/a&gt; and &lt;a href="http://jettison.codehaus.org/"&gt;Jettison&lt;/a&gt;. Following the &lt;a href="http://xstream.codehaus.org/json-tutorial.html"&gt;XStream&lt;/a&gt; tutorial, I did the following:&lt;br /&gt;&lt;br /&gt;   // This ensure that we drop the root element&lt;br /&gt;    XStream xstream = new XStream(new JsonHierarchicalStreamDriver() {&lt;br /&gt;        public HierarchicalStreamWriter createWriter(Writer writer) {&lt;br /&gt;            return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;&lt;br /&gt;    xstream.setMode(XStream.NO_REFERENCES);&lt;br /&gt;&lt;br /&gt;// Stream the class I want converted into JSON&lt;br /&gt;    xstream.alias("site", ProjectBean.class);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 3 - Post the JSON Stream&lt;/span&gt;&lt;br /&gt;Next up, is putting the two together and posting the JSON.&lt;br /&gt;&lt;br /&gt;// Model bean to stream&lt;br /&gt;ProjectBean site = new ProjectBean();&lt;br /&gt;&lt;br /&gt;    post.setRequestHeader("Content-Type", "application/json");&lt;br /&gt;    &lt;br /&gt;// apply content-length here if known (i.e. from proxied req)&lt;br /&gt;        // if this is not set, then the content will be buffered in memory&lt;br /&gt;        post.setRequestEntity(new StringRequestEntity(xstream.toXML(site), "application/json", null));&lt;br /&gt;    &lt;br /&gt;// execute the POST&lt;br /&gt;        int status = clientService.executeMethod(post);&lt;br /&gt;&lt;br /&gt;// Check response code&lt;br /&gt;        if (status != HttpStatus.SC_OK) {&lt;br /&gt;                 throw new Exception("Received error status " + status);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;That is all there.  I hope this helps.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1022147621335552644-8840043213614885767?l=rdifrango.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rdifrango.blogspot.com/feeds/8840043213614885767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rdifrango.blogspot.com/2009/02/posting-json-with-commons-httpclient.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/8840043213614885767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/8840043213614885767'/><link rel='alternate' type='text/html' href='http://rdifrango.blogspot.com/2009/02/posting-json-with-commons-httpclient.html' title='Posting JSON with Commons HTTPClient and XStream'/><author><name>Ron DiFrango</name><uri>http://www.blogger.com/profile/17489618571530887897</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_ClnrVvpnHaY/SbAdjjEiizI/AAAAAAAABYQ/UJPx1LjL-LU/S220/IMG_0740.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1022147621335552644.post-6411054354059822790</id><published>2007-11-26T07:00:00.000-08:00</published><updated>2009-02-22T18:39:03.543-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Castor'/><category scheme='http://www.blogger.com/atom/ns#' term='ANT'/><category scheme='http://www.blogger.com/atom/ns#' term='XML Beans'/><category scheme='http://www.blogger.com/atom/ns#' term='SOA'/><category scheme='http://www.blogger.com/atom/ns#' term='JAXB'/><category scheme='http://www.blogger.com/atom/ns#' term='JBoss Rules Engine'/><title type='text'>Where The Rubber Meets The Road With Your SOA Domain Model</title><content type='html'>As discussed in an earlier posting, creating a Domain Model is critical to a successful SOA implementation. But how do you effectively utilize this model within your code base as you start to develop applications that are in tools or languages that do not manipulate the XML directly?&lt;br /&gt;&lt;br /&gt;In my most recent project I had a team of off-shore and on-shore developers developing a new service based web application. We followed best practices and created our Domain Model in XML Schema. The architecture consisted of a Web front end that was to be implemented with a combination of Java Server Faces and Spring and a Business Service Layer that utilized TIBCO Business Works. On both sides of the equation we had to convert the XML Stream into Java objects that could be manipulated for display on the client side and rules execution on the Service side. The dilemma I had was how to eliminate the need for multiple sets of XML parsing code and the proliferation of Data Transfer style objects that typically followed along.&lt;br /&gt;&lt;br /&gt;After some thought, I decided to create an single project that utilized an XML Binding framework to process the underlying schema. This ensured that we had one code base for both sides. In order to ease the integration, we evaluated frameworks that would work well with Spring on the client side; &lt;a id="gdxs" title="JAXB" href="https://jaxb.dev.java.net/"&gt;JAXB&lt;/a&gt;, &lt;a id="mccn" title="XML Beans" href="http://xmlbeans.apache.org/"&gt;XML Beans&lt;/a&gt; and &lt;a id="g51f" title="Castor" href="http://www.castor.org/"&gt;Castor&lt;/a&gt;. After careful review of the features of each and some quick prototyping on which one would work well on both platforms, we settled on &lt;a id="yra5" title="Castor" href="http://www.castor.org/"&gt;Castor&lt;/a&gt;. The main reason we choose &lt;a id="yra5" title="Castor" href="http://www.castor.org/"&gt;Castor&lt;/a&gt; was because it interacted the smoothest with the &lt;a id="fsw-" title="JBoss Rules Engine" href="http://labs.jboss.com/drools/"&gt;JBoss Rules Engine&lt;/a&gt; that we were running on the service tier. The &lt;a id="yra5" title="Castor" href="http://www.castor.org/"&gt;Castor&lt;/a&gt; generated objects act more like POJO's in that we can create them on the fly then perform the marshaling/unmarshaling as needed.&lt;br /&gt;&lt;br /&gt;To ease the introduction of this approach to the development team, I created an ANT based process that pulled the Domain Model from our repository, built our Java Classes from the schema via Castor's &lt;a id="cf.9" title="Source Generator" href="http://www.castor.org/sourcegen.html"&gt;Source Generator&lt;/a&gt;, and then created a standardized JAR file that both the web and services teams could utilize.&lt;br /&gt;&lt;br /&gt;We estimated that this approach reduced the amount of code generated by at least 50% and simplified both code bases greatly. I will definitely leverage this approach on all my future projects.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1022147621335552644-6411054354059822790?l=rdifrango.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rdifrango.blogspot.com/feeds/6411054354059822790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rdifrango.blogspot.com/2007/11/where-rubber-meets-road-with-your-soa.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/6411054354059822790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1022147621335552644/posts/default/6411054354059822790'/><link rel='alternate' type='text/html' href='http://rdifrango.blogspot.com/2007/11/where-rubber-meets-road-with-your-soa.html' title='Where The Rubber Meets The Road With Your SOA Domain Model'/><author><name>Ron DiFrango</name><uri>http://www.blogger.com/profile/17489618571530887897</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_ClnrVvpnHaY/SbAdjjEiizI/AAAAAAAABYQ/UJPx1LjL-LU/S220/IMG_0740.jpg'/></author><thr:total>1</thr:total></entry></feed>
