├── .classpath ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── README.md ├── bin └── server │ ├── HttpRequest.class │ ├── MinimalServlets$HelloServlet.class │ └── MinimalServlets.class ├── commons-io-2.5.jar ├── jetty-all-9.3.11.v20160721-uber.jar ├── src └── server │ ├── HttpRequest.java │ └── MinimalServlets.java └── wind ├── current ├── current-temp-surface-level-gfs-0.5.epak ├── current-wind-isobaric-850hPa-gfs-0.5.epak └── current-wind-surface-level-gfs-0.5.epak ├── data └── earth-topo.json ├── favicon.ico ├── index.html ├── js ├── bundle.js └── bundle.min.js └── styles ├── NotoSansCJKsc-Light-sub.woff2 ├── fontawesome-sub.woff2 └── mplus-2p-light-sub.woff2 /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jproxy 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jproxy 2 | 3 | one quite simple java proxy project. 4 | 5 | I try to build a little proxy with Jetty and Servlet, so I can visit earth nullschool real-time epak data in localhost mode. 6 | 7 | ## How to use 8 | 1 Import this project with Eclipse and fix the correct path of jars 9 | 10 | 11 | 2 Run this application 12 | 13 | 14 | 3 Visit http://localhost:8080/wind/index.html through your Browser 15 | 16 | ## Note 17 | 18 | 19 | As a naive Java beginner, this is only a Java Project for me to practice, so do not expect too much and pls encourage me, thanks~ 20 | 21 | And to everyone, look at this beautiful world, it is our obligation to protect this planet, it is ours' home. The worst agreement is better than the withdrawal you did. 22 | -------------------------------------------------------------------------------- /bin/server/HttpRequest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/bin/server/HttpRequest.class -------------------------------------------------------------------------------- /bin/server/MinimalServlets$HelloServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/bin/server/MinimalServlets$HelloServlet.class -------------------------------------------------------------------------------- /bin/server/MinimalServlets.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/bin/server/MinimalServlets.class -------------------------------------------------------------------------------- /commons-io-2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/commons-io-2.5.jar -------------------------------------------------------------------------------- /jetty-all-9.3.11.v20160721-uber.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/jetty-all-9.3.11.v20160721-uber.jar -------------------------------------------------------------------------------- /src/server/HttpRequest.java: -------------------------------------------------------------------------------- 1 | package server; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileWriter; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.io.PrintWriter; 8 | import java.net.URL; 9 | import java.net.URLConnection; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | import org.apache.commons.io.IOUtils; 14 | 15 | public class HttpRequest { 16 | /** 17 | * ������URL����GET���������� 18 | * 19 | * @param url 20 | * ����������URL 21 | * @param param 22 | * ������������������������ name1=value1&name2=value2 �������� 23 | * @return URL ������������������������ 24 | */ 25 | public static String sendGet(String url, String param) { 26 | String result = ""; 27 | BufferedReader in = null; 28 | try { 29 | String urlNameString = url; 30 | if(!param.isEmpty()) 31 | { 32 | urlNameString += "?" + param; 33 | } 34 | URL realUrl = new URL(urlNameString); 35 | // ������URL���������� 36 | URLConnection connection = realUrl.openConnection(); 37 | // ������������������ 38 | connection.setRequestProperty("accept", "*/*"); 39 | connection.setRequestProperty("connection", "Keep-Alive"); 40 | connection.setRequestProperty("user-agent", 41 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); 42 | // �������������� 43 | connection.connect(); 44 | // ������������������ 45 | Map> map = connection.getHeaderFields(); 46 | // �������������������� 47 | for (String key : map.keySet()) { 48 | System.out.println(key + "--->" + map.get(key)); 49 | } 50 | // ���� BufferedReader������������URL������ 51 | 52 | in = new BufferedReader(new InputStreamReader( 53 | connection.getInputStream())); 54 | String line; 55 | while ((line = in.readLine()) != null) { 56 | result += line; 57 | } 58 | } catch (Exception e) { 59 | System.out.println("����GET��������������" + e); 60 | e.printStackTrace(); 61 | } 62 | // ����finally�������������� 63 | finally { 64 | try { 65 | if (in != null) { 66 | in.close(); 67 | } 68 | } catch (Exception e2) { 69 | e2.printStackTrace(); 70 | } 71 | } 72 | 73 | return result; 74 | } 75 | 76 | /** 77 | * ������ URL ����POST���������� 78 | * 79 | * @param url 80 | * ���������� URL 81 | * @param param 82 | * ������������������������ name1=value1&name2=value2 �������� 83 | * @return ������������������������ 84 | */ 85 | public static String sendPost(String url, String param) { 86 | PrintWriter out = null; 87 | BufferedReader in = null; 88 | String result = ""; 89 | try { 90 | URL realUrl = new URL(url); 91 | // ������URL���������� 92 | URLConnection conn = realUrl.openConnection(); 93 | // ������������������ 94 | conn.setRequestProperty("accept", "*/*"); 95 | conn.setRequestProperty("connection", "Keep-Alive"); 96 | conn.setRequestProperty("user-agent", 97 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); 98 | // ����POST�������������������� 99 | conn.setDoOutput(true); 100 | conn.setDoInput(true); 101 | // ����URLConnection���������������� 102 | out = new PrintWriter(conn.getOutputStream()); 103 | // ������������ 104 | out.print(param); 105 | // flush������������ 106 | out.flush(); 107 | // ����BufferedReader������������URL������ 108 | in = new BufferedReader( 109 | new InputStreamReader(conn.getInputStream())); 110 | String line; 111 | while ((line = in.readLine()) != null) { 112 | result += line; 113 | } 114 | } catch (Exception e) { 115 | System.out.println("���� POST ��������������"+e); 116 | e.printStackTrace(); 117 | } 118 | //����finally���������������������� 119 | finally{ 120 | try{ 121 | if(out!=null){ 122 | out.close(); 123 | } 124 | if(in!=null){ 125 | in.close(); 126 | } 127 | } 128 | catch(IOException ex){ 129 | ex.printStackTrace(); 130 | } 131 | } 132 | return result; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/server/MinimalServlets.java: -------------------------------------------------------------------------------- 1 | package server; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.InputStreamReader; 8 | import java.io.OutputStream; 9 | import java.net.HttpURLConnection; 10 | import java.net.URL; 11 | import java.net.URLConnection; 12 | import java.nio.charset.Charset; 13 | import java.util.Enumeration; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | import javax.servlet.ServletException; 18 | import javax.servlet.ServletInputStream; 19 | import javax.servlet.http.HttpServlet; 20 | import javax.servlet.http.HttpServletRequest; 21 | import javax.servlet.http.HttpServletResponse; 22 | 23 | import org.apache.commons.io.FileUtils; 24 | import org.apache.commons.io.IOUtils; 25 | import org.eclipse.jetty.server.Server; 26 | import org.eclipse.jetty.servlet.FilterHolder; 27 | import org.eclipse.jetty.servlet.ServletHandler; 28 | 29 | import javax.net.ssl.HttpsURLConnection; 30 | import javax.net.ssl.SSLContext; 31 | import javax.net.ssl.TrustManager; 32 | import javax.net.ssl.X509TrustManager; 33 | 34 | public class MinimalServlets 35 | { 36 | public static void main( String[] args ) throws Exception 37 | { 38 | // Create a basic jetty server object that will listen on port 8080. 39 | // Note that if you set this to port 0 then a randomly available port 40 | // will be assigned that you can either look in the logs for the port, 41 | // or programmatically obtain it for use in test cases. 42 | Server server = new Server(8080); 43 | 44 | // The ServletHandler is a dead simple way to create a context handler 45 | // that is backed by an instance of a Servlet. 46 | // This handler then needs to be registered with the Server object. 47 | ServletHandler handler = new ServletHandler(); 48 | 49 | 50 | server.setHandler(handler); 51 | 52 | // Passing in the class for the Servlet allows jetty to instantiate an 53 | // instance of that Servlet and mount it on a given context path. 54 | 55 | // IMPORTANT: 56 | // This is a raw Servlet, not a Servlet that has been configured 57 | // through a web.xml @WebServlet annotation, or anything similar. 58 | handler.addServletWithMapping(HelloServlet.class, "/wind/*"); 59 | 60 | // Start things up! 61 | server.start(); 62 | 63 | // The use of server.join() the will make the current thread join and 64 | // wait until the server is done executing. 65 | // See 66 | // http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join() 67 | server.join(); 68 | } 69 | 70 | @SuppressWarnings("serial") 71 | public static class HelloServlet extends HttpServlet 72 | { 73 | @Override 74 | protected void doGet( HttpServletRequest request, 75 | HttpServletResponse response ) throws ServletException, 76 | IOException 77 | { 78 | String strType = "image/jpg"; 79 | String strUrl = null; 80 | Boolean bProxy = true; 81 | 82 | String strName = request.getRequestURI(); 83 | if(strName.indexOf("Proxy") == -1) 84 | { 85 | bProxy = false; 86 | } 87 | 88 | if(bProxy) 89 | { 90 | Enumeration paramNames = request.getParameterNames(); 91 | while (paramNames.hasMoreElements()) { 92 | String paramName = (String) paramNames.nextElement(); 93 | 94 | String[] paramValues = request.getParameterValues(paramName); 95 | if (paramValues.length == 1) { 96 | String paramValue = paramValues[0]; 97 | if (paramValue.length() != 0) { 98 | if(paramName.equalsIgnoreCase("type")){ 99 | strType = paramValue; 100 | } 101 | 102 | if(paramName.equalsIgnoreCase("url")){ 103 | strUrl = paramValue; 104 | } 105 | } 106 | } 107 | } 108 | //FileUtils.readFileToByteArray(file) 109 | // String strResult = HttpRequest.sendGet(strUrl,""); 110 | // response.setContentType(strType); 111 | // OutputStream outputStream = response.getOutputStream();//获取OutputStream输出流 112 | // byte[] dataByteArr = strResult.getBytes("UTF-8");//将字符转换成字节数组,指定以UTF-8编码进行转换 113 | // outputStream.write(dataByteArr);//使用OutputStream流向客户端输出字节数组 114 | //////////////////////////////////////////////////////// 115 | try { 116 | String reqUrl = strUrl; 117 | 118 | URL url = new URL(reqUrl); 119 | 120 | /////////////////////////////// 121 | // TrustManager[] trustAllCerts = new TrustManager[]{ 122 | // new X509TrustManager() { 123 | // 124 | // public java.security.cert.X509Certificate[] getAcceptedIssuers() 125 | // { 126 | // return null; 127 | // } 128 | // public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) 129 | // { 130 | // //No need to implement. 131 | // } 132 | // public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) 133 | // { 134 | // //No need to implement. 135 | // } 136 | // } 137 | // }; 138 | // 139 | // SSLContext sc = SSLContext.getInstance("SSL"); 140 | // sc.init(null, trustAllCerts, new java.security.SecureRandom()); 141 | // HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 142 | /////////////////////////////// 143 | HttpURLConnection con = (HttpURLConnection)url.openConnection(); 144 | 145 | con.setRequestProperty("accept", "*/*"); 146 | con.setRequestProperty("connection", "Keep-Alive"); 147 | con.setRequestProperty("user-agent", 148 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); 149 | 150 | con.setRequestProperty("referer", "https://earth.nullschool.net/"); 151 | 152 | con.setDoOutput(true); 153 | con.setRequestMethod(request.getMethod()); 154 | 155 | response.setContentType(con.getContentType()); 156 | IOUtils.copy(con.getInputStream(), response.getOutputStream(),2048); 157 | 158 | // int data; 159 | // InputStream is = con.getInputStream(); 160 | // OutputStream os = response.getOutputStream(); 161 | // while((data = is.read()) != -1) { 162 | // os.write(data); 163 | // } 164 | // is.close(); 165 | 166 | } catch(Exception e) { 167 | System.out.println(0); 168 | System.out.println(e); 169 | 170 | response.setStatus(500); 171 | } 172 | /////////////////////////////////////////////////////////// 173 | } 174 | else 175 | { 176 | if(strName.indexOf("favicon") != -1) 177 | { 178 | strName = "/wind/favicon.ico"; 179 | } 180 | 181 | File remoteFile = new File("." + strName); 182 | 183 | byte[] strContent = FileUtils.readFileToByteArray(remoteFile); 184 | response.setContentType("text/html; charset=utf-8"); 185 | OutputStream outputStream = response.getOutputStream(); 186 | outputStream.write(strContent); 187 | response.setStatus(HttpServletResponse.SC_OK); 188 | 189 | } 190 | } 191 | } 192 | } -------------------------------------------------------------------------------- /wind/current/current-temp-surface-level-gfs-0.5.epak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/current/current-temp-surface-level-gfs-0.5.epak -------------------------------------------------------------------------------- /wind/current/current-wind-isobaric-850hPa-gfs-0.5.epak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/current/current-wind-isobaric-850hPa-gfs-0.5.epak -------------------------------------------------------------------------------- /wind/current/current-wind-surface-level-gfs-0.5.epak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/current/current-wind-surface-level-gfs-0.5.epak -------------------------------------------------------------------------------- /wind/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/favicon.ico -------------------------------------------------------------------------------- /wind/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/index.html -------------------------------------------------------------------------------- /wind/styles/NotoSansCJKsc-Light-sub.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/styles/NotoSansCJKsc-Light-sub.woff2 -------------------------------------------------------------------------------- /wind/styles/fontawesome-sub.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/styles/fontawesome-sub.woff2 -------------------------------------------------------------------------------- /wind/styles/mplus-2p-light-sub.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pasu/jproxy/772b07231a18746b2c892228476af584463cba4c/wind/styles/mplus-2p-light-sub.woff2 --------------------------------------------------------------------------------