기술교육 JEUS JNLP Sample 가이드 2015. 06. 19
목차 JEUS JNLP Client Sample 가이드... 3 1. JNLP 란... 3 2. JNLP의이점... 3 3. TEST... 3 3.1 TEST 환경... 3 3.2 TEST Sample... 4 3.2.1 sample application 셋팅 (server side)... 4 3.2.2 sample application 셋팅 (client side)... 5 3.2.3 sample application 셋팅 (JEUS 셋팅 )... 6 3.3 TEST 결과확인... 7 3.3.1 jnlp 파일호출확인... 7 3.3.2 예외상황및조치... 8 3.3.3 JWS를통해서 client 프로그램실행하기... 8 3.3.4 로그확인... 9 4. 최종정리... 9 2
JEUS JNLP Client Sample 가이드 1. JNLP 란 JNLP란 (Java Network Lunching Protocol) 의약어로써, application 의 size가크거나, 변경이자주일어날때소프트웨어의컴포넌트의배포및실행을위해서 JAVA 에서제공하는 API입니다. JAVA 는 JNLP의참조구현을할수있는 JWS(Java Web Start) 기능을제공합니다. JNLP Client 프로그램을사용하려면, 즉 JNLP 파일을웹상에서다운받고, jar파일들을웹상에서다운받고직접실행하기위해서는 JNLP 프로토콜을구현한서블릿이필요합니다. JEUS에서는이를직접제공하지않기때문에 JDK1.5 에서제공하는 JNLP 서블릿 API(jnlp-servlet.jar) 를사용합니다. 그림 1 2. JNLP 의이점 1. Application 을위한자바런타임환경의버전탐지와설치및사용이용이. 2. 브라우저나데스크톱으로부터 application 을실행할수있음. 예로, heapdump 분석기인MemoryAnalyzer 등을구현할수있음. 3. 애플릿이나 application 으로실행가능하며사용자의기호에따라필요한 native library 등을다운받을수있음. 3. TEST 3.1 TEST 환경 - Java : 1.6버전 - JNLP clinet API : j아1.5 이상지원 jnlp-servlet.jar - JEUS버전 : jeus 6.0.0.7 - OS : any 3
3.2 TEST Sample 3.2.1 sample application 셋팅 (server side) WebRoot : /user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web suntest:/user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web>ls -l 총 10 drwxrwxr-x 5 wonyoung ia 512 6월 2일 11:44 WEB-INF drwxrwxr-x 2 wonyoung ia 512 6월 2일 19:02 app -rw-rw-r-- 1 wonyoung ia 298 6월 2일 11:41 index.html 서블릿을구현해둔 jnlp-servlet.jar 파일은 WEBROOT/WEB-INF/lib 에위치시킵니다. suntest:/user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web/web-inf/lib>ls - al 총 120 drwxrwxr-x 2 wonyoung ia 512 6 월 19 일 17:36. drwxrwxr-x 5 wonyoung ia 512 6 월 2 일 11:44.. -rw-rw-r-- 1 wonyoung ia 59078 2013 년 3 월 6 일 jnlp-servlet.jar 여기서 index.html 을 jnlp 파일다운을검증을위한 sample page ( 생략가능 ) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>hello JavaEE</title> </head> <body> <center> <h1>hello JavaEE Sample Application!</h1> <form action="app/helloclient.jnlp"> <input type="submit" value="invoke HelloJnlp" /> </form> </center> </body> </html> HelloClient.jnlp 파일작성 /user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web/app/ HelloClient.jnlp 아래 jnlp 파일은 JEUS 매뉴얼을이용한 sample 이며, JWS 를이용해서실행할 client 소스는 <resources> 부분에추 가하면됩니다. <?xml version="1.0" encoding="utf-8"?> <jnlp spec="1.0" codebase="$$codebase"> <information> <title>helloclient</title> <vendor>tmaxsoft</vendor> </information> <resources> <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/> 4
<jar href="hello-client.jar"/> <jar href="jclient.jar"/> </resources> <application-desc main-class="helloejb.helloclient"/> </jnlp> WEB-INF/web.xml 등록 <?xml version="1.0" encoding="utf-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/x ml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>jnlpdownloadservlet</servlet-name> <servlet-class>jnlp.sample.servlet.jnlpdownloadservlet</servlet-class> <init-param> <param-name>loglevel</param-name> <param-value>debug</param-value> </init-param> <init-param> <param-name>logpath</param-name> <param-value>jnlpdownloadservlet.log</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>jnlpdownloadservlet</servlet-name> <url-pattern>*.jnlp</url-pattern> </servlet-mapping> </web-app> 3.2.2 sample application 셋팅 (client side) HelloClient.class(HelloClient.java) 작성 package helloejb; import java.awt.borderlayout; import java.awt.container; import java.awt.font; import java.util.hashtable; import javax.naming.context; import javax.naming.initialcontext; import javax.swing.jframe; import javax.swing.jlabel; public class HelloClient extends JFrame { public static void main(string[] args) { new HelloClient(); } public HelloClient() { try { Hashtable env = new Hashtable(); env.put("java.naming.factory.initial", "jeus.jndi.jnscontextfactory"); Context context = new InitialContext(env); Hello hello = (Hello)context.lookup("helloejb.Hello"); 5
JLabel label = new JLabel(hello.sayHello()); label.setfont(new Font("Helevetica", 1, 15)); getcontentpane().setlayout(new BorderLayout()); getcontentpane().add(label, "Center"); setsize(500, 250); setvisible(true); } catch (Exception ex) { ex.printstacktrace(); } } } Hello.class(Hello.java) 작성 package helloejb; import javax.ejb.remote; @Remote public abstract interface Hello { public abstract String sayhello(); } 위의두개의소스 code 를컴파일한후에 jar 로패키징합니다. suntest:/user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web/app/hello-client >ls Hello.class HelloClient.class suntest:/user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web/app>jar cvf hello-client.jar hello-client 추가된 manifest 추가중 : hello-client/( 내부 = 0) ( 외부 = 0)(0% 가저장되었습니다.) 추가중 : hello-client/hello.class( 내부 = 203) ( 외부 = 166)(18% 가감소되었습니다.) 추가중 : hello-client/helloclient.class( 내부 = 1721) ( 외부 = 957)(44% 가감소되었습니다.) suntest:/user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web/app>ls -al 총 9930 drwxrwxr-x 3 wonyoung ia 512 6 월 19 일 17:19. drwxrwxr-x 4 wonyoung ia 512 6 월 19 일 16:49.. -rw-rw-r-- 1 wonyoung ia 421 6 월 2 일 11:41 HelloClient.jnlp drwxr-xr-x 2 wonyoung ia 512 6 월 2 일 15:01 hello-client -rw-r--r-- 1 wonyoung ia 1838 6 월 19 일 17:19 hello-client.jar -rw-r--r-- 1 wonyoung ia 5056548 6 월 2 일 19:02 jclient.jar suntest:/user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web/app>jar tvf hello-client.jar 0 Fri Jun 19 17:19:42 KST 2015 META-INF/ 71 Fri Jun 19 17:19:42 KST 2015 META-INF/MANIFEST.MF 0 Tue Jun 02 15:01:40 KST 2015 hello-client/ 203 Tue Jun 02 15:01:40 KST 2015 hello-client/hello.class 1721 Tue Jun 02 15:01:40 KST 2015 hello-client/helloclient.class 위에서패키징한 hello-client.jar 는 url path 가 WEBROOT/app 로되어있기때문에 jnlp 파일이있는동일경로에위치시 키고, 위의 sample jnlp 파일에의거하여 jclient.jar 파일은 $JEUS_HOME/lib/client 의 jclient.jar 를사용합니다. 3.2.3 sample application 셋팅 (JEUS 셋팅 ) 6
JEUSMain.xml (application deploy path 셋팅 ) <application> <name>jnlp</name> <path>/user/wonyoung/jeus6/samples/client/hellojnlp/hello-war/web</path> <deployment-type>component</deployment-type> <web-component> <context-root>/</context-root> </web-component> <deployment-target> <target> <engine-container-name>suntest_container1</engine-container-name> </target> </deployment-target> </application> 3.3 TEST 결과확인 3.3.1 jnlp 파일호출확인 Explorer 브라우저에서 URL 호출로위의 HelloClient.jnlp 파일을다운받아봅니다. <jnlp> 태그에서 codebase 속성의 '$$codebase' 는 JNLP 서블릿을포함한웹애플리케이션이 deploy된 Context 에따라자동으로교체되는것을확인합니다. 또한, <security> 의옵션을추가하지않으면나중에 JSW를통해서 jnlp를 call했을때아래의표내용과같은 Exception 을회피하기위해추가합니다. java.security.accesscontrolexception: access denied ("java.util.propertypermission" "user.dir" "read") at java.security.accesscontrolcontext.checkpermission(unknown Source) at java.security.accesscontroller.checkpermission(unknown Source) at java.lang.securitymanager.checkpermission(unknown Source) at java.lang.securitymanager.checkpropertyaccess(unknown Source) at java.lang.system.getproperty(unknown Source) at jeus.util.jeusbootstrappropertyvalues.<clinit>(jeusbootstrappropertyvalues.java:23) at jeus.util.logging.jeuslogger.<clinit>(jeuslogger.java:78) <?xml version="1.0" encoding="utf-8"?> <jnlp spec="1.0" codebase="$$codebase"> <information> 7
<title>helloclient</title> <vendor>tmaxsoft</vendor> </information> <security> <all-permissions/> </security> <resources> <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/> <jar href="jclient.jar"/> <jar href="hello-client.jar"/> </resources> <application-desc main-class="helloejb.helloclient"/> </jnlp> ######################### 교체 ############################# <jnlp spec="1.0" codebase="http://xxx.xxx.xxx.xxx:8200/app/"> 3.3.2 예외상황및조치 위의내용대로하면 jnlp 파일은정상적으로 down 되지만, JWS 를통해서실행하게되면아래와같은 error 가발생합 니다. 그이유는 JWS 프로그래밍의경우는 Permission 을체크하기때문에 j2ee-application-client-permissions 를기술 하고 JAR 파일은반드시 sign 을해야하기때문입니다. com.sun.deploy.net.jarsigningexception: 리소스에서서명되지않은항목을찾음 : http://xxx.xxx.xxx.xxx:8200/app/jclient.jar at com.sun.javaws.security.signinginfo.getcommoncodesignersforjar(unknown Source) at com.sun.javaws.security.signinginfo.check(unknown Source) at com.sun.javaws.security.jnlpsignedresourceshelper.checksignedresourceshelper(unknown Source) at com.sun.javaws.security.jnlpsignedresourceshelper.checksignedresources(unknown Source) at com.sun.javaws.launcher.prepareresources(unknown Source) at com.sun.javaws.launcher.prepareallresources(unknown Source) at com.sun.javaws.launcher.preparetolaunch(unknown Source) at com.sun.javaws.launcher.preparetolaunch(unknown Source) at com.sun.javaws.launcher.launch(unknown Source) at com.sun.javaws.main.launchapp(unknown Source) at com.sun.javaws.main.continueinsecurethread(unknown Source) at com.sun.javaws.main.access$000(unknown Source) 따라서 jnlp 의 <resource> 에등록된 jar 파일을 sign 해야합니다. Sign 하는방법은아래와같습니다. jdk 에서제공하는 keytool 을이용해서 keystore 를만들고해당 jar 파일을 jarsigner 하여 keystore 에등록해줍니다. keytool -genkey -alias helloclient -keypass 123456 -keystore helloks -storepass 123456 jarsigner -keystore helloks hello-client.jar helloclient jarsigner -keystore helloks jclient.jar helloclient 3.3.3 JWS 를통해서 client 프로그램실행하기 web 상에서열기를통해서열어도되고, jnlp 를다운로드받은후에연결프로그램을통해서실행해도마찬가지입니 8
다. 3.3.4 로그확인 4. 최종정리 WEBROOT/app/ jnlpdownloadservlet.log 내용 (jnlp 호출시 ) JnlpDownloadServlet(3): Request: /app/helloclient.jnlp JnlpDownloadServlet(3): User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko JnlpDownloadServlet(4): DownloadRequest[path=/app/HelloClient.jnlp encoding=gzip, deflate isplatformrequest=false] JnlpDownloadServlet(4): Basic Protocol lookup JnlpDownloadServlet(4): JnlpResource: JnlpResource[WAR Path: /app/helloclient.jnlp lastmodified=wed Jun 24 13:26:05 KST 2015]] JnlpDownloadServlet(3): Resource returned: /app/helloclient.jnlp JnlpDownloadServlet(4): SupportQuery in Href: true JnlpDownloadServlet(4): lastmodified: 1435119965000 Wed Jun 24 13:26:05 KST 2015 1) 클라이언트에서웹브라우저를통해 JWS 애플리케이션에대한링크 (.jnlp 파일 ) 를클릭 2) 웹서버는클라이언트가클릭한링크에해당하는.jnlp 파일을제공 (serve) 3) 웹브라우저에의해서 'JWS 보조애플리케이션 ' 실행. 이보조애플리케이션은.jnlp 파일의내용을해독하여실제애플리케이션인.jar 파일을서버에요청 4) 서버는요청받은.jar 파일을제공 (serve) 5) JWS는서버로부터.jar 파일을받아지정된 main() 메소드를호출하여애플리케이션을실행 6) 이다음부터 JWS 애플리케이션을실행하고자할때에는이미받은 JWS 애플리케이션을실행 9
Copyright 2015 TmaxSoft Co., Ltd. All Rights Reserved. Trademarks Tmax, WebtoB, WebT, JEUS, ProFrame, SysMaster and OpenFrame are registered trademarks of TmaxSoft Co., Ltd. Other products, titles or services may be registered trademarks of their respective companies. Contact Information TmaxSoft can be contacted at the following addresses to arrange for a consulting team to visit your company and discuss your options. Korea TmaxSoft Co., Ltd 5, Hwangsaeul-ro 329beon-gil, Bundang-gu, Seongnam-si, Gyeonggi-do. South Korea Tel: +82-31-8018-1000 Fax: +82-31-8018-1115 Email: info@tmax.co.kr Web (Korean): http://www.tmaxsoft.com Technical Support: http://technet.tmaxsoft.com USA TmaxSoft, Inc. 560 Sylvan Avenue Englewood Cliffs, NJ 07632. U.S.A Tel: +1-201-567-8266 Fax: +1-201-567-7339 Email: info@tmaxsoft.com Web (English): http://www.tmaxsoft.com Russia Tmax Russia L.L.C. Grand Setun Plaza, No A204 Gorbunova st.2, Moscow, 121596 Tel: +7(495)970-01-35 Email: info.rus@tmaxsoft.com Web (Russian): http://ru.tmaxsoft.com Singapore Tmax Singapore Pte. Ltd. 430 Lorong 6, Toa Payoh #10-02, OrangeTee Building. Singapore 319402 Tel: +65-6259-7223 Email: info.sg@tmaxsoft.com United Kingdom TmaxSoft UK Ltd. Surrey House, Suite 221, 34 Eden Street, Kingston-Upon- Thames, KT1 1ER United Kingdom Tel: + 44-(0)20-8481-3776 Email: info.uk@tmaxsoft.com Web (English): http:/www.tmaxsoft.com Japan TmaxSoft Japan Co., Ltd. 5F Sanko Bldg, 3-12-16 Mita, Minato-Ku, Tokyo, 108-0073 Japan Tel: +81-3-5765-2550 Fax: +81-3-5765-2567 Email: info.jp@tmaxsoft.com Web (Japanese): http://www.tmaxsoft.co.jp China TmaxSoft China Co., Ltd. Beijing Silver Tower, RM 1508, 2 North Rd Dong San Huan, Chaoyang District, Beijing, China, 100027. China Tel: +86-10-6410-6145~8 Fax: +86-10-6410-6144 Email: info.cn@tmaxsoft.com Web (Chinese): http://www.tmaxsoft.com.cn Brazil TmaxSoft Brazil Avenida Copacabana, 177-3 andar 18 do Forte Empresarial, Alphaville - Barueri, Sao Paulo, SP-Brasil CEP 06472-001 Email: contato.brasil@tmaxsoft.com TD-JSGI-E0619001 10