root / src / gr / ebs / gss / server / Invitations.java @ 8c0fa677
History | View | Annotate | Download (2.7 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2010 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
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.
|
10 |
*
|
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.
|
15 |
*
|
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/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.server; |
20 |
|
21 |
import gr.ebs.gss.client.exceptions.RpcException; |
22 |
import gr.ebs.gss.server.domain.Invitation; |
23 |
|
24 |
import java.io.IOException; |
25 |
|
26 |
import javax.servlet.http.HttpServletRequest; |
27 |
import javax.servlet.http.HttpServletResponse; |
28 |
|
29 |
import org.apache.commons.logging.Log; |
30 |
import org.apache.commons.logging.LogFactory; |
31 |
|
32 |
/**
|
33 |
* The servlet that handles registration invitations.
|
34 |
*
|
35 |
* @author past
|
36 |
*/
|
37 |
public class Invitations extends BaseServlet { |
38 |
/**
|
39 |
* The request parameter name for the invitation code.
|
40 |
*/
|
41 |
private static final String CODE_PARAM = "code"; |
42 |
|
43 |
/**
|
44 |
* The serial version UID of the class.
|
45 |
*/
|
46 |
private static final long serialVersionUID = 1L; |
47 |
|
48 |
/**
|
49 |
* The logger.
|
50 |
*/
|
51 |
private static Log logger = LogFactory.getLog(Invitations.class); |
52 |
|
53 |
@Override
|
54 |
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { |
55 |
String code = request.getParameter(CODE_PARAM);
|
56 |
response.setContentType("text/html");
|
57 |
|
58 |
// Validate input parameters.
|
59 |
if (code == null || code.isEmpty()) { |
60 |
response.sendRedirect("invites.jsp?error=" + encode("No code was specified")); |
61 |
return;
|
62 |
} |
63 |
|
64 |
try {
|
65 |
Invitation invite = getService().findInvite(code); |
66 |
if (invite == null) { |
67 |
response.sendRedirect("invites.jsp?code=&error=" + encode("The specified code was not found")); |
68 |
return;
|
69 |
} |
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) {
|
76 |
logger.error(e); |
77 |
handleException(response, encode("An error occurred while communicating with the service"));
|
78 |
} |
79 |
} |
80 |
|
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); |
84 |
} |
85 |
} |