I didn't. Sorry.
At the second attempt:
baos = ByteArrayOutputStream()
oos = ObjectOutputStream(baos)
oos.writeObject(req)
oos.close()
conn = httplib.HTTPConnection("192.168.1.111:80")
conn.request("POST", "/Listener", oos.toByteArray())
Traceback (innermost last):
File "<console>", line 1, in ?
AttributeError: 'javainstance' object has no attribute 'toByteArray'
dir(oos)
['PROTOCOL_VERSION_1', 'PROTOCOL_VERSION_2', 'SC_BLOCK_DATA', 'SC_ENUM', 'SC_EXTERNALIZABLE', 'SC_SERIALIZABLE', 'SC_WRITE_METHOD', 'STREAM_MAGIC', 'STREAM_VERSION', 'SUBCLASS_IMPLEMENTATION_PERMISSION', 'SUBSTITUTION_PERMISSION', 'TC_ARRAY', 'TC_BASE', 'TC_BLOCKDATA', 'TC_BLOCKDATALONG', 'TC_CLASS', 'TC_CLASSDESC', 'TC_ENDBLOCKDATA', 'TC_ENUM', 'TC_EXCEPTION', 'TC_LONGSTRING', 'TC_MAX', 'TC_NULL', 'TC_OBJECT', 'TC_PROXYCLASSDESC', 'TC_REFERENCE', 'TC_RESET', 'TC_STRING', '__init__', 'baseWireHandle', 'class', 'close', 'defaultWriteObject', 'equals', 'flush', 'getClass', 'hashCode', 'notify', 'notifyAll', 'putFields', 'reset', 'toString', 'useProtocolVersion', 'wait', 'write', 'writeBoolean', 'writeByte', 'writeBytes', 'writeChar', 'writeChars', 'writeDouble', 'writeFields', 'writeFloat', 'writeInt', 'writeLong', 'writeObject', 'writeShort', 'writeUTF', 'writeUnshared']
Marcel
----- Original Message ----
From: Jeff Emanuel <jemanuel@frii.com>
To: marcel liker <m_liker@yahoo.com>
Cc: jython-users@lists.sourceforge.net
Sent: Thursday, 16 November, 2006 6:09:57 PM
Subject: Re: [Jython-users] Sending a hashtable with httplib
Did you try passing baos.toByteArray()? The traceback indicates
that a byte[] is an acceptable arg. (A ByteArrayInputStream
in not a byte[].)
marcel liker wrote:
Thanks Jeff.
I tried what you suggested below but that would give the same error as earlier ("TypeError: write(): 1st arg can't be coerced to byte[] or int").
After double checking the java code I posted your jython version looked slightly different so I tried this:
baos = ByteArrayOutputStream()
oos = ObjectOutputStream(baos)
oos.writeObject(req)
bais = ByteArrayInputStream(baos.toByteArray())
conn = httplib.HTTPConnection("192.168.1.111:80")
conn.request("POST", "/Listener", bais)
Traceback (innermost last):
File "<console>", line 1, in ?
File "/home/marcel/j22/Lib/httplib.py", line 701, in request
File "/home/marcel/j22/Lib/httplib.py", line 720, in _send_request
AttributeError: __len__
len(bais)
Traceback (innermost last):
File "<console>", line 1, in ?
AttributeError: __len__
I am unsure, however, whether this is a step forward.
I do not do much programming so please bear with me. Also if somebody could point to some documentation discussing this topic that would be very helpful as well.
Thanks,
Marcel
----- Original Message ----
From: Jeff Emanuel <jemanuel@frii.com>
To: marcel liker <m_liker@yahoo.com>
Cc: jython-users@lists.sourceforge.net
Sent: Thursday, 16 November, 2006 5:50:51 PM
Subject: Re: [Jython-users] Sending a hashtable with httplib
In Jython:
from java.io import *
baos = ByteArrayOutputStream()
oos = ObjectOutputStream(baos)
oos.writeObject(yourHashtable)
oos.close()
yourHttpRequest.send(otherArgsHere, oos.toByteArray())
marcel liker wrote:
Thank you for your reply Jeff.
Yes, you are right with the text nature of http.
Below is a bit of java code which I think does the conversion from Hashtable to a serialized (? - I don't know java) object.
How can this be achieved in jython?
Marcel
PostMethod method = new PostMethod(destURL);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(regObj);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
method.setRequestBody(bais);
----- Original Message ----
From: Jeff Emanuel <jemanuel@frii.com>
To: marcel liker <m_liker@yahoo.com>
Cc: Kent Johnson <kent37@tds.net>; jython-users@lists.sourceforge.net
Sent: Thursday, 16 November, 2006 5:30:12 PM
Subject: Re: [Jython-users] Sending a hashtable with httplib
Isn't http still a text protocol? How is the server expecting
the hashtable to be encoded in the text? Create a
string representation of your hashtable as the server
expects it and send the string on the request.
marcel liker wrote:
Thanks for your reply Ken.
Unfortunately I have to use hashtable as this is what the server expects.
Marcel
----- Original Message ----
From: Kent Johnson <kent37@tds.net>
To: marcel liker <m_liker@yahoo.com>
Cc: jython-users@lists.sourceforge.net
Sent: Thursday, 16 November, 2006 4:50:47 PM
Subject: Re: [Jython-users] Sending a hashtable with httplib
marcel liker wrote:
Hi there.
I am creating an http client to send some data to a http server.
The problem I am having is that the data is a Hashtable which I am trying to send using httplib.
Unfortunately I am getting the error below.
What if you use a dict rather than a Hashtable?
Kent
Any help is appreciated.
Thanks,
Marcel
>from java.util import Hashtable
req=Hashtable()
req.put('ADDRESS','my address')
req.put('NAME','my name')
import httplib
conn = httplib.HTTPConnection("192.168.1.111:80")
conn.request("POST", "/Listener", req)
Traceback (innermost last):
File "<console>", line 1, in ?
File "/home/marcel/j22/Lib/httplib.py", line 701, in request
File "/home/marcel/j22/Lib/httplib.py", line 726, in _send_request
File "/home/marcel/j22/Lib/httplib.py", line 560, in send
File "/home/marcel/j22/Lib/socket.py", line 211, in send
TypeError: write(): 1st arg can't be coerced to byte[] or int
Send instant messages to your online friends http://uk.messenger.yahoo.com
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users