java client;what's worng with me ?
wuhao at bokee.net
wuhao at bokee.net
Thu Mar 23 16:07:20 UTC 2006
Hi:
I write a java test class. bu CREATE_CLOSE ses
ERR unknown_command Unknown+server+command
but a sent it by telnet
it's ok.
my code:
public class Test01 extends TestCase {
private static Log log = LogFactory.getLog(Test01.class);
// CREATE_CLASS domain=bokee&class=my01&mindevcount=1
// CREATE_OPEN domain=bokee&key=wuhao&class=my01
// devid=10&fid=2&path=http://192.168.18.3:7500/dev10/0/000/000/0000000002.fid
// CREATE_CLOSE
//
domain=bokee&key=wuhao&fid=2&devid=10&path=http://192.168.18.3:7500/dev10/0/000/000/0000000002.fid
// CREATE_OPEN domain=bokee&key=wuhao02&class=my01
// devid=10&fid=3&path=http://192.168.18.3:7500/dev10/0/000/000/0000000003.fid
// CREATE_CLOSE
//
domain=bokee&key=wuhao02&fid=3&devid=10&path=http://192.168.18.3:7500/dev10/0/000/000/0000000003.fid
// GET_PATHS domain=bokee&key=file_key023
// CREATE_OPEN domain=bokee&key=wuhao03&class=my01
// CREATE_CLOSE
//
domain=bokee&key=wuhao03&fid=5&devid=10&path=http://192.168.18.3:7500/dev10/0/000/000/0000000005.fid
public void test01() throws Exception {
String uri="http://192.168.18.3:7500/dev10/0/000/000/0000000005.fid";
put(uri);
}
private void put(String uri) throws FileNotFoundException, IOException,
HttpException {
HttpClient client = new HttpClient();
PutMethod put = new PutMethod(uri);
RequestEntity en = new ByteArrayRequestEntity("this is test ÖÐÎÄ"
.getBytes());
File f = new File("/home/wuhao/download/2.gif");
en = new InputStreamRequestEntity(new FileInputStream(f));
put.setRequestEntity(en);
int statusCode = client.executeMethod(put);
log.debug("code=" + statusCode);
}
public void test02() throws Exception {
TelnetClient t = new TelnetClient();
t.connect(InetAddress.getByName("wuhaoHome"), 6001);
log.debug(t.getLocalAddress());
log.debug(t.getRemoteAddress());
log.debug("" + t.getLocalPort());
t.setSoTimeout(60 * 1000);
log.debug(t);
PrintStream out = new PrintStream(t.getOutputStream());
InputStream in = t.getInputStream();
write(out,"CREATE_OPEN domain=bokee&key=wuhao05&class=my01");
t.sendAYT(5 * 1000);
log.debug(t);
String str = readUntil(in, "fid\n");
log.debug(str);
String s1[] = StringUtils.split(str, " ");
Map r = new HashMap();
if (s1[0].equals("OK")) {
String[] s2 = StringUtils.split(s1[1], "&");
for (int i = 0; i < s2.length; i++) {
log.debug(s2[i]);
String[] s3 = StringUtils.split(s2[i], "=");
r.put(s3[0], s3[1]);
}
}
put((String)r.get("path"));
String cmd2 ="CREATE_CLOSE domain=bokee&key=wuhao05&fid=" + r.get("fid")
+ "&devid=" + r.get("devid") + "&path=" + r.get("path");
log.debug(cmd2);
write(out,cmd2);
str = readUntil(in, "OK");
log.debug(str);
write(out,"GET_DOMAINS");
str = readUntil(in,"OK");
log.debug(str);
write(out,"GET_PATHS domain=bokee&key=wuhao05");
str = readUntil(in,"OK");
log.debug(str);
write(out,"GET_HOSTS");
str = readUntil(in,"OK");
log.debug(str);
write(out,"GET_DEVICES");
str = readUntil(in,"OK");
log.debug(str);
t.disconnect();
}
public String readUntil(InputStream in, String pattern) {
StringBuffer sb = new StringBuffer();
try {
char ch = (char) in.read();
while (ch!='\n') {
//System.out.print(ch);
sb.append(ch);
ch = (char) in.read();
}
//System.out.print(ch);
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
public void write(PrintStream out, String value) {
try {
out.println(value);
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}
run result
DEBUG [main] Test01.test02(62) | /192.168.18.3
DEBUG [main] Test01.test02(63) | wuhaoHome/192.168.18.3
DEBUG [main] Test01.test02(64) | 33492
DEBUG [main] Test01.test02(66) | org.apache.commons.net.telnet.TelnetClient at 7fdcde
DEBUG [main] Test01.test02(75) | org.apache.commons.net.telnet.TelnetClient at 7fdcde
DEBUG [main] Test01.test02(77) | OK
devid=10&fid=44&path=http://192.168.18.3:7500/dev10/0/000/000/0000000044.fid
DEBUG [main] Test01.test02(83) | devid=10
DEBUG [main] Test01.test02(83) | fid=44
DEBUG [main] Test01.test02(83) |
path=http://192.168.18.3:7500/dev10/0/000/000/0000000044.fid
DEBUG [main] Test01.put(56) | code=200
DEBUG [main] Test01.test02(94) | CREATE_CLOSE
domain=bokee&key=wuhao05&fid=44&devid=10&path=http://192.168.18.3:7500/dev10/0/000/000/0000000044.fid
DEBUG [main] Test01.test02(97) | ERR unknown_command Unknown+server+command
DEBUG [main] Test01.test02(101) | OK
domains=1&domain1=bokee&domain1class2name=default&domain1class1name=my01&domain1classes=2&domain1class1mindevcount=1&domain1class2mindevcount=2
DEBUG [main] Test01.test02(105) | OK
path1=http://192.168.18.3:7500/dev10/0/000/000/0000000043.fid&paths=1
DEBUG [main] Test01.test02(110) | OK
host1_hostip=192.168.18.3&hosts=1&host1_hostid=10&host1_remoteroot=&host1_status=alive&host1_hostname=wuhaoHome&host1_http_port=7500
DEBUG [main] Test01.test02(114) | OK
dev1_devid=10&dev1_status=alive&dev1_hostid=10&dev1_mb_total=200&dev1_mb_used=0&devices=1
RUN
CREATE_CLOSE
domain=bokee&key=wuhao05&fid=44&devid=10&path=http://192.168.18.3:7500/dev10/0/000/000/0000000044.fid
by telnet
CREATE_CLOSE
domain=bokee&key=wuhao05&fid=44&devid=10&path=http://192.168.18.3:7500/dev10/0/000/000/0000000044.fid
OK
but in java ;it return
ERR unknown_command Unknown+server+command
what's worng with me ?
More information about the mogilefs
mailing list