##################################### # Servlet Test ÇÁ·Î±×·¥ # ##################################### ÀÛ¼ºÀÚ : ÀåÇüÈ­(hhjang97@venus.uos.ac.kr) ÀÛ¼ºÀÏ : 2004. 12. 17 ¼öÁ¤ÀÏ : ¿øº» : ¼³¸í : Servlet À» TestÇÒ¶§ »ç¿ëÇϸé ÁÁÀº ÇÁ·Î±×·¥ÀÌ´Ù. URL¿¡ Á¢¼ÓÇÏ¿© XMLÇüÅ·Πµ¥ÀÌÅ͸¦ º¸³½´Ù. ################################# ################################# ################################# package com.portal.test; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import java.net.UnknownHostException; /** * * @author hhjang97 * * ¼­ºí¸´À» »ç¿ëÇÏ´Â °æ¿ì Å×½ºÆ®¸¦ À§ÇÑ ÇÁ·Î±×·¥ * */ public class ServletTest implements Runnable { private String pushxml = null; private boolean flag2 = false; private String Url = null; private OutputStream out = null; private InputStream in = null; private URLConnection con =null; public ServletTest(){} public ServletTest(String pushxml) { this.pushxml = pushxml; } public boolean getFlag() { return flag2;} public void setPushXml(String pushxml){this.pushxml=pushxml;} public void setUrl(String Url){ this.Url = Url; } public void run() { try{ System.out.print("(************ SP ¿¡ ¿¬°áÇÕ´Ï´Ù ************)"); byte[] bytes = null; bytes = pushxml.getBytes(); System.out.println("bytes : "+bytes); System.out.println("URL : "+ Url); String pushresult = PushOutPut(bytes); System.out.print("(************ SP¿¡ º¸³½ °á°ú************)"); System.out.print(pushresult); //sendPostMessage("123456789", "http://129.254.176.120:9081/servlet/push.TrGetPush"); } catch(Exception ve) { System.err.println(ve); } flag2 = true; } private String PushOutPut(byte[] sendmsg) { String result = null; try{ byte[] bytes = sendmsg; URL url = new URL(Url); con = url.openConnection(); con.setUseCaches(false); con.setDoOutput(true); con.setRequestProperty("Content-Length",String.valueOf(bytes.length)); con.setRequestProperty("Content-Type","text/plain"); out = con.getOutputStream(); out.write(bytes); result ="Succeed.."; in = con.getInputStream(); int len = in.available(); byte[] receive = new byte[len]; in.read(receive,0,len); // result = new String(receive, "UTF-8"); result = new String(receive); }catch (UnknownHostException e){ e.printStackTrace(); }catch (IOException e){ }catch (Exception e){ e.printStackTrace(); }finally{ closeConnect(); } return result; } public void closeConnect() { try{ out.close(); if(in!=null) in.close(); con=null; }catch(IOException e){} } public static void main(String args[]) { try{ ServletTest tpc = new ServletTest(); // EMNPush Å×½ºÆ® String req_id = "200412130059521951007"; tpc.setPushXml("< ?xml version='1.0' encoding='EUC-KR'? ><svc_init><hdr><client><id>S001</id></client> </hdr></svc_init>"); tpc.setUrl("http://168.192.1.1:9080/servlet/com.EMNPush"); Thread thread = new Thread(tpc); thread.start(); }catch(Exception e){} } } ################################# # #################################