streaming with jbossws with small packets, or getting HttpUr
suvigy Jan 29, 2008 4:27 PMhi!
I'm developing a hyperterminal applet, where I'd like that the user can send data to COM ports via applet, and the COM port sends data back via web-service (streaming). Is it possible to do it with JBOSSWS? I need streaming for that. But often only few bytes (even 1 byte) comes from the COM port, I would like this even 1 byte to be flushed. I don't want any buffering.
I created a test service in that I enabled MTOM, but it's buffering, because I have to wait 10 seconds on the client side till the data arrives:
Server side, in that I simulate the hyperterminal, after each byte I wait 1 second. It should be flushed each time :
@MTOM @BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING) @WebService public class TestService { @WebMethod public @XmlMimeType("application/octet-stream") DataHandler getStream() { return new DataHandler(new DataSource() { public String getContentType() { return "application/octet-stream"; } public InputStream getInputStream() throws IOException { return new InputStream() { private int count = 0; @Override public int read() throws IOException { if (count!=0) try { Thread.sleep(1000); } catch (InterruptedException e) { } count++; if (count>10) return -1; return 'a'; } }; } public String getName() { return "test"; } public OutputStream getOutputStream() throws IOException { return null; } }); } }
If there is no Binding annotation at the beginning, then the behaviour is the same
Client Side:
public class ConsoleTest { /** * @param args */ public static void main(String[] args) throws Exception { MTOMFeature feature = new MTOMFeature(); TestServiceService service = new TestServiceService(); TestService port = service.getTestServicePort(feature); Map<String, Object> ctxt = ((BindingProvider)port).getRequestContext(); // Enable HTTP chunking mode, otherwise HttpURLConnection buffers ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 1); DataHandler dh = port.getStream(); InputStream is = dh.getInputStream(); int data; while ((data = is.read())>-1) { System.out.print((char)data); } is.close(); } }
And I have to wait 10 seconds, till the result comes. I would except the data to come continuously.
I don't know if it is possible.
If not, then I would write an own servlet for that. In the real application I maintain session, so the client uses cookie, but then I would need the http client of jbossws on the client side. Can I get it somehow (What type does it have? HttpUrlConnection?)?
Thnx
George