updated client
This commit is contained in:
@@ -5,4 +5,5 @@ module net.woggioni.jpacrepo.client {
|
||||
requires org.slf4j;
|
||||
requires org.apache.logging.log4j;
|
||||
requires net.woggioni.jpacrepo.api;
|
||||
requires info.picocli;
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package net.woggioni.jpacrepo.client;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Objects;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
|
||||
abstract class AbstractVersionProvider implements CommandLine.IVersionProvider {
|
||||
private final String version;
|
||||
private final String vcsHash;
|
||||
|
||||
@SneakyThrows
|
||||
protected AbstractVersionProvider(String specificationTitle) {
|
||||
String version = null;
|
||||
String vcsHash = null;
|
||||
Enumeration<URL> it = getClass().getClassLoader().getResources(JarFile.MANIFEST_NAME);
|
||||
while (it.hasMoreElements()) {
|
||||
URL manifestURL = it.nextElement();
|
||||
Manifest mf = new Manifest();
|
||||
try (InputStream is = manifestURL.openStream()) {
|
||||
mf.read(is);
|
||||
}
|
||||
Attributes mainAttributes = mf.getMainAttributes();
|
||||
if (Objects.equals(specificationTitle, mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE))) {
|
||||
version = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
|
||||
vcsHash = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
|
||||
}
|
||||
}
|
||||
if (version == null || vcsHash == null) {
|
||||
throw new RuntimeException("Version information not found in manifest");
|
||||
}
|
||||
this.version = version;
|
||||
this.vcsHash = vcsHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getVersion() {
|
||||
if (version.endsWith("-SNAPSHOT")) {
|
||||
return new String[] { version, vcsHash };
|
||||
} else {
|
||||
return new String[] { version };
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,111 @@
|
||||
package net.woggioni.jpacrepo.client;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.woggioni.jpacrepo.api.service.FileSystemSynchronizer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import java.util.Properties;
|
||||
|
||||
class VersionProvider extends AbstractVersionProvider {
|
||||
protected VersionProvider() {
|
||||
super(("jpacrepo-client"));
|
||||
}
|
||||
}
|
||||
|
||||
@Slf4j
|
||||
@CommandLine.Command(
|
||||
name = "jpacrepo-cli",
|
||||
versionProvider = VersionProvider.class)
|
||||
public class JpacrepoCli implements Runnable {
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"-ssl", "--tls"},
|
||||
description = "Connect using SSL/TLS"
|
||||
)
|
||||
private boolean ssl = false;
|
||||
@CommandLine.Option(
|
||||
names = {"-H", "--host"},
|
||||
description = "Wildfly server hostname"
|
||||
)
|
||||
private String host = "localhost";
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"-P", "--port"},
|
||||
description = "Wildfly server RPC port"
|
||||
)
|
||||
private int port = 8080;
|
||||
|
||||
@CommandLine.Option(
|
||||
required = true,
|
||||
names = {"-u", "--user"},
|
||||
description = "Wildfly RPC username"
|
||||
)
|
||||
private String rpcUsername;
|
||||
|
||||
@CommandLine.Option(
|
||||
required = true,
|
||||
names = {"-p", "--password"},
|
||||
description = "Wildfly RPC password"
|
||||
)
|
||||
private String rpcPassword;
|
||||
|
||||
private static void traverseJndiNode(String nodeName, Context context) {
|
||||
try {
|
||||
NamingEnumeration<NameClassPair> list = context.list(nodeName);
|
||||
while (list.hasMore()) {
|
||||
String childName = nodeName + "" + list.next().getName();
|
||||
System.out.println(childName);
|
||||
traverseJndiNode(childName, context);
|
||||
}
|
||||
} catch (NamingException ex) {
|
||||
// We reached a leaf
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private Context createContext() {
|
||||
Properties prop = new Properties();
|
||||
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
|
||||
|
||||
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
|
||||
if(ssl) {
|
||||
prop.put(Context.PROVIDER_URL, String.format("remote+https://%s:%d", host, port));
|
||||
} else {
|
||||
prop.put(Context.PROVIDER_URL, String.format("http-remoting://%s:%d", host, port));
|
||||
}
|
||||
prop.put(Context.SECURITY_PRINCIPAL, rpcUsername);
|
||||
prop.put(Context.SECURITY_CREDENTIALS, rpcPassword);
|
||||
|
||||
prop.put("jboss.naming.client.ejb.context", true);
|
||||
return new InitialContext(prop);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void run() {
|
||||
Context ctx = createContext();
|
||||
// traverseJndiNode("/", context);
|
||||
final FileSystemSynchronizer service = (FileSystemSynchronizer) ctx.lookup(
|
||||
"/jpacrepo/PackageSynchronizerEJB!net.woggioni.jpacrepo.api.service.FileSystemSynchronizer"
|
||||
);
|
||||
service.syncDb();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Logger log = LoggerFactory.getLogger("jpacrepo-cli");
|
||||
CommandLine commandLine = new CommandLine(new JpacrepoCli());
|
||||
commandLine.setExecutionExceptionHandler((ex, cl, parseResult) -> {
|
||||
log.error(ex.getLocalizedMessage(), ex);
|
||||
return CommandLine.ExitCode.SOFTWARE;
|
||||
});
|
||||
System.exit(commandLine.execute(args));
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
package net.woggioni.jpacrepo.client;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.woggioni.jpacrepo.api.service.FileSystemSynchronizer;
|
||||
import net.woggioni.jpacrepo.api.service.PacmanServiceRemote;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
public class Main {
|
||||
|
||||
private static void traverseJndiNode(String nodeName, Context context) {
|
||||
try {
|
||||
NamingEnumeration<NameClassPair> list = context.list(nodeName);
|
||||
while (list.hasMore()) {
|
||||
String childName = nodeName + "" + list.next().getName();
|
||||
System.out.println(childName);
|
||||
traverseJndiNode(childName, context);
|
||||
}
|
||||
} catch (NamingException ex) {
|
||||
// We reached a leaf
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void main(String[] args) {
|
||||
Properties prop = new Properties();
|
||||
// InputStream in = Main.class.getClassLoader().getResourceAsStream("jboss-ejb-client.properties");
|
||||
// prop.load(in);
|
||||
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
|
||||
|
||||
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
|
||||
prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
|
||||
// prop.put(Context.PROVIDER_URL, "http-remoting://nuc:8080");
|
||||
// prop.put(Context.PROVIDER_URL, "remote://odroid-u3:4447");
|
||||
prop.put(Context.SECURITY_PRINCIPAL, "walter");
|
||||
prop.put(Context.SECURITY_CREDENTIALS, "27ff5990757d1d");
|
||||
// prop.put(Context.SECURITY_PRINCIPAL, "luser");
|
||||
// prop.put(Context.SECURITY_CREDENTIALS, "123456");
|
||||
|
||||
prop.put("jboss.naming.client.ejb.context", true);
|
||||
Context context = new InitialContext(prop);
|
||||
Context ctx = new InitialContext(prop);
|
||||
traverseJndiNode("/", context);
|
||||
// final PacmanService stateService = (PacmanService) ctx.lookup("/jpacrepo-1.0/remote/PacmanServiceEJB!service.PacmanService");
|
||||
final FileSystemSynchronizer service = (FileSystemSynchronizer) ctx.lookup(
|
||||
"/jpacrepo/PackageSynchronizerEJB!net.woggioni.jpacrepo.api.service.FileSystemSynchronizer"
|
||||
);
|
||||
|
||||
// List<PkgData> pkgs = service.searchPackage("google-earth", null, null, 1, 10);
|
||||
// System.out.println(new XStream().toXML(pkgs));
|
||||
service.syncDb();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user