Monday, August 8, 2016

SOA - Unable to edit file/jms/db adapter; shows red cross mark

Problem:
Migrated composites to the 12c version are unable to be edited, even with the <?binding.jca dbAdapter_db.jca> fix. The adapter is also showing a red cross mark.

Solution:
The solution is provided in this Oracle community post:

Open .jca file for JMS adapter  and change from  adapter="JMS Adapter" to adapter="jms" . If you use database adapter as well , then change from adapter="Database Adapter" to adapter="db". (  ... adapter="File Adapter" to adapter="file")

The adapter is now able to be edited normally.

Wednesday, July 27, 2016

FYI - JMS Polling and Error Queues

FYI:

When polling a JMS queue in OSB, in order for it to go to the configured error queue, an error must be raised. Raising an error and then handling this error won't cause the message to be sent to the error queue. If the error is handled, then a fault must be raised again.

Take this simple proxy service as an example that polls from a JMS queue configured in weblogic and calls a stored procedure to insert the polled record:



EmployeePS Pipeline:



Should an unexpected error occur somewhere in this pipeline, it will be caught by the error handler. The error will be reported in the EM Message Reports but the error is raised again so that it can be sent to the error queue.

Doing a Reply with Failure will NOT send the message to the error queue. As explained by AbhishekJ here:

In case of JMS transport the JMS Queue or Topic will receive a NACK back but the message will NOT roll back and will be removed from the destination just like in case of Reply with Success. This happens because using a Reply action is considered as an exception being handled properly and a commit will be sent back to the JMS destination. To roll back the message ensure that you use Raise Error instead of a Reply action.

Monday, July 25, 2016

Resources: Helpful Weblogic JMS Links

Creating a JMS Server and Queue in Weblogic:
https://blogs.oracle.com/soaproactive/entry/how_to_create_a_simple

Creating a JMS Error Queue:
http://middlewaremagic.com/weblogic/?p=4670

Tuesday, December 8, 2015

BPEL - FTP Adapter writes XML file without prefix in the root element

Problem:

When writing a file using the FTP adapter with the message schema defined, for some reason the output would come out without a prefix in the root element, like so:
















This would happen even with the XSL transformation declaring the prefix in the root element:



I'm not sure if it's a bug or the fact that we have our schema/transformation wrong, but a coworker and I just couldn't get it to work, so we opted for a workaround using Java embedding.

Solution:

We used the following code to add the prefix to the root element by transforming the XML into a string:


 try{   
   oracle.xml.parser.v2.XMLElement responseFile = (oracle.xml.parser.v2.XMLElement)getVariableData("varResponseFile");   
   //setting prefix to root   
   oracle.xml.parser.v2.XMLNode firstChild = (oracle.xml.parser.v2.XMLNode)responseFile.getFirstChild();   
   responseFile.setPrefix(firstChild.getPrefix());   
   //getting xml document   
   oracle.xml.parser.v2.XMLDocument responseFileXML = (oracle.xml.parser.v2.XMLDocument)responseFile.getDocument();   
   //setting prologue   
   responseFileXML.setVersion("1.0");   
   responseFileXML.setEncoding("UTF-8");   
   //writing xml document   
   java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();   
   responseFileXML.print(outputStream );   
   String responseFileString = outputStream.toString();   
   //encode xml document   
   oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();   
   String stringEnconded = null;   
   stringEnconded = encoder.encode(responseFileString);   
   //setting xml encoded   
   setVariableData("encodedBody",stringEnconded);   
 } catch (Exception e) {   
   addAuditTrailEntry("Error encoding Response File: " + e.getMessage());   
   throw new RuntimeException(e);   
 }  

We would of course change the FTP message schema to opaque instead. Applying this code would then write the XML file correctly:



If anyone knows how to do this without Java (or perhaps what we are doing wrong in the first place), please let us know in the comments!

Tuesday, September 29, 2015

DbAdapter - RowSet Column Type Mismatch Error

Problem: 
Invoking an SQL Server stored procedure with the Db Adapter would return the following error:

JCA Binding execute of Reference operation 'dbGetPromotions' failed due to: RowSet Column Type Mismatch Error. The SQL type in the XSD (INT) does not match the SQL type in the RowSet (int identity) for column ReservationID of parameter RowSet0.

This would happen when the DB Adapter would try to return the Output Parameters for the dbGetPromotions operation.

Solution:
Fix the XSD that was generated during the DB Adapter Wizard.

Originally, the XSD had been generated like this:

  <element name="ReservationID" type="int" db:type="INT" minOccurs="0" nillable="true"/>  

However, apparently the db:type needed for the element ReservationID needed to be int identity, so I changed it as follows:

 <element name="ReservationID" type="int" db:type="INT IDENTITY" minOccurs="0" nillable="true"/>  

Usually the same error will tell you what you need to change the db:type to, so just change it accordingly and you're ready to go!

BPEL - Append multiple elements to a list

Problem: I had a list of XML elements like so:
<Messages> <Message Area="RES" Code="Code1"/> <Message Area="RES" Code="Code2"/> <Message Area="RES" Code="Code3"/> </Message>

