From do-not-reply at jboss.org Mon Jun 13 08:02:51 2011 Content-Type: multipart/mixed; boundary="===============5111506554514442484==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: hornetq-commits at lists.jboss.org Subject: [hornetq-commits] JBoss hornetq SVN: r10794 - in branches/Branch_2_2_EAP_export_tool: src/main/org/hornetq/core/persistence/tools/xmlmodel and 3 other directories. Date: Mon, 13 Jun 2011 08:02:50 -0400 Message-ID: <201106131202.p5DC2oS7000402@svn01.web.mwc.hst.phx2.redhat.com> --===============5111506554514442484== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: jicken Date: 2011-06-13 08:02:50 -0400 (Mon, 13 Jun 2011) New Revision: 10794 Added: branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integrat= ion/persistence/ExportDataJmsTest.java Modified: branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persistenc= e/tools/ImportData.java branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persistenc= e/tools/ManageDataTool.java branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persistenc= e/tools/xmlmodel/MessageType.java branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integrat= ion/cluster/failover/FailoverTest.java branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integrat= ion/persistence/ExportDataTest.java branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/util/Ser= viceTestBase.java Log: added secured server handling added a JMS test to check for correct UserId Modified: branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/per= sistence/tools/ImportData.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persisten= ce/tools/ImportData.java 2011-06-13 02:59:47 UTC (rev 10793) +++ branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persisten= ce/tools/ImportData.java 2011-06-13 12:02:50 UTC (rev 10794) @@ -25,13 +25,21 @@ = public static void main(String args[]) { - if (args.length !=3D 3) { - System.out.println("Usage Export: java org.hornetq.core.persisten= ce.tools.ImportData "); + if (args.length !=3D 3 && args.length !=3D 5) { + System.out.println("Usage Export: java org.hornetq.core.persisten= ce.tools.ImportData " + + " [user= ] [password]"); System.exit(-1); } try { - ManageDataTool.importMessages(args[0], args[1], args[2]); + String user =3D null; + String password =3D null; + + if (args.length =3D=3D 5) { + user =3D args[3]; + password =3D args[4]; + } + ManageDataTool.importMessages(args[0], args[1], args[2], user, pa= ssword); } catch (Exception e) { Modified: branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/per= sistence/tools/ManageDataTool.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persisten= ce/tools/ManageDataTool.java 2011-06-13 02:59:47 UTC (rev 10793) +++ branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persisten= ce/tools/ManageDataTool.java 2011-06-13 12:02:50 UTC (rev 10794) @@ -71,20 +71,19 @@ import org.hornetq.core.server.ServerMessage; import org.hornetq.utils.Base64; import org.hornetq.utils.ExecutorFactory; +import org.hornetq.utils.UUID; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; = /** * @author Torben Jaeger */ -public class ManageDataTool extends JournalStorageManager -{ +public class ManageDataTool extends JournalStorageManager { private static final Logger log =3D Logger.getLogger(ManageDataTool.cla= ss); = private static long messageCounter =3D 0; = - private ManageDataTool(final Configuration config, final ExecutorFactor= y executorFactory) - { + private ManageDataTool(final Configuration config, final ExecutorFactor= y executorFactory) { super(config, executorFactory); } = @@ -113,15 +112,13 @@ * @param messagesDir directory with the messages journal * @throws Exception if something goes wrong */ - public static void exportMessages(final String bindingsDir, final Strin= g messagesDir, final OutputStream out) throws Exception - { + public static void exportMessages(final String bindingsDir, final Strin= g messagesDir, final OutputStream out) throws Exception { = // Will use only default values. The load function should adapt to a= nything different ConfigurationImpl defaultValues =3D new ConfigurationImpl(); defaultValues.setJournalDirectory(messagesDir); = - if (log.isInfoEnabled()) - { + if (log.isInfoEnabled()) { log.info("Generating backup of original journal ..."); } = @@ -147,34 +144,28 @@ = HornetQExport hqJournalExport =3D new HornetQExport(); = - if (log.isInfoEnabled()) - { + if (log.isInfoEnabled()) { log.info("Exporting bindings ..."); } hqJournalExport.setQueues(exportBindings(bindingsJournal)); = - if (log.isInfoEnabled()) - { + if (log.isInfoEnabled()) { log.info("Exporting journal ..."); } hqJournalExport.setMessages(exportMessages(messagesJournal)); = - if (log.isInfoEnabled()) - { + if (log.isInfoEnabled()) { log.info("Writing export file ..."); } writeExportToFile(hqJournalExport, out); = - if (log.isInfoEnabled()) - { + if (log.isInfoEnabled()) { log.info("Export done!"); } } = - private static BindingsJournalType exportBindings(JournalImpl original)= throws Exception - { - try - { + private static BindingsJournalType exportBindings(JournalImpl original)= throws Exception { + try { final List records =3D new LinkedList(); final Set recordsToDelete =3D new HashSet(); = @@ -182,9 +173,7 @@ = return buildXmlBindings(records); = - } - finally - { + } finally { original.stop(); } } @@ -196,11 +185,9 @@ * @return an XML representation of the journal * @throws Exception if the journal is corrupt */ - private static MessagesExportType exportMessages(JournalImpl original) = throws Exception - { + private static MessagesExportType exportMessages(JournalImpl original) = throws Exception { = - try - { + try { final List records =3D new LinkedList(); final Set recordsToDelete =3D new HashSet(); = @@ -212,61 +199,48 @@ = return journal; = - } - finally - { + } finally { original.stop(); } = } = - private static void loadData(Journal original, final List r= ecords, final Set recordsToDelete) throws Exception - { + private static void loadData(Journal original, final List r= ecords, final Set recordsToDelete) throws Exception { original.start(); = - original.load(new LoaderCallback() - { - private void logNotExportedRecord(long id, String reason) - { - if (log.isDebugEnabled()) - { + original.load(new LoaderCallback() { + private void logNotExportedRecord(long id, String reason) { + if (log.isDebugEnabled()) { log.debug("Record " + id + " will not be exported due to " = + reason + "!"); } } = - private void addToNotExportedRecords(List list, Strin= g reason) - { - for (RecordInfo record : list) - { + private void addToNotExportedRecords(List list, Strin= g reason) { + for (RecordInfo record : list) { logNotExportedRecord(record.id, reason); recordsToDelete.add(record.id); } } = - public void addPreparedTransaction(PreparedTransactionInfo prepar= edTransaction) - { + public void addPreparedTransaction(PreparedTransactionInfo prepar= edTransaction) { addToNotExportedRecords(preparedTransaction.records, "prepared= TX"); addToNotExportedRecords(preparedTransaction.recordsToDelete, "= prepared TX"); } = - public void addRecord(RecordInfo info) - { + public void addRecord(RecordInfo info) { records.add(info); } = - public void deleteRecord(long id) - { + public void deleteRecord(long id) { logNotExportedRecord(id, "DEL"); recordsToDelete.add(id); } = - public void updateRecord(RecordInfo info) - { + public void updateRecord(RecordInfo info) { records.add(info); } = - public void failedTransaction(long transactionID, List records, List _recordsToDelete) - { + public void failedTransaction(long transactionID, List records, List _recordsToDelete) { addToNotExportedRecords(records, "failed TX"); addToNotExportedRecords(_recordsToDelete, "failed TX"); } @@ -279,11 +253,10 @@ * * @param hqJournalExport the root JAXB context * @throws java.io.FileNotFoundException if the export file could not b= e created - * @throws javax.xml.bind.JAXBException if an error occurs during marsh= alling + * @throws javax.xml.bind.JAXBException if an error occurs during mars= halling */ private static void writeExportToFile(HornetQExport hqJournalExport, Ou= tputStream os) throws JAXBException, - = FileNotFoundException - { + FileNotFoundException { = // todo: http://jaxb.java.net/guide/Different_ways_of_marshalling.ht= ml#Marshalling_into_a_subtree = @@ -302,23 +275,19 @@ * @param recordsToDelete records which are @see DeleteRecord * @return @see BindingsJournalType or @see MessagesJournalType */ - private static MessagesExportType buildXmlMessages(List rec= ords, Set recordsToDelete) - { + private static MessagesExportType buildXmlMessages(List rec= ords, Set recordsToDelete) { = MessagesExportType journalType =3D new MessagesExportType(); = // Export Journal - for (RecordInfo info : records) - { + for (RecordInfo info : records) { = - if (recordsToDelete.contains(info.id)) - { + if (recordsToDelete.contains(info.id)) { // deleted records are not exported continue; } = - switch (info.getUserRecordType()) - { + switch (info.getUserRecordType()) { = case JournalStorageManager.ADD_MESSAGE: handleAddMessage(journalType, info); @@ -333,12 +302,11 @@ break; = default: - if (log.isDebugEnabled()) - { + if (log.isDebugEnabled()) { log.debug(new StringBuilder().append("Record ") - .append(info.id) - .append(" is not exported!") - .toString()); + .append(info.id) + .append(" is not exported!") + .toString()); } break; } @@ -347,9 +315,8 @@ return journalType; } = - private static void handleAddMessage(MessagesExportType journalType, Re= cordInfo info) - { - final Message msg =3D ((MessageDescribe)JournalStorageManager.newObj= ectEncoding(info)).msg; + private static void handleAddMessage(MessagesExportType journalType, Re= cordInfo info) { + final Message msg =3D ((MessageDescribe) JournalStorageManager.newOb= jectEncoding(info)).msg; MessageType messageType =3D new MessageType((ServerMessage) msg); = final HornetQBuffer bodyBuffer =3D msg.getBodyBuffer(); @@ -359,14 +326,12 @@ journalType.getMessage().add(messageType); } = - private static void handleAddRef(MessagesExportType journalType, Record= Info info) - { - JournalStorageManager.ReferenceDescribe ref =3D (JournalStorageManag= er.ReferenceDescribe)JournalStorageManager.newObjectEncoding(info); + private static void handleAddRef(MessagesExportType journalType, Record= Info info) { + JournalStorageManager.ReferenceDescribe ref =3D (JournalStorageManag= er.ReferenceDescribe) JournalStorageManager.newObjectEncoding(info); = MessageType message =3D getMessage(journalType, info); = - if (message =3D=3D null) - { + if (message =3D=3D null) { throw new IllegalStateException("Journal is corrupt: AddRef witho= ut Add!"); } = @@ -377,21 +342,18 @@ = } = - private static MessageType getMessage(MessagesExportType journalType, R= ecordInfo info) - { + private static MessageType getMessage(MessagesExportType journalType, R= ecordInfo info) { List messages =3D journalType.getMessage(); final int index =3D messages.indexOf(new MessageType(info.id)); return index =3D=3D -1 ? null : messages.get(index); } = - private static void handleAckRef(MessagesExportType journalType, Record= Info info) - { - JournalStorageManager.AckDescribe ack =3D (JournalStorageManager.Ack= Describe)JournalStorageManager.newObjectEncoding(info); + private static void handleAckRef(MessagesExportType journalType, Record= Info info) { + JournalStorageManager.AckDescribe ack =3D (JournalStorageManager.Ack= Describe) JournalStorageManager.newObjectEncoding(info); = MessageType message =3D getMessage(journalType, info); = - if (message =3D=3D null) - { + if (message =3D=3D null) { throw new IllegalStateException("Journal is corrupt: Ack without = Add!"); } = @@ -402,29 +364,25 @@ = } = - private static BindingsJournalType buildXmlBindings(List re= cords) - { + private static BindingsJournalType buildXmlBindings(List re= cords) { = BindingsJournalType journalType =3D new BindingsJournalType(); = // Export Journal - for (RecordInfo info : records) - { + for (RecordInfo info : records) { = - switch (info.getUserRecordType()) - { + switch (info.getUserRecordType()) { = case JournalStorageManager.QUEUE_BINDING_RECORD: handleQBindingRecord(journalType, info); break; = default: - if (log.isDebugEnabled()) - { + if (log.isDebugEnabled()) { log.debug(new StringBuilder().append("Record ") - .append(info.id) - .append(" is not exported!") - .toString()); + .append(info.id) + .append(" is not exported!") + .toString()); } break; = @@ -435,8 +393,7 @@ return journalType; } = - private static void handleQBindingRecord(BindingsJournalType journalTyp= e, RecordInfo info) - { + private static void handleQBindingRecord(BindingsJournalType journalTyp= e, RecordInfo info) { JournalStorageManager.PersistentQueueBindingEncoding persistentQueue= BindingEncoding =3D JournalStorageManager.newBindingEncoding(info.id, = HornetQBuffers.w= rappedBuffer(info.data)); = @@ -455,43 +412,41 @@ = /** * Imports messages which were exported as a XML representation using @= see #exportMessages(String,String,String). - * + *

