avro - c# to Java, on Flush or Close - “The underlying connection was closed” C# side upon Java HttpExchange.getResponseBody().flush()
C#
1
Posts
1
Posters
0
Views
1
Watching
-
I am 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 someRequestWriter = new SpecificDatumWriter(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 someResponseReader = new SpecificDatumReader(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 someRequestReader = new org.apache.avro.specific.SpecificDatumReader(GenericRequest.class) ;
SomeRequest req = someRequestReader.read(null, decoder);
...SomeResponse someResponse = new SomeResponse(); someResponse.setUserId("john.doe"); someResponse.setResultItemList(results); DatumWriter someRequestWriter = new org.apache.avro.specific.SpecificDatumWriter(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.cl