Hello,
I run into same problem described in
http://stackoverflow.com/questions/33197580/avro-c-sharp-to-java-on-flush-or-close-the-underlying-connection-was-close
Here it is...
Simple project using avro calling Java from c#. Error message "*The
underlying connection was closed: The connection was closed unexpectedly."* C#
side upon Java call to *flush or close*
C# side fires off the request from here:
httpRequest = HttpWebRequest.Create(targetUrl) as HttpWebRequest;
httpRequest.Method = "POST";
httpRequest.Accept = "avro/binary";
httpRequest.ContentType = "avro/binary";
httpRequest.KeepAlive = false;
SpecificDatumWriter<SomeRequest> someRequestWriter = new
SpecificDatumWriter<SomeRequest>(SomeRequest._SCHEMA);
...
using (var requestStream = httpRequest.GetRequestStream())
{
someRequestWriter.Write(someRequest, new
Avro.IO.BinaryEncoder(requestStream));
// C# blows up here!!!
using (var responseStream =
httpRequest.GetResponse().GetResponseStream())
{
SpecificDatumReader<SomeResponse>
someResponseReader = new SpecificDatumReader<SomeResponse>(null,
SomeResponse._SCHEMA);
someResponse = someResponseReader.Read(null, new
Avro.IO.BinaryDecoder(responseStream));
...
}
}
And java side handles the request, and respond like this:
HttpExchange.getResponseBody().flush() or HttpExchange.close()
public void handle(HttpExchange t) throws IOException {
final DecoderFactory decoderFactory = DecoderFactory.get();
final Decoder decoder =
decoderFactory.binaryDecoder(t.getRequestBody(), null);
SpecificDatumReader<demo.avro.SomeRequest> someRequestReader =
new
org.apache.avro.specific.SpecificDatumReader<demo.avro.SomeRequest>(GenericRequest.class)
;
SomeRequest req = someRequestReader.read(null, decoder);
...
SomeResponse someResponse = new SomeResponse();
someResponse.setUserId("john.doe");
someResponse.setResultItemList(results);
DatumWriter<SomeResponse> someRequestWriter = new
org.apache.avro.specific.SpecificDatumWriter<SomeResponse>(SomeResponse.class);
final EncoderFactory encoderFactory = EncoderFactory.get();
final Encoder encoder =
encoderFactory.binaryEncoder(t.getResponseBody(), null);
someRequestWriter.write(genericResponse, encoder);
**// HERE!!! flush or close will blow up C# side**
// encoder.flush();
// t.getResponseBody().flush();
// t.close();
return;
}
I don't know how else to "Flush" my response from Java side back to C#. (If
I don't flush or close, C# side will still eventually blow up on timeout)
Any suggestion?