if (null == bytes) {
bytes = new byte[10000];
}
int total = readBytes(bytes, ctx.getInputStream());
OutputStreamMessageContext octx = null;
if (decoupled) {
EndpointReferenceType ref = new EndpointReferenceType();
EndpointReferenceUtils.setAddress(ref, DECOUPLED_ADDRESS);
octx = server.rebase(ctx, ref);
server.finalPrepareOutputStreamContext(octx);
octx.getOutputStream().flush();
octx.getOutputStream().close();
assertEquals(ctx.get(HTTPServerInputStreamContext.HTTP_RESPONSE), ref);
if (!oneWay) {
awaitPartialResponseReceived();
}
}
if (oneWay) {
octx = transport.createOutputStreamContext(ctx);
octx.setOneWay(oneWay);
transport.finalPrepareOutputStreamContext(octx);
octx.getOutputStream().close();
transport.postDispatch(ctx, octx);
}
// simulate implementor call
if (delay > 0) {
Thread.sleep(delay);
}
if (!oneWay) {
octx = transport.createOutputStreamContext(ctx);
octx.setOneWay(oneWay);
transport.finalPrepareOutputStreamContext(octx);
octx.getOutputStream().write(bytes, 0, total);
octx.getOutputStream().flush();
octx.getOutputStream().close();
transport.postDispatch(ctx, octx);
}
} catch (Exception ex) {
ex.printStackTrace();
}