From airavata-commits-return-576-apmail-incubator-airavata-commits-archive=incubator.apache.org@incubator.apache.org Thu Oct 6 18:20:33 2011 Return-Path: X-Original-To: apmail-incubator-airavata-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-airavata-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ED6477619 for ; Thu, 6 Oct 2011 18:20:32 +0000 (UTC) Received: (qmail 28878 invoked by uid 500); 6 Oct 2011 18:20:32 -0000 Delivered-To: apmail-incubator-airavata-commits-archive@incubator.apache.org Received: (qmail 28838 invoked by uid 500); 6 Oct 2011 18:20:32 -0000 Mailing-List: contact airavata-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: airavata-dev@incubator.apache.org Delivered-To: mailing list airavata-commits@incubator.apache.org Received: (qmail 28831 invoked by uid 99); 6 Oct 2011 18:20:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Oct 2011 18:20:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Oct 2011 18:20:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7D079238889B; Thu, 6 Oct 2011 18:20:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1179742 - /incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java Date: Thu, 06 Oct 2011 18:20:08 -0000 To: airavata-commits@incubator.apache.org From: patanachai@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111006182008.7D079238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: patanachai Date: Thu Oct 6 18:20:08 2011 New Revision: 1179742 URL: http://svn.apache.org/viewvc?rev=1179742&view=rev Log: AIRAVATA-129 Read subscription as InputStream instead of String Modified: incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java Modified: incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java?rev=1179742&r1=1179741&r2=1179742&view=diff ============================================================================== --- incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java (original) +++ incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java Thu Oct 6 18:20:08 2011 @@ -99,9 +99,9 @@ public class WsmgPersistantStorage imple public void dispose() { if (db != null) { db.closeAllConnections(); - } + } } - + /* * (non-Javadoc) * @@ -124,13 +124,55 @@ public class WsmgPersistantStorage imple stmt = conn.prepareStatement(SubscriptionConstants.EXP_SELECT_QUERY); ResultSet rs = stmt.executeQuery(); ret.ensureCapacity(size); - + if (rs != null) { + + /* + * Buffer data + */ + int nRead; + byte[] buffer = new byte[1024]; + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + while (rs.next()) { SubscriptionEntry subscriptionEntry = new SubscriptionEntry(); subscriptionEntry.setSubscriptionId(rs.getString("SubscriptionId")); - subscriptionEntry.setSubscribeXml(rs.getString("content")); + + /* + * Read Binary Stream + */ + InputStream inStream = null; + + try { + inStream = rs.getBinaryStream("content"); + while ((nRead = inStream.read(buffer)) != -1) { + outStream.write(buffer, 0, nRead); + } + outStream.flush(); + + subscriptionEntry.setSubscribeXml(new String(outStream.toByteArray())); + + } catch (IOException ie) { + logger.error("Unable to read XML from database", ie); + + //skip this subscription entry + continue; + } finally{ + //clear all data in outputStream + outStream.reset(); + + //close database stream + if(inStream != null){ + try{ + inStream.close(); + }catch(Exception e){ + logger.error("Cannot close database stream", e); + } + } + } + ret.add(subscriptionEntry); + } } } catch (SQLException ex) { @@ -722,5 +764,5 @@ public class WsmgPersistantStorage imple public static String SQL_MIN_ID_INCREMENT = "UPDATE " + TABLE_NAME_MINID + " SET minID = minID+1 WHERE minID ="; - } + } }