Espero se aproveche.
Saludos!
Cómo usar software libre y vivir para contarlo.
interface WebSocket {
readonly attribute DOMString URL;
// ready state
const unsigned short CONNECTING = 0;
const unsigned short OPEN = 1;
const unsigned short CLOSED = 2;
readonly attribute unsigned short readyState;
readonly attribute unsigned long bufferedAmount;
// networking
attribute Function onopen;
attribute Function onmessage;
attribute Function onclose;
boolean send(in DOMString data);
void close();
};
WebSocket implements EventTarget;
var socket = new WebSocket("ws://some.host:10123/resource", [subprotocol]);
socket.onopen = function() { alert("Opened!") };
socket.onmessage = function (e) { alert("Message: "+e.data); };
socket.onclose = function() { alert("Closed!") };
socket.onerror = function() { alert("Error!") };
@Singleton
public class BirthDateManager {
private EntityManager em;
@Inject
public BirthDateManager(EntityManager em) {
this.em = em;
}
...
}
public class BirthDateModule extends AbstractModule {
@Override
protected void configure() {
bind(EntityManager.class).toProvider(PersistenceFacade.class);
}
}
public class PersistenceFacade implements Provider<EntityManager> {
@Override
public EntityManager get() {
return emf.createEntityManager();
}
...
}
Injector in = Guice.createInjector(new BirthDateModule());
BirthDateManager bdm = in.getInstance(BirthDateManager.class);
<security-constraint>
<web-resource-collection>
<url-pattern>/seguro/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import appspot.client.CommonService;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import javax.servlet.http.HttpServletRequest;
Lo primero que vemos entonces son los import comunes de GWT para los servicios RPC, también vemos importada la interfaz necesaria para que la magia funcione "CommonService" (ese nombre lo elegí yo). Luego vemos las clases de google para acceder a sus cuentas, la "UserService" y "UserServiceFactory", de los nombres mismos ya se puede inferir el uso.public class CommonServiceImpl extends RemoteServiceServlet
implements CommonService {
@Override
public String getUserMail() {
UserService us = UserServiceFactory.getUserService();
if (!us.isUserLoggedIn()) {
return null;
}
HttpServletRequest req = getThreadLocalRequest();
String name = req.getUserPrincipal().getName();
return name;
}
@Override
public String getLoginUrl(String baseUrl) {
UserService us = UserServiceFactory.getUserService();
return us.createLoginURL(baseUrl);
}
@Override
public String getLogoutUrl(String baseUrl) {
UserService us = UserServiceFactory.getUserService();
return us.createLogoutURL(baseUrl);
}
}