|
1 |
| -//package com.webank; |
2 |
| -// |
3 |
| -//import com.webank.wedatasphere.dss.schedulis.exception.SchedulisSchedulerException; |
4 |
| -//import com.webank.wedatasphere.dss.schedulis.linkisjob.AbstractLinkisAzkabanJob; |
5 |
| -//import com.webank.wedatasphere.dss.schedulis.linkisjob.LinkisAzkabanJobFactory; |
6 |
| -//import org.apache.commons.io.IOUtils; |
7 |
| -//import org.apache.http.NameValuePair; |
8 |
| -//import org.apache.http.client.CookieStore; |
9 |
| -//import org.apache.http.client.entity.UrlEncodedFormEntity; |
10 |
| -//import org.apache.http.client.methods.CloseableHttpResponse; |
11 |
| -//import org.apache.http.client.methods.HttpGet; |
12 |
| -//import org.apache.http.client.methods.HttpPost; |
13 |
| -//import org.apache.http.client.protocol.HttpClientContext; |
14 |
| -//import org.apache.http.cookie.Cookie; |
15 |
| -//import org.apache.http.impl.client.BasicCookieStore; |
16 |
| -//import org.apache.http.impl.client.CloseableHttpClient; |
17 |
| -//import org.apache.http.impl.client.HttpClients; |
18 |
| -//import org.apache.http.message.BasicNameValuePair; |
19 |
| -//import org.apache.http.protocol.HTTP; |
20 |
| -//import org.apache.http.util.EntityUtils; |
21 |
| -//import org.junit.Test; |
22 |
| -// |
23 |
| -//import java.io.File; |
24 |
| -//import java.io.IOException; |
25 |
| -//import java.util.ArrayList; |
26 |
| -//import java.util.List; |
27 |
| -// |
28 |
| -// |
29 |
| -//public class HttpTest { |
30 |
| -// |
31 |
| -// //@Test |
32 |
| -// public Cookie test01() throws IOException { |
33 |
| -// HttpPost httpPost = new HttpPost("http://127.0.0.1:8088/checkin"); |
34 |
| -// List<NameValuePair> params = new ArrayList<>(); |
35 |
| -// params.add(new BasicNameValuePair("username", "neiljianliu")); |
36 |
| -// params.add(new BasicNameValuePair("userpwd", "*****")); |
37 |
| -// params.add(new BasicNameValuePair("action", "login")); |
38 |
| -// httpPost.setEntity(new UrlEncodedFormEntity(params)); |
39 |
| -// CookieStore cookieStore = new BasicCookieStore(); |
40 |
| -// CloseableHttpClient httpClient = null; |
41 |
| -// CloseableHttpResponse response = null; |
42 |
| -// HttpClientContext context = null; |
43 |
| -// try { |
44 |
| -// httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); |
45 |
| -// context = HttpClientContext.create(); |
46 |
| -// response = httpClient.execute(httpPost, context); |
47 |
| -// } finally { |
48 |
| -// IOUtils.closeQuietly(response); |
49 |
| -// IOUtils.closeQuietly(httpClient); |
50 |
| -// } |
51 |
| -// List<Cookie> cookies = context.getCookieStore().getCookies(); |
52 |
| -// return cookies.get(0); |
53 |
| -// } |
54 |
| -// |
55 |
| -// @Test |
56 |
| -// public void test02() throws IOException { |
57 |
| -// List<String> strings = new ArrayList<>(); |
58 |
| -// strings.add("1"); |
59 |
| -// strings.add("bbb"); |
60 |
| -// strings.add("ccc"); |
61 |
| -// } |
62 |
| -// |
63 |
| -// public void print(String string) throws IOException, IllegalAccessException{ |
64 |
| -// switch (string){ |
65 |
| -// case "1":throw new IOException("a"); |
66 |
| -// case "2":throw new IllegalAccessException("b"); |
67 |
| -// default: |
68 |
| -// System.out.println(string); |
69 |
| -// } |
70 |
| -// } |
71 |
| -// @Test |
72 |
| -// public void test03() throws IOException, SchedulisSchedulerException { |
73 |
| -// Cookie cookie = test01(); |
74 |
| -// List<NameValuePair> params = new ArrayList<>(); |
75 |
| -// params.add(new BasicNameValuePair("ajax","fetchProjectPage")); |
76 |
| -// params.add(new BasicNameValuePair("start","0")); |
77 |
| -// params.add(new BasicNameValuePair("length","10")); |
78 |
| -// params.add(new BasicNameValuePair("projectsType","personal")); |
79 |
| -// params.add(new BasicNameValuePair("pageNum","1")); |
80 |
| -// params.add(new BasicNameValuePair("order","orderProjectName")); |
81 |
| -// CookieStore cookieStore = new BasicCookieStore(); |
82 |
| -// cookieStore.addCookie(cookie); |
83 |
| -// HttpClientContext context = HttpClientContext.create(); |
84 |
| -// CloseableHttpResponse response = null; |
85 |
| -// CloseableHttpClient httpClient = null; |
86 |
| -// try { |
87 |
| -// String finalUrl = "http://127.0.0.1:8088/index" + "?" + EntityUtils.toString(new UrlEncodedFormEntity(params)); |
88 |
| -// HttpGet httpGet = new HttpGet(finalUrl); |
89 |
| -// httpGet.addHeader(HTTP.CONTENT_ENCODING, "UTF-8"); |
90 |
| -// httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); |
91 |
| -// response = httpClient.execute(httpGet, context); |
92 |
| -// /*Header[] allHeaders = context.getRequest().getAllHeaders(); |
93 |
| -// Optional<Header> header = Arrays.stream(allHeaders).filter(f -> "Cookie".equals(f.getAppJointName())).findFirst(); |
94 |
| -// header.ifPresent(AzkabanUtils.handlingConsumerWrapper(this::parseCookie));*/ |
95 |
| -// } catch (Exception e) { |
96 |
| -// throw new SchedulisSchedulerException(90002, e.getMessage()); |
97 |
| -// } finally { |
98 |
| -// IOUtils.closeQuietly(response); |
99 |
| -// IOUtils.closeQuietly(httpClient); |
100 |
| -// } |
101 |
| -// } |
102 |
| -// |
103 |
| -// @Test |
104 |
| -// public void test04(){ |
105 |
| -///* A a = new A(); |
106 |
| -// Tuple2<String, String> hello = a.hello(); |
107 |
| -// Tuple2<String, String> stringStringTuple2 = new Tuple2<>("","");*/ |
108 |
| -// } |
109 |
| -// |
110 |
| -// @Test |
111 |
| -// public void test05(){ |
112 |
| -// //String subFlowPath = "C:\\Users\\v_wbjftang\\linuxDownloads\\project_0926_tjf\\flow2\\subFlows\\subFlow21\\subFlows\\subFlow211"; |
113 |
| -// String subFlowPath = "/Users/v_wbjftang/linuxDownloads/project_0926_tjf/flow2/subFlows/subFlow21/subFlows/subFlow211"; |
114 |
| -// int indexOf = subFlowPath.indexOf("subFlows"); |
115 |
| -// if(indexOf != -1){ |
116 |
| -// subFlowPath = subFlowPath.substring(0, indexOf-1); |
117 |
| -// } |
118 |
| -// String substring1 = subFlowPath.substring(0, subFlowPath.lastIndexOf("/")); |
119 |
| -// System.out.println(substring1); |
120 |
| -// String allPath = "/Users/v_wbjftang/linuxDownloads/project_0926_tjf/flow2/subFlows/subFlow21/subFlows/subFlow211"; |
121 |
| -// String substring = allPath.substring(substring1.length() +1 ); |
122 |
| -// System.out.println("\\" + File.separator); |
123 |
| -// //String s = substring.replaceAll("\\\\subFlows\\\\", "...."); |
124 |
| -// String s = substring.replaceAll("\\" + File.separator +"subFlows" + "\\" + File.separator, "...."); |
125 |
| -// System.out.println(s); |
126 |
| -// } |
127 |
| -// @Test |
128 |
| -// public void test06(){ |
129 |
| -///* String nodeType = "spark.sql"; |
130 |
| -// try { |
131 |
| -// AbstractLinkisAzkabanJob job = LinkisAzkabanJobFactory.createJob(nodeType); |
132 |
| -// } catch (ClassNotFoundException e) { |
133 |
| -// e.printStackTrace(); |
134 |
| -// } catch (IllegalAccessException e) { |
135 |
| -// e.printStackTrace(); |
136 |
| -// } catch (InstantiationException e) { |
137 |
| -// e.printStackTrace(); |
138 |
| -// } |
139 |
| -// System.out.println("sdf");*/ |
140 |
| -// } |
141 |
| -//} |
| 1 | +package com.webank; |
| 2 | + |
| 3 | +import com.webank.wedatasphere.dss.schedulis.exception.SchedulisSchedulerException; |
| 4 | +import com.webank.wedatasphere.dss.schedulis.linkisjob.AbstractLinkisAzkabanJob; |
| 5 | +import com.webank.wedatasphere.dss.schedulis.linkisjob.LinkisAzkabanJobFactory; |
| 6 | +import org.apache.commons.io.IOUtils; |
| 7 | +import org.apache.http.NameValuePair; |
| 8 | +import org.apache.http.client.CookieStore; |
| 9 | +import org.apache.http.client.entity.UrlEncodedFormEntity; |
| 10 | +import org.apache.http.client.methods.CloseableHttpResponse; |
| 11 | +import org.apache.http.client.methods.HttpGet; |
| 12 | +import org.apache.http.client.methods.HttpPost; |
| 13 | +import org.apache.http.client.protocol.HttpClientContext; |
| 14 | +import org.apache.http.cookie.Cookie; |
| 15 | +import org.apache.http.impl.client.BasicCookieStore; |
| 16 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 17 | +import org.apache.http.impl.client.HttpClients; |
| 18 | +import org.apache.http.message.BasicNameValuePair; |
| 19 | +import org.apache.http.protocol.HTTP; |
| 20 | +import org.apache.http.util.EntityUtils; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +import java.io.File; |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.List; |
| 27 | + |
| 28 | + |
| 29 | +public class HttpTest { |
| 30 | + |
| 31 | + //@Test |
| 32 | + public Cookie test01() throws IOException { |
| 33 | + HttpPost httpPost = new HttpPost("http://127.0.0.1:8088/checkin"); |
| 34 | + List<NameValuePair> params = new ArrayList<>(); |
| 35 | + params.add(new BasicNameValuePair("username", "neiljianliu")); |
| 36 | + params.add(new BasicNameValuePair("userpwd", "*****")); |
| 37 | + params.add(new BasicNameValuePair("action", "login")); |
| 38 | + httpPost.setEntity(new UrlEncodedFormEntity(params)); |
| 39 | + CookieStore cookieStore = new BasicCookieStore(); |
| 40 | + CloseableHttpClient httpClient = null; |
| 41 | + CloseableHttpResponse response = null; |
| 42 | + HttpClientContext context = null; |
| 43 | + try { |
| 44 | + httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); |
| 45 | + context = HttpClientContext.create(); |
| 46 | + response = httpClient.execute(httpPost, context); |
| 47 | + } finally { |
| 48 | + IOUtils.closeQuietly(response); |
| 49 | + IOUtils.closeQuietly(httpClient); |
| 50 | + } |
| 51 | + List<Cookie> cookies = context.getCookieStore().getCookies(); |
| 52 | + return cookies.get(0); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void test02() throws IOException { |
| 57 | + List<String> strings = new ArrayList<>(); |
| 58 | + strings.add("1"); |
| 59 | + strings.add("bbb"); |
| 60 | + strings.add("ccc"); |
| 61 | + } |
| 62 | + |
| 63 | + public void print(String string) throws IOException, IllegalAccessException{ |
| 64 | + switch (string){ |
| 65 | + case "1":throw new IOException("a"); |
| 66 | + case "2":throw new IllegalAccessException("b"); |
| 67 | + default: |
| 68 | + System.out.println(string); |
| 69 | + } |
| 70 | + } |
| 71 | + @Test |
| 72 | + public void test03() throws IOException, SchedulisSchedulerException { |
| 73 | + Cookie cookie = test01(); |
| 74 | + List<NameValuePair> params = new ArrayList<>(); |
| 75 | + params.add(new BasicNameValuePair("ajax","fetchProjectPage")); |
| 76 | + params.add(new BasicNameValuePair("start","0")); |
| 77 | + params.add(new BasicNameValuePair("length","10")); |
| 78 | + params.add(new BasicNameValuePair("projectsType","personal")); |
| 79 | + params.add(new BasicNameValuePair("pageNum","1")); |
| 80 | + params.add(new BasicNameValuePair("order","orderProjectName")); |
| 81 | + CookieStore cookieStore = new BasicCookieStore(); |
| 82 | + cookieStore.addCookie(cookie); |
| 83 | + HttpClientContext context = HttpClientContext.create(); |
| 84 | + CloseableHttpResponse response = null; |
| 85 | + CloseableHttpClient httpClient = null; |
| 86 | + try { |
| 87 | + String finalUrl = "http://127.0.0.1:8088/index" + "?" + EntityUtils.toString(new UrlEncodedFormEntity(params)); |
| 88 | + HttpGet httpGet = new HttpGet(finalUrl); |
| 89 | + httpGet.addHeader(HTTP.CONTENT_ENCODING, "UTF-8"); |
| 90 | + httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); |
| 91 | + response = httpClient.execute(httpGet, context); |
| 92 | + /*Header[] allHeaders = context.getRequest().getAllHeaders(); |
| 93 | + Optional<Header> header = Arrays.stream(allHeaders).filter(f -> "Cookie".equals(f.getAppJointName())).findFirst(); |
| 94 | + header.ifPresent(AzkabanUtils.handlingConsumerWrapper(this::parseCookie));*/ |
| 95 | + } catch (Exception e) { |
| 96 | + throw new SchedulisSchedulerException(90002, e.getMessage()); |
| 97 | + } finally { |
| 98 | + IOUtils.closeQuietly(response); |
| 99 | + IOUtils.closeQuietly(httpClient); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void test04(){ |
| 105 | +/* A a = new A(); |
| 106 | + Tuple2<String, String> hello = a.hello(); |
| 107 | + Tuple2<String, String> stringStringTuple2 = new Tuple2<>("","");*/ |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void test05(){ |
| 112 | + //String subFlowPath = "C:\\Users\\v_wbjftang\\linuxDownloads\\project_0926_tjf\\flow2\\subFlows\\subFlow21\\subFlows\\subFlow211"; |
| 113 | + String subFlowPath = "/Users/v_wbjftang/linuxDownloads/project_0926_tjf/flow2/subFlows/subFlow21/subFlows/subFlow211"; |
| 114 | + int indexOf = subFlowPath.indexOf("subFlows"); |
| 115 | + if(indexOf != -1){ |
| 116 | + subFlowPath = subFlowPath.substring(0, indexOf-1); |
| 117 | + } |
| 118 | + String substring1 = subFlowPath.substring(0, subFlowPath.lastIndexOf("/")); |
| 119 | + System.out.println(substring1); |
| 120 | + String allPath = "/Users/v_wbjftang/linuxDownloads/project_0926_tjf/flow2/subFlows/subFlow21/subFlows/subFlow211"; |
| 121 | + String substring = allPath.substring(substring1.length() +1 ); |
| 122 | + System.out.println("\\" + File.separator); |
| 123 | + //String s = substring.replaceAll("\\\\subFlows\\\\", "...."); |
| 124 | + String s = substring.replaceAll("\\" + File.separator +"subFlows" + "\\" + File.separator, "...."); |
| 125 | + System.out.println(s); |
| 126 | + } |
| 127 | + @Test |
| 128 | + public void test06(){ |
| 129 | +/* String nodeType = "spark.sql"; |
| 130 | + try { |
| 131 | + AbstractLinkisAzkabanJob job = LinkisAzkabanJobFactory.createJob(nodeType); |
| 132 | + } catch (ClassNotFoundException e) { |
| 133 | + e.printStackTrace(); |
| 134 | + } catch (IllegalAccessException e) { |
| 135 | + e.printStackTrace(); |
| 136 | + } catch (InstantiationException e) { |
| 137 | + e.printStackTrace(); |
| 138 | + } |
| 139 | + System.out.println("sdf");*/ |
| 140 | + } |
| 141 | +} |
0 commit comments