11 Replies Latest reply on Jul 8, 2015 10:08 AM by htcprasad

    MessageProducer not able to connect in wildfly9.0.0

    htcprasad

      I deployed a mesageDriven Bean in wildfly9.0.0. but when i am trying to send an object message, i am getting an error

           [java] error:javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [remote://127.0.0.1:4447 (java.net.ConnectException: Connection refused: no further information)]

       

      my MessageProducer is

      package htc.mdb3;

      import javax.naming.InitialContext;

      import javax.naming.Context;

      import javax.jms.QueueConnectionFactory;

      import javax.jms.QueueConnection;

      import javax.jms.QueueSession;

      import javax.jms.Queue;

      import javax.jms.QueueSender;

      import javax.jms.Session;

      import javax.jms.Message;

      import javax.jms.TopicPublisher;

      import javax.jms.ObjectMessage;

      import java.util.Properties;

      public class HotProductCreator {

             public static final String FACTORY_NAME =

                        "jms/RemoteConnectionFactory"; 

         public static final String DEST_NAME = "jms/queue/test";

           public static InitialContext getInitialContext()  {

            Properties props = new Properties();

            InitialContext jndiCtx = null;

            try {

              props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");

              jndiCtx = new InitialContext(props); 

            }catch(Exception ex) {}

             return jndiCtx;

          }

      public static void main(String[] args) {

        try {

         Context ctx = getInitialContext();

        QueueConnectionFactory factory =

             (QueueConnectionFactory)ctx.lookup(FACTORY_NAME);

        QueueConnection con = factory.createQueueConnection();

         QueueSession session = con.createQueueSession(false,

                                    Session.AUTO_ACKNOWLEDGE);

         Queue queue = (Queue)ctx.lookup(DEST_NAME);

         QueueSender sender = session.createSender(queue);

         ObjectMessage msg = session.createObjectMessage();

        ProductDTO dto = new ProductDTO(1000,"SonyTV","A",23432.20);

        msg.setObject(dto);

      sender.send(msg);

        System.out.println("Sent Message");

        con.close();

        }catch(Exception e){

           System.out.println("error:"+e);

        }

      }

      }

      jboss-ejb-client.properties

      endpoint.name=client-endpoint

      remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

       

      remote.connections=default

       

      remote.connection.default.host=127.0.0.1

      remote.connection.default.port = 8080

      remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

       

      remote.connection.default.username=tester

      remote.connection.default.password=testing9@

      remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false

      remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

      remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER

       

      jndi.properties

      java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory

      java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

      java.naming.provider.url=remote://127.0.0.1:4447

      java.naming.security.principal=tester

      java.naming.security.credentials=testing9@

       

      this has run well in JBOSS7.1.1

        • 1. Re: MessageProducer not able to connect in wildfly9.0.0
          jbertram

          Wildfly 9 uses port 8080 for JNDI by default.  See an example remote JMS client here.

          • 2. Re: MessageProducer not able to connect in wildfly9.0.0
            htcprasad

            Thanks a lot after your suggested change i am getting

             

            error:javax.jms.JMSSecurityException: HQ119032: User: null doesnt have permission=SEND on address {2}

            i had created >jms-queue entries=["java:/jms/queue/test","java:/jboss/exported/jms/queue/test"]

            in MDB

            @MessageDriven

            (activationConfig = {

            @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/queue/test"),

            @ActivationConfigProperty(propertyName="destinationType"  ,propertyValue="javax.jms.Queue"),

            @ActivationConfigProperty(propertyName="destination",propertyValue="java:/jms/queue/test"),

            @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})

            public  class  MsgActBean    implements   MessageListener {

              @PersistenceContext(unitName="myplaindb")

            EntityManager em;

            private    HotProduct    prod;

            @PrePassivate

            public void passivateEntity() {

              prod = null;

            }

            public  boolean createProduct(ProductDTO dto) {

              boolean ret = false;

              prod = new HotProduct();

              prod.setProdId(new Long(dto.getProdId()));

              prod.setProdName(dto.getName());

              prod.setProdType(dto.getType());

              prod.setProdCost(dto.getCost());

              try {

               em.persist(prod);

               ret = true;

              }

              catch(Exception e){

               System.out.println(e);

              }

              return ret;

            }

             

            public String getInfo(){

              StringBuilder sb = new StringBuilder();

              sb.append("Id:" + prod.getProdId());

              sb.append("\nName:" + prod.getProdName());

              sb.append("\nType:" + prod.getProdType());

              sb.append("\nCost:" + prod.getProdCost());

              return sb.toString();

            }

             

            public void onMessage(Message msg) {

              boolean boo = false;

              try {

               if(msg instanceof ObjectMessage){

                ObjectMessage om = (ObjectMessage)msg;

                ProductDTO prd =  (ProductDTO)om.getObject();

                boo = createProduct(prd);

                if(boo){

                 System.out.println("Product is created");

                 System.out.println(getInfo());

                }

               }     

              }

              catch(JMSException e) {

               e.printStackTrace();

              }

            }

            producer class is

            public class HotProductCreator {

                   public static final String FACTORY_NAME =

                              "jms/RemoteConnectionFactory"; 

              public static final String DEST_NAME = "jms/queue/test";

                public static InitialContext getInitialContext()  {

                  Properties props = new Properties();

                  InitialContext jndiCtx = null;

                  try {

                    props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");

                    props.put("destinationLookup","queue/testQueue");     

                    jndiCtx = new InitialContext(props); 

                  }catch(Exception ex) {}

                   return jndiCtx;

                }

            public static void main(String[] args) {

              try {

               Context ctx = getInitialContext();

              QueueConnectionFactory factory =

                   (QueueConnectionFactory)ctx.lookup(FACTORY_NAME);

               QueueConnection con = factory.createQueueConnection();

               QueueSession session = con.createQueueSession(false,

                                          Session.AUTO_ACKNOWLEDGE);

               Queue queue = (Queue)ctx.lookup(DEST_NAME);

              QueueSender sender = session.createSender(queue);

               ObjectMessage msg = session.createObjectMessage();

            ProductDTO dto = new ProductDTO(1000,"SonyTV","A",23432.20);

               msg.setObject(dto);

               sender.send(msg);

               System.out.println("Sent Message");

               con.close();

              }catch(Exception e){

                 System.out.println("error:"+e);

              }

            }

            i have not changed any Security-domain

            • 3. Re: MessageProducer not able to connect in wildfly9.0.0
              mayerw01

              Did you check the security settings? Per standard role "guest" has assigned the "send" permission

              /subsystem=messaging/hornetq-server=default/security-setting=#:read-resource(recursive=true)

              {

                  "outcome" => "success",

                  "result" => {"role" => {"guest" => {

                      "consume" => true,

                      "create-durable-queue" => false,

                      "create-non-durable-queue" => true,

                      "delete-durable-queue" => false,

                      "delete-non-durable-queue" => true,

                      "manage" => false,

                      "send" => true

                  }}}

              }

               

              You would therefore need to assign role guest to your user (tester).

              • 4. Re: MessageProducer not able to connect in wildfly9.0.0
                htcprasad

                when i created tester , i had assigned 'guest' role to tester

                you can see my standalone/configuration/application-roles.properties file

                #

                # Properties declaration of users roles for the realm 'ApplicationRealm' which is the default realm

                # for application services on a new installation.

                #

                # This includes the following protocols: remote ejb, remote jndi, web, remote jms

                #

                # Users can be added to this properties file at any time, updates after the server has started

                # will be automatically detected.

                #

                # The format of this file is as follows: -

                # username=role1,role2,role3

                #

                # A utility script is provided which can be executed from the bin folder to add the users: -

                # - Linux

                #  bin/add-user.sh

                #

                # - Windows

                #  bin\add-user.bat

                #

                # The following illustrates how an admin user could be defined.

                #

                #admin=PowerUser,BillingAdmin,

                #guest=guest

                tester=guest

                • 5. Re: MessageProducer not able to connect in wildfly9.0.0
                  jbertram

                  Wolfgang is correct.  This is a basic security error.  You can either set <security-enabled>false</security-enabled> on the HornetQ server or you can add a new application user to Wildfly (add-user.sh), put that user in the "guest" role, and create your connection with the new user's credentials.

                  • 6. Re: MessageProducer not able to connect in wildfly9.0.0
                    htcprasad

                    there is no separate hornetq-configuration.xml,only

                    standard-full.xml has

                    <hornetq-server>

                                    <journal-file-size>102400</journal-file-size>

                     

                     

                                    <connectors>

                                        <http-connector name="http-connector" socket-binding="http">

                                            <param key="http-upgrade-endpoint" value="http-acceptor"/>

                                        </http-connector>

                                        <http-connector name="http-connector-throughput" socket-binding="http">

                                            <param key="http-upgrade-endpoint" value="http-acceptor-throughput"/>

                                            <param key="batch-delay" value="50"/>

                                        </http-connector>

                                        <in-vm-connector name="in-vm" server-id="0"/>

                                    </connectors>

                     

                     

                                    <acceptors>

                                        <http-acceptor http-listener="default" name="http-acceptor"/>

                                        <http-acceptor http-listener="default" name="http-acceptor-throughput">

                                            <param key="batch-delay" value="50"/>

                                            <param key="direct-deliver" value="false"/>

                                        </http-acceptor>

                                        <in-vm-acceptor name="in-vm" server-id="0"/>

                                    </acceptors>

                     

                     

                                    <security-settings>

                                        <security-setting match="#">

                                            <permission type="send" roles="guest"/>

                                            <permission type="consume" roles="guest"/>

                                            <permission type="createNonDurableQueue" roles="guest"/>

                                            <permission type="deleteNonDurableQueue" roles="guest"/>

                                        </security-setting>

                                    </security-settings>

                     

                     

                                    <address-settings>

                                        <address-setting match="#">

                                            <dead-letter-address>jms.queue.DLQ</dead-letter-address>

                                            <expiry-address>jms.queue.ExpiryQueue</expiry-address>

                                            <max-size-bytes>10485760</max-size-bytes>

                                            <page-size-bytes>2097152</page-size-bytes>

                                            <message-counter-history-day-limit>10</message-counter-history-day-limit>

                                        </address-setting>

                                    </address-settings>

                     

                     

                                    <jms-connection-factories>

                                        <connection-factory name="InVmConnectionFactory">

                                            <connectors>

                                                <connector-ref connector-name="in-vm"/>

                                            </connectors>

                                            <entries>

                                                <entry name="java:/ConnectionFactory"/>

                                            </entries>

                                        </connection-factory>

                                        <connection-factory name="RemoteConnectionFactory">

                                            <connectors>

                                                <connector-ref connector-name="http-connector"/>

                                            </connectors>

                                            <entries>

                                                <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>

                                            </entries>

                                        </connection-factory>

                                        <pooled-connection-factory name="hornetq-ra">

                                            <transaction mode="xa"/>

                                            <connectors>

                                                <connector-ref connector-name="in-vm"/>

                                            </connectors>

                                            <entries>

                                                <entry name="java:/JmsXA"/>

                                                <entry name="java:jboss/DefaultJMSConnectionFactory"/>

                                            </entries>

                                        </pooled-connection-factory>

                                    </jms-connection-factories>

                     

                     

                                    <jms-destinations>

                                        <jms-queue name="ExpiryQueue">

                                            <entry name="java:/jms/queue/ExpiryQueue"/>

                                        </jms-queue>

                                        <jms-queue name="DLQ">

                                            <entry name="java:/jms/queue/DLQ"/>

                                        </jms-queue>

                                        <jms-queue name="testQueue">

                                            <entry name="java:/jms/queue/test"/>

                                            <entry name="java:/jboss/exported/jms/queue/test"/>

                                        </jms-queue>

                                    </jms-destinations>

                                </hornetq-server>

                            </subsystem>

                    where <security-enabled>false</security-enabled> is to be given

                    even a new user with guest role is created and used it is showing same error.

                    please look int this

                    • 7. Re: MessageProducer not able to connect in wildfly9.0.0
                      jbertram

                      there is no separate hornetq-configuration.xml...

                      I never said anything about a separate hornetq-configuration.xml.  Here's what I said, "You can either set <security-enabled>false</security-enabled> on the HornetQ server or you can add a new application user to Wildfly (add-user.sh), put that user in the "guest" role, and create your connection with the new user's credentials."  Notice I said "HornetQ server."  In other words, in the <hornetq-server> element that exists in your standalone-full.xml (that you even pasted). 

                       

                      where <security-enabled>false</security-enabled> is to be given

                      See above.

                       

                      even a new user with guest role is created and used it is showing same error.

                      Based on the code that you pasted above you weren't actually passing any user credentials previously.  Have you changed your client to use the credentials for the new users you added on the server?

                      • 8. Re: MessageProducer not able to connect in wildfly9.0.0
                        htcprasad

                        I had created new user with guest role and tested the application. it is showing same exception.

                        However if i removed security-sttings and tried with security-enabled false value element , i am getting

                        the result. but when i run session beans ,there is no problem. only with MDB, i am getting this User: null ..............

                        • 9. Re: MessageProducer not able to connect in wildfly9.0.0
                          mayerw01

                          Maybe you can try to change

                          QueueConnection con = factory.createQueueConnection();

                           

                          to:

                            QueueConnection con = factory.createQueueConnection("tester", "testing9");

                           

                          (Re: javax.jms.JMSSecurityException: Unable to validate user: null)

                          • 10. Re: MessageProducer not able to connect in wildfly9.0.0
                            jbertram

                            If you have an MDB consuming messages from a secure server then you'll have to configure the MDB with the "user" and "password" activation configuration properties.

                            1 of 1 people found this helpful
                            • 11. Re: MessageProducer not able to connect in wildfly9.0.0
                              htcprasad

                              thanks a lot, i changed connection creation as advised . i got the output correctly