id
stringlengths
36
36
text
stringlengths
1
1.25M
5ec8ce68-fd87-4e57-8de4-7272d50951ff
@RequestMapping(value = "/mci/invalidSession") public String invalidSession(Model model, Locale locale) { logger.info("Session Invalidated"); date = new Date(); dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); model.addAttribute("title", "Invalid Session"); model.addAttribute("msg", "Invalid session. Please login again." ); model.addAttribute("serverTime", dateFormat.format(date)); return "/mci/message"; }
71be4661-978a-4056-aa19-3a755f854238
public testCase(String input, String[] tokens, double result) { this.input = input; this.tokens = tokens; this.result = result; }
f5176d37-1b17-4714-ad0b-4788ff4ebea4
@Test public void testGetTokens() { int i = 0; for (testCase c : cases) { assertArrayEquals("Test Case " + i + " failed", c.tokens, Calculator.parseInfix(c.input)); i++; } }
bf24ed59-715b-4457-b396-d8165affe88a
@Test public void testEval() throws CalcException { int i = 0; for (testCase c : cases) { try { assertEquals(c.result, Calculator.evaluate(c.input), epsilon); }catch(CalcException e) { fail("Test Case " + i + " threw exception: " + e.getMessage()); } i++; } thrown.expect(CalcException.class); for (String s : incorrect) { Calculator.evaluate(s); } }
0b52854c-ee6a-434d-9160-33ea104314ed
public StandardCSVFileIoTo readFile(InputStream inputStream, char delimiter) throws IOException { StandardCSVFileIoTo returnTo = new StandardCSVFileIoTo(); CsvReader reader = new CsvReader(inputStream, delimiter, Charset.defaultCharset()); reader.readHeaders(); String[] headersStrings = reader.getHeaders(); returnTo.setHeader(this.convertData(headersStrings)); while(reader.readRecord()) { String[] dataSet = reader.getValues(); returnTo.addDataSet(this.convertData(dataSet)); } return returnTo; }
cb29e64f-13c8-4d39-840a-22cd619ccbe7
public StandardCSVFileIoTo readFile(InputStream inputStream) throws IOException { return this.readFile(inputStream, ';'); }
c9a2bdad-6e98-4be8-8c79-9adb590b84de
public StandardCSVFileIoTo readFile(String fileName, char delimiter) throws IOException { return this.readFile(new FileInputStream(fileName), ';'); }
a188e0c5-675a-4cce-aea9-502cde222a6d
public StandardCSVFileIoTo readFile(String fileName) throws IOException { return this.readFile(new FileInputStream(fileName), ';'); }
8efc4305-4333-4e70-a2a4-f45661a8e607
private List<String> convertData(String[] dataSet) { List<String> returnList = new ArrayList<>(); for(String dataBlock:dataSet) { returnList.add(dataBlock); } return returnList; }
f0d73bfd-d717-44e3-bb6e-9f447b54a5c9
public StandardCSVFileIoTo() { this.header = new ArrayList<>(); this.data = new ArrayList<>(); }
6179de72-d472-4cb7-8a43-e2feb7f59a42
public StandardCSVFileIoTo(List<String> header, List<List<String>> allData) { this.header = header; this.data = allData; }
45a4505b-2e3c-4524-aefc-f271833db366
public List<String> getHeader() { return header; }
54f38fd3-6c80-48d0-a027-ee35eb802930
public void setHeader(List<String> header) { this.header = header; }
e6345273-9ea8-4715-a07f-92ba4aee10ab
public void addHeader(String header) { this.header.add(header); }
5f8ed6df-db6d-4420-917f-f164ca3e34c5
public List<List<String>> getData() { return data; }
2d295762-44c6-41b0-9e6a-7b837eaee335
public void setData(List<List<String>> data) { this.data = data; }
02a6a12a-2a0a-4168-9f70-f2072bd4eacf
public void addDataSet(List<String> dataSet) { this.data.add(dataSet); }
22bb783c-2bee-41e2-9912-54b6dc24b9b7
@Test public void testReadFile() { String fileName = "de/csp/fileio/csv/readertestsemicolon.csv"; InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileName); CSVReader csvReader = new CSVReader(); StandardCSVFileIoTo to; try { to = csvReader.readFile(inputStream); assertEquals(3, to.getHeader().size()); List<String> header = to.getHeader(); assertTrue(header.contains("header1")); assertTrue(header.contains("header2")); assertTrue(header.contains("header3")); assertEquals(1, to.getData().size()); List<String> dataSet = to.getData().get(0); assertEquals(3, dataSet.size()); assertTrue(dataSet.contains("data1")); assertTrue(dataSet.contains("data2")); assertTrue(dataSet.contains("data3")); } catch (IOException e) { LOGGER.error(e); fail(e.toString()); } }
793d649b-0b62-471c-802a-9dcb7edbc071
@Test public final void testSetHeader() { List<String> header = new ArrayList<>(); header.add("A"); header.add("Header"); header.add("Test"); StandardCSVFileIoTo to = new StandardCSVFileIoTo(); to.setHeader(header); assertEquals(3, to.getHeader().size()); assertTrue(to.getHeader().contains("A")); assertTrue(to.getHeader().contains("Header")); assertTrue(to.getHeader().contains("Test")); }
87b36f7d-6fa2-422c-8857-119ebc6f4df8
@Test public final void testAddHeader() { List<String> header = new ArrayList<>(); header.add("A"); header.add("Header"); header.add("Test"); StandardCSVFileIoTo to = new StandardCSVFileIoTo(header, null); String headerAppend = "Append"; to.addHeader(headerAppend); assertEquals(4, to.getHeader().size()); assertTrue(to.getHeader().contains("A")); assertTrue(to.getHeader().contains("Header")); assertTrue(to.getHeader().contains("Test")); assertTrue(to.getHeader().contains("Append")); }
671761be-520e-4318-818c-9c683428446e
@Test public final void testSetData() { List<List<String>> data = new ArrayList<>(); List<String> dataSet = new ArrayList<>(); dataSet.add(new String("1")); dataSet.add(new String("Data")); StandardCSVFileIoTo to = new StandardCSVFileIoTo(); data.add(dataSet); to.setData(data); assertEquals(1, to.getData().size()); List<String> dataRet = to.getData().get(0); assertEquals(2, dataRet.size()); assertTrue(dataRet.contains(new String("1"))); assertTrue(dataRet.contains("Data")); }
4e5536c2-f954-48d4-8adc-f8c6442b5cd0
@Test public final void testAddDataSet() { List<String> dataSet = new ArrayList<>(); dataSet.add(new String("1")); dataSet.add(new String("Data")); StandardCSVFileIoTo to = new StandardCSVFileIoTo(); to.addDataSet(dataSet); assertEquals(1, to.getData().size()); List<String> dataRet = to.getData().get(0); assertEquals(2, dataRet.size()); assertTrue(dataRet.contains(new String("1"))); assertTrue(dataRet.contains("Data")); }
4d908668-2e37-4a2f-9338-9e1a8608f4cf
public Client(String id, double purchases) { this.id = id; this.purchases = purchases; }
9d107c66-342a-43c0-a5d2-64a568d125c8
public String getId() { return id; }
298774cf-b88c-472f-848b-e80179192ea6
public double getPurchases() { return purchases; }
0caaad1c-af13-41b0-a583-5391fbbb6b1e
public ClientServiceImpl() { initDatabase(); }
947bc9fe-3b87-462a-83a2-87d4ca0b35a2
@Override public Client getClient(String id) { return clients.get(id); }
b040c070-7780-420a-8b74-216ad5753336
private void initDatabase() { clients.put("C01", new Client("C01", 1.0)); clients.put("C02", new Client("C02", 1.0)); clients.put("C03", new Client("C03", 1.0)); clients.put("C04", new Client("C04", 1.0)); clients.put("C05", new Client("C05", 1.0)); clients.put("C06", new Client("C06", 1.0)); clients.put("C07", new Client("C07", 1.0)); clients.put("C08", new Client("C08", 1.0)); clients.put("C09", new Client("C09", 1.0)); clients.put("C10", new Client("C10", 1.0)); clients.put("C11", new Client("C11", 1.0)); clients.put("C12", new Client("C12", 1.0)); clients.put("C13", new Client("C13", 1.0)); clients.put("C14", new Client("C14", 1.0)); clients.put("C15", new Client("C15", 1.0)); clients.put("C16", new Client("C16", 1.0)); clients.put("C17", new Client("C17", 1.0)); clients.put("C18", new Client("C18", 1.0)); clients.put("C19", new Client("C19", 1.0)); clients.put("C20", new Client("C20", 1.0)); }
3e70bea4-b897-49f3-ada5-9c17c43d6df0
Client getClient(String id);
96d30cec-b0ac-4381-8ad7-46a44e074ae2
@RequestMapping(value="/{clientId}", method = RequestMethod.GET) public @ResponseBody Client getClientWithDelay(@PathVariable String clientId) throws InterruptedException { Thread.sleep(2000); Client client = service.getClient(clientId); System.out.println("Returning client " + client.getId()); return client; }
07ab8605-b104-4426-88cf-e5c930c227fa
public String getCourseId() { return courseId; }
0d791b0b-f152-4a55-860c-70095f81ba57
public void setCourseId(String value) { this.courseId = value; }
ddbe6cd4-7771-462c-bdff-06e48426e0bc
public String getDescription() { return description; }
2749a3f4-b8d6-4fbb-8c35-dc3edf4b1b4d
public void setDescription(String value) { this.description = value; }
36ea5988-f786-45f5-8d10-bb6dcb36b34d
public String getName() { return name; }
f1d07328-b609-45c6-917e-e801b2f47c12
public void setName(String value) { this.name = value; }
14fa8136-0c6e-446f-b70e-86a0a7fd0820
public BigInteger getSubscriptors() { return subscriptors; }
05023a46-7304-4f28-b584-7b9b395ff7a5
public void setSubscriptors(BigInteger value) { this.subscriptors = value; }
28996d66-3cdb-49df-8931-cec80a980ebe
public ObjectFactory() { }
5cf8b708-4a7b-47df-9928-940a4f9add0e
public Course createCourse() { return new Course(); }
b1168b05-5150-4bbf-af11-5f81bd41b640
public GetCourseListResponse createGetCourseListResponse() { return new GetCourseListResponse(); }
c0d94d82-fa65-488e-a905-dd29e841a952
public GetCourseListRequest createGetCourseListRequest() { return new GetCourseListRequest(); }
746500b6-5013-4be0-b719-64b2dc995ead
public GetCourseResponse createGetCourseResponse() { return new GetCourseResponse(); }
26e54039-4ac7-468e-8b80-9e2b1c7188f2
public GetCourseRequest createGetCourseRequest() { return new GetCourseRequest(); }
5708175b-ad31-42e8-8e03-d6babee28b1c
public String getCourseId() { return courseId; }
67bc3a8b-9926-4796-8e6b-0f29f6b23c62
public void setCourseId(String value) { this.courseId = value; }
995986c7-5755-4254-8b64-d87ce83034e4
public String getDescription() { return description; }
85d4691f-a567-451b-8193-43c5ee6de925
public void setDescription(String value) { this.description = value; }
ff4b31b7-5c77-4109-9a56-faa862d87bd7
public String getName() { return name; }
b4345ab8-ffd3-4ff5-92f3-c5c7c1d8c04a
public void setName(String value) { this.name = value; }
eb8e23a6-f803-4e5e-a9ae-e980b02c222d
public BigInteger getSubscriptors() { return subscriptors; }
fd35d896-0c83-4f49-b6cd-ab0b331a94c7
public void setSubscriptors(BigInteger value) { this.subscriptors = value; }
f99f45d7-ffb4-4546-b55d-02aa361e2c2f
public List<Course> getCourse() { if (course == null) { course = new ArrayList<Course>(); } return this.course; }
54f97033-02c3-458c-a267-10276042934b
public String getCourseId() { return courseId; }
2d792b41-9666-46e9-a726-4cc1f6c5d253
public void setCourseId(String value) { this.courseId = value; }
216e41e7-ccbe-4a3a-a252-d681560c172b
public CourseServiceImpl() { courses = new HashMap<>(); Course course1 = new Course(); course1.setCourseId("BC-45"); course1.setDescription("An introduction to Java"); course1.setName("Introduction to Java"); course1.setSubscriptors(new BigInteger("25")); courses.put("BC-45", course1); Course course2 = new Course(); course2.setCourseId("DF-21"); course2.setDescription("Learn about functional programming"); course2.setName("Functional Programming Principles in Scala"); course2.setSubscriptors(new BigInteger("12")); courses.put("DF-21", course2); }
ab320cfa-99ea-4386-af21-2634ac413c93
@Override public Map<String, Course> getCourses() { return Collections.unmodifiableMap(courses); }
a9601735-aebd-48d7-8197-36571688abef
@Override public Course getCourse(String courseId) { if ("DF-21".equals(courseId)) { try { Thread.sleep(4000); //added sleep in order to test client timeout } catch (InterruptedException e) { } } return courses.get(courseId); }
d2f84e0e-f3f4-4f46-b069-8d3df4f9c20c
Map<String, Course> getCourses();
1c5b7b2c-dbb9-421d-86b4-a107ba8e7185
Course getCourse(String courseId);
de75b357-83da-4fd7-a9c7-190704089cce
public CourseNotFoundException(String message) { super(message); }
63b3dd02-769f-4550-b560-6015168ddde4
public CourseNotFoundException(String message, Throwable t) { super(message, t); }
71b2082c-5e18-4dd5-9902-0e8ccca8186b
@PayloadRoot(localPart="getCourseRequest", namespace=NAMESPACE) public @ResponsePayload GetCourseResponse getCourse(@RequestPayload GetCourseRequest request) { Course course = service.getCourse(request.getCourseId()); if (course == null) { throw new CourseNotFoundException("course [" + request.getCourseId() + "] does not exist"); } GetCourseResponse response = new GetCourseResponse(); response.setCourseId(course.getCourseId()); response.setDescription(course.getDescription()); response.setName(course.getName()); response.setSubscriptors(course.getSubscriptors()); return response; }
5a41e52c-a74f-40cd-8bb0-9122b39d1e58
@PayloadRoot(localPart="getCourseListRequest", namespace=NAMESPACE) public @ResponsePayload GetCourseListResponse getCourseList(@RequestPayload GetCourseListRequest request) { GetCourseListResponse response = new GetCourseListResponse(); for (Map.Entry<String, Course> entry : service.getCourses().entrySet()) { response.getCourse().add(entry.getValue()); } return response; }
f922f809-72b3-4146-8d48-2b6355e17b21
@Test public void invokeGetCourseOperation() throws Exception { GetCourseRequest request = new GetCourseRequest(); request.setCourseId("BC-45"); GetCourseResponse response = (GetCourseResponse) wsTemplate.marshalSendAndReceive(request); assertNotNull(response); assertEquals("BC-45", response.getCourseId()); assertEquals("Introduction to Java", response.getName()); assertEquals("An introduction to Java", response.getDescription()); assertEquals(new BigInteger("25", 10), response.getSubscriptors()); }
f769dcc4-39e6-40f9-94ee-b4be31903c95
@Test(expected=SoapFaultClientException.class) public void invokeOnInvalidCourse() { GetCourseRequest request = new GetCourseRequest(); request.setCourseId("non_existing_course"); GetCourseResponse response = (GetCourseResponse) wsTemplate.marshalSendAndReceive(request); assertNull(response); }
526cc73a-5154-4ec0-b7e0-37a8278cdc9a
@Test public void invokeGetCourseListOperation() { GetCourseListRequest request = new GetCourseListRequest(); GetCourseListResponse response = (GetCourseListResponse) wsTemplate.marshalSendAndReceive(request); assertNotNull(response); List<Course> courses = response.getCourse(); assertEquals(2, courses.size()); }
7fbb78a1-d59b-4179-8993-63a9458ce1d1
public String getTime() { return time; }
f2390bbf-69e9-4d22-b934-ac65f0e3513a
public void setTime(String time) { this.time = time; }
28857241-1768-4db1-9fc4-3b5b224ca94b
public double getOpenPrice() { return openPrice; }
af359742-6902-417d-b2fd-5c92987e8faa
public void setOpenPrice(double openPrice) { this.openPrice = openPrice; }
9410c510-78c4-4208-a308-867d1f7693ec
public double getHighPrice() { return highPrice; }
0157bcaa-7473-4ced-a0f1-02484f5462dc
public void setHighPrice(double highPrice) { this.highPrice = highPrice; }
e74efc01-712d-4d47-a63b-7015bffe071d
public double getEndPrice() { return endPrice; }
df7fcc3a-8031-4f88-bd7d-66c1eb7931df
public void setEndPrice(double endPrice) { this.endPrice = endPrice; }
965b9480-a27c-4cec-80a2-28e807904b92
public double getLowPrice() { return lowPrice; }
fd13236b-0bec-4056-b6df-12fb3b6ea1c9
public void setLowPrice(double lowPrice) { this.lowPrice = lowPrice; }
90a8d5b3-206a-4625-87db-81897ec4ca31
public int getDealCount() { return dealCount; }
92550728-4a3b-4090-9129-5ef8bd7b3f31
public void setDealCount(int dealCount) { this.dealCount = dealCount; }
817c18ec-9523-4e1f-8617-f58394e17400
public int getDealAmount() { return dealAmount; }
c2398a18-3dcc-4863-94da-174aacce0b8e
public void setDealAmount(int dealAmount) { this.dealAmount = dealAmount; }
b9caeb0c-859f-4a67-aa35-32569cb3b596
@Override public String toString() { return "HisStockData [time=" + time + ", openPrice=" + openPrice + ", highPrice=" + highPrice + ", endPrice=" + endPrice + ", lowPrice=" + lowPrice + ", dealCount=" + dealCount + ", dealAmount=" + dealAmount + "]"; }
a73e16ab-cb45-4c96-ac15-af4fc571baf8
public static HttpClientTestServer getSingleInstance() { return singleInstance; }
84746709-58a7-43a4-af0c-ff38b7a7fd04
public boolean startServer() { try { int times = Integer.parseInt(VarManageServer.getSingleInstance().getVarStringValue("chongqing_times")); long sleepTime = 0; for(int i=0;i<times;i++){ long start = new Date().getTime(); testHttpClientTime(); sleepTime = 100000+Math.round(Math.random() * 60000); long cost=System.currentTimeMillis() - start; System.out.println("=========================消耗时间:" + cost); sleepTime = 100000+Math.round(Math.random() * 60000); System.out.println("=========================sleepTime:" + sleepTime); try{ Thread.sleep(sleepTime); }catch(Exception ex){ ex.printStackTrace(); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } this.isRunning = true; return true; }
31ed112c-7ab5-442e-8098-9339bd3e3f5a
public void stopServer() { }
3d011b8c-61de-4595-861c-1f86ad6becd0
private static List<String> testHttpClientTime() throws Exception { String xml = "323A003E7CDCBA0177D5CC213B192DAE55"; String url = "http://101.231.67.134:8050"; if (StrFilter.hasValue(VarManageServer.getSingleInstance().getVarStringValue("url"))) { url = VarManageServer.getSingleInstance().getVarStringValue("url"); } List<String> list = new ArrayList<String>(); HttpClient httpClient = getHttpClient(url); HttpPost post =null; // 获得HttpPost对象 try { post= new HttpPost(url); if (Boolean.parseBoolean(VarManageServer.getSingleInstance().getVarStringValue("debug"))) { System.out.println(url); System.out.println(xml); } post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); post.setEntity(new InputStreamEntity(new ByteArrayInputStream(xml.getBytes()), ContentType.create( "application/xml", "utf-8"))); // 发送请求 HttpResponse response = httpClient.execute(post); // 输出返回值 InputStream is = response.getEntity().getContent(); String s = EntityUtils.toString(response.getEntity()); if (Boolean.parseBoolean(VarManageServer.getSingleInstance().getVarStringValue("debug"))) { System.out.println(s); } } finally { if(post!=null){ post.releaseConnection(); } } return list; }
7413f047-2889-43ab-9caa-c3eb54569044
private void testSqlServer() { HIBADbServer dbServer = HIBADbServer.getSingleInstance(); DbHandle conn = null; try { conn = dbServer.getConn(); StatementHandle stmt = conn.createStatement(); String sql = "select * from orderinfo where id>230"; ResultSet rs = stmt.executeQuery(sql); int i = 0; StringBuffer buff = new StringBuffer(); while (rs.next()) { buff.append("INSERT INTO orderInfo (OrderId, Result, CreateDate, xmlContent, HandleStatus, orderType) VALUES "); buff.append("("); buff.append("'" + rs.getString("OrderId") + "',"); buff.append("'" + rs.getString("Result") + "',"); buff.append("'" + rs.getString("CreateDate") + "',"); buff.append("'" + rs.getString("xmlContent") + "',"); buff.append("'" + rs.getString("HandleStatus") + "',"); buff.append("'" + rs.getString("orderType") + "');"); i++; } System.out.println(buff.toString()); System.out.println("总记录数:" + i); } catch (Exception ex) { ex.printStackTrace(); } finally { dbServer.releaseConn(conn); } }
5ed66edb-feab-4dba-b280-c2fb85e3cfbc
private static org.apache.http.client.HttpClient getHttpClient(String url){ System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug"); org.apache.http.client.HttpClient client=httpClientMap.get(url); if(client!=null){ return client; } SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); HttpParams params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,15000); params.setParameter(CoreConnectionPNames.SO_TIMEOUT,30000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); cm.setMaxTotal(100); cm.setDefaultMaxPerRoute(50); client = new DefaultHttpClient(cm, params); httpClientMap.put(url, client); return client; }
d32fcbbb-9506-4bc5-875a-d9fe91dbe03e
public static HttpsClientTestServer1 getSingleInstance() { if (instance == null) { instance = new HttpsClientTestServer1(); } return instance; }
eb5e8494-a4c3-460c-9acc-7032a2333452
@Override public boolean startServer() { int times = Integer.parseInt(VarManageServer.getSingleInstance().getVarStringValue("chongqing_times")); long sleepTime = 0; for (int i = 0; i < times; i++) { long start = System.currentTimeMillis(); testConnection(); long cost=System.currentTimeMillis() - start; logger.info("=========================消耗时间:" + cost); sleepTime = Math.round(Math.random() * 300000); logger.info("=========================sleepTime:" + sleepTime); try { Thread.sleep(sleepTime); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // TODO Auto-generated method stub this.isRunning = true; return true; }
d74dbd15-3618-41e9-b5ee-901616e50249
public static void testConnection() { System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug"); // TODO Auto-generated method stub String url = "https://wexpress-mobipay.ymcft.com:4431/MobilePay/MobilePayService.aspx"; String chongqingUrl = VarManageServer.getSingleInstance().getVarStringValue("chongqing_url"); if (StrFilter.hasValue(chongqingUrl)) { url = chongqingUrl; } String charset = "utf-8"; HttpClient client = getHttpClient(); HttpPost httpPost = new HttpPost(url); try { RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(0) .setConnectTimeout(15000) .setConnectionRequestTimeout(15000).build(); httpPost.setConfig(requestConfig); String xmlInfo = "323A003E7CDCBA0177D5CC213B192DAE55<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<SERVICE>" + "<SYS_HEAD><TRAN_CODE>AM0003</TRAN_CODE><MER_CODE>30103005</MER_CODE>" + "<POS_CODE>10000001</POS_CODE><TRAN_DATE>20140418</TRAN_DATE>" + "<TRAN_TIME>102310</TRAN_TIME><TRAN_SEQ>00002001</TRAN_SEQ></SYS_HEAD>" + "<BODY>" + "<MER_ORDER>301030052</MER_ORDER>" + "<TRAN_AMT>123.09</TRAN_AMT>" + "<ACCT_NO>OD31234519</ACCT_NO>" + "<PAY_STAT>1</PAY_STAT>" + "</BODY>" + "</SERVICE>"; byte[] reqBytes = (byte[]) xmlInfo.getBytes(charset); httpPost.setEntity(new InputStreamEntity(new ByteArrayInputStream(reqBytes), ContentType.create( "application/xml", charset))); // httpPost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, // false); HttpResponse response = client.execute(httpPost); HttpEntity entity = response.getEntity(); byte[] result = EntityUtils.toByteArray(entity); String receiveMsg = new String(result, charset); logger.info("recieve:" + new String(receiveMsg.getBytes(charset), charset)); } catch (Exception ex) { ex.printStackTrace(); }finally{ if(httpPost!=null){ httpPost.releaseConnection(); } } }
e059d479-5886-4643-9228-54584eacc850
private static HttpClient getHttpClient() { try { if (httpClient != null) { return httpClient; } ConnectionKeepAliveStrategy myStrategy = new ConnectionKeepAliveStrategy() { public long getKeepAliveDuration(HttpResponse response, HttpContext context) { // Honor 'keep-alive' header HeaderElementIterator it = new BasicHeaderElementIterator( response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { try { logger.info("服务端的保持连接时常:"+value); return Long.parseLong(value) * 1000; } catch(NumberFormatException ignore) { } } } return 300 * 1000; } }; PoolingHttpClientConnectionManager connManager = null; try { SSLContext sslContext = SSLContexts.custom().useTLS().build(); sslContext.init(null, new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted( X509Certificate[] certs, String authType) { } public void checkServerTrusted( X509Certificate[] certs, String authType) { } }}, null); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslContext)) .build(); connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); httpClient = HttpClients.custom().setConnectionManager(connManager).setKeepAliveStrategy(myStrategy).build(); // Create socket configuration SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).build(); connManager.setDefaultSocketConfig(socketConfig); // Create message constraints MessageConstraints messageConstraints = MessageConstraints.custom() .setMaxHeaderCount(200) .setMaxLineLength(2000) .build(); // Create connection configuration ConnectionConfig connectionConfig = ConnectionConfig.custom() .setMalformedInputAction(CodingErrorAction.IGNORE) .setUnmappableInputAction(CodingErrorAction.IGNORE) .setCharset(Consts.UTF_8) .setMessageConstraints(messageConstraints) .build(); connManager.setDefaultConnectionConfig(connectionConfig); connManager.setMaxTotal(200); connManager.setDefaultMaxPerRoute(20); } catch (KeyManagementException e) { logger.info("KeyManagementException"+ e.getMessage()); } catch (NoSuchAlgorithmException e) { logger.info("NoSuchAlgorithmException"+ e.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); } return httpClient; }
f642abb8-4889-4205-b23e-f8966016a540
public long getKeepAliveDuration(HttpResponse response, HttpContext context) { // Honor 'keep-alive' header HeaderElementIterator it = new BasicHeaderElementIterator( response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { try { logger.info("服务端的保持连接时常:"+value); return Long.parseLong(value) * 1000; } catch(NumberFormatException ignore) { } } } return 300 * 1000; }
3189e5c3-98b0-4074-8970-3137999b0d98
public X509Certificate[] getAcceptedIssuers() { return null; }
7eeb87dc-a697-4ff5-bbd7-03f82f4a1adc
public void checkClientTrusted( X509Certificate[] certs, String authType) { }
ff12ee6b-2433-48b8-b37b-689b6304c57d
public void checkServerTrusted( X509Certificate[] certs, String authType) { }
73c3f701-23ee-42cc-a1ba-339d6554b0f0
public static void main(String[] args) { System.out.println(Math.round(Math.random() * 120000)); }
45c8ece8-cbcb-473a-8d38-c750a814238b
public static JsoupTestServer getSingleInstance(){ if(instance==null){ instance=new JsoupTestServer(); } return instance; }
72fd8a04-28b6-481f-8b08-6d24475d84cb
@Override public boolean startServer() { // TODO Auto-generated method stub this.parseUrl(); this.test(); this.test1(); this.isRunning=true; return true; }
e0f81586-5e30-4e82-aac8-a8ac9e595528
public void parseUrl() { try { Document doc = Jsoup.connect("http://www.baidu.com/").get(); Elements hrefs = doc.select("a[href]"); System.out.println(hrefs); System.out.println("------------------"); System.out.println(hrefs.select("[href^=http]")); } catch (IOException e) { e.printStackTrace(); } }