Mercurial > dive4elements > river
changeset 14:fe2f4d1dd784
Integrated the httpclient for the communication between client and server. It is now possible to create a new WINFO artifact.
flys-client/trunk@1326 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 17 Feb 2011 11:52:55 +0000 |
parents | 8d9075c07667 |
children | eb425ab34fd8 |
files | flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java |
diffstat | 6 files changed, 75 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Thu Feb 17 09:17:37 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Thu Feb 17 11:52:55 2011 +0000 @@ -117,7 +117,9 @@ * Create a new Artifact. */ public void newArtifact(String factory) { - artifactService.create(factory, new AsyncCallback<Artifact>() { + String url = Config.getInstance().getServerUrl(); + + artifactService.create(url, factory, new AsyncCallback<Artifact>() { public void onFailure(Throwable caught) { GWT.log("Could not create the new artifact."); GWT.log(caught.getMessage());
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java Thu Feb 17 09:17:37 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java Thu Feb 17 11:52:55 2011 +0000 @@ -17,10 +17,11 @@ /** * This method creates a new artifact based on the given <i>factory</i>. * + * @param serverUrl The url of the artifact server. * @param factory The factory that should be used for the artifact creation. * * @return the new artifact. */ - public Artifact create(String factory); + public Artifact create(String serverUrl, String factory); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java Thu Feb 17 09:17:37 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java Thu Feb 17 11:52:55 2011 +0000 @@ -13,6 +13,7 @@ */ public interface ArtifactServiceAsync { - public void create(String factory, AsyncCallback<Artifact> callback); + public void create( + String serverUrl, String factory, AsyncCallback<Artifact> callback); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Thu Feb 17 09:17:37 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Thu Feb 17 11:52:55 2011 +0000 @@ -17,6 +17,7 @@ import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.client.FLYSMessages; import de.intevation.flys.client.client.services.ArtifactService; @@ -124,16 +125,20 @@ IButton go = new IButton(messages.next()); go.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { - artifactService.create("winfo", new AsyncCallback<Artifact>() { - public void onFailure(Throwable caught) { - GWT.log("Could not create the new artifact."); - GWT.log(caught.getMessage()); - } + String serverUrl = Config.getInstance().getServerUrl(); - public void onSuccess(Artifact artifact) { - GWT.log("Successfully created a new artifact."); - setArtifact(artifact); - } + artifactService.create( + serverUrl, "winfo", + new AsyncCallback<Artifact>() { + public void onFailure(Throwable caught) { + GWT.log("Could not create the new artifact."); + GWT.log(caught.getMessage()); + } + + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created a new artifact."); + setArtifact(artifact); + } }); } });
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java Thu Feb 17 09:17:37 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java Thu Feb 17 11:52:55 2011 +0000 @@ -4,10 +4,11 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.google.gwt.core.client.GWT; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.ClientProtocolUtils; -import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.client.services.ArtifactService; @@ -23,10 +24,17 @@ extends RemoteServiceServlet implements ArtifactService { - public Artifact create(String factory) { - Document create = ClientProtocolUtils.newCreateDocument(factory); + public Artifact create(String serverUrl, String factory) { + Document create = ClientProtocolUtils.newCreateDocument(factory); + HttpClient client = new HttpClientImpl(serverUrl); - // TODO Implement the artifact creation. + try { + return (Artifact) client.create(create, new FLYSArtifactCreator()); + } + catch (ConnectionException ce) { + System.err.println(ce.getLocalizedMessage()); + } + return null; } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java Thu Feb 17 11:52:55 2011 +0000 @@ -0,0 +1,40 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.httpclient.utils.ArtifactCreator; + +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.DefaultArtifact; + + +/** + * An implementation of an {@link ArtifactCreator}. This class uses the document + * that is returned by the artifact server to parse important information (like + * uuid, hash) and returns a new {@link Artifact} instance. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class FLYSArtifactCreator implements ArtifactCreator { + + /** + * Creates a new instance of an {@link ArtifactCreator}. + */ + public FLYSArtifactCreator() { + } + + + /** + * This concreate implementation returns an instance of {@link Artifact} + * that is used in the FLYS GWT Client code. + * + * @param doc A document that describes the artifact that has been created + * in the artifact server. + * + * @return an instance if {@link Artifact}. + */ + public Object create(Document doc) { + return new DefaultArtifact("TODO-UUID", "TODO-HASH"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :