I have a class like below:
public class Poligon {
public static void main(String[] args) {
try {
Context ctx = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/javaee7/ConnectionFactory");
Destination destination = (Destination) ctx.lookup("jms/javaee7/Topic");
JMSContext context = connectionFactory.createContext();
OrderDTO order = context.createConsumer(destination).receiveBody(OrderDTO.class);
System.out.println("Order received: " + order);
} catch (NamingException ex) {
Logger.getLogger(Poligon.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
I would like to get the InitialContext() form the server (glassfish) running on localhost, but I get the below error:
SEVERE: null
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at poligon.Poligon.main(Poligon.java:29)
I know I have to create ldap realm on glassfish and add the below code (? - dont know the exact values) to my class:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"?");
env.put(Context.PROVIDER_URL, "?");
env.put(Context.SECURITY_PRINCIPAL, "?");
env.put(Context.SECURITY_CREDENTIALS, "?");
Context ctx = new InitialContext(env);
My problem is that I dont know what values should be at:
Context.INITIAL_CONTEXT_FACTORY
Context.PROVIDER_URL (I want it on localhost)
Context.SECURITY_PRINCIPAL
Context.SECURITY_CREDENTIALS
And I dont know how I should configure glassfish server?
maven dependencies
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.appclient.client</groupId>
<artifactId>gf-client</artifactId>
<version>3.1.2.2</version>
</dependency>