J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 4191147 |
| 26 | * @summary 1.2beta4 does not load user defined content handlers |
| 27 | * @build UserContentHandler |
| 28 | * @run main UserContentHandler |
| 29 | */ |
| 30 | import java.net.*; |
| 31 | import java.io.*; |
| 32 | import java.util.*; |
| 33 | |
| 34 | public class UserContentHandler implements Runnable { |
| 35 | |
| 36 | ServerSocket ss; |
| 37 | |
| 38 | public void run() { |
| 39 | try { |
| 40 | |
| 41 | Socket s = ss.accept(); |
| 42 | s.setTcpNoDelay(true); |
| 43 | |
| 44 | PrintStream out = new PrintStream( |
| 45 | new BufferedOutputStream( |
| 46 | s.getOutputStream() )); |
| 47 | |
| 48 | out.print("HTTP/1.1 200 OK\r\n"); |
| 49 | out.print("Content-Length: 11\r\n"); |
| 50 | out.print("Content-Type: text/plain\r\n"); |
| 51 | out.print("\r\n"); |
| 52 | out.print("l;ajfdjafd\n"); |
| 53 | out.flush(); |
| 54 | |
| 55 | // don't close the connection immediately as otherwise |
| 56 | // the http headers may not have been received and the |
| 57 | // http client will re-connect. |
| 58 | Thread.currentThread().sleep(2000); |
| 59 | |
| 60 | s.close(); |
| 61 | |
| 62 | } catch (Exception e) { |
| 63 | e.printStackTrace(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | UserContentHandler() throws Exception { |
| 68 | |
| 69 | ss = new ServerSocket(0); |
| 70 | Thread thr = new Thread(this); |
| 71 | thr.start(); |
| 72 | |
| 73 | try { |
| 74 | Object o = new COM.foo.content.text.plain(); |
| 75 | } catch (Exception ex) { |
| 76 | ex.printStackTrace(); |
| 77 | } |
| 78 | Properties props = System.getProperties(); |
| 79 | props.put("java.content.handler.pkgs", "COM.foo.content"); |
| 80 | System.setProperties(props); |
| 81 | |
| 82 | URL u = new URL("http://localhost:" + ss.getLocalPort() + |
| 83 | "/anything.txt"); |
| 84 | if (!(u.openConnection().getContent() instanceof String)) { |
| 85 | throw new RuntimeException("Load user defined content handler failed."); |
| 86 | } else { |
| 87 | System.err.println("Load user defined content handler succeed!"); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | public static void main(String args[]) throws Exception { |
| 92 | new UserContentHandler(); |
| 93 | } |
| 94 | } |