套接字读取 IOException 没有被捕获?
Socket read IOException not being caught?
在grails中,socket读取失败或者ioexception可以捕获吗?即使我将错误部分包装在 try catch 块中,也会触发以下错误。
ERROR 2021-03-28 08:34:10,170 [ajp-bio-8109-exec-39783] errors.GrailsExceptionResolver: IOException occurred when processing request: [POST] /race/results/
Socket read failed. Stacktrace follows:
java.io.IOException: Socket read failed
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at java.io.PushbackInputStream.read(PushbackInputStream.java:186)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1485)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1461)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1436)
at org.apache.commons.io.IOUtils.toString(IOUtils.java:585)
at grails.converters.JSON.parse(JSON.java:312)
at grails.converters.JSON.parse(JSON.java:347)
在抛出错误的地方,我将其包装在 try catch 块中,如下所示。
def results(){
def results
try {
results = request.JSON
} catch (IOException e1) {
log.error "ERROR WHILE request.json in /results******************************************************************"
render contentType: "text/json", text: '{"status":"fail"}'
return
}
此时报错
results = request.JSON
我很感激任何见解。我正在使用 Grails 2.2。
谢谢!
更新:
这是完整的堆栈跟踪。谢谢!
ERROR 2021-03-28 08:34:10,170 [ajp-bio-8109-exec-39783] errors.GrailsExceptionResolver: IOException occurred when processing request: [POST] /race/results/
Socket read failed. Stacktrace follows:
java.io.IOException: Socket read failed
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at java.io.PushbackInputStream.read(PushbackInputStream.java:186)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1485)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1461)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1436)
at org.apache.commons.io.IOUtils.toString(IOUtils.java:585)
at grails.converters.JSON.parse(JSON.java:312)
at grails.converters.JSON.parse(JSON.java:347)
at race.results(VirtualRaceController.groovy:2011)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
您可能会发现它抛出的是 ConverterException,而不是 IOException。这是代码:
class ConvertersExtension {
static getJSON(HttpServletRequest request) {
JSON.parse(request)
}
}
public class JSON {
public static Object parse(HttpServletRequest request) throws ConverterException {
// blah blah
try {
/// blah blah
}
catch (IOException e) {
throw new ConverterException("Error parsing JSON", e);
}
}
}
如果您使用的是 IDE,请右键单击有问题的 API 并 select“转到声明”,或者您的 [=16] 中的任何等效项=] 直到你追踪你的方式,看看什么抛出什么。
在grails中,socket读取失败或者ioexception可以捕获吗?即使我将错误部分包装在 try catch 块中,也会触发以下错误。
ERROR 2021-03-28 08:34:10,170 [ajp-bio-8109-exec-39783] errors.GrailsExceptionResolver: IOException occurred when processing request: [POST] /race/results/
Socket read failed. Stacktrace follows:
java.io.IOException: Socket read failed
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at java.io.PushbackInputStream.read(PushbackInputStream.java:186)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1485)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1461)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1436)
at org.apache.commons.io.IOUtils.toString(IOUtils.java:585)
at grails.converters.JSON.parse(JSON.java:312)
at grails.converters.JSON.parse(JSON.java:347)
在抛出错误的地方,我将其包装在 try catch 块中,如下所示。
def results(){
def results
try {
results = request.JSON
} catch (IOException e1) {
log.error "ERROR WHILE request.json in /results******************************************************************"
render contentType: "text/json", text: '{"status":"fail"}'
return
}
此时报错
results = request.JSON
我很感激任何见解。我正在使用 Grails 2.2。
谢谢!
更新:
这是完整的堆栈跟踪。谢谢!
ERROR 2021-03-28 08:34:10,170 [ajp-bio-8109-exec-39783] errors.GrailsExceptionResolver: IOException occurred when processing request: [POST] /race/results/
Socket read failed. Stacktrace follows:
java.io.IOException: Socket read failed
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at java.io.PushbackInputStream.read(PushbackInputStream.java:186)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1485)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1461)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1436)
at org.apache.commons.io.IOUtils.toString(IOUtils.java:585)
at grails.converters.JSON.parse(JSON.java:312)
at grails.converters.JSON.parse(JSON.java:347)
at race.results(VirtualRaceController.groovy:2011)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
您可能会发现它抛出的是 ConverterException,而不是 IOException。这是代码:
class ConvertersExtension {
static getJSON(HttpServletRequest request) {
JSON.parse(request)
}
}
public class JSON {
public static Object parse(HttpServletRequest request) throws ConverterException {
// blah blah
try {
/// blah blah
}
catch (IOException e) {
throw new ConverterException("Error parsing JSON", e);
}
}
}
如果您使用的是 IDE,请右键单击有问题的 API 并 select“转到声明”,或者您的 [=16] 中的任何等效项=] 直到你追踪你的方式,看看什么抛出什么。