Skip to content

Commit ea9ffc3

Browse files
author
Jerome Louvel
committed
- Added log traces in case of error with custom status representation.
- Fixed potential threading/pipe issues with OutputRepresentation and WriterRepresentation classes.
1 parent 50fbf0d commit ea9ffc3

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ modules/org.restlet.ext.xml/bin/
3333
modules/org.restlet.ext.xstream/bin/
3434
modules/org.restlet.test/bin/
3535
modules/org.restlet/bin/
36+
/build/temp

build/tmpl/text/changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ Changes log
1313
cause erros such as "no Restlet defined to process calls. Maybe it
1414
wasn't properly started" errors (500). Reported by several persons
1515
including David Fuchs, Danny Leshem, Yunwu Zhu and Bjorn Roche.
16+
- Fixed potential threading/pipe issues with OutputRepresentation
17+
and WriterRepresentation classes.
1618
- Misc
1719
- Reverted Role equality test to default Java object equality as
1820
equality based on name could cause issues with MemoryRealm
1921
mapping if several applications used the same role names.
22+
- Added log traces in case of error with custom status representation.
2023

2124
- 2.0.14 (2012-05-23)
2225
- Bug fixed

modules/org.restlet/src/org/restlet/engine/application/StatusFilter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,15 @@ public Reference getHomeRef() {
249249
*/
250250
protected Representation getRepresentation(Status status, Request request,
251251
Response response) {
252-
Representation result = getStatusService().getRepresentation(status,
253-
request, response);
252+
Representation result = null;
253+
254+
try {
255+
result = getStatusService().getRepresentation(status, request,
256+
response);
257+
} catch (Exception e) {
258+
getLogger().log(Level.WARNING,
259+
"Unable to get the custom status representation", e);
260+
}
254261

255262
if (result == null) {
256263
result = getDefaultRepresentation(status, request, response);

modules/org.restlet/src/org/restlet/engine/io/BioUtils.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,29 +310,37 @@ public static Reader getReader(
310310
final java.io.PipedWriter pipedWriter = new java.io.PipedWriter();
311311
java.io.PipedReader pipedReader = new java.io.PipedReader(
312312
pipedWriter);
313-
org.restlet.Application application = org.restlet.Application
314-
.getCurrent();
313+
315314
// Gets a thread that will handle the task of continuously
316315
// writing the representation into the input side of the pipe
317316
Runnable task = new Runnable() {
318317
public void run() {
319318
try {
320319
representation.write(pipedWriter);
321320
pipedWriter.flush();
322-
pipedWriter.close();
323321
} catch (IOException ioe) {
324322
Context.getCurrentLogger()
325-
.log(Level.FINE,
323+
.log(Level.WARNING,
326324
"Error while writing to the piped reader.",
327325
ioe);
326+
} finally {
327+
try {
328+
pipedWriter.close();
329+
} catch (IOException ioe2) {
330+
Context.getCurrentLogger().log(Level.WARNING,
331+
"Error while closing the pipe.", ioe2);
332+
}
328333
}
329334
}
330335
};
331336

337+
org.restlet.Application application = org.restlet.Application
338+
.getCurrent();
339+
332340
if (application != null && application.getTaskService() != null) {
333341
application.getTaskService().execute(task);
334342
} else {
335-
new Thread(task).start();
343+
new Thread(task, "Restlet-PipeWriter").start();
336344
}
337345

338346
result = pipedReader;
@@ -401,27 +409,34 @@ public static InputStream getStream(final Representation representation) {
401409
}
402410

403411
final PipeStream pipe = new PipeStream();
404-
org.restlet.Application application = org.restlet.Application
405-
.getCurrent();
406-
407-
// Gets a thread that will handle the task of continuously
412+
final java.io.OutputStream os = pipe.getOutputStream();
413+
414+
// Creates a thread that will handle the task of continuously
408415
// writing the representation into the input side of the pipe
409416
Runnable task = new Runnable() {
410417
public void run() {
411418
try {
412-
java.io.OutputStream os = pipe.getOutputStream();
413419
representation.write(os);
414420
os.flush();
415-
os.close();
416421
} catch (IOException ioe) {
417422
Context.getCurrentLogger()
418-
.log(Level.FINE,
419-
"Error while writing to the piped input stream.",
423+
.log(Level.WARNING,
424+
"Error while writing to the piped input stream.",
420425
ioe);
426+
} finally {
427+
try {
428+
os.close();
429+
} catch (IOException ioe2) {
430+
Context.getCurrentLogger().log(Level.WARNING,
431+
"Error while closing the pipe.", ioe2);
432+
}
421433
}
422434
}
423435
};
424436

437+
org.restlet.Application application = org.restlet.Application
438+
.getCurrent();
439+
425440
if (application != null && application.getTaskService() != null) {
426441
application.getTaskService().execute(task);
427442
} else {

0 commit comments

Comments
 (0)