receipt server answer
This commit is contained in:
@@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext
|
import io.netty.channel.ChannelHandlerContext
|
||||||
import io.netty.channel.SimpleChannelInboundHandler
|
import io.netty.channel.SimpleChannelInboundHandler
|
||||||
|
import io.netty.handler.codec.http.DefaultHttpContent
|
||||||
import io.netty.handler.codec.http.HttpContent
|
import io.netty.handler.codec.http.HttpContent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,15 +20,11 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
|
|||||||
|
|
||||||
override fun channelReadComplete(ctx: ChannelHandlerContext) {
|
override fun channelReadComplete(ctx: ChannelHandlerContext) {
|
||||||
|
|
||||||
var resultCode: Int = 0
|
if (contentBytes.size == 0) {
|
||||||
// try {
|
ctx.close()
|
||||||
// val uploadResult: Carkot.UploadResult = Carkot.UploadResult.parseFrom(contentBytes)
|
return
|
||||||
// resultCode = uploadResult.resultCode
|
}
|
||||||
// } catch (e: InvalidProtocolBufferException) {
|
val resultCode: Int = contentBytes[0].toInt()
|
||||||
// e.printStackTrace()
|
|
||||||
//
|
|
||||||
// resultCode = 2
|
|
||||||
// }
|
|
||||||
synchronized(requestResult, {
|
synchronized(requestResult, {
|
||||||
requestResult.code = resultCode
|
requestResult.code = resultCode
|
||||||
})
|
})
|
||||||
@@ -35,7 +32,7 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun channelRead0(ctx: ChannelHandlerContext?, msg: Any?) {
|
override fun channelRead0(ctx: ChannelHandlerContext?, msg: Any?) {
|
||||||
if (msg is HttpContent) {
|
if (msg is DefaultHttpContent) {
|
||||||
val contentsBytes = msg.content();
|
val contentsBytes = msg.content();
|
||||||
contentBytes = ByteArray(contentsBytes.capacity())
|
contentBytes = ByteArray(contentsBytes.capacity())
|
||||||
contentsBytes.readBytes(contentBytes)
|
contentsBytes.readBytes(contentBytes)
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
|
|||||||
|
|
||||||
object requestResult {
|
object requestResult {
|
||||||
var code: Int = -1
|
var code: Int = -1
|
||||||
|
var stdOut: String = ""
|
||||||
|
var stdErr: String = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
@@ -22,17 +24,24 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
|
|||||||
|
|
||||||
override fun channelReadComplete(ctx: ChannelHandlerContext) {
|
override fun channelReadComplete(ctx: ChannelHandlerContext) {
|
||||||
|
|
||||||
var resultCode = 0
|
val resultCode:Int
|
||||||
|
val resultStdOut:String
|
||||||
|
val resultStdErr:String
|
||||||
try {
|
try {
|
||||||
val uploadResult: Carkot.UploadResult = Carkot.UploadResult.parseFrom(contentBytes)
|
val uploadResult: Carkot.UploadResult = Carkot.UploadResult.parseFrom(contentBytes)
|
||||||
resultCode = uploadResult.resultCode
|
resultCode = uploadResult.resultCode
|
||||||
|
resultStdOut = uploadResult.stdOut
|
||||||
|
resultStdErr = uploadResult.stdErr
|
||||||
} catch (e: InvalidProtocolBufferException) {
|
} catch (e: InvalidProtocolBufferException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
resultStdErr = ""
|
||||||
|
resultStdOut = ""
|
||||||
resultCode = 2
|
resultCode = 2
|
||||||
}
|
}
|
||||||
synchronized(requestResult, {
|
synchronized(requestResult, {
|
||||||
requestResult.code = resultCode
|
requestResult.code = resultCode
|
||||||
|
requestResult.stdErr = resultStdErr
|
||||||
|
requestResult.stdOut = resultStdOut
|
||||||
})
|
})
|
||||||
ctx.close()
|
ctx.close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user