22 |
|
|
23 |
import java, org |
import java, org |
24 |
|
|
|
|
|
25 |
from org.nongnu.storm.http.client import HTTPConnection |
from org.nongnu.storm.http.client import HTTPConnection |
26 |
from org.nongnu.storm.http.client import HTTPRequest |
from org.nongnu.storm.http.client import HTTPRequest |
27 |
from org.nongnu.storm.http.client import HTTPResponse |
from org.nongnu.storm.http.client import HTTPResponse |
28 |
from org.nongnu.storm.impl import TransientPool |
from org.nongnu.storm.impl import TransientPool |
|
from org.nongnu.storm.modules.gispmap import GispP2PMap |
|
|
from org.nongnu.storm.impl.p2p import Peer |
|
|
from org.nongnu.storm.impl import DirPool |
|
29 |
from org.nongnu.storm.util import HTTPProxy |
from org.nongnu.storm.util import HTTPProxy |
30 |
|
|
31 |
host0 = "127.0.0.1" |
host0 = "127.0.0.1" |
43 |
|
|
44 |
def testHTTPClient(): |
def testHTTPClient(): |
45 |
|
|
46 |
|
|
47 |
|
# Create a empty pool (transient pool) |
48 |
empty = java.util.Collections.EMPTY_SET |
empty = java.util.Collections.EMPTY_SET |
49 |
pool = TransientPool(empty) |
pool = TransientPool(empty) |
50 |
|
|
51 |
#pub = TransientPool(empty) |
# Create data form block |
52 |
#cache = TransientPool(empty) |
bos = pool.getBlockOutputStream("text/plain") |
53 |
#map1 = GispP2PMap("/home/hemppah/cvs/storm") |
osw = java.io.OutputStreamWriter(bos) |
54 |
#peer = Peer(pub, cache, map1) |
osw.write("Hello, world!") |
55 |
#pool = peer.getPool() |
osw.close() |
56 |
|
block = pool.get(bos.getBlockId()) |
57 |
|
blockid = block.getId().toString() |
|
serverthread = java.lang.Thread(HTTPProxy(pool, 5555)) |
|
|
serverthread.start() |
|
58 |
|
|
59 |
|
|
60 |
|
# Start HTTP-proxy thread |
61 |
|
serverthread = java.lang.Thread(HTTPProxy(pool, 5555)) |
62 |
|
serverthread.start() |
63 |
print "HTTP proxy thread started..." |
print "HTTP proxy thread started..." |
64 |
|
|
65 |
|
|
66 |
|
#Create HTTP connection to localhost |
67 |
httpconn = org.nongnu.storm.http.client.HTTPConnection(host0, port) |
httpconn = org.nongnu.storm.http.client.HTTPConnection(host0, port) |
68 |
|
|
69 |
req = httpconn.newRequest("GET", request, protocol2, java.lang.Boolean.FALSE) |
|
70 |
print "Make GET request(s)..." |
# Perform GET request using the ID of created block |
71 |
|
print "Perform GET request(s)..." |
72 |
|
req = httpconn.newRequest("GET", "rewrite/" + blockid, protocol2, java.lang.Boolean.FALSE) |
73 |
|
# Add more requests here... |
74 |
|
|
75 |
|
|
76 |
resp = httpconn.send(req) |
resp = httpconn.send(req) |
77 |
print resp.status, resp.reason |
print resp.status, resp.reason |
78 |
#assert resp.status == "Ok" |
|
79 |
|
# Conditions here... |
80 |
httpconn.close |
assert resp.status == 200 |
81 |
#java.lang.Thread.currentThread().interrupt() |
|
82 |
|
httpconn.close |
83 |
java.lang.Thread(serverthread).interrupt() |
java.lang.Thread(serverthread).interrupt() |
84 |
print "HTTP proxy thread stopped..." |
print "HTTP proxy thread stopped..." |