[jboss-user] [JNDI and Naming] - Remote connection failed - Authentication failed: all available authentication mechanisms failed

Laura delli Paoli do-not-reply at jboss.com
Fri Nov 9 04:30:02 EST 2012


Laura delli Paoli [https://community.jboss.org/people/lauradp] created the discussion

"Remote connection failed - Authentication failed: all available authentication mechanisms failed"

To view the discussion, visit: https://community.jboss.org/message/775710#775710

--------------------------------------------------------------
Hello everybody,
I implemented this queue writer:
package writer;


import java.io.IOException;
import java.util.Properties;


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


/**
 * @author Laura delli Paoli
 *
 */
public class QueueWriter {
          private final static String JMS_FACTORY="jms/RemoteConnectionFactory";

          private ConnectionFactory conFactory;
          private Connection con;
          private Session session;
          private static MessageProducer producer;
          private Destination destination;
          private static TextMessage msg;

          private String username = null, password = null;

          public QueueWriter(String username, String password, Context ctx, String destName) throws NamingException, JMSException {
                    super();
                    this.username = username;
                    this.password = password;
                    init(ctx, destName);
          }

          private void init(Context ctx, String destName)throws NamingException, JMSException {
                    conFactory = (ConnectionFactory) ctx.lookup(JMS_FACTORY);
                    //*************** Creating Queue Connection using the UserName & Password *************************
                    con = conFactory.createConnection(username, password);
                    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
                    destination = (Destination) ctx.lookup("jms/"+destName);
                    producer = session.createProducer(destination);
                    msg = session.createTextMessage();
                    con.start();
          }

          public void sendTextMsg(String mess) throws IOException, JMSException {
                    System.out.println("Generic Sender"+"\n"+"Following Messages has been sent !!!");
                    String [] colors = {"BLUE", "RED", "BLUE"};
                    for(int j=1;j<=3;j++) {
                              msg.setText("Message #" + j + ": "+mess);           // Messages
                              msg.setStringProperty("color", colors[j-1]);
                        producer.send(msg);           // Messages sent
                                 System.out.println("Message ("+colors[j-1]+") sent = "+j +": " + msg.getText());
                    }
          }

          public static InitialContext getInitialContext(String PROVIDER_URL, String username, String password) {
                    /*Properties env = new Properties();
                    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                    env.put(Context.PROVIDER_URL, PROVIDER_URL);
                    env.put(Context.SECURITY_PRINCIPAL, username);
                    env.put(Context.SECURITY_CREDENTIALS, password);
                    env.put("jboss.naming.client.ejb.context", true);*/
                    Context remoteContext = null;
                    try {
                              //remoteContext = new InitialContext(env);
                              remoteContext = new InitialContext();
                    } catch (NamingException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                    }

                    return (InitialContext) remoteContext;
          }

          public void close () throws JMSException {
                    if (producer != null) producer.close();
                    if (session != null) session.close();
                    if (con != null) con.close();
          }
}

when I tryed to run in with the folllowing main:

package writer;


import java.io.IOException;
import java.util.Properties;


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


/**
 * @author Laura delli Paoli
 *  mailto:l.dellipaoli at reply.it l.dellipaoli at reply.it
 */
public class QueueWriter {
//          private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
          private final static String JMS_FACTORY="jms/RemoteConnectionFactory";

          private ConnectionFactory conFactory;
          private Connection con;
          private Session session;
          private static MessageProducer producer;
          private Destination destination;
          private static TextMessage msg;

          private String username = null, password = null;

          public QueueWriter(String username, String password, Context ctx, String destName) throws NamingException, JMSException {
                    super();
                    this.username = username;
                    this.password = password;
                    init(ctx, destName);
          }

          private void init(Context ctx, String destName)throws NamingException, JMSException {
                    conFactory = (ConnectionFactory) ctx.lookup(JMS_FACTORY);
                    //*************** Creating Queue Connection using the UserName & Password *************************
                    con = conFactory.createConnection(username, password);
                    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
                    destination = (Destination) ctx.lookup("jms/"+destName);
                    producer = session.createProducer(destination);
                    msg = session.createTextMessage();
                    con.start();
          }

          public void sendTextMsg(String mess) throws IOException, JMSException {
                    System.out.println("Generic Sender"+"\n"+"Following Messages has been sent !!!");
                    String [] colors = {"BLUE", "RED", "BLUE"};
                    for(int j=1;j<=3;j++) {
                              msg.setText("Message #" + j + ": "+mess);           // Messages
                              msg.setStringProperty("color", colors[j-1]);
                        producer.send(msg);           // Messages sent
                                 System.out.println("Message ("+colors[j-1]+") sent = "+j +": " + msg.getText());
                    }
          }

          public static InitialContext getInitialContext(String PROVIDER_URL, String username, String password) {
                    /*Properties env = new Properties();
                    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                    env.put(Context.PROVIDER_URL, PROVIDER_URL);
                    env.put(Context.SECURITY_PRINCIPAL, username);
                    env.put(Context.SECURITY_CREDENTIALS, password);
                    env.put("jboss.naming.client.ejb.context", true);*/
                    Context remoteContext = null;
                    try {
                              //remoteContext = new InitialContext(env);
                              remoteContext = new InitialContext();
                    } catch (NamingException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                    }

                    return (InitialContext) remoteContext;
          }

          public void close () throws JMSException {
                    if (producer != null) producer.close();
                    if (session != null) session.close();
                    if (con != null) con.close();
          }
}

I got the following excepiton:
9-nov-2012 9.57.19 org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.3.GA
9-nov-2012 9.57.22 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
9-nov-2012 9.57.24 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.3.GA
9-nov-2012 9.57.40 org.jboss.remoting3.remote.RemoteConnection handleException
ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: Operation failed with status WAITING]
          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(Unknown Source)
          at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
          at javax.naming.InitialContext.init(Unknown Source)
          at javax.naming.InitialContext.<init>(Unknown Source)
          at writer.QueueWriter.getInitialContext(QueueWriter.java:73)
          at writer.runWriter.main(runWriter.java:29)
Caused by: java.lang.RuntimeException: Operation failed with status WAITING
          at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:89)
          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)
          ... 6 more
Undefined initial context

Can anyone help me?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/775710#775710]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20121109/81feb53d/attachment-0001.html 


More information about the jboss-user mailing list