Project

General

Profile

1 3032 perry
<%
2
/**
3
 * This is a JSP replacement for ProxyRedirect servlet from mapbuilder,
4
 * so it is no needed to include the servlet into the geoserver code base
5
 */
6
7
	if("GET".equals(request.getMethod())){
8
		//execute the GET
9
		String serverUrl = request.getParameter("url");
10
		java.net.URL url = new java.net.URL(serverUrl);
11
		if (!"http".equals(url.getProtocol())) {
12
			throw new javax.servlet.ServletException(
13
					"only use HTTP Url's, please don't hack this server!");
14
		}
15
		java.io.InputStream in = url.openStream();
16
17
		response.setContentType("text/xml");
18
		byte[] buff = new byte[1024];
19
		int count;
20
		java.io.OutputStream o = response.getOutputStream();
21
		while ((count = in.read(buff)) > -1) {
22
			o.write(buff, 0, count);
23
		}
24
		o.flush();
25
		o.close();
26
	}else{
27
		//execute the POST
28
    try {
29
      // Transfer bytes from in to out
30
      java.io.PrintWriter o = response.getWriter();
31
      javax.servlet.ServletInputStream in = request.getInputStream();
32
33
      org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
34
35
      String serverUrl = request.getHeader("serverUrl");
36
      org.apache.commons.httpclient.methods.PostMethod httppost = new org.apache.commons.httpclient.methods.PostMethod(serverUrl);
37
38
      httppost.setRequestBody(in);
39
      //httppost.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
40
41
      client.executeMethod(httppost);
42
43
      if (httppost.getStatusCode() == org.apache.commons.httpclient.HttpStatus.SC_OK) {
44
        response.setContentType("text/xml");
45
        String responseBody = httppost.getResponseBodyAsString();
46
        response.setContentLength(responseBody.length());
47
        System.out.println("responseBody:" + responseBody);
48
        o.print( responseBody );
49
      } else {
50
        throw new javax.servlet.ServletException("Unexpected failure: " + httppost.getStatusLine().toString());
51
      }
52
      httppost.releaseConnection();
53
      o.flush();
54
      o.close();
55
    } catch (java.io.IOException e) {
56
      throw new javax.servlet.ServletException(e);
57
    }
58
	}
59
	%>