# HG changeset patch # User Ingo Weinzierl # Date 1297943575 0 # Node ID fe2f4d1dd784b52b28b6eb489d776bf46e83156b # Parent 8d9075c07667c778f7ec866a5a0ead3b10b42039 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 diff -r 8d9075c07667 -r fe2f4d1dd784 flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java --- 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() { + String url = Config.getInstance().getServerUrl(); + + artifactService.create(url, factory, new AsyncCallback() { public void onFailure(Throwable caught) { GWT.log("Could not create the new artifact."); GWT.log(caught.getMessage()); diff -r 8d9075c07667 -r fe2f4d1dd784 flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java --- 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 factory. * + * @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 : diff -r 8d9075c07667 -r fe2f4d1dd784 flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java --- 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 callback); + public void create( + String serverUrl, String factory, AsyncCallback callback); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 8d9075c07667 -r fe2f4d1dd784 flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java --- 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() { - 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() { + 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); + } }); } }); diff -r 8d9075c07667 -r fe2f4d1dd784 flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java --- 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; } } diff -r 8d9075c07667 -r fe2f4d1dd784 flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java --- /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 Ingo Weinzierl + */ +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 :