<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-7064760583138976546</atom:id><lastBuildDate>Wed, 28 Aug 2024 17:24:16 +0000</lastBuildDate><category>ColdFusion</category><category>Hibernate</category><category>Junit</category><category>Transaction</category><category>Web Service</category><title>eee94180</title><description></description><link>http://eee94180.blogspot.com/</link><managingEditor>noreply@blogger.com (adey)</managingEditor><generator>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7064760583138976546.post-1175560584549800103</guid><pubDate>Sat, 29 Aug 2009 15:48:00 +0000</pubDate><atom:updated>2009-08-29T22:24:36.947+05:30</atom:updated><title>Binding XML to Java Code with JiBX</title><description>&lt;span class=&quot;Apple-style-span&quot;   style=&quot;  white-space: normal; font-family:Georgia;font-size:16px;&quot;&gt;I was looking for a simple, lightweight, fast xml-java binding solution. Tried few libraries like JAXB, XMLBean, JiBX, Castor and finally settled down with JiBX. JiBX is simple, it generates very few classes from a given schema and its fast!  We can also write a binding.xml to map java to xml document. &lt;a href=&quot;http://jibx.sourceforge.net/index.html&quot;&gt;JiBX project site&lt;/a&gt; has great documentation if you want to get started with JiBX.&lt;/span&gt; &lt;div&gt;
&lt;/div&gt;&lt;div&gt;Lets go through the basic steps of generating java objects, doing jibx binding and marshal &amp;amp; unmarshal&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;download &lt;a href=&quot;http://sourceforge.net/projects/jibx/files/&quot;&gt;JiBX&lt;/a&gt;&lt;/li&gt;&lt;li&gt;set JIBX_HOME environment variable&lt;/li&gt;&lt;li&gt;generate java source from my_schema.xsd&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;blockquote&gt;java -cp $JIBX_HOME/lib/jibx-tools.jar org.jibx.schema.codegen.CodeGen -t source_dir my_schema.xsd&lt;/blockquote&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;compile generated java source:- javac source_dir/**/*.java&lt;/li&gt;&lt;li&gt;jibx binding:- &lt;b&gt;&lt;i&gt;java -jar $JIBX_HOME/lib/jibx-bind.jar binding.xml&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;write sample code to marshal &amp;amp; unmarshal&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;blockquote&gt;java -cp $JIBX_HOME/lib/jibx-run.jar:$$JIBX_HOME/lib/xpp3.jar MyTestClass&lt;/blockquote&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;Code in MyTestClass would look as below&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;blockquote&gt;IBindingFactory bfact = BindingDirectory.getFactory(MyAnyGenerated.class); IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); IMarshallingContext mctx = bfact.createMarshallingContext();&lt;/blockquote&gt;&lt;blockquote&gt;Object obj = uctx.unmarshalDocument(new FileInputStream(&quot;input.xml&quot;), null); mctx.marshalDocument(obj, &quot;UTF-8&quot;, null, new FileInputStream(&quot;output.xml&quot;));&lt;/blockquote&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span class=&quot;Apple-style-span&quot;   style=&quot;  white-space: normal; font-family:Georgia;font-size:16px;&quot;&gt;Compare to JAXB, JiBX generates very few classes from a given schema. We can also &lt;a href=&quot;http://jibx.sourceforge.net/fromschema/codegen-example2.html&quot;&gt;customize source code generation&lt;/a&gt; using custom.xml. JiBX generates a binding.xml which is used for JIBX binding. We can also write the binding.xml manually and bind existing value object to xml definition.  I had run a small test to compare marshal &amp;amp; unmarshal with JIBX, JAXB &amp;amp; XMLBean and found that JIBX is almost 2x faster than other two.&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://eee94180.blogspot.com/2009/08/binding-xml-to-java-code-with-jibx.html</link><author>noreply@blogger.com (adey)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7064760583138976546.post-4868443649068100639</guid><pubDate>Sun, 23 Aug 2009 14:12:00 +0000</pubDate><atom:updated>2009-08-23T22:15:01.528+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><category domain="http://www.blogger.com/atom/ns#">Junit</category><category domain="http://www.blogger.com/atom/ns#">Transaction</category><title>Unit Test Java EE Code Outside Container</title><description>Java EE application depends a lots on the application server container for various resources like JNDI datasource, transaction manager etc. The application I am working on uses Hibernate as persistence layer.  It should support transactions spanning multiple hibernate sessions.&lt;div&gt;
&lt;div&gt;Distributed transaction is piece of cake when the application runs in the container. Datasources can be configured in the application server and be bound to JNDI tree. UserTransaction is also available in the JNDI tree. Application code just uses the JTA interface, UserTransaction, for transaction demarcation.&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;Lets have a quick look at how this is done in the application code. Then we will see how to unit test this code layer, that participate in distributed transaction, outside the container.&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Configure XA datasources in application server with JNDI name say ds1 &amp;amp; ds2. You can either use admin console provided by the application server or update server specific datasource configuration file.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Configure two hibernate session factory, one for each datasource.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;
&lt;/div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;one_hibernate.cfg.xml for datasource: &lt;property name=&quot;hibernate.connection.datasource&quot;&gt;ds1&lt;/property&gt;&lt;/div&gt;&lt;div&gt;two_hibernate.cfg.xml for datasource: &lt;property name=&quot;hibernate.connection.datasource&quot;&gt;ds2&lt;/property&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;property name=&quot;hibernate.connection.datasource&quot;&gt;&lt;/property&gt;&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;Code in my Hibernate Util class:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;blockquote&gt;SessionFactory sessionFactory = new Configuration().configure(&quot;/one_hibernate.cfg.xml&quot;).buildSessionFactory();&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;static_sessionFactory_Map.put(&quot;DS_ONE&quot;, sessionFactory);&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;sessionFactory = new Configuration().configure(&quot;/two_hibernate.cfg.xml&quot;).buildSessionFactory();&lt;/div&gt;&lt;div&gt;static_sessionFactory_Map.put(&quot;DS_TWO&quot;, sessionFactory);&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Add transactional properties to hibernate.cfg.xml. I am using JBoss Application Server.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&amp;lt;property name=&quot;hibernate.current_session_context_class&quot;&amp;gt;jta&amp;lt;/property&amp;gt;
&lt;/div&gt;&lt;div&gt;&amp;lt;property name=&quot;hibernate.transaction.factory_class&quot;&amp;gt;org.hibernate.transaction.JTATransactionFactory&amp;lt;/property&amp;gt;
&lt;/div&gt;&lt;div&gt;&amp;lt;property name=&quot;hibernate.transaction.manager_lookup_class&quot;&amp;gt;org.hibernate.transaction.JBossTransactionManagerLookup&amp;lt;/property&amp;gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;
&lt;ul&gt;&lt;li&gt;Add transaction demarcation at business layer. Code in the business component typically would look like below&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;InitialContext ic = new InitialContext();&lt;/div&gt;&lt;div&gt;UserTransaction ut = (javax.transaction.UserTransaction) ic.lookup(&quot;UserTransaction&quot;);&lt;/div&gt;&lt;/div&gt;&lt;div&gt;try&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;ut.begin();&lt;/div&gt;&lt;div&gt;  //invoke dao that uses ds1&lt;/div&gt;&lt;div&gt;  //send xa jms messages&lt;/div&gt;&lt;div&gt;  //run some other business logic&lt;/div&gt;&lt;div&gt;  //invoke dao that uses ds2&lt;/div&gt;&lt;div&gt;  //etc etc&lt;/div&gt;&lt;div&gt;  ut.commit();&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;catch(SomeException ex)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;  ut.rollback();&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;So we are all set. Code will nicely handle distributed transactions! Now challenge here is: how to write junit tests to test this application outside the server container. How do we make JNDI datasources, UserTransaction, Transaction context available to the code? We need a standalone Transaction Manager. Junit tests need setup code to bind datasources and UserTransaction object. Lets go step by step.&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Configure hibernate to use &lt;a href=&quot;http://docs.codehaus.org/display/BTM/Hibernate&quot;&gt;Bitronix&lt;/a&gt; Transaction Manager&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&amp;lt;property name=&quot;hibernate.current_session_context_class&quot;&amp;gt;jta&amp;lt;/property&amp;gt;
&lt;/div&gt;&lt;div&gt;&amp;lt;property name=&quot;hibernate.transaction.factory_class&quot;&amp;gt;org.hibernate.transaction.JTATransactionFactory&amp;lt;/property&amp;gt;
&lt;/div&gt;&lt;div&gt;&amp;lt;property name=&quot;hibernate.transaction.manager_lookup_class&quot;&amp;gt;custom.lookup.manager.see.bitronix.doc&amp;lt;/property&amp;gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Use &lt;a href=&quot;http://directory.apache.org/subprojects/naming&quot;&gt;Apache Naming&lt;/a&gt; in-memory JNDI service provider to bind the resources&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;Setup code in junit tests:&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;System.setProperty(Context.INITIAL_CONTEXT_FACTORY, &quot;org.apache.naming.java.javaURLContextFactory&quot;);&lt;/div&gt;&lt;div&gt;System.setProperty(Context.URL_PKG_PREFIXES, &quot;org.apache.naming&quot;);&lt;/div&gt;&lt;div&gt;InitialContext ic = new InitialContext();&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;//create and bind datasources. We are using Oracle database server&lt;/div&gt;&lt;div&gt;OracleConnectionPoolDataSource ds = new OracleConnectionPoolDataSource();&lt;/div&gt;&lt;div&gt;ds.setURL(&quot;jdbc:oracle:thin:@host:port:sid1&quot;);&lt;/div&gt;&lt;div&gt;ds.setUser(&quot;username&quot;);&lt;/div&gt;&lt;div&gt;ds.setPassword(&quot;password&quot;);&lt;/div&gt;&lt;div&gt;ic.rebind(&quot;ds1&quot;, ds);&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;ds = new OracleConnectionPoolDataSource();&lt;/div&gt;&lt;div&gt;ds.setURL(&quot;jdbc:oracle:thin:@host:port:sid2&quot;);&lt;/div&gt;&lt;div&gt;ds.setUser(&quot;username&quot;);&lt;/div&gt;&lt;div&gt;ds.setPassword(&quot;password&quot;);&lt;/div&gt;&lt;div&gt;ic.rebind(&quot;ds2&quot;, ds);&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;//we are using bitronix.tm.TransactionManagerServices&lt;/div&gt;&lt;div&gt;UserTransaction userTransaction = TransactionManagerServices.getTransactionManager();&lt;/div&gt;&lt;div&gt;ic.rebind(&quot;UserTransaction&quot;, userTransaction);

