Init non working version

This commit is contained in:
Mediha Zukic
2017-06-19 20:00:06 +02:00
parent 3193011dbf
commit d2fa2df0b2
63 changed files with 27846 additions and 0 deletions

BIN
TestGWT/src/.DS_Store vendored Normal file

Binary file not shown.

BIN
TestGWT/src/com/.DS_Store vendored Normal file

Binary file not shown.

BIN
TestGWT/src/com/test/.DS_Store vendored Normal file

Binary file not shown.

BIN
TestGWT/src/com/test/gwt/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
<module rename-to='testgwt'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<inherits name="com.google.gwt.resources.Resources" />
<inherits name="gwt.react.React" />
<inherits name="gwt.redux.Redux" />
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.test.gwt.client.TestGWT'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<set-configuration-property name="CssResource.style" value="pretty" />
<set-configuration-property name="CssResource.obfuscationPrefix" value="empty" />
<!-- allow Super Dev Mode -->
<add-linker name="xsiframe"/>
<set-configuration-property name="devModeRedirectEnabled" value="true"/>
<set-property name="compiler.useSourceMaps" value="true" />
</module>

View File

@@ -0,0 +1,19 @@
package com.test.gwt.client;
import com.google.gwt.core.client.ScriptInjector;
import com.test.gwt.client.TestGWT.JsClientBundle;
public class GWTReactBundleWrapper {
public static void injectScript() {
if (!isInjected()) {
ScriptInjector.fromString(JsClientBundle.INSTANCE.gwtreactbundlejs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
}
}
private native final static boolean isInjected() /*-{
if (!(typeof $wnd.TestGWT === "undefined") && !(null===$wnd.TestGWT)) {
return true;
}
return false;
}-*/;
}

View File

@@ -0,0 +1,14 @@
package com.test.gwt.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.test.gwt.shared.UserDTO;
@RemoteServiceRelativePath("login")
public interface LoginService extends RemoteService
{
UserDTO loginServer(String name, String password);
UserDTO loginFromSessionServer();
void logout();
}

View File

@@ -0,0 +1,13 @@
package com.test.gwt.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.test.gwt.shared.UserDTO;
public interface LoginServiceAsync
{
void loginServer(String name, String password, AsyncCallback<UserDTO> callback);
void loginFromSessionServer(AsyncCallback<UserDTO> callback);
void logout(AsyncCallback<Void> callback);
}

View File

@@ -0,0 +1,235 @@
package com.test.gwt.client;
import com.test.gwt.shared.UserDTO;
import jdk.management.resource.internal.inst.WindowsAsynchronousFileChannelImplRMHooks;
import java.util.Date;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import gwt,react.client.api.GwtReact;
import gwt.react.client.api.React;
import gwt.react.client.api.ReactDOM;
import gwt.react.client.components.ClassicComponentClass;
import gwt.react.client.events.MouseEventHandler;
import gwt.react.client.proptypes.BaseProps;
import gwt.react.client.utils.ObjLiteral;
import gwt.react_examples.redux.counter.client.components.Counter;
import gwt.react_examples.redux.counter.client.reducers.CounterReducer;
import gwt.redux.client.Action;
import gwt.redux.client.Redux;
import gwt.redux.client.Store;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TestGWT implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network " + "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
public interface JsClientBundle extends ClientBundle {
final JsClientBundle INSTANCE = GWT.create(JsClientBundle.class);
@Source("resources/gwt-react-bundle.min.js")
TextResource gwtreactbundlejs();
@Source("resources/gwt-react-router-bundle.min.js")
TextResource gwtreactrouterbundlejs();
}
private final LoginServiceAsync loginService = GWT.create(LoginService.class);
/**
* This is the entry point method.
*/
final TextBox userNameField = new TextBox();
final TextBox passwordField = new PasswordTextBox();
final Button loginButton = new Button("LOGIN");
final Button goToReactButton = new Button("GO TO REACT APP");
final Label loggedUserInfo = new Label();
final Label errorLabel = new Label();
private void displayLoginWindow(boolean displayLogin){
// Hide info and React button
if(displayLogin)
loggedUserInfo.setText("");
goToReactButton.setVisible(!displayLogin);
RootPanel.get("userNameFieldLabel").setVisible(displayLogin);
RootPanel.get("passwordFieldLabel").setVisible(displayLogin);
userNameField.setVisible(displayLogin);
passwordField.setVisible(displayLogin);
loginButton.setVisible(displayLogin);
}
private void checkWithServerIfSessionIdIsStillLegal(String sessionID)
{
loginService.loginFromSessionServer(new AsyncCallback<UserDTO>()
{
@Override
public void onFailure(Throwable caught)
{
displayLoginWindow(true);
}
@Override
public void onSuccess(UserDTO result)
{
if (result == null)
{
displayLoginWindow(true);
} else
{
if (result.getLoggedIn())
{
displayLoginWindow(false);
loggedUserInfo.setText("Current logged in user: " + result.getUserName());
} else
{
displayLoginWindow(true);
}
}
}
});
}
public void onModuleLoad() {
ScriptInjector.fromString(JsClientBundle.INSTANCE.gwtreactbundlejs().getText()).inject();
ScriptInjector.fromString(JsClientBundle.INSTANCE.gwtreactrouterbundlejs().getText()).inject();
// GWTReactBundleWrapper.injectScript();
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("userNameFieldContainer").add(userNameField);
RootPanel.get("passwordFieldContainer").add(passwordField);
RootPanel.get("loginButtonContainer").add(loginButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
RootPanel.get("loggedInUserInfoContainer").add(loggedUserInfo);
RootPanel.get("goToReactApplicationButtonContainer").add(goToReactButton);
// Focus the cursor on the name field when the app loads
userNameField.setFocus(true);
userNameField.selectAll();
String sessionID = Cookies.getCookie("sid");
if (sessionID == null)
{
displayLoginWindow(true);
} else
{
checkWithServerIfSessionIdIsStillLegal(sessionID);
}
// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler, KeyUpHandler {
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
Widget sender = (Widget) event.getSource();
if (sender == loginButton) {
loginUser();
} else if (sender == goToReactButton) {
Window.Location.replace("http://127.0.0.1:3000");
}
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
loginUser();
}
}
private void loginUser(){
loginService.loginServer(userNameField.getValue(), passwordField.getValue(), new AsyncCallback<UserDTO>()
{
@Override
public void onSuccess(UserDTO result)
{
if (result.getLoggedIn())
{
//set session cookie for 10s expiry.
String sessionID = result.getSessionId();
final long DURATION = 1000 * 60 * 10;
Date expires = new Date(System.currentTimeMillis() + DURATION);
Cookies.setCookie("sid", sessionID, expires, null, "/", false);
displayLoginWindow(false);
loggedUserInfo.setText("Current logged in user: " + result.getUserName());
} else
{
Window.alert("Access Denied 1. Check your user-name and password.");
}
}
@Override
public void onFailure(Throwable caught)
{
Window.alert("Access Denied 2. Check your user-name and password.");
}
});
}
}
// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
loginButton.addClickHandler(handler);
passwordField.addKeyUpHandler(handler);
goToReactButton.addClickHandler(handler);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
package com.test.gwt.server;
public class JSONLoginService {
}

