Discussion:
[jboss-user] [Beginner's Corner] - Hello World AS JMS - URGENT!
Niraj Patel
2013-06-17 07:33:06 UTC
Permalink
Niraj Patel [https://community.jboss.org/people/nirajpatel] created the document:

"Hello World AS JMS - URGENT!"

To view the document, visit: https://community.jboss.org/docs/DOC-48891

--------------------------------------------------------------
*Hi,*

*I am very new to jBoss and I have a client deadline of tomorrow to show a working example of our product using jBoss.I cannot for the life of me figure out how to run the Hello World AS JMS example provided by jboss on my computer. I want to deploy it and obtain the messages as well. How do I do that? Or must I have 2 seperate computers? Please provide a detailed explanation.*

*THANK YOU!*

--------

/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.quickstarts.jms;


import java.util.logging.Logger;
import java.util.Properties;


import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;


public class HelloWorldJMSClient {
    private static final Logger log = Logger.getLogger(HelloWorldJMSClient.class.getName());


    // Set up all the default values
    private static final String DEFAULT_MESSAGE = "Hello, World!";
    private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
    private static final String DEFAULT_DESTINATION = "jms/queue/test";
    private static final String DEFAULT_MESSAGE_COUNT = "1";
    private static final String DEFAULT_USERNAME = "quickstartUser";
    private static final String DEFAULT_PASSWORD = "quickstartPassword";
    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
    private static final String PROVIDER_URL = "remote://localhost:4447";


    public static void main(String[] args) throws Exception {


        ConnectionFactory connectionFactory = null;
        Connection connection = null;
        Session session = null;
        MessageProducer producer = null;
        MessageConsumer consumer = null;
        Destination destination = null;
        TextMessage message = null;
        Context context = null;


        try {
            // Set up the context for the JNDI lookup
            final Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
            env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
            env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));
            env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));
            context = new InitialContext(env);


            // Perform the JNDI lookups
            String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
            log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
            connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString);
            log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");


            String destinationString = System.getProperty("destination", DEFAULT_DESTINATION);
            log.info("Attempting to acquire destination \"" + destinationString + "\"");
            destination = (Destination) context.lookup(destinationString);
            log.info("Found destination \"" + destinationString + "\" in JNDI");


            // Create the JMS connection, session, producer, and consumer
            connection = connectionFactory.createConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            producer = session.createProducer(destination);
            consumer = session.createConsumer(destination);
            connection.start();


            int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));
            String content = System.getProperty("message.content", DEFAULT_MESSAGE);


            log.info("Sending " + count + " messages with content: " + content);


            // Send the specified number of messages
            for (int i = 0; i < count; i++) {
                message = session.createTextMessage(content);
                producer.send(message);
            }


            // Then receive the same number of messaes that were sent
            for (int i = 0; i < count; i++) {
                message = (TextMessage) consumer.receive(5000);
                log.info("Received message with content " + message.getText());
            }
        } catch (Exception e) {
            log.severe(e.getMessage());
            throw e;
        } finally {
            if (context != null) {
                context.close();
            }


            // closing the connection takes care of the session, producer, and consumer
            if (connection != null) {
                connection.close();
            }
        }
    }
}
--------------------------------------------------------------

Comment by going to Community
[https://community.jboss.org/docs/DOC-48891]

Create a new document in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2075]
Niraj Patel
2013-06-17 07:44:37 UTC
Permalink
Niraj Patel [https://community.jboss.org/people/nirajpatel] modified the document:

"Hello World AS JMS - URGENT!"

To view the document, visit: https://community.jboss.org/docs/DOC-48891

--------------------------------------------------------------
Hi,

I am very new to jBoss and I have a client deadline of tomorrow to show a working example of our product using jBoss.I cannot for the life of me figure out how to run the Hello World AS JMS example provided by jboss on my computer. I want to deploy it and obtain the messages as well. How do I do that? Or must I have 2 seperate computers? Below is the error I receive when running the program.



RROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
Jun 17, 2013 2:28:48 AM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
SEVERE: Failed to create remoting connection
Exception in thread "main" javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed]
          at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
          at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
          at javax.naming.InitialContext.init(InitialContext.java:223)
          at javax.naming.InitialContext.<init>(InitialContext.java:197)
          at org.jboss.as.quickstarts.jms.HelloWorldJMSClient.main(HelloWorldJMSClient.java:63)
Caused by: java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
          at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:87)
          at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
          at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)
          at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)
          at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
          ... 5 more
Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
          at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:365)
          at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:214)
          at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)
          at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:189)
          at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:103)
          at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)
          at org.xnio.nio.NioHandle.run(NioHandle.java:90)
          at org.xnio.nio.WorkerThread.run(WorkerThread.java:184)
          at ...asynchronous invocation...(Unknown Source)
          at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:270)
          at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:251)
          at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:349)
          at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:333)
          at org.jboss.naming.remote.client.EndpointCache$EndpointWrapper.connect(EndpointCache.java:105)
          at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:55)
          ... 8 more



Why is this?

THANK YOU!
--------------------------------------------------------------

Comment by going to Community
[https://community.jboss.org/docs/DOC-48891]

Create a new document in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2075]
erasmo2 marciano2
2013-06-17 07:56:04 UTC
Permalink
erasmo2 marciano2 [https://community.jboss.org/people/erasmomarciano] commented on the document

"Hello World AS JMS - URGENT!"

To view all comments on this document, visit: https://community.jboss.org/docs/DOC-48891#comment-12281

--------------------------------------------------
You have to open a new Topic question don't a new document

Please , you have to move this question in this area of the community

https://community.jboss.org/community/jbossas7 https://community.jboss.org/community/jbossas7
--------------------------------------------------

Loading...