*/
package gr.ebs.gss.server;
-import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
import gr.ebs.gss.client.exceptions.RpcException;
import gr.ebs.gss.server.domain.Invitation;
-import gr.ebs.gss.server.ejb.ExternalAPI;
import java.io.IOException;
-import java.net.URLEncoder;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.rmi.PortableRemoteObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
*
* @author past
*/
-public class Invitations extends Registration {
+public class Invitations extends BaseServlet {
/**
* The request parameter name for the invitation code.
*/
*/
private static Log logger = LogFactory.getLog(Invitations.class);
- /**
- * A helper method that retrieves a reference to the ExternalAPI bean and
- * stores it for future use.
- *
- * @return an ExternalAPI instance
- * @throws RpcException in case an error occurs
- */
- private ExternalAPI getService() throws RpcException {
- try {
- final Context ctx = new InitialContext();
- final Object ref = ctx.lookup(getConfiguration().getString("externalApiPath"));
- return (ExternalAPI) PortableRemoteObject.narrow(ref, ExternalAPI.class);
- } catch (final NamingException e) {
- logger.error("Unable to retrieve the ExternalAPI EJB", e);
- throw new RpcException("An error occurred while contacting the naming service");
- }
- }
-
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
String code = request.getParameter(CODE_PARAM);
// Validate input parameters.
if (code == null || code.isEmpty()) {
- String error = URLEncoder.encode("No code was specified", "UTF-8");
- String errorUrl = "invites.jsp?error=" + error;
- response.sendRedirect(errorUrl);
+ response.sendRedirect("invites.jsp?error=" + encode("No code was specified"));
return;
}
try {
Invitation invite = getService().findInvite(code);
if (invite == null) {
- String error = URLEncoder.encode("The specified code was not found", "UTF-8");
- String errorUrl = "invites.jsp?code=&error=" + error;
- response.sendRedirect(errorUrl);
+ response.sendRedirect("invites.jsp?code=&error=" + encode("The specified code was not found"));
return;
}
- String name = invite.getName() == null? "": invite.getName();
+ String firstname = invite.getFirstname() == null? "": invite.getFirstname();
+ String lastname = invite.getLastname() == null? "": invite.getLastname();
String email = invite.getEmail() == null? "": invite.getEmail();
- response.sendRedirect("register.jsp?name=" + name + "&email=" + email);
+ response.sendRedirect("register.jsp?firstname=" + encode(firstname) +
+ "&lastname=" + encode(lastname) + "&email=" + encode(email));
} catch (RpcException e) {
- String error = "An error occurred while communicating with the service";
- logger.error(error, e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
+ logger.error(e);
+ handleException(response, encode("An error occurred while communicating with the service"));
}
}
+
+ private void handleException(HttpServletResponse response, String error) throws IOException {
+ String errorUrl = "invites.jsp?username=&firstname=&lastname=&email=&error=" + error;
+ response.sendRedirect(errorUrl);
+ }
}