This is the XSD:


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://danytests.com/soa/bpel-append" targetNamespace="http://danytests.com/soa/bpel-append" elementFormDefault="qualified"> <xsd:element name="Messages" type="MessagesType"> <xsd:annotation> <xsd:documentation>A sample element</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:complexType name="MessagesType"> <xsd:sequence> <xsd:element name="Message" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="Area" type="xsd:string"/> <xsd:attribute name="Code" type="xsd:string"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:schema>
What I needed to do was append more items to the already existing list without affecting the ones that were already in there.

At first what I was doing was adding the new items to add to a BPEL variable ($varMessages) that was also of MessagesType. Then, with another variable ($messageCount), I would assign the count of Messages/Message PLUS 1 to it (so, in this case, it would be 4). In a foreach loop, starting with $messageCount, I would do a simple Copy to Messages/Message[$messageCount] and setting the insertMissingToData flag. This, however, isn't really the right way to go about this.

Solution: Use the BPEL Append action instead of the Copy action.

To accomplish this, I would still have the $varMessages variable assigned with the new items to add, but instead my BPEL assign activity would look like this:


<assign name="appendMessages"> <extensionAssignOperation> <bpelx:append> <bpelx:from>$varMessages/ns1:Message</bpelx:from> <bpelx:to>$outputVariable.payload</bpelx:to> </bpelx:append> </extensionAssignOperation> </assign>

That is, I'd assign the Messages from $varMessages to the final list ($outputVariable) in the Messages complexType.

The results were as expected while looking at it in the audit trail. First I'd assign a Message element to the $outputVariable:



Then I'd add elements to $varMessages:



Finally, after the append action, the output variable's final list would look like this:



Neat!

Monday, April 27, 2015

WS Security - Calling a secured Web Service with nonce from BPEL

Problem:

We had to call a secured web service that required a username token to be sent in the SOAP header, but being a WS Security newbie, I bumped into a lot of issues trying to get it to work. After adding the certificate into the SOA Server trust store, I was getting the following error after applying the oracle/wss_username_token_policy:

oracle.j2ee.ws.client.jaxws.JRFSOAPFaultException: Client received SOAP Fault from server : Exception thrown while trying to deserialize the SOAP message
at oracle.j2ee.ws.client.jaxws.DispatchImpl.throwJAXWSSoapFaultException(DispatchImpl.java:1053)
at oracle.j2ee.ws.client.jaxws.DispatchImpl.invoke(DispatchImpl.java:839)
at oracle.j2ee.ws.client.jaxws.OracleDispatchImpl.synchronousInvocationWithRetry(OracleDispatchImpl.java:235)
at oracle.j2ee.ws.client.jaxws.OracleDispatchImpl.invoke(OracleDispatchImpl.java:106)

After reading this very useful post from the AMIS Technology blog, I was able to attach the WS Security header right into the SOAP message which included the Nonce section, like so:

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <wsse:Username>username</wsse:Username>
      <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
      <wsse:Nonce>Gt0q/QzAnQn/KMzhXYgR8Q==</wsse:Nonce>
   </wsse:UsernameToken>
</wsse:Security>

The call to the web service would now complete successfully since the original policy does not include the nonce, but this isn't the best way to do it since it's hardcoded into the BPEL process and it's just not very dynamic. The other, better way to do it is by using the OWSM policies and the credential store. I won't go too much into detail on how to setup the keystore and the credential store (I will do a follow-up post on this later on), but I will explain how I managed to send a nonce in the header using the policies, which...isn't really that hard at all!

Solution:

1) Go to the Oracle Enterprise Manager.

2) Under the farm name, expand the Weblogic Domain folder and right-click on the name of your domain, then select WebServices -> Policies.


3) Filter the policies by Service Clients and scroll down until you find one called oracle/wss_username_token_policy. This is the policy I attached on the webservice I had to call, but by default, this policy does NOT include the Nonce. Select it and click at the top "Create Like". I created a copy of this policy so I wouldn't mess with the original.

4) Give your policy a name (I named mine oracle/wss_username_token_nonce_policy) and then scroll down to the area that says "Assertions", Under the Settings tab, click "Show Advanced Fields":

5) Check the box that says "Nonce Required" and save your new policy. My web service only required the nonce, but if yours also needs a creation time, then go ahead and click that, too.


6) Now go to your composite, and below the composite name click SOA Composite -> Service/Reference Properties -> Web Service that you are calling




7) Here, click the Policies tab, then under Directly Attached Policies, click Attach/Detach.


8) Look for your new policy, click Attach, then OK.

9) Your policy should now appear under Directly Attached Policies. If you click on it, its information will be displayed under Security Configuration Details, including the csf-key. These are the credentials that the web service sends for the Username and Password. They can be configured in the Credential Store. In my case, since I had configured the basic.credentials with the username and password that the web service required, there was no need to override this value so the Current Value is left as blank.


When I tried the Web Service again, the policy did the same job as manually adding the SOAP header and the composite completed successfully! :)