diff -r e413e4676929 tests/jnlp_tests/simple/ReadResourceFromURL/resources/ReadResourceFromURL_in.jnlp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/ReadResourceFromURL/resources/ReadResourceFromURL_in.jnlp Tue Jun 21 14:38:32 2011 +0200 @@ -0,0 +1,12 @@ + + + + read properties using System.getenv() + + + + + + [%res_url%] + + diff -r e413e4676929 tests/jnlp_tests/simple/ReadResourceFromURL/srcs/ReadResourceFromURL.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/ReadResourceFromURL/srcs/ReadResourceFromURL.java Tue Jun 21 14:38:32 2011 +0200 @@ -0,0 +1,86 @@ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +/* ReadResourceFromURL.java +Copyright (C) 2011 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ +public class ReadResourceFromURL { + + + public static void main(String[] args) throws Exception{ + + // System.getProperty("user.name"); + // System.getProperty("user.home"); + String resource=args[0]; + URL url=new URL(resource); + String s=getResourceAsString(url); + System.out.println(s); + } + + private static String getResourceAsString(URL u) throws IOException { + HttpURLConnection connection = (HttpURLConnection) u.openConnection(); + connection = (HttpURLConnection) u.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(true); + connection.setReadTimeout(10000); + connection.connect(); + return getContentOfStream(connection.getInputStream()); + } + + private static String getContentOfStream(InputStream is) throws IOException { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + StringBuilder sb = new StringBuilder(); + while (true) { + String s = br.readLine(); + if (s == null) { + break; + } + sb.append(s).append("\n"); + + } + return sb.toString(); + } finally { + is.close(); + } + + } +} diff -r e413e4676929 tests/jnlp_tests/simple/ReadResourceFromURL/testcases/ReadResourceFromURLTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/ReadResourceFromURL/testcases/ReadResourceFromURLTest.java Tue Jun 21 14:38:32 2011 +0200 @@ -0,0 +1,219 @@ +/* ReadResourceFromURLTest.java +Copyright (C) 2011 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import net.sourceforge.jnlp.ServerAccess; +import org.junit.Assert; +import org.junit.Test; + +public class ReadResourceFromURLTest { + + private static ServerAccess server = new ServerAccess(); + private static final String JNLP_IN = "ReadResourceFromURL_in.jnlp"; + private static final String JNLP = "ReadResourceFromURL.jnlp"; + private static final File jnlp_in=new File(server.getDir(), JNLP_IN) ; + private static final File jnlp=new File(server.getDir(), JNLP); + private static final String REPLACEMENT="[%res_url%]"; + private static final String NUMBERIZED_LOCALHOST="127.0.0.1"; + + /** + * this test is trying to load resource http://nameA:portA/res by webstart app loaded from http://nameA:portA/ + * Loading of resource should be sucessfull + * + * @throws Exception + */ + @Test + public void ReadResourceFromMyURL() throws Exception { + try{ + System.out.println("connecting ReadResourceFromURL request upon resources url"); + Assert.assertTrue(jnlp_in.exists()); + if (jnlp.exists())jnlp.delete(); + Assert.assertFalse(jnlp.exists()); + String resourceUrl=server.getUrl("/"+JNLP).toString(); + prepareJNLP(resourceUrl); + Assert.assertTrue(jnlp.exists()); + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/" + JNLP); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + Assert.assertFalse(pr.stderr.contains("java.security")); + Assert.assertFalse(pr.stderr.contains("ClassNotFoundException")); + Assert.assertFalse(pr.stdout.contains("java.security")); + Assert.assertFalse(pr.stdout.contains("ClassNotFoundException")); + Assert.assertTrue(pr.stdout.length() > 50); + Assert.assertTrue(pr.stdout.contains(" Loading of resource should be sucessfull + * + * @throws Exception + */ + @Test + public void ReadResourceFromMyURL2() throws Exception { + try{ + System.out.println("connecting ReadResourceFromURL request upon resources url"); + Assert.assertTrue(jnlp_in.exists()); + if (jnlp.exists())jnlp.delete(); + Assert.assertFalse(jnlp.exists()); + ServerAccess.getInstance().setServerName(ServerAccess.DEFAULT_LOCALHOST_NAME); + Assert.assertTrue(server.getUrl().getHost().contains(ServerAccess.DEFAULT_LOCALHOST_NAME)); + String resourceUrl=("http://"+NUMBERIZED_LOCALHOST+":"+server.getPort()+"/"+JNLP); + prepareJNLP(resourceUrl); + Assert.assertTrue(jnlp.exists()); + Assert.assertFalse(server.getUrl().getHost().contains(NUMBERIZED_LOCALHOST)); + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/" + JNLP); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + Assert.assertFalse(pr.stderr.contains("java.security")); + Assert.assertFalse(pr.stderr.contains("ClassNotFoundException")); + Assert.assertFalse(pr.stdout.contains("java.security")); + Assert.assertFalse(pr.stdout.contains("ClassNotFoundException")); + Assert.assertTrue(pr.stdout.length() > 50); + Assert.assertTrue(pr.stdout.contains("5) throw new IllegalStateException("Server is starting too long!"); + } + Assert.assertTrue(nwServer.isRunning()); + Assert.assertFalse(server.getPort()==nwServer.getPort()); + Assert.assertFalse(server.getUrl().equals(nwServer.getUrl())); + Assert.assertTrue(jnlp_in.exists()); + if (jnlp.exists())jnlp.delete(); + Assert.assertFalse(jnlp.exists()); + String resourceUrl=nwServer.getUrl("/"+JNLP).toString(); + prepareJNLP(resourceUrl); + Assert.assertTrue(jnlp.exists()); + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/" + JNLP); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + Assert.assertFalse(pr.stderr.contains("ClassNotFoundException")); + Assert.assertFalse(pr.stdout.contains(" 2); + Assert.assertTrue(pr.stderr.contains("java.security")); + Assert.assertFalse(pr.wasTerminated); + Assert.assertEquals((Integer) 0, pr.returnValue); + }finally{ + jnlp.delete(); + Assert.assertFalse(jnlp.exists()); + } + } + + + /** + * this test is trying to load resource http://nameA:portA/res by webstart app loaded from http://nameB:portB/ + * Although hosts are same by meaning (and differes by letters), ports differe, so whole URL is diferent so loading of resources should fail + * + * @throws Exception + */ + @Test + public void ReadResourceFromForeignURL2() throws Exception { + try{ + System.out.println("connecting ReadResourceFromURL request upon foreign url"); + ServerAccess.ServerLuncher nwServer= ServerAccess.getIndependentInstance(); + Assert.assertNotNull(nwServer); + nwServer.setServerName(NUMBERIZED_LOCALHOST); + long stime=System.nanoTime()/1000l/1000l/1000l;//s + while(!nwServer.isRunning()){ + long t=System.nanoTime()/1000l/1000l/1000l-stime;//s + if (t>5) throw new IllegalStateException("Server is starting too long!"); + } + Assert.assertTrue(nwServer.isRunning()); + Assert.assertFalse(server.getPort()==nwServer.getPort()); + Assert.assertFalse(server.getUrl().equals(nwServer.getUrl())); + + Assert.assertTrue(jnlp_in.exists()); + if (jnlp.exists())jnlp.delete(); + Assert.assertFalse(jnlp.exists()); + String resourceUrl=nwServer.getUrl("/"+JNLP).toString(); + prepareJNLP(resourceUrl); + Assert.assertTrue(jnlp.exists()); + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/" + JNLP); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + Assert.assertFalse(pr.stderr.contains("ClassNotFoundException")); + Assert.assertFalse(pr.stdout.contains(" 2); + Assert.assertTrue(pr.stderr.contains("java.security")); + Assert.assertFalse(pr.wasTerminated); + Assert.assertEquals((Integer) 0, pr.returnValue); + }finally{ + jnlp.delete(); + Assert.assertFalse(jnlp.exists()); + } + } + + private void prepareJNLP(String replacement) throws IOException { + String s = ServerAccess.getContentOfStream(new FileInputStream(jnlp_in)); + String ss = s.replace(REPLACEMENT, replacement); + ServerAccess.saveFile(ss, jnlp); + + } +}