Getting the size of BLOB in MySql

If you want to store binary in database, you can use BLOB as the data type of that column. In Mysql you can use TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB depending on your space requirement. Here is an example of database table using BLOB as a column type.

    filename VARCHAR( 32 ) NOT NULL,
    content BLOB NOT NULL,
    PRIMARY KEY ( id )

Storing Data


$filename = "myimage.png";
$filecontent = file_get_contents($filename);
$filecontent_escaped = mysql_real_escape_string($filecontent);

$sql = "INSERT INTO BloBTest(filename, content) " +
mysql_query($sql, $link);


String filename = "myimage.png";
InputStream filecontent = new FileInputStream(filename);

String sql = "INSERT INTO BloBTest(filename, content) VALUES(?, ?)";

int size = filecontent.available();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, filename);
ps.setBinaryStream(2, filecontent, size);

Retrieving Data


$sql = "SELECT filename, content FROM BloBTest";
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {

    $filename = $row["filename"];
    $content = $row["content"];
    $new_filename = "new_" . $filename;
    file_put_contents($new_filename, $content);


String sql = "SELECT filename, content FROM BloBTest";

PrepareStatement ps  = conn.prepareStatement(resourceContentSQL);
ResultSet result = ps.executeQuery();

if ({
    String filename = result.getString("filename");
    InputStream contentStream = result.getBinaryStream("content");
    String newFilename = "new_" + filename;
    // storing the input stream in the file

    OutputStream out=new FileOutputStream(newFilename);
    byte buf[]=new byte[1024];
    int len;


Retrieving the Size of the Blob

After you store your data as a blob, you can manipulate or query the data with some of the in-built String functions in mysql. For an example if you want to query the size of the blob you just stored, you can use OCTET_LENGTH function. Here is an example,  (this will give you the size in bytes.)

SELECT OCTET_LENGTH(content) FROM BloBTest WHERE filename='myimage.png'
Posted in database, php, Tutorial/Guide | Tagged , , , , | Leave a comment

Register Today for WSO2 Governance as a Service

WSO2 Governance as a Service is an online multi-tenant supported instance of WSO2 Governance Registry which is the solution for SOA Governance from the WSO2 SOA stack. You can start trying out WSO2 Governance as a Service by accessing the and creating an account for your organization (free for limited use).

In order to identify your account, you have to provide the domain name of your organization. I will demonstrate how to create an account using the “” as my domain name.

1. First go to from a web browser and click the ‘Register’ button. You will be asked to enter the domain name as the first step.

Enter the domain

Enter the domain

After that, you have the option of validating the ownership of the domain right at the registration process, or you can skip the validation and continue to the next step in which case your domain will be appended ‘-trial’ suffix. You can validate the ownership of the domain later at any stage.

Here I want to validate the domain right now, so I click ‘Take me to the domain ownership confirmation page straight-away’ and click the ‘Submit’ button.

2. This will redirect you to the domain ownership validation page. You can validate the ownership of your domain in one of two ways.

Method i). Just create a text file named ‘wso2gaas.txt’ in the web root of your domain and enter the given text. This is the most simplest method of two.

Validate domain name using Textfile

Validate domain name using Textfile

Method ii). You can put a DNS entry according to the given instructions. This is a little tedious approch to validate the domain. In fact it may take a while to propagate the new DNS information, so you may have to wait hours without refreshing the page until you finally validate the domain ownership.

Click the continue button after the domain validation done. Then you will be redirected to a page requesting more information.

3. Tenant Registration Page

Tenant Registration

Tenant Registration

4) After this step, you will be notified to check for your email which will contain a mail with a link to proceed with the registration. There you will be able to select a theme for your organization and finalize creating your account. Login to the admin account for your tenant with the credential you provided a the time of the registration.

The domain ownership validation was introduced to WSO2 Governance as a Service account registration only now. So for organizations who have already have account will have a message similar to this when they are trying to login to their account.

Info box at login

Info box at login

So the account I have registered using the domain name ‘’ has been renamed to ‘’. As the instruction of the message says you can go to the account management page after the login and validate the domain ownership.

Account Management Page

Account Management Page

Posted in Cloud, GaaS, Governance, Governance Registry, SOA, Tutorial/Guide, Uncategorized, web services | Tagged , , , , , | 3 Comments

WSO2 Bringing Cloud Computing and SOA Together

Posted in carbon, Cloud, SOA, web services, wso2 | Tagged , , , , | Leave a comment

WSO2 SOA Platform Enters in to the Cloud

WSO2 announced the launch of their SOA platform inside the Cloud earlier this week. With this launch, you can try out and use their comprehensive SOA platform inside the cloud.

WSO2 Cloud Platform consists of various products, including

Posted in Cloud, Governance, SOA, web services, wso2 | Leave a comment

WSO2 SOA Workshop 2009, Santa Clara, CA

