3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 require 'src/common/HttpServlet.php';
22 require 'src/gadgets/GadgetContext.php';
23 require 'src/gadgets/ProxyBase.php';
24 require 'src/gadgets/MakeRequestHandler.php';
25 require 'src/common/RemoteContentRequest.php';
26 require 'src/common/RemoteContent.php';
27 require 'src/common/Cache.php';
28 require 'src/common/RemoteContentFetcher.php';
29 require 'src/gadgets/oauth/OAuth.php';
30 require 'src/gadgets/oauth/OAuthStore.php';
32 class MakeRequestServlet
extends HttpServlet
{
34 public function doGet() {
36 $this->noHeaders
= true;
37 $context = new GadgetContext('GADGET');
38 $url = urldecode(isset($_GET['url']) ?
$_GET['url'] : (isset($_POST['url']) ?
$_POST['url'] : false));
39 if (! $url ||
empty($url)) {
40 header("HTTP/1.0 400 Bad Request", true);
41 echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
43 $method = (isset($_GET['httpMethod']) ?
$_GET['httpMethod'] : (isset($_POST['httpMethod']) ?
$_POST['httpMethod'] : 'GET'));
44 $signingFetcherFactory = $gadgetSigner = false;
45 if (! empty($_GET['authz']) ||
! empty($_POST['authz'])) {
46 $gadgetSigner = Config
::get('security_token_signer');
47 $gadgetSigner = new $gadgetSigner();
48 $signingFetcherFactory = new SigningFetcherFactory(Config
::get("private_key_file"));
50 $makeRequestHandler = new MakeRequestHandler($context, $signingFetcherFactory);
51 $makeRequestHandler->fetchJson($url, $gadgetSigner, $method);
52 } catch (Exception
$e) {
53 // catch all exceptions and give a 500 server error
54 header("HTTP/1.0 500 Internal Server Error");
55 echo "<h1>Internal server error</h1><p>" . $e->getMessage() . "</p>";
59 public function doPost() {