View File

@@ -0,0 +1,60 @@
package com.test.gwt.server;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.test.gwt.client.LoginService;
import com.test.gwt.shared.UserDTO;
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService
{
private static final long serialVersionUID = 4456105400553118785L;
@Override
public UserDTO loginServer(String name, String password)
{
UserDTO user = new UserDTO(name, password);
storeUserInSession(user);
return user;
}
@Override
public UserDTO loginFromSessionServer()
{
return getUserAlreadyFromSession();
}
@Override
public void logout()
{
deleteUserFromSession();
}
private UserDTO getUserAlreadyFromSession()
{
UserDTO user = null;
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
HttpSession session = httpServletRequest.getSession();
Object userObj = session.getAttribute("user");
if (userObj != null && userObj instanceof UserDTO)
{
user = (UserDTO) userObj;
}
return user;
}
private void storeUserInSession(UserDTO user)
{
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
HttpSession session = httpServletRequest.getSession(true);
user.setSessionId(session.getId());
session.setAttribute("user", user);
}
private void deleteUserFromSession()
{
HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
HttpSession session = httpServletRequest.getSession();
session.removeAttribute("user");
}
}

View File

@@ -0,0 +1,42 @@
package com.test.gwt.shared;
/**
* <p>
* FieldVerifier validates that the name the user enters is valid.
* </p>
* <p>
* This class is in the <code>shared</code> package because we use it in both
* the client code and on the server. On the client, we verify that the name is
* valid before sending an RPC request so the user doesn't have to wait for a
* network round trip to get feedback. On the server, we verify that the name is
* correct to ensure that the input is correct regardless of where the RPC
* originates.
* </p>
* <p>
* When creating a class that is used on both the client and the server, be sure
* that all code is translatable and does not use native JavaScript. Code that
* is not translatable (such as code that interacts with a database or the file
* system) cannot be compiled into client-side JavaScript. Code that uses native
* JavaScript (such as Widgets) cannot be run on the server.
* </p>
*/
public class FieldVerifier {
/**
* Verifies that the specified name is valid for our service.
*
* In this example, we only require that the name is at least four
* characters. In your application, you can use more complex checks to ensure
* that usernames, passwords, email addresses, URLs, and other fields have the
* proper syntax.
*
* @param name the name to validate
* @return true if valid, false if invalid
*/
public static boolean isValidName(String name) {
if (name == null) {
return false;
}
return name.length() > 3;
}
}

View File

@@ -0,0 +1,59 @@
package com.test.gwt.shared;
import java.io.Serializable;
public class UserDTO implements Serializable
{
private static final long serialVersionUID = 3196402615838002153L;
private String userName;
private String password;
private boolean loggedIn;
private String sessionId;
public UserDTO()
{
}
public UserDTO(String name, String password)
{
setUserName(name);
setPassword(password);
setLoggedIn(true);
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean getLoggedIn() {
return loggedIn;
}
public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
}