added client and server REST support
This commit is contained in:
40
src/test/java/ClientTest.java
Normal file
40
src/test/java/ClientTest.java
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user