Monday, November 18, 2013

Drop all user tables in Oracle


Simple anonymous code segment clear your DB!

BEGIN
   FOR cur_rec IN (SELECT object_name, object_type
                     FROM user_objects
                    WHERE object_type IN
                             ('TABLE',
                              'VIEW',
                              'PACKAGE',
                              'PROCEDURE',
                              'FUNCTION',
                              'SEQUENCE'
                             ))
   LOOP
      BEGIN
         IF cur_rec.object_type = 'TABLE'
         THEN
            EXECUTE IMMEDIATE    'DROP '
                              || cur_rec.object_type
                              || ' "'
                              || cur_rec.object_name
                              || '" CASCADE CONSTRAINTS';
         ELSE
            EXECUTE IMMEDIATE    'DROP '
                              || cur_rec.object_type
                              || ' "'
                              || cur_rec.object_name
                              || '"';
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line (   'FAILED: DROP '
                                  || cur_rec.object_type
                                  || ' "'
                                  || cur_rec.object_name
                                  || '"'
                                 );
      END;
   END LOOP;
END;
/

Monday, November 4, 2013

JMS Correlation ID in WSO2 ESB


You can retrieve original message id from the $header Synapse XPath expression and set it as the JMS_COORELATION_ID property in your message flow. That'll set as the correlation id of the underline JMS message.

<property name="JMS_COORELATION_ID" action="set" scope="axis2" expression="$header/wsa:MessageID" xmlns:wsa="http://www.w3.org/2005/08/addressing"/>

You'll need to define the Xpath appropriately to make sure that it address the both SOAP 1.1 and 1.2 messages.

Or else you can work around it in following method aslo.

1) In the request sequence we grab the message id:
 <property name="msgID" expression="get-property('MessageID')" />
2) In the response sequence we set the correlation id using:
 < roperty name="JMS_COORELATION_ID" expression="get-property('msgID')" scope="axis2" />






Saturday, November 2, 2013

Upload a file Using JSP

This demonstration will guide you, how to upload a file into folder (you can define the path) using JSP.

Pre-Request

Application server - I am using Wso2 Application Server. Since it is very user friendly to configure and mange my application using cool user interfaces.

Further Readings,
[1]http://wso2.org/library/articles/2012/10/getting-full-features-apache-tomcat-supported-wso2-application-server
[2] http://docs.wso2.org/wiki/display/AS510/Installation+Guide

Maven - As build tool i am using.

Further Readings,
[1] http://vanjikumaran.blogspot.com/2013/04/installing-maven-and-ant-in-ubuntu.html

let see the codes
<%--
Created by IntelliJ IDEA.
User: vanji
Date: 6/22/13
Time: 2:18 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.io.*,java.util.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="org.apache.commons.fileupload.disk.*" %>
<%@ page import="org.apache.commons.fileupload.servlet.*" %>
<%
int MAX_MEMORY_SIZE = 1024 * 1024 * 2;
final int MAX_REQUEST_SIZE = 1024 * 1024;
DiskFileItemFactory factory = new DiskFileItemFactory();
// Sets the size threshold beyond which files are written directly to disk.
factory.setSizeThreshold(MAX_MEMORY_SIZE);
// Sets the directory used to temporarily store files that are larger
// than the configured size threshold. We use temporary directory for java
factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
// constructs the folder where uploaded file will be stored
String uploadFolder = "/home/vanjikumaran/Area51/IN";
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Set overall request size constraint
upload.setSizeMax(MAX_REQUEST_SIZE);
try {
// Parse the request
List items = upload.parseRequest(request);
for (Object item1 : items) {
FileItem item = (FileItem) item1;
if (!item.isFormField()) {
String fileName = new File(item.getName()).getName();
String filePath = uploadFolder + File.separator + fileName;
File uploadedFile = new File(filePath);
// saves the file to upload directory
item.write(uploadedFile);
}
}
response.sendRedirect("success.jsp");
} catch (Exception e) {
response.sendRedirect("errorPage.jsp");
}
%>
<html>
<head>
<title>File Processor</title>
</head>
<body>
system currently processing the file
</body>
</html>



<%--
Created by IntelliJ IDEA.
User: vanji
Date: 6/22/13
Time: 2:07 PM
This example is demonstrate how to upload a file into given location of the server
--%>
<html lang="en">
<head>
<title>File Uploading Form</title>
</head>
<body>
<div>
<h1>Batch Order Upload</h1>
<form action="batch_Order_Process.jsp" method="post" enctype="multipart/form-data">
<ul>
<h3>File Upload:</h3>
Select a file to upload: <br />
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</ul>
</form>
</div>
</body>
</html>
view raw index.jsp hosted with ❤ by GitHub

Friday, November 1, 2013

Multicast based Clustering With deployment Systematization

In current competitive enterprise environment, integration is playing very important role. Using integration systems are not going to improve the environment, Unless Having right pattern and solution. Having said that, making integration platform in a high availability manner is make more meaningful to scale your enterprise.

In this blog, I am explaining how to make the Carbon 4.2.0 based products in high available manner and how to synchronize the deployment a cross the same products. Furthermore, in this example I have taken WSO2 DSS as product to experiment this feature. You can download this in official website of the WSO2 for free of charge!

Lets have look at the illustrated deployment pattern, I have deployed DSS in 3 diffident machines(Nodes). Important to note is, i have not create Master/Salve setup. Each and every node are in peer to peer way.  All the servers are load balanced by external hardware based "F5 Load Balancer  and inside the Demilitarized Zone(DMZ).


Deployment Diagram

Lets take a step into configuration to understand, How to implement above scenario! 

Step 1 - Downloaded a product into any one of the box and started and shutdown to testing purpose.

Step 2 - Since I have 3 different machine to configure and i wont to use the my domain name instant of localhost/127.0.0.1!!! There for  i used a simple script to replace the values with in "conf" directory.
example - find ./ -type f -exec sed -i 's/localhost/box1.vanji.com/g' {} \;


Step 3 - Configure deployment synchronization in  /repository/conf/carbon.xml
 To understand further on SVN based Deployment synchronization, refer  [1]

Step 4 - Configure registry to maintain the metadata across the all three nodes. Refer further on [2]

Step 5 - Configure User Store to cater external user store. Refer further on [3]

Step 6 - Configure /repository/conf/axis2/axis2.xml to cluster the system.
This step is very important to understand! We are enabling the clustering in multicast mode! Let see the config .
  • In Line 2, I have enabled the clustering
  • In Line 5, I have mentioned "membershipScheme" as multicast.
  • In line 10, I have mentioned "localMemberHost" as name of my current machine "box1.vanji.com"
  • And more importantly, i have mentioned my other members detail (Line 20)
Note
I have removed the comment in the configuration to compact the config file!


Step 7 - Just Start the server and observe is there any expedition or error due to the configuration. If there is anything resolve the issues. If there is no miss configuration, You will see the carbon log as above.
 Server is waiting for other nodes to start to make the clustering.
So now stop this sever for while and move to step 8.

Step 8 -  Take the copy of this server and copy to other servers and run the find and replace script to change the name.
Example:- find ./ -type f -exec sed -i 's/box1.vanji.com/box2.vanji.com/g' {} \;

Step 9 - Go to /repository/conf/axis2/axis2.xml and make sure Step 6 followed or not in each and every nodes and make sure Members are defined properly!

Step 10 - Time to Start the servers and enjoy the High Available WSO2 Carbon 4.2.0 based server.

[1] http://docs.wso2.org/display/DSS300/Configuring+the+SVN-Based+Deployment+Synchronizer

[2] http://docs.wso2.org/display/ESB470/Governance+Partition+in+a+Remote+Registry

[3] http://docs.wso2.org/display/DSS310/Configuring+External+User+Stores