&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;All set! Just write junit tests to test business methods&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;public void testBuzApi()&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;  MyBizClass bizObj = new MyBizClass();&lt;/div&gt;&lt;div&gt;  SomeObject retObj = bizObj.myMethodOne();&lt;/div&gt;&lt;div&gt;  //some assertXXX(.....);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;Looks like its not a challenging task to unit test java EE code, right. We just need to provide all the resources application code expect while running in a server container.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://eee94180.blogspot.com/2009/08/unit-test-java-ee-code-outside.html</link><author>noreply@blogger.com (adey)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7064760583138976546.post-6983208968153538488</guid><pubDate>Sat, 22 Nov 2008 14:34:00 +0000</pubDate><atom:updated>2008-11-23T12:15:45.929+05:30</atom:updated><title>Leverage FlexSession to secure java based amf destination</title><description>&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;Flex is gaining popularity in enterprise world. Authentication &amp;amp; authorization are common requirement of an enterprise application. To achieve this we often provide a login screen as the entry point to the application. Login screen validates user&#39;s credentials and based on role user will see various menu options and screens. &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;Typical flex application consists of one or more swf file hosted on the net and remote service deployed as amf destinations. Using flex remoting application can talk to various backend systems based on ColdFusion, java etc. &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;So where is the question of security. Flex app won&#39;t let you in unless you login to the application and flex app would let you perform only those operations available to your role.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;Lets see how a java based remote object would look like. Before that lets consider this requirement&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;Two type of user: Read Only User &amp;amp; R/W user&lt;/span&gt;
&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;Read-only user can see data on a screen&lt;/span&gt;
&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;Read/Write user can read as well as update data on that screen&lt;/span&gt;
&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;So, java backend class will have 3 main API exposed via remoting &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;public User login(String username, String password) throws AuthException&lt;/span&gt;
&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;public MyData getData() &lt;/span&gt;
&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;public void updateData(MyData data)&lt;/span&gt;
&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;Login screen makes remote call to login() API to validate credentials and get users detail including roles. Based on role UI shows/hides the Update button to view/update data on post login screen.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;Everything looks good but note that all the above 3 APIs are publicly exposed! Its very easy to forget about the fact that any remoting client, knowing the call details, will be able to invoke any of those exposed APIs. Thats where flex session would be useful to secure the APIs. Let see code snippet to get better picture.&lt;/span&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;public User login(String username, String password) throws AuthException
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;User user = myBusObj.login(username, password);
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;registerSession(user);
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;public MyData getData() throws AuthException
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;checkSession(reqRole);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;return myBusObj.getData();
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:verdana;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:Georgia;&quot;&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;public void updateData(MyData data) throws AuthException
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;checkSession(reqRole);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;return myBusObj.updateData(data);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;private void registerSession(User user)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;FlexContext.getFlexSession().setAttribute(&quot;AUTH_USER&quot;, user);&lt;/div&gt;&lt;div&gt;}
&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;private void checkSession(String reqRole)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre; &quot;&gt; &lt;/span&gt;if(FlexContext.getFlexSession() == null || &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;FlexContext.getFlexSession().getAttribute(&quot;AUTH_USER&quot;) == null || &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;FlexContext.getFlexSession().getAttribute(&quot;AUTH_LEVEL&quot;) == null) throw new &lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:verdana;&quot;&gt;AuthException&lt;/span&gt;(&quot;some error message&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//check users role and compare with reqRole. if req role not present throw auth exception&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;With the above code in place, remote APIs can only called by authenticated &amp;amp; authorized clients. Find more detail on &lt;a href=&quot;http://livedocs.adobe.com/flex/2/fds2javadoc/flex/messaging/FlexSession.html&quot;&gt;Flex Session here&lt;/a&gt;. &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://eee94180.blogspot.com/2008/11/leverage-flexsession-to-secure-java.html</link><author>noreply@blogger.com (adey)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7064760583138976546.post-8842949998094708485</guid><pubDate>Sat, 06 Sep 2008 14:23:00 +0000</pubDate><atom:updated>2008-09-06T22:07:26.590+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">ColdFusion</category><category domain="http://www.blogger.com/atom/ns#">Web Service</category><title>How to invoke web service with complex arguments in ColdFusion</title><description>&lt;div&gt;Here is an &lt;a href=&quot;http://tjordahl.blogspot.com/2008/04/reprint-consuming-web-service-complex.html&quot;&gt;excellent article&lt;/a&gt; describing how we can call web service with complex input arguments in ColdFusion. If you are well versed in WSDL, it may be easier to figure out and construct the input parameter as struct, array and simple types.&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;I am not good at understanding the WSDL and easily mapping those complex types to CF struct of array of struct of... Lets see if we have alternative ways to deal with the complex types.&lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;Lets try to consume the web service described by below WSDL:
&lt;textarea rows=&quot;10&quot; cols=&quot;50&quot; style=&quot;margin-left: 0px; margin-right: 0px; width: 637px; margin-top: 1px; margin-bottom: 1px; height: 174px; &quot;&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;wsdl:definitions targetnamespace=&quot;urn:MyWebService&quot; apachesoap=&quot;http://xml.apache.org/xml-soap&quot; impl=&quot;urn:MyWebService&quot; intf=&quot;urn:MyWebService&quot; soapenc=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; tns2=&quot;http://vo.test.com&quot; wsdl=&quot;http://schemas.xmlsoap.org/wsdl/&quot; wsdlsoap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;&lt;!--WSDL created by Apache Axis version: 1.2.1Built on Jun 14, 2005 (09:15:57 EDT)--&gt; &lt;wsdl:types&gt;  &lt;schema targetnamespace=&quot;http://vo.test.com&quot; xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;   &lt;import namespace=&quot;urn:MyWebService&quot;&gt;   &lt;import namespace=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;&gt;   &lt;complextype name=&quot;Address&quot;&gt;    &lt;sequence&gt;     &lt;element name=&quot;address1&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;address2&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;city&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;country&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;pincode&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;state&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;    &lt;/sequence&gt;   &lt;/complextype&gt;   &lt;complextype name=&quot;Account&quot;&gt;    &lt;sequence&gt;     &lt;element name=&quot;accountNumber&quot; type=&quot;xsd:long&quot;&gt;     &lt;element name=&quot;billingAddress&quot; nillable=&quot;true&quot; type=&quot;tns2:Address&quot;&gt;     &lt;element name=&quot;email&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;firstName&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;lastName&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;mailingAddress&quot; nillable=&quot;true&quot; type=&quot;tns2:Address&quot;&gt;     &lt;element name=&quot;phoneNumber&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;shippingAddress&quot; nillable=&quot;true&quot; type=&quot;tns2:Address&quot;&gt;    &lt;/sequence&gt;   &lt;/complextype&gt;   &lt;complextype name=&quot;Product&quot;&gt;    &lt;sequence&gt;     &lt;element name=&quot;productName&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;productNumber&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;quality&quot; type=&quot;xsd:double&quot;&gt;     &lt;element name=&quot;unitPrice&quot; type=&quot;xsd:double&quot;&gt;    &lt;/sequence&gt;   &lt;/complextype&gt;   &lt;complextype name=&quot;Invoice&quot;&gt;    &lt;sequence&gt;     &lt;element name=&quot;currency&quot; nillable=&quot;true&quot; type=&quot;soapenc:string&quot;&gt;     &lt;element name=&quot;customer&quot; nillable=&quot;true&quot; type=&quot;tns2:Account&quot;&gt;     &lt;element name=&quot;products&quot; nillable=&quot;true&quot; type=&quot;impl:ArrayOf_tns2_Product&quot;&gt;     &lt;element name=&quot;subTotal&quot; type=&quot;xsd:double&quot;&gt;     &lt;element name=&quot;tax&quot; type=&quot;xsd:double&quot;&gt;     &lt;element name=&quot;total&quot; type=&quot;xsd:double&quot;&gt;    &lt;/sequence&gt;   &lt;/complextype&gt;  &lt;/schema&gt;  &lt;schema targetnamespace=&quot;urn:MyWebService&quot; xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;   &lt;import namespace=&quot;http://vo.test.com&quot;&gt;   &lt;import namespace=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;&gt;   &lt;complextype name=&quot;ArrayOf_tns2_Product&quot;&gt;    &lt;complexcontent&gt;     &lt;restriction base=&quot;soapenc:Array&quot;&gt;      &lt;attribute ref=&quot;soapenc:arrayType&quot; arraytype=&quot;tns2:Product[]&quot;&gt;     &lt;/restriction&gt;    &lt;/complexcontent&gt;   &lt;/complextype&gt;  &lt;/schema&gt; &lt;/wsdl:types&gt;   &lt;wsdl:message name=&quot;createInvoiceRequest&quot;&gt;      &lt;wsdl:part name=&quot;invoice&quot; type=&quot;tns2:Invoice&quot;&gt;   &lt;/wsdl:message&gt;   &lt;wsdl:message name=&quot;createInvoiceResponse&quot;&gt;      &lt;wsdl:part name=&quot;createInvoiceReturn&quot; type=&quot;tns2:Invoice&quot;&gt;   &lt;/wsdl:message&gt;   &lt;wsdl:porttype name=&quot;MyWebService&quot;&gt;      &lt;wsdl:operation name=&quot;createInvoice&quot; parameterorder=&quot;invoice&quot;&gt;         &lt;wsdl:input message=&quot;impl:createInvoiceRequest&quot; name=&quot;createInvoiceRequest&quot;&gt;         &lt;wsdl:output message=&quot;impl:createInvoiceResponse&quot; name=&quot;createInvoiceResponse&quot;&gt;      &lt;/wsdl:operation&gt;   &lt;/wsdl:portType&gt;   &lt;wsdl:binding name=&quot;MyWebServiceSoapBinding&quot; type=&quot;impl:MyWebService&quot;&gt;      &lt;wsdlsoap:binding style=&quot;rpc&quot; transport=&quot;http://schemas.xmlsoap.org/soap/http&quot;&gt;      &lt;wsdl:operation name=&quot;createInvoice&quot;&gt;         &lt;wsdlsoap:operation soapaction=&quot;&quot;&gt;         &lt;wsdl:input name=&quot;createInvoiceRequest&quot;&gt;            &lt;wsdlsoap:body encodingstyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; namespace=&quot;urn:MyWebService&quot; use=&quot;encoded&quot;&gt;         &lt;/wsdl:input&gt;         &lt;wsdl:output name=&quot;createInvoiceResponse&quot;&gt;            &lt;wsdlsoap:body encodingstyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; namespace=&quot;urn:MyWebService&quot; use=&quot;encoded&quot;&gt;         &lt;/wsdl:output&gt;      &lt;/wsdl:operation&gt;   &lt;/wsdl:binding&gt;   &lt;wsdl:service name=&quot;MyWebServiceService&quot;&gt;      &lt;wsdl:port binding=&quot;impl:MyWebServiceSoapBinding&quot; name=&quot;MyWebService&quot;&gt;         &lt;wsdlsoap:address location=&quot;http://myserver/myendpoint/MyWebService&quot;&gt;      &lt;/wsdl:port&gt;   &lt;/wsdl:service&gt;&lt;/wsdl:definitions&gt;&lt;/textarea&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: auto;&quot;&gt;
&lt;/div&gt;&lt;div&gt;Dumping the webservice object will clearly show Method=createInvoice(com.test.vo.Invoice) and Return Type=com.test.vo.Invoice &lt;/div&gt;&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;   &amp;lt;cfdump var=&quot;#createObject(&#39;webservice&#39;, &#39;http://myhost/above_test.wsdl&#39;)#&quot;&amp;gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;
Won&#39;t it be nice if we can just populate the value object Invoice and pass it the createInvoice() method? 
But when I try to create an instance of com.test.vo.Invoice using createObject(&#39;java&#39;, &#39;com.test.vo.Invoice&#39;), it throws Object Instantiation Exception. ColdFusion does like the idea of creating objects of axis generated classes? 
No problem. We can still load these classes using Axis class loader (may not be a good idea though).
&lt;/div&gt;

&lt;div&gt;
&lt;pre&gt;
&amp;lt;cfset ws = createObject(&#39;webservice&#39;, &#39;http://adey03/java/testws.wsdl&#39;) /&amp;gt;&lt;br&gt;
&amp;lt;cfset invoice = ws.getClass().getClassLoader().loadClass(&amp;quot;com.test.vo.Invoice&amp;quot;).newInstance() /&amp;gt;&lt;br&gt;
&amp;lt;cfdump var=&amp;quot;#invoice#&amp;quot;&amp;gt;&lt;br&gt;
...&lt;br&gt;
&amp;lt;cfset account= ws.getClass().getClassLoader().loadClass(&amp;quot;com.test.vo.Account&amp;quot;).newInstance() /&amp;gt;&lt;br&gt;
&amp;lt;cfdump var=&amp;quot;#account#&amp;quot;&amp;gt;&lt;br&gt;
...&lt;br&gt;
&amp;lt;cfset address= ws.getClass().getClassLoader().loadClass(&amp;quot;com.test.vo.Address&amp;quot;).newInstance() /&amp;gt;&lt;br&gt;
&amp;lt;cfdump var=&amp;quot;#address#&amp;quot;&amp;gt;&lt;br&gt;
...&lt;br&gt;
&amp;lt;cfset product= ws.getClass().getClassLoader().loadClass(&amp;quot;com.test.vo.Product&amp;quot;).newInstance() /&amp;gt;&lt;br&gt;
&amp;lt;cfdump var=&amp;quot;#product#&amp;quot;&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;Above code will clearly describe the composite objects like Invoice, Account etc. So we just need to follow simple steps after that: &lt;/div&gt;&lt;div&gt;-create and populate Address, Account, Product &lt;/div&gt;&lt;div&gt;-create and populate Invoice &lt;/div&gt;&lt;div&gt;-call the web service method createInvoice() and pass the invoice object created above.  &lt;/div&gt;&lt;div&gt;
&lt;/div&gt;&lt;div&gt;Isn&#39;t it little more object oriented than struct of array of struct of...:-)
&lt;/div&gt;</description><link>http://eee94180.blogspot.com/2008/09/how-to-invoke-web-service-with-complex.html</link><author>noreply@blogger.com (adey)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7064760583138976546.post-2033019992940762347</guid><pubDate>Thu, 04 Sep 2008 17:58:00 +0000</pubDate><atom:updated>2008-09-06T11:37:09.024+05:30</atom:updated><title>JavaScript : form.submit is not a function</title><description>&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;border-collapse: separate; color: rgb(255, 0, 0);   font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;font-size:10px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;I was just trying to submit an HTML form using document.formname.submit() method and was getting these error on different browser.

&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(255, 153, 102);&quot;&gt;document.formname.submit is not a function
Uncaught TypeError: Property &#39;submit&#39; of object #HTMLForm element is not a function
&lt;/span&gt;&lt;/span&gt;
Thats weird! It worked all the time. I was clueless why JavaScript would behave like this...?

Yeah, that was a silly mistake. I didn&#39;t realize that I named the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;submit button as &#39;submit&#39;&lt;/span&gt; and that why javascript is failing. We may do this kind of mistakes every now and then...&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;   style=&quot;border-collapse: separate; color: rgb(255, 0, 0);   font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;font-family:Monaco;font-size:10px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;</description><link>http://eee94180.blogspot.com/2008/09/javascript-formsubmit-is-not-function.html</link><author>noreply@blogger.com (adey)</author><thr:total>8</thr:total></item></channel></rss>