WSO2 is hosting a SOA Workshop in Santa Clara, California in November 3rd 2009. You will be able to attend to the following sessions covered by the industry leading experts in SOA.

  • ESBS and SOA
  • SOA Security
  • Mashups and Business Process Management for SOA
  • SOA Governance
  • SOA with C, C++, PHP
  • SOA Architecture Pattern

Visit here to find more details about the event,

Posted in bps, carbon, esb, Governance, Governance Registry, mashup server, SOA, wso2 | Tagged , , , , , | Leave a comment

WSO2 Releases Goernance Registry 3.0.1, ESB 2.1.1, WSAS 3.1.1, IS 2.0.1 AND Mashup Server 2.0.0

WSO2 announced an another round of release of their famous SOA products.

Although the version numbers say this is minor patch release (Other than the Mashup Server which is shipping as a major release), in fact there are new features and improvements. Some basic new features shares among all of these products are

  1. Improved registry level transaction Support.
  2. Improved Support for deploying on top of Application Servers other than tomcat like WebSphere, WebLogic, and
  3. Support for Eclipse P2 based provisioning. (Yes, you can add/remove features from these WSO2 products , see for more details)
  4. Improved Remote Registry model
Posted in carbon, esb, Governance, Governance Registry, mashup server, SOA, SQL, web services, wsas, wso2 | Tagged , , , , , , , | 2 Comments

WSO2 Releases Eclipse IDE Tooling for WSAS and BPS

Saminda Wijerathna the lead of the WSO2 tooling team, announced the release of a new version of IDE tools for WSO2 WSAS and BPS. These tools will help you to write web services or web service clients and test them within your Eclipse IDE.

You can download the tools and the related documentation from

Here are the key features of the set of IDE tools,

  • Create Web services
  • Create web service client
  • Convert WSDL 1.1 to 2.0
  • Module and service validators
  • Creating wsdl from a java class
  • Create Axis2 archives
  • Hot update a Web service
  • Debug Web services
  • Test Web services
  • Conversion of WSDL 1.1 to 2.0 can now be done vice versa as well.
  • Creating Bpel archives for deploy
  • Start WSAS 3.0.x inside Eclipse
  • Run multiple instances of WSAS inside eclipse
Posted in bps, eclipse tools, SOA, web services, wso2 | Tagged , , , , | Leave a comment

WSO2 Releases Web Service Framework For C++

WSO2 announced the release of the Web Services Framework for C++ (WSF/C++) version 2.0.0. Similar to WSF/PHP which is really popular among the PHP community, WSF/CPP is the C++ language binding for the Apache Axis2/C and the other supporting web services projects like Apache Sandesha/C, Apache Rampart/C.

With this release C++ developers will be able to write web services and web service clients to inter-op with .NET/Java/PHP or any other platform built-on web service standards. The release is shiped with a code generation tool that will be used to generate the code for skeletons and stubs from a WSDL, so developers only need to concentrate on their business logic as the generated code will take care of building or parsing xmls and running them on top of the framework.
Here are the key features of the new release.

  1. Support core web service standards like SOAP 1.1, SOAP 1.2, WSDL 1.1, WSDL 2.0, REST
  2. Support for web services QoS specifications.
    • WS-Addressing
    • WS-Security
    • WS-Policy
    • WS-Security-Policy
    • WS-Reliable-Messaging
  3. Support binary attachment with MTOM and SWA (With the Support for large binaries)
  4. Code generation tool.
  5. Proven interoperability with .NET.

As a side note, you will be able to participate to a free summer school training session on the WSF/CPP conducted by Nandika Jayawardane who is the project lead of both WSF/CPP and WSF/PHP on 30th July. You can register to it (for free) from here.

Posted in REST, RESTful, SOA, web services, WSDL, wsf/c++, wso2 | Tagged , , , , | Leave a comment

WSO2 Governance Registry 3.0.0 – What’s New?

WSO2 Governance Registry (G-Reg) (Formally known as WSO2 Registry) is released its 3.0.0 version along with two other sibling WSO2 products, WSAS 3.1.0 and ESB 2.1.0. This is a major release specially for WSO2 Governance Registry as it contain number of new features and improvements.

1. The New Name – s/Registry/Governance Registry

The product name itself changed from ‘Registry’ to ‘Governance Registry’ (abbreviated as ‘G-Reg’). As it may hint you, now the product is more focused on the ‘Governance’ aspects than just the ‘registry’ or a ‘repository’ aspects. In early releases, it mainly used to store, retrieve configurations and persistence data that the other products would need. Now you can govern these resources (Services, Policies, Processes, People) inside the G-Reg itself. It has emerged to become a complete tool that help you in governing your SOA platform.

2. Separate Views for Add/View/Remove Services

In G-Reg ‘Services’ along with Service MetaData (policies, wsdls, schemas) are distinguished from other resources, as they are the key resources in a SOA platform. You will be able to add/list/view services directly from the main menu in the G-Reg UI.

Add Service Metadata