* This is done by starting an embedded HQ server which connects the qu= eues transparently. * - * @param importFile full qualified name of the import file (/path/fil= e) + * @param importFile full qualified name of the import file (/pa= th/file) * @param configurationFile the configuration URL of a running HQ server - * @param connectorName the name of the connector used to connect to th= e HQ server + * @param connectorName the name of the connector used to connect t= o the HQ server * @return the number of imported records * @throws Exception if an error occurs while importing */ - public static long importMessages(final String importFile, final String= configurationFile, final String connectorName) throws Exception - { + public static long importMessages(final String importFile, final String= configurationFile, + final String connectorName, final Str= ing user, + final String password) throws Excepti= on { FileConfiguration configuration =3D null; - try - { + try { configuration =3D new FileConfiguration(); configuration.setConfigurationUrl(configurationFile); configuration.start(); - } - finally - { - if (configuration !=3D null) - { + } finally { + if (configuration !=3D null) { configuration.stop(); } } = ServerLocator serverLocator =3D HornetQClient.createServerLocatorWit= houtHA(configuration.getConnectorConfigurations() - = .get(connectorName)); + = .get(connectorName)); = FileInputStream input =3D new FileInputStream(new File(importFile)); = - return importMessages(input, serverLocator); + return importMessages(input, serverLocator, user, password); } = public static long importMessages(final InputStream importFile, - final ServerLocator serverLocator) th= rows Exception - { + final ServerLocator serverLocator, + final String user, + final String password) throws Excepti= on { final JAXBContext context =3D JAXBContext.newInstance(HornetQExport.= class); = final Unmarshaller unmarshaller =3D context.createUnmarshaller(); @@ -500,15 +455,24 @@ = ClientSessionFactory sf =3D null; = - try - { + try { sf =3D serverLocator.createSessionFactory(); - final ClientSession coreSession =3D sf.createSession(); + final ClientSession coreSession; + if (user !=3D null && password !=3D null) { + coreSession =3D sf.createSession(user, + password, + false, + true, + true, + serverLocator.isPreAcknowledge(= ), + serverLocator.getAckBatchSize()= ); + } else { + coreSession =3D sf.createSession(); + } = // message notification callback final ClientSessionFactory finalSf =3D sf; - final MessagesExportType.Listener listener =3D new MessagesExport= Type.Listener() - { + final MessagesExportType.Listener listener =3D new MessagesExport= Type.Listener() { public void handleMessage(MessageType message) throws Exceptio= n { final List originalQueues =3D message.getAllPrev= iousBindings().getQueue(); final List originalBindings =3D message.getBi= ndings().getQueue(); @@ -536,27 +500,29 @@ } = private long getNewQueueId(QueueType queue) throws Exception { - final ClientSession requestorSession =3D finalSf.createSess= ion(false, true, true); + final ClientSession requestorSession =3D finalSf.createSess= ion(user, + password, + false, + true, + true, + serverLocator.isPreAcknowledge(= ), + serverLocator.getAckBatchSize()= ); requestorSession.start(); ClientRequestor requestor =3D new ClientRequestor(requestor= Session, ConfigurationImpl.DEFAULT_MANAGEMENT_ADDRESS); ClientMessage m =3D requestorSession.createMessage(false); ManagementHelper.putAttribute(m, ResourceNames.CORE_QUEUE += queue.getName(), "ID"); = - try - { + try { final ClientMessage reply =3D requestor.request(m); Object result =3D ManagementHelper.getResult(reply); = return ((Integer) result).longValue(); - } - catch (Exception e) - { + } catch (Exception e) { throw new IllegalStateException(e); } } = - private ClientMessage generateClientMessage(MessageType messag= e) throws IOException - { + private ClientMessage generateClientMessage(MessageType messag= e) throws IOException { ClientMessage clientMessage =3D coreSession.createMessage(m= essage.getType(), mes= sage.isDurable(), mes= sage.getExpiration(), @@ -571,10 +537,8 @@ = // Routing // only map Q if not already ACKed - for (QueueRefType binding : bindings) - { - if (!ackedQueues.contains(new QueueRefType(binding.getId= ()))) - { + for (QueueRefType binding : bindings) { + if (!ackedQueues.contains(new QueueRefType(binding.getId= ()))) { queues.add(queueMapping.get(binding.getId())); } } @@ -582,41 +546,39 @@ = // Properties List properties =3D message.getProperties().g= etProperty(); - for (PropertyType property : properties) - { + for (PropertyType property : properties) { clientMessage.putStringProperty(property.getKey(), prope= rty.getValue()); } = // Payload - clientMessage.getBodyBuffer().writeBytes(Base64.decode(mess= age.getPayload(), Base64.DONT_BREAK_LINES | Base64.URL_SAFE)); + clientMessage.getBodyBuffer().writeBytes(Base64.decode(mess= age.getPayload(), + Base= 64.DONT_BREAK_LINES | Base64.URL_SAFE)); = // UserID - // todo: need to set? + // todo: need to set or regenerate? + String userId =3D message.getUserId(); + if (userId !=3D null && !"".equals(userId)) { + clientMessage.setUserID(new UUID(UUID.TYPE_TIME_BASED, + Base64.decode(userId, + Base64.DO= NT_BREAK_LINES | Base64.URL_SAFE))); + } = return clientMessage; } = - private byte[] getByteArrayOf(List queues) throws IOExce= ption - { + private byte[] getByteArrayOf(List queues) throws IOExce= ption { ByteArrayOutputStream bos =3D new ByteArrayOutputStream(); DataOutputStream dos =3D new DataOutputStream(bos); - try - { - for (long id : queues) - { + try { + for (long id : queues) { dos.writeLong(id); } dos.flush(); - } - finally - { - try - { + } finally { + try { dos.close(); bos.close(); - } - catch (IOException e) - { + } catch (IOException e) { // could not close streams } } @@ -629,24 +591,19 @@ messageCounter =3D 0; = // install the callback on all message instances - unmarshaller.setListener(new Unmarshaller.Listener() - { - public void beforeUnmarshal(Object target, Object parent) - { - if (target instanceof MessagesExportType) - { - ((MessagesExportType)target).setMessageListener(listener= ); + unmarshaller.setListener(new Unmarshaller.Listener() { + public void beforeUnmarshal(Object target, Object parent) { + if (target instanceof MessagesExportType) { + ((MessagesExportType) target).setMessageListener(listene= r); if (((MessagesExportType) target).getBindings() =3D=3D n= ull) { - ((MessagesExportType)target).setOriginalBindings(((Ho= rnetQExport)parent).getQueues()); + ((MessagesExportType) target).setOriginalBindings(((H= ornetQExport) parent).getQueues()); } } } = - public void afterUnmarshal(Object target, Object parent) - { - if (target instanceof MessagesExportType) - { - ((MessagesExportType)target).setMessageListener(null); + public void afterUnmarshal(Object target, Object parent) { + if (target instanceof MessagesExportType) { + ((MessagesExportType) target).setMessageListener(null); messageCounter++; } } @@ -658,11 +615,8 @@ reader.setContentHandler(unmarshaller.getUnmarshallerHandler()); = reader.parse(new InputSource(importFile)); - } - finally - { - if (sf !=3D null) - { + } finally { + if (sf !=3D null) { sf.close(); } } @@ -670,13 +624,11 @@ return messageCounter; } = - private static Map loadBindings(final String bindingsDire= ctry) throws Exception - { + private static Map loadBindings(final String bindingsDire= ctry) throws Exception { final Map queueMapping; = JournalImpl bindingsJournal =3D null; - try - { + try { = SequentialFileFactory bindingsFF =3D new NIOSequentialFileFactory= (bindingsDirectry); bindingsJournal =3D new JournalImpl(FileConfiguration.DEFAULT_JOU= RNAL_FILE_SIZE, @@ -695,21 +647,16 @@ = queueMapping =3D new HashMap(); = - for (RecordInfo bindingRecord : committedRecordsB) - { - if (bindingRecord.getUserRecordType() =3D=3D JournalStorageMan= ager.QUEUE_BINDING_RECORD) - { + for (RecordInfo bindingRecord : committedRecordsB) { + if (bindingRecord.getUserRecordType() =3D=3D JournalStorageMan= ager.QUEUE_BINDING_RECORD) { // mapping old/new queue binding PersistentQueueBindingEncoding queueBinding =3D JournalStor= ageManager.newBindingEncoding(bindingRecord.id, = HornetQBuffers.wrappedBuffer(bindingRecord.data= )); queueMapping.put(queueBinding.getAddress().toString(), queu= eBinding.getId()); } } - } - finally - { - if (bindingsJournal !=3D null) - { + } finally { + if (bindingsJournal !=3D null) { bindingsJournal.stop(); } } Modified: branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/per= sistence/tools/xmlmodel/MessageType.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persisten= ce/tools/xmlmodel/MessageType.java 2011-06-13 02:59:47 UTC (rev 10793) +++ branches/Branch_2_2_EAP_export_tool/src/main/org/hornetq/core/persisten= ce/tools/xmlmodel/MessageType.java 2011-06-13 12:02:50 UTC (rev 10794) @@ -9,6 +9,8 @@ = import org.hornetq.api.core.SimpleString; import org.hornetq.core.server.ServerMessage; +import org.hornetq.utils.Base64; +import org.hornetq.utils.TypedProperties; = = /** @@ -97,14 +99,20 @@ for (SimpleString propName : msg.getPropertyNames()) { PropertyType propertyType =3D new PropertyType(); propertyType.setKey(propName.toString()); - propertyType.setValue(msg.getSimpleStringProperty(propName).toStr= ing()); + // ie. _HQ_DUPL_ID cannot be handled as a SimpleString prop becau= se it's a byte array + if (isInternalProperty(propName)) { + Object objectProperty =3D msg.getObjectProperty(propName); + propertyType.setValue(getObjectPropertyValue(objectProperty)); + } else { + propertyType.setValue(msg.getSimpleStringProperty(propName).to= String()); + } properties.getProperty().add(propertyType); } setProperties(properties); setPriority(msg.getPriority()); if (msg.getUserID() !=3D null) { - setUserId(msg.getUserID().toString()); + setUserId(Base64.encodeBytes(msg.getUserID().asBytes(),Base64.DON= T_BREAK_LINES|Base64.URL_SAFE)); } else { @@ -112,6 +120,22 @@ } } = + private String getObjectPropertyValue(Object objectProperty) { + if (objectProperty instanceof SimpleString) { + return objectProperty.toString(); + } else { + try { + return Base64.encodeBytes((byte[]) objectProperty, Base64.DONT= _BREAK_LINES | Base64.URL_SAFE); + } catch (Exception e) { + return "could not decode property value"; + } + } + } + + private boolean isInternalProperty(SimpleString propName) { + return propName.startsWith(new SimpleString("_HQ")); + } + /** * Ctor for equals. * Modified: branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/i= ntegration/cluster/failover/FailoverTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integra= tion/cluster/failover/FailoverTest.java 2011-06-13 02:59:47 UTC (rev 10793) +++ branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integra= tion/cluster/failover/FailoverTest.java 2011-06-13 12:02:50 UTC (rev 10794) @@ -76,8 +76,8 @@ public FailoverTest(final String name) { super(name); + } - public FailoverTest() { } Added: branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/inte= gration/persistence/ExportDataJmsTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integra= tion/persistence/ExportDataJmsTest.java (rev 0) +++ branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integra= tion/persistence/ExportDataJmsTest.java 2011-06-13 12:02:50 UTC (rev 10794) @@ -0,0 +1,113 @@ +package org.hornetq.tests.integration.persistence; + +import org.hornetq.api.core.TransportConfiguration; +import org.hornetq.api.core.client.ServerLocator; +import org.hornetq.api.jms.HornetQJMSClient; +import org.hornetq.api.jms.JMSFactoryType; +import org.hornetq.core.config.Configuration; +import org.hornetq.core.persistence.tools.ManageDataTool; +import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory; +import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; +import org.hornetq.core.server.HornetQServers; +import org.hornetq.jms.client.HornetQMessage; +import org.hornetq.jms.server.impl.JMSServerManagerImpl; +import org.hornetq.tests.unit.util.InVMContext; +import org.hornetq.tests.util.JMSTestBase; + +import javax.jms.*; +import javax.management.MBeanServerFactory; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +/** + * Created by IntelliJ IDEA. + * User: torben + * Date: 13.06.11 + * Time: 12:57 + * To change this template use File | Settings | File Templates. + */ +public class ExportDataJmsTest extends JMSTestBase { + + public static final String QUEUE =3D "Q1"; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + + jmsServer.stop(); + + server =3D createServer(true, false,true); + + jmsServer =3D new JMSServerManagerImpl(server); + context =3D new InVMContext(); + jmsServer.setContext(context); + jmsServer.start(); + + jmsServer.createQueue(false, QUEUE, null, true, QUEUE); + cf =3D (ConnectionFactory) HornetQJMSClient.createConnectionFactoryW= ithoutHA(JMSFactoryType.CF, new TransportConfiguration("org.hornetq.core.re= moting.impl.invm.InVMConnectorFactory")); + } + + @Override + protected void tearDown() throws Exception + { + cf =3D null; + + super.tearDown(); + } + + public void testExportImportJmsMessages() throws Exception { + Connection connection =3D cf.createConnection("a", "b"); + connection.start(); + + Session jmsSession =3D connection.createSession(true, Session.CLIENT= _ACKNOWLEDGE); + Destination q =3D HornetQJMSClient.createQueue(QUEUE); + + MessageProducer producer =3D jmsSession.createProducer(q); + + TextMessage message =3D jmsSession.createTextMessage("foobar"); + producer.send(message); + + jmsSession.commit(); + producer.close(); + jmsSession.close(); + connection.close(); + + jmsServer.stop(); + + ByteArrayOutputStream bout =3D new ByteArrayOutputStream(); + ManageDataTool.exportMessages(getBindingsDir(), getJournalDir(), bou= t); + + InputStream is =3D new ByteArrayInputStream(bout.toByteArray()); + + clearData(); + + server =3D createServer(true, false, true); + server.start(); + + ServerLocator locator =3D createNonHALocator(false); + ManageDataTool.importMessages(is, locator, "a", "b"); + + jmsServer =3D new JMSServerManagerImpl(server); + jmsServer.setContext(context); + jmsServer.start(); + + Connection newConnection =3D cf.createConnection("a", "b"); + newConnection.start(); + + Session newJmsSession =3D newConnection.createSession(false, Session= .CLIENT_ACKNOWLEDGE); + + MessageConsumer consumer =3D newJmsSession.createConsumer(q); + Message received =3D consumer.receive(1000); + assertNotNull(received); + assertNotNull(received.getJMSMessageID()); + assertEquals("foobar", ((TextMessage) received).getText()); + received.acknowledge(); + + consumer.close(); + newJmsSession.close(); + newConnection.close(); + + } +} Property changes on: branches/Branch_2_2_EAP_export_tool/tests/src/org/horn= etq/tests/integration/persistence/ExportDataJmsTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Date Revision Added: svn:eol-style + native Modified: branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/i= ntegration/persistence/ExportDataTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integra= tion/persistence/ExportDataTest.java 2011-06-13 02:59:47 UTC (rev 10793) +++ branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/integra= tion/persistence/ExportDataTest.java 2011-06-13 12:02:50 UTC (rev 10794) @@ -25,7 +25,6 @@ import org.hornetq.api.core.client.ServerLocator; import org.hornetq.core.persistence.tools.ManageDataTool; import org.hornetq.core.server.HornetQServer; -import org.hornetq.jms.client.HornetQJMSConnectionFactory; import org.hornetq.tests.util.ServiceTestBase; = /** @@ -38,7 +37,6 @@ */ public class ExportDataTest extends ServiceTestBase { = - protected static HornetQJMSConnectionFactory myCf; private static final int MSG_SIZE =3D 1024; = public void testExportImport() throws Exception { @@ -106,7 +104,7 @@ = locator =3D createInVMNonHALocator(); = - ManageDataTool.importMessages(is, locator); + ManageDataTool.importMessages(is, locator, "a", "b"); = ClientSessionFactory csf =3D locator.createSessionFactory(); = Modified: branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/u= til/ServiceTestBase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/util/Se= rviceTestBase.java 2011-06-13 02:59:47 UTC (rev 10793) +++ branches/Branch_2_2_EAP_export_tool/tests/src/org/hornetq/tests/util/Se= rviceTestBase.java 2011-06-13 12:02:50 UTC (rev 10794) @@ -15,10 +15,7 @@ = import java.io.File; import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; = import javax.management.MBeanServer; = @@ -38,6 +35,7 @@ import org.hornetq.core.remoting.impl.invm.InVMRegistry; import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory; import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; +import org.hornetq.core.security.Role; import org.hornetq.core.server.HornetQServer; import org.hornetq.core.server.HornetQServers; import org.hornetq.core.server.NodeManager; @@ -48,6 +46,7 @@ import org.hornetq.jms.client.HornetQTextMessage; import org.hornetq.spi.core.security.HornetQSecurityManager; import org.hornetq.spi.core.security.HornetQSecurityManagerImpl; +import org.hornetq.tests.integration.cluster.util.TestableServer; = /** * = @@ -272,11 +271,34 @@ return createServer(realFiles, false); } = - protected HornetQServer createServer(final boolean realFiles, final boo= lean netty) + protected HornetQServer createServer(final boolean realFiles, final boo= lean netty) { + return createServer(realFiles, netty, false); + } + + protected HornetQServer createServer(final boolean realFiles, final boo= lean netty, final boolean secured) { - return createServer(realFiles, createDefaultConfig(netty), -1, -1, n= ew HashMap()); + Configuration defaultConfig =3D createDefaultConfig(netty); + defaultConfig.setSecurityEnabled(secured); + + HornetQServer server =3D createServer(realFiles, defaultConfig, -1, = -1, new HashMap()); + if (secured) { + installSecurity(server); + } + return server; } = + protected HornetQSecurityManager installSecurity(HornetQServer server) + { + HornetQSecurityManager securityManager =3D server.getSecurityManager= (); + securityManager.addUser("a", "b"); + Role role =3D new Role("arole", true, true, true, true, true, true, = true); + Set roles =3D new HashSet(); + roles.add(role); + server.getSecurityRepository().addMatch("#", roles); + securityManager.addRole("a", "arole"); + return securityManager; + } + protected HornetQServer createServer(final boolean realFiles, final Con= figuration configuration) { return createServer(realFiles, configuration, -1, -1, new HashMap()); --===============5111506554514442484==--