Using BPEL process to Read a file over the HTTP / Web (A Remote Location) .... ex : http://ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf
To do this you would need to use Java Embedding in your BPEL process. (To read the URL and get the data in base64 format). We will later right the read file into a file and aswell as into a table (with BLOB column for the read file) using DB adapter
Pre-Setup:
==========
(1) Set Transaction time out parameter in 3 places
A.1.1 Setting Properties for BPEL Processes to Successfully Complete and Catch Exception Errors
The values to which you set the transaction-timeout and syncMaxWaitTime properties can impact whether a transaction scope successfully completes or times out and catches exception errors. For example, assume you have two processes:
* TimeoutSubprocess (A synchronous detail process that includes a wait activity set to three minutes)
* TimeoutMainProcess (An asynchronous main process that calls the TimeoutSubprocess)
If syncMaxWaitTime is set to 45 seconds (the default value) and transaction-timeout is set to 30 seconds, after 45 seconds the main process continues running and does not successfully complete and catch the following exception error as expected:
com.oracle.bpel.client.delivery.ReceiveTimeOutException
In the domain.log file, the following exception error displays:
An exception occurred during transaction completion:; nested exception is:
javax.transaction.RollbackException: Timed out
javax.transaction.RollbackException: Timed out
Perform the following procedures for the main process to successfully complete and catch the exception error.
A. Property: transaction-timeout
File Location: SOA_Oracle_Home\j2ee\home\config\transaction-manager.xml
Value to be set to: Larger than the transaction-timeout value in orion-ejb-jar.xml and the syncMaxWaitTime value
Example: 7200
B. Property: transaction-timeout (every transaction-timeout parameter in this file)
File Location: SOA_Oracle_Home\j2ee\home\application-deployments\orabpel\ejb_ob_engine\orion-ejb-jar.xml
Value to be set to: Less than the transaction-timeout value in transaction-manager.xml.
Example: 3600
C. Property: syncMaxWaitTime
File Location: SOA_Oracle_Home\bpel\domains\domain_name\config\domain.xml , where domain_name is the name of the domain to which you are deploying.
Value to be set to: Less than the transaction-timeout value in orion-ejb-jar.xml.
Example: 300
This causes the main process to successfully complete and catch the exception error.
(2) Set Transaction type as not 'Global' in while creating the datasources (JNDI Entry)
(3) add SetBigStringTryBlob = true property to connection pool
eg:
<connection-pool name="MY_POOL" connection-retry-interval="5" max-connect-attempts="30" min-connections="10" SetBigStringTryBlob="true">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="user" password="password" url="jdbc:oracle:thin:@//myserver:1521/myservice" commit-record-table-name=""/>
</connection-pool>
(4) Has to be async process
(5) while writing the data into BLOB , the data has to be in base64 binary format.
===================================
Java Embedding :
import these in the bpel code:
<bpelx:exec import="java.util.*"/>
<bpelx:exec import="java.io.*"/>
<bpelx:exec import="java.lang.*"/>
<bpelx:exec import="java.math.*"/>
<bpelx:exec import="java.net.*"/>
<bpelx:exec import="com.collaxa.common.util.Base64Decoder"/>
<bpelx:exec import="com.collaxa.common.util.Base64Encoder"/>
write this java code in the Java Embedding block:
try{
URL u = new URL("http://ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf");
URLConnection uc = u.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
InputStream raw = uc.getInputStream();
InputStream in = new BufferedInputStream(raw);
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength) {
bytesRead = in.read(data, offset, data.length - offset);
if (bytesRead == -1)
break;
offset += bytesRead;
}
in.close();
if (offset != contentLength) {
throw new IOException("Only read " + offset + " bytes; Expected " + contentLength + " bytes");
}
// String filename = u.getFile().substring(filename.lastIndexOf('/') + 1);
String filename = "C:\\Projects\\Tests\\TestFile.pdf";
FileOutputStream out = new FileOutputStream(filename);
out.write(data);
out.flush();
out.close();
Base64Encoder Encoder = new Base64Encoder();
String encodedString = Base64Encoder.encode(data);
setVariableData("BLOBPayload",encodedString);
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
===============================
Crate a table where you want to insert the data with a BLOB column type and insert into this table using the DB adapter.
===================
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment