Reconfigurede service impl
This commit is contained in:
parent
072036036f
commit
a229f29e44
|
@ -18,7 +18,7 @@ public class CkanToZenodoPublisher implements EntryPoint {
|
|||
/**
|
||||
* Create a remote service proxy to talk to the server-side Greeting service.
|
||||
*/
|
||||
private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
|
||||
private final CkanToZenodoPublisherServiceAsync greetingService = GWT.create(CkanToZenodoPublisherService.class);
|
||||
|
||||
/**
|
||||
* This is the entry point method.
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
|||
/**
|
||||
* The client side stub for the RPC service.
|
||||
*/
|
||||
@RemoteServiceRelativePath("greet")
|
||||
public interface GreetingService extends RemoteService {
|
||||
@RemoteServiceRelativePath("ckantozenodo")
|
||||
public interface CkanToZenodoPublisherService extends RemoteService {
|
||||
String greetServer(String name) throws IllegalArgumentException;
|
||||
}
|
|
@ -3,12 +3,12 @@ package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
|
|||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
public interface GreetingServiceAsync
|
||||
public interface CkanToZenodoPublisherServiceAsync
|
||||
{
|
||||
|
||||
/**
|
||||
* GWT-RPC service asynchronous (client-side) interface
|
||||
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.GreetingService
|
||||
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService
|
||||
*/
|
||||
void greetServer( java.lang.String name, AsyncCallback<java.lang.String> callback );
|
||||
|
||||
|
@ -18,13 +18,13 @@ public interface GreetingServiceAsync
|
|||
*/
|
||||
public static final class Util
|
||||
{
|
||||
private static GreetingServiceAsync instance;
|
||||
private static CkanToZenodoPublisherServiceAsync instance;
|
||||
|
||||
public static final GreetingServiceAsync getInstance()
|
||||
public static final CkanToZenodoPublisherServiceAsync getInstance()
|
||||
{
|
||||
if ( instance == null )
|
||||
{
|
||||
instance = (GreetingServiceAsync) GWT.create( GreetingService.class );
|
||||
instance = (CkanToZenodoPublisherServiceAsync) GWT.create( CkanToZenodoPublisherService.class );
|
||||
}
|
||||
return instance;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
|
||||
|
||||
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
||||
/**
|
||||
* The server side implementation of the RPC service.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet implements
|
||||
CkanToZenodoPublisherService {
|
||||
|
||||
public String greetServer(String input) throws IllegalArgumentException {
|
||||
|
||||
|
||||
return "Hello";
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape an html string. Escaping data received from the client helps to
|
||||
* prevent cross-site script vulnerabilities.
|
||||
*
|
||||
* @param html the html string to escape
|
||||
* @return the escaped string
|
||||
*/
|
||||
private String escapeHtml(String html) {
|
||||
if (html == null) {
|
||||
return null;
|
||||
}
|
||||
return html.replaceAll("&", "&").replaceAll("<", "<").replaceAll(
|
||||
">", ">");
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
|
||||
|
||||
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.GreetingService;
|
||||
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.FieldVerifier;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
||||
/**
|
||||
* The server side implementation of the RPC service.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class GreetingServiceImpl extends RemoteServiceServlet implements
|
||||
GreetingService {
|
||||
|
||||
public String greetServer(String input) throws IllegalArgumentException {
|
||||
// Verify that the input is valid.
|
||||
if (!FieldVerifier.isValidName(input)) {
|
||||
// If the input is not valid, throw an IllegalArgumentException back to
|
||||
// the client.
|
||||
throw new IllegalArgumentException(
|
||||
"Name must be at least 4 characters long");
|
||||
}
|
||||
|
||||
String serverInfo = getServletContext().getServerInfo();
|
||||
String userAgent = getThreadLocalRequest().getHeader("User-Agent");
|
||||
|
||||
// Escape data from the client to avoid cross-site script vulnerabilities.
|
||||
input = escapeHtml(input);
|
||||
userAgent = escapeHtml(userAgent);
|
||||
|
||||
return "Hello, " + input + "!<br><br>I am running " + serverInfo
|
||||
+ ".<br><br>It looks like you are using:<br>" + userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape an html string. Escaping data received from the client helps to
|
||||
* prevent cross-site script vulnerabilities.
|
||||
*
|
||||
* @param html the html string to escape
|
||||
* @return the escaped string
|
||||
*/
|
||||
private String escapeHtml(String html) {
|
||||
if (html == null) {
|
||||
return null;
|
||||
}
|
||||
return html.replaceAll("&", "&").replaceAll("<", "<").replaceAll(
|
||||
">", ">");
|
||||
}
|
||||
}
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
<!-- Servlets -->
|
||||
<servlet>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.widgets.ckan2zenodopublisher.server.GreetingServiceImpl</servlet-class>
|
||||
<servlet-name>ckanToZenodoServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.widgets.ckan2zenodopublisher.server.CkanToZenodoPublisherServiceImpl</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<url-pattern>/CkanToZenodoPublisher/greet</url-pattern>
|
||||
<servlet-name>ckanToZenodoServlet</servlet-name>
|
||||
<url-pattern>/CkanToZenodoPublisher/ckantozenodo</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Default page to serve -->
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
|
||||
|
||||
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.FieldVerifier;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.junit.client.GWTTestCase;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.rpc.ServiceDefTarget;
|
||||
|
||||
/**
|
||||
* GWT JUnit <b>integration</b> tests must extend GWTTestCase.
|
||||
* Using <code>"GwtTest*"</code> naming pattern exclude them from running with
|
||||
* surefire during the test phase.
|
||||
*
|
||||
* If you run the tests using the Maven command line, you will have to
|
||||
* navigate with your browser to a specific url given by Maven.
|
||||
* See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html
|
||||
* for details.
|
||||
*/
|
||||
public class GwtTestCkanToZenodoPublisher extends GWTTestCase {
|
||||
|
||||
/**
|
||||
* Must refer to a valid module that sources this class.
|
||||
*/
|
||||
public String getModuleName() {
|
||||
return "org.gcube.portlets.widgets.ckan2zenodopublisher.CkanToZenodoPublisherJUnit";
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the FieldVerifier.
|
||||
*/
|
||||
public void testFieldVerifier() {
|
||||
assertFalse(FieldVerifier.isValidName(null));
|
||||
assertFalse(FieldVerifier.isValidName(""));
|
||||
assertFalse(FieldVerifier.isValidName("a"));
|
||||
assertFalse(FieldVerifier.isValidName("ab"));
|
||||
assertFalse(FieldVerifier.isValidName("abc"));
|
||||
assertTrue(FieldVerifier.isValidName("abcd"));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test will send a request to the server using the greetServer method in
|
||||
* GreetingService and verify the response.
|
||||
*/
|
||||
public void testGreetingService() {
|
||||
// Create the service that we will test.
|
||||
GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
|
||||
ServiceDefTarget target = (ServiceDefTarget) greetingService;
|
||||
target.setServiceEntryPoint(GWT.getModuleBaseURL() + "CkanToZenodoPublisher/greet");
|
||||
|
||||
// Since RPC calls are asynchronous, we will need to wait for a response
|
||||
// after this test method returns. This line tells the test runner to wait
|
||||
// up to 10 seconds before timing out.
|
||||
delayTestFinish(10000);
|
||||
|
||||
// Send a request to the server.
|
||||
greetingService.greetServer("GWT User", new AsyncCallback<String>() {
|
||||
public void onFailure(Throwable caught) {
|
||||
// The request resulted in an unexpected error.
|
||||
fail("Request failure: " + caught.getMessage());
|
||||
}
|
||||
|
||||
public void onSuccess(String result) {
|
||||
// Verify that the response is correct.
|
||||
assertTrue(result.startsWith("Hello, GWT User!"));
|
||||
|
||||
// Now that we have received a response, we need to tell the test runner
|
||||
// that the test is complete. You must call finishTest() after an
|
||||
// asynchronous test finishes successfully, or the test will time out.
|
||||
finishTest();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue