added client and server REST support

This commit is contained in:
2015-03-29 22:16:27 +02:00
parent 9b37788528
commit 4a9a01068f
15 changed files with 692 additions and 281 deletions

View File

@@ -0,0 +1,40 @@
import com.thoughtworks.xstream.XStream;
import model.PkgData;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.junit.Test;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
/**
* Created by walter on 29/03/15.
*/
public class ClientTest
{
@Test
public void test() throws Exception
{
ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
RegisterBuiltin.register(instance);
instance.registerProvider(ResteasyJacksonProvider.class);
Client client = ClientBuilder.newClient();
UriBuilder builder = UriBuilder.fromUri("http://odroid-u3:8080/").path("jpacrepo/rest/pkg/search");
// builder.queryParam("name", "linux");
// builder.queryParam("version", "324");
builder.queryParam("md5sum", "19787793429AF74D4D2D09890247E2EC");
WebTarget target = client.target(builder.build());
Invocation invocation = target.request().accept("application/xml").buildGet();
Response response = invocation.invoke();
if (response.getStatusInfo() == Response.Status.OK)
{
PkgData pkg = response.readEntity(PkgData.class);
System.out.println(new XStream().toXML(pkg));
}
}
}

View File

@@ -1,17 +1,15 @@
import com.thoughtworks.xstream.XStream;
import model.PkgData;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.junit.Test;
import pacbase.Parser;
import service.PacmanService;
import javax.naming.*;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
/**
@@ -19,14 +17,14 @@ import java.util.*;
*/
public class ParseTest
{
@Test
// @Test
public void test() throws Exception
{
Collection<File> ls = FileUtils.listFiles(new File("/var/cache/pacman/pkg"), new RegexFileFilter(".*\\.pkg\\.tar\\.xz"), DirectoryFileFilter.DIRECTORY);
int i=0;
int i = 0;
List<PkgData> lista = new ArrayList<>();
for(File file : ls)
for (File file : ls)
{
PkgData data = Parser.parseFile(file);
lista.add(data);
@@ -35,4 +33,41 @@ public class ParseTest
}
System.out.print(lista);
}
@Test
public void invokeStatelessBean() throws NamingException, IOException
{
// Let's lookup the remote stateless calculator
Properties prop = new Properties();
InputStream in = getClass().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.jboss.naming.remote.client.InitialContextFactory");
prop.put(Context.PROVIDER_URL, "http-remoting://odroid-u3:8080");
// prop.put(Context.PROVIDER_URL, "remote://odroid-u3:4447");
prop.put(Context.SECURITY_PRINCIPAL, "jpacrepo");
prop.put(Context.SECURITY_CREDENTIALS, "password01.");
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 PacmanService stateService = (PacmanService) ctx.lookup("/jpacrepo-1.0/PacmanServiceEJB!service.PacmanService");
stateService.syncDB();
}
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
}
}
}

View File

@@ -0,0 +1,21 @@
#remote.connections=default
#remote.connection.default.host=odroid-u3
#remote.connection.default.port=8080
#remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
#remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
#remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=${host.auth:JBOSS-LOCAL-USER}
#
#remote.connection.default.username=jpacrepo
#remote.connection.default.password=password01.
#
#remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
#remote.connections=default
#remote.connection.default.host=odroid-u3
#remote.connection.default.port=4447
#remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
#jboss.naming.client.ejb.context=true
#
#java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
#java.naming.factory.initial=java.naming.spi.InitialContextFactory
#java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
#java.naming.provider.url=remote://odroid-u3:4447

View File

@@ -0,0 +1,11 @@
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=odroid-u3
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
jboss.naming.client.ejb.context=true
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
#java.naming.factory.initial=java.naming.spi.InitialContextFactory
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.provider.url=remote://odroid-u3:4447