diff --git a/src/main/java/org/gcube/data/transfer/library/client/Client.java b/src/main/java/org/gcube/data/transfer/library/client/Client.java index a9d77d6..97553bd 100644 --- a/src/main/java/org/gcube/data/transfer/library/client/Client.java +++ b/src/main/java/org/gcube/data/transfer/library/client/Client.java @@ -1,6 +1,7 @@ package org.gcube.data.transfer.library.client; import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import javax.xml.bind.JAXBElement; @@ -40,9 +41,11 @@ public class Client { } + public TransferTicket submit(TransferRequest request){ + return rootTarget.path(ServiceConstants.REQUESTS_SERVLET_NAME).request(MediaType.APPLICATION_XML_TYPE).post(Entity.entity(request,MediaType.APPLICATION_XML),TransferTicket.class); + } - -// public TransferTicket submit(TransferRequest request){ -// return -// } + public TransferTicket getTransferStatus(String transferId){ + return rootTarget.path(ServiceConstants.STATUS_SERVLET_NAME).path(transferId).request(MediaType.APPLICATION_XML).get(TransferTicket.class); + } } diff --git a/src/test/java/org/gcube/data/transfer/library/TestClientCalls.java b/src/test/java/org/gcube/data/transfer/library/TestClientCalls.java index 04b0880..35e9b3b 100644 --- a/src/test/java/org/gcube/data/transfer/library/TestClientCalls.java +++ b/src/test/java/org/gcube/data/transfer/library/TestClientCalls.java @@ -1,35 +1,66 @@ package org.gcube.data.transfer.library; +import java.net.MalformedURLException; +import java.net.URL; + import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.data.transfer.library.client.AuthorizationFilter; import org.gcube.data.transfer.library.client.Client; -import org.gcube.data.transfer.model.TransferCapabilities; +import org.gcube.data.transfer.model.TransferRequest; +import org.gcube.data.transfer.model.TransferTicket; +import org.gcube.data.transfer.model.TransferTicket.Status; +import org.gcube.data.transfer.model.options.HttpDownloadOptions; +import org.gcube.data.transfer.model.settings.HttpDownloadSettings; import org.glassfish.jersey.client.ClientConfig; +import org.junit.Before; import org.junit.Test; public class TestClientCalls { + String hostname="http://pc-fabio.isti.cnr.it:8080"; + String scope="/gcube/devNext"; + Client client; + + + @Before + public void init(){ + ScopeProvider.instance.set(scope); + client=new Client(hostname); + } + + @Test public void getCapabilties(){ - ScopeProvider.instance.set("/gcube/devNext"); - String hostname="http://pc-fabio.isti.cnr.it:8080"; - System.out.println("Direct call"); + System.out.println(client.getCapabilties()); + } + + + @Test + public void doTheTransfer() throws MalformedURLException{ + TransferRequest request= new TransferRequest("", new HttpDownloadSettings(new URL("http://goo.gl/oLP7zG"), HttpDownloadOptions.DEFAULT)); + System.out.println("Submitting "+request); + TransferTicket ticket=client.submit(request); + System.out.println("Ticket is "+ticket); - - - System.out.println(new Client(hostname).getCapabilties()); + boolean continuePolling=true; + do{ + ticket=client.getTransferStatus(ticket.getId()); + System.out.println("Status : "+ticket); + continuePolling=ticket.getStatus().equals(Status.PENDING)||ticket.getStatus().equals(Status.TRANSFERRING)||ticket.getStatus().equals(Status.WAITING); + try{ + Thread.sleep(1000); + }catch(InterruptedException e){} + }while(continuePolling); } @Test - public void directCall(){ - ScopeProvider.instance.set("/gcube/devNext"); + public void directCall(){ javax.ws.rs.client.Client client = ClientBuilder.newClient(new ClientConfig().register(AuthorizationFilter.class)); System.out.println(client.target("http://pc-fabio.isti.cnr.it:8080/data-transfer-service/gcube/service/Capabilities"). request(MediaType.APPLICATION_XML).get());