Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

Bloco de código
languagejava
titleExemplo
 package com.totvs.fluig.custom.dm;


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;


@MessageDriven(mappedName = "custom/DocumentListener", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/wdkAbstract")
})
public class AbstractListenerMessageBean implements MessageListener {
    @Override
    public void onMessage(Message message) {
        try {
            System.out.println("==============Abstract Listener====================");
            System.out.println("Message received: " + message.getJMSMessageID());
            if (message instanceof MapMessage) {
                MapMessage mm = (MapMessage) message;
                @SuppressWarnings("unchecked")
                Enumeration<String> es = mm.getMapNames();
                while (es.hasMoreElements()) {
                    String prop = es.nextElement();
                    System.out.println(prop + ": " + mm.getObject(prop));
                    if(prop.equalsIgnoreCase("mapNewVersion")
                            || prop.equalsIgnoreCase("mapOldVersion")){
                        Map<String, Object> m = decoderMap(mm.getBytes(prop));
                        Iterator it = m.entrySet().iterator();
                        while (it.hasNext()) {
                            Map.Entry e = (Map.Entry)it.next();
                            System.out.println(prop + " - " + e.getKey() + ": " + e.getValue());
                        }
                    }
                }
            }
            System.out.println("==========Fim Abstract Listener===============");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
      
    private Map<String, Object> decoderMap(byte[] array) throws IOException, ClassNotFoundException{
        if(array.length>0){
            ByteArrayInputStream bos = new ByteArrayInputStream(array);
            ObjectInputStream p = new ObjectInputStream(bos);
            Object docObject = p.readObject();
            try{
                Map<String, Object> map = (Map<String, Object>) docObject;
                return map;
            }catch(java.lang.ClassCastException e){
                e.printStackTrace();
            }
        }                   
        return null;
    }


}
 

  

Third Party Trademarks

Adobe, Flash, Flex, Flex Builder, PostScript and Reader are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries.

Apache is a trademark of The Apache Software Foundation.

Firefox and Mozilla are registered trademarks of the Mozilla Foundation.

JavaScript is a trademark of Oracle Corporation.

Microsoft, Active Directory, Excel, Internet Explorer, Outlook, PowerPoint, SQL Server, Windows and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

MySQL is a trademark of Oracle Corporation and/or its affiliates.

Oracle, Java and OpenOffice.org are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

Progress and OpenEdge are trademarks or registered trademarks of Progress Software Corporation or one of its subsidiaries or affiliates in the U.S. and other countries.

Red Hat and JBoss are registered trademarks of Red Hat, Inc. in the United States and other countries.

Any other third party trademarks are the property of their respective owners.