Sunday, August 27, 2017

XPath. One with the clingy attributes


Hi there. Winter is coming, just not today. Because today it's raining cats, dogs and gators; High Florida season is on his way and I have time for the another little trinket. It's based on the same data types we have played around with apples and oranges. It's not exactly related. but I've reused XML Schema to show you a little side effect of the XPath selector. You have run into that if you use strict type validation for each and every activity in your process, but I bet you don't. It's pretty normal to validate data on the edges, in the BPEL case - check the service input and make sure that you produce the response, that composite's clients expect to have.

 This minimalistic composite has only a few steps, but can simulate behavior we need:

  • Check Incoming XML document (using partner link property)
  • Perform XPath query by attribute value
  • Validate output  variable
  • Return response
The one truly interesting activity here is the assign SetResponse. Let's take a look into source code:
<assign name="SetResponse">
<copy>
 <from>
  <literal>
   <GroceryList xmlns="http://mmikhail.com/sample/xml/Orchard">
    <Item Name="Apples" Type="bushel">1</Item>
    <Item NMame="Pears" Type="pound">4</Item>
   </GroceryList>
  </literal>
 </from>
 <to expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0">$VariableWitthAttributes</to>
</copy>
<copy>
 <from>$VariableWitthAttributes/ns2:Item[@Name="Apples"]</from>
 <to expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0">$outputVariable.payload/client:response</to>
</copy>
</assign>

Activity populates variable with the array of the element Item. You can select Item from the list either by index or by attribute name. That's exactly what the second copy does.  It selects Item value with the attribute Name equal to "Apples". Nothing fancy so far, good old XPath expressions and assignments. The CheckOutput activity validates output message against XML Schema.  It's a string and we do not expect any traps here. Le'ts compile, deploy and test the process.

Ouch, validation failed with the error message:

<bpelFault>
 <faultType>0</faultType>
 <invalidVariables xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
  <part name="summary">
   <summary>Failed to validate bpel variable.
Validation of variable outputVariable failed.
The reason was: Attribute 'Name' not expected.
Please handle the exception in bpel.</summary>
  </part>
 </invalidVariables>
</bpelFault>

And if you check the assign activity you'll see that all element attributes have traversed to the target variable. I bet it's not exactly what you have expected to see, but you do and it's the same for 12c and 11g. The solution is quite simple, just slightly modify selector for instance:

 <from>string($VariableWitthAttributes/ns2:Item[@Name="Apples"])</from>

Now composite works exactly as expected.

It looks like nothing, but think about it:
You have selected something by one attribute, but in fact, you have exposed not only this one but all of them and they may contain some sensitive information, like dates, user names, entity IDs and so on.
Hope it will help you to build more reliable and secure applications. Good luck with that.



Tuesday, August 22, 2017

Ant: instant property file


Good time of the day my patient readers. Yesterday among the millions I saw the second big solar eclipse in my life. The first one I've watched through the soot-covered glass, this one I observed one through the DVR-R disk. The benefits of the progress as they are, aren't they?

Today I'm going show you a little workaround for the situation when you need a property file, but you can't afford it or don't want to keep sensitive information in the plain-text file on the file system. I have run into such issue with the SOA test automation. Oracle offers a set of the Ant tasks for the build, deploy, and test composites. Although, test task requires JNDI properties in form of the property file.

You could create such files one for every target environment, but I foresee without a crystal ball your administrators and security team will be quite unhappy with that. I have tried to substitute the properties from the file, but it doesn't work at all. Test task still wants to read property file.
The next my thought was: if I can't store the file, but I need one, what if I create one at run-time and drop it when the task is completed. So there are such Ant commands and it works with the SOA automation just fine.

<!-- create temporary file for the JNDI propeties -->
<tempfile property="jndi.properties" prefix="jndi" 
                  suffix=".properties" deleteonexit="true"/>
      
<!-- Add properties to the temporary file -->      
<propertyfile file="${jndi.properties}">
 <entry key="java.naming.factory.initial"
                   value="weblogic.jndi.WLInitialContextFactory"/>
 <entry key="java.naming.provider.url"
                   value='${test.target.url}/soa-infra'/>
 <entry key="java.naming.security.principal" value="${user}"/>
 <entry key="java.naming.security.credentials" value="${password}"/>
 <entry key="dedicated.connection" value="true"/>
 <entry key="dedicated.rmicontext" value="true"/>
</propertyfile>  

The task tempfile creates a new empty file. You can specify prefix and suffix and some other attributes, Task updates or creates the specified property (jndi.property in the example) with the file name and path as a value. The attribute deleteonexit helps you with the temporary file elimination.Temporary file disappears when the task is done.

The propertyfile task populates our temporary file with the properties. Task writes all its' children entries to the file. Don't forget to check task documentation, it can do country mile more than just store properties in the files.

Now you can use your temporary property file as a parameter for the SOA test tasks or for any other purposes where you need one.

Wednesday, August 16, 2017

Github: unexpected news


It's a great day for me. It's turned out that someone uses my Github repositories.
While ago I've created an Oracle-free version of FOP servlet for Apex application reports. The reason why I've created the code was simple. Naturally, I've blogged all the details and it's one of the most visited publications of mine. At the same time, servlet repository has not been used at all or I used to think so. Now I know that at least one more person, who has found this project useful. Please meet Roger Pilkey, who is so kind that he has adopted my doodles and developed new servlet for the latest Apache FOP version.
After such unexpectable and invaluable input, I have to upgrade project itself.  The major changes are:
  • Project structure has been reconfigured to use with the Apache Maven 
  • JSP page uses the latest FOP code to generate PDF response
  • Lifted index.html (with a brief description and sample form to test application)
  • Updated README.md with some project information. 
I guess it's hard to find the Apex installation with no Oracle REST Database Services installed, but if you are the happy owner of such system - you may find it useful.