Add Service Metadata

When adding a service you will be prompted to provide additional details on the services. As they will help users in discovering these services. The fields of these details are configurable as you will change them according to the policies and requirements of your organizations, but the defaults will be adequate for most of the scenarios.  Additionally G-Reg will do WS-I validation as you add WSDLs, Schemas.
Note that this is an additional view you will get as you can still discover services on a tree view arranged according to their namespaces using the registry browser as in previous releases.

3. Service Life cycle Management with Check-lists

Managing service lifecycle is a core part of governing services. G-Reg provides you this functionality with a simple user interface.

Life Cycle Management with Check-Lists

Lifecycle states can be promoted or demoted. The state transition can be ‘Designing’ -> ‘Developing’ -> ‘Testing’ -> ‘Deployed’. You can enforce a validation of a checklist in promoting the state to the next level. This states and the associated check-list items are highly configurable as you will change them to suit to the process of your organizations as you wish.

And G-Reg is shipped with a sample that extend the lifecycle management functionality by making it distributed. In there as you promote or demote the state, the service resource will move its position. The user guide on ‘Distributed Life Cycle Management Sample’ will describe how to use this functionality in more details. This will be really useful if you are enforcing a structured permission model in managing lifecycles. For an example you can enforce only developer role will be able to modify, check or promote a service in the ‘Developing’ state and QA role has permission in promoting a service in ‘Testing’ state and so on.

4. Business Activity Monitoring (BAM)

This is a brand new feature provide in G-Reg. You may find the user guide on ‘BAM’ will be really helpful in configuring the servers you want to monitor. But in order to view the monitoring data you have to go to the dashboard, which is the next new feature.

5. Dashboard

For most of the you, this will be the coolest feature in the new G-Reg., an eye-catching dashboard filled with bunch of Gadgets.



The dashboard provides you the information related to runtime governance as well as design-time governance as described in the ‘Dashboard’ user guide.

6. Eventing and Notifications

If you want you to notified when a resource is updated or a lifecycle state of a service is changed, this feature will be really helpful. Look at the ‘Eventing and Notifications’ user guide on how you can get notified and the built-in events that you can listen.

7. Mount Remote Resources – Federating Registries

If you are maintaining two separate registry instances, this feature will enable you to share resources among them. In G-Reg you can create links to resources in remote registries (remote-links) as well as to the resources in the same registry (sym-links). Here is the user guide for ‘Sym Links and Remote Links’ to read more details of the subject.

8. User Profiles
The new G-Reg has the ability to keep multiple user profiles per user. A simple how to on creating profiles can be found in the user guide on ‘User Profiles’.

9. Checkin/Checkout with Local Filesystem

The new G-Reg is shipped with a command line tool that allows you to checkin and checkout registry resources with your local filesystem. If you are familiar with a version control system like subversion, the checkin/checkout commands will not be much difficult to you.

Checking out a resource is simple as (the following command is what you typed in linux, in windows you will use the checkin-client.bat instead).

./ co / -u user -p user_pw

And to checkin,

./ ci -u user -p user_pw

Similarly you can use this tool to create backups or move resource or resource hierarchy off-line. Here is a complete user guide on ‘Checkin-Client’.

10. Performance Boost

Last but not least, the new G-Reg is performing very fast than its predecessor. In the performance test, it was seen each primitive operation in the registry is at least 10% faster in this release, where as some operations are performing much faster (for an example, ‘Add Collection’ operation seemed 50% faster). And the remote registry calls also optimized by keeping a local cache (http-level-caching).

This was a list of most notable new features in addition to the bunch of the features that was already there in the previous releases. You will be able to download WSO2 Governance Registry freely from the product website, and evaulate these features as you want.

Posted in Governance, Governance Registry, SOA, wso2 | Tagged , , , , , , | Leave a comment

WSO2 Carbon 2 – WSAS, ESB & Governance Registry Released

WSO2 -An open source middleware company- announced the release of bunch of their SOA enabling products along with Carbon 2.0.0 which is an OSGI based unified platform that all the WSO2 java products are built on.

  • WSAS (Web Service Application Server) – Provide and consume web services, data services with full WS-*, REST support, GUI tools, Integration with Eclipse, etc..
  • ESB (Enterprise Service Bus) – Message routing, mediation, transformation, logging, task scheduling, load balancing, failover routing, event brokering, etc. with number of transports support
  • Governance Registry – Govern you SOA platform, introducing number of new features including Dashboard with Gadgets, lifecycle management with checklists, eventing and notifications, remote/symbolic links, checkin/checkout functionality and new meta data management UI.

You will be able to get the advantage of the carbon platform by extending the functionality of any of these products, just by mixing components from other products (Just like running an ESB within WSAS).

Download, Play around with them and Enjoy:)!!!

Posted in carbon, data services, DataServices, esb, Governance, registry, SOA, web services, wsas, wso2 | Tagged , , , , , , , | Leave a comment