Skip to content

Instantly share code, notes, and snippets.

@ricardojob
Created October 26, 2017 11:30
Show Gist options
  • Save ricardojob/dcf3a37a98bea94914fae8d317f8194c to your computer and use it in GitHub Desktop.
Save ricardojob/dcf3a37a98bea94914fae8d317f8194c to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ifpb.ads</groupId>
<artifactId>jse</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<finalName>dac-jse</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ifpb.ads.jse.Principal</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package ifpb.ads.jse;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Ricardo Job
* @mail ricardo.job@ifpb.edu.br
* @since 13/07/2017, 09:24:13
*/
public class ServiceLocator {
public <T> T lookup(String resource) {
try {
Properties properties = new Properties();
properties.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
properties.setProperty("org.omg.CORBA.ORBInitialHost", "host-core");
properties.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext context = new InitialContext(properties);
// NamingEnumeration<NameClassPair> list = context.list("");
// while (list.hasMore()) {
// System.out.println(list.next().getName());
// }
return (T) context.lookup(resource);
} catch (NamingException ex) {
Logger.getLogger(ServiceLocator.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment