1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.parameter.protocol;
12
13 import org.astrogrid.component.descriptor.ComponentDescriptor;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
18 import java.net.URI;
19
20 import junit.framework.Test;
21
22 /*** Protocol implementation for http:/
23 * @todo replae with more robust implementation based on commons HttpClient.
24 * @author Noel Winstanley nw@jb.man.ac.uk 16-Jun-2004
25 *
26 */
27 public class HttpProtocol implements Protocol, ComponentDescriptor {
28 /*** Construct a new HttpProtocol
29 *
30 */
31 public HttpProtocol() {
32 super();
33 }
34 /***
35 * @see org.astrogrid.applications.parameter.protocol.Protocol#getProtocolName()
36 */
37 public String getProtocolName() {
38 return "http";
39 }
40 /***
41 * @see org.astrogrid.applications.parameter.protocol.Protocol#createIndirectValue(java.net.URI)
42 */
43 public ExternalValue createIndirectValue(final URI reference) throws InaccessibleExternalValueException {
44 return new ExternalValue() {
45
46 public InputStream read() throws InaccessibleExternalValueException {
47 try {
48 return reference.toURL().openStream();
49 } catch (IOException e) {
50 throw new InaccessibleExternalValueException(reference.toString(),e );
51 }
52 }
53
54 public OutputStream write() throws InaccessibleExternalValueException {
55 try {
56 return reference.toURL().openConnection().getOutputStream();
57 } catch (IOException e) {
58 throw new InaccessibleExternalValueException(reference.toString(),e );
59 }
60 }
61 };
62 }
63 /***
64 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
65 */
66 public String getName() {
67 return "HttpProtocol";
68 }
69 /***
70 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
71 */
72 public String getDescription() {
73 return "Protocol adapter for http:/ protocol";
74 }
75 /***
76 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
77 */
78 public Test getInstallationTest() {
79 return null;
80 }
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101