1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.action;
16  
17  import com.liferay.portal.kernel.util.HttpUtil;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.util.servlet.ServletResponseUtil;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import org.apache.struts.action.Action;
26  import org.apache.struts.action.ActionForm;
27  import org.apache.struts.action.ActionForward;
28  import org.apache.struts.action.ActionMapping;
29  
30  /**
31   * <a href="RESTProxyAction.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author David Truong
34   * @author Gavin Wan
35   */
36  public class RESTProxyAction extends Action {
37  
38      public ActionForward execute(
39              ActionMapping mapping, ActionForm form, HttpServletRequest request,
40              HttpServletResponse response)
41          throws Exception {
42  
43          String url = ParamUtil.getString(request, "url");
44  
45          if (Validator.isNotNull(url)) {
46              String content = HttpUtil.URLtoString(url, true);
47  
48              ServletResponseUtil.write(response, content);
49          }
50  
51          return null;
52      }
53  
54  }