2 * Copyright 2010 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server;
21 import gr.ebs.gss.client.exceptions.RpcException;
22 import gr.ebs.gss.server.domain.Invitation;
24 import java.io.IOException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
33 * The servlet that handles registration invitations.
37 public class Invitations extends BaseServlet {
39 * The request parameter name for the invitation code.
41 private static final String CODE_PARAM = "code";
44 * The serial version UID of the class.
46 private static final long serialVersionUID = 1L;
51 private static Log logger = LogFactory.getLog(Invitations.class);
54 public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
55 String code = request.getParameter(CODE_PARAM);
56 response.setContentType("text/html");
58 // Validate input parameters.
59 if (code == null || code.isEmpty()) {
60 response.sendRedirect("invites.jsp?error=" + encode("No code was specified"));
65 Invitation invite = getService().findInvite(code);
67 response.sendRedirect("invites.jsp?code=&error=" + encode("The specified code was not found"));
70 String firstname = invite.getFirstname() == null? "": invite.getFirstname();
71 String lastname = invite.getLastname() == null? "": invite.getLastname();
72 String email = invite.getEmail() == null? "": invite.getEmail();
73 response.sendRedirect("register.jsp?firstname=" + encode(firstname) +
74 "&lastname=" + encode(lastname) + "&email=" + encode(email));
75 } catch (RpcException e) {
77 handleException(response, encode("An error occurred while communicating with the service"));
81 private void handleException(HttpServletResponse response, String error) throws IOException {
82 String errorUrl = "invites.jsp?username=&firstname=&lastname=&email=&error=" + error;
83 response.sendRedirect(errorUrl);