Skip to content

Commit 8ef20d5

Browse files
committed
Fixed OutputRepresentation in the GAE edition (issue restlet#954). Reported by Edouard Mercier.
1 parent 94b5c0c commit 8ef20d5

File tree

10 files changed

+77
-84
lines changed

10 files changed

+77
-84
lines changed

build/tmpl/text/changes.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Changes log
1414
- Removed XML serialization using Jackson extension from Android edition as
1515
it depends on classes not supported by Android SDK (issue #964).
1616
Reported by Ralph van Etten.
17+
- Fixed OutputRepresentation in the GAE edition (issue #954).
18+
Reported by Edouard Mercier.
19+
20+
- Enhancements
21+
- Upgraded Google App Engine API to version 1.9.15.
1722

1823
- 2.3 Release Candidate 2 (12/08/2014)
1924
- Bugs fixed
File renamed without changes.
File renamed without changes.

libraries/com.google.appengine_1.4/com.google.appengine.jar renamed to libraries/com.google.appengine_1.9/com.google.appengine.jar

15.8 MB
Binary file not shown.

libraries/com.google.appengine_1.4/library.xml renamed to libraries/com.google.appengine_1.9/library.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<library id="appengine" symbolicName="com.google.appengine">
22
<name>Google App Engine API</name>
33
<description>Google App Engine API.</description>
4-
<version>1.4</version>
5-
<release>3</release>
4+
<version>1.9</version>
5+
<release>15</release>
66
<homeUri>http://code.google.com/appengine/</homeUri>
77
<downloadUri>http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Java</downloadUri>
88
<provider>Google Inc.</provider>
File renamed without changes.
File renamed without changes.

modules/org.restlet/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<dependencies>
1313
<dependency includes="osgi" type="library" id="osgi" maven-scope="compile" />
1414
<dependency includes="gwt" type="library" id="gwt" />
15+
<dependency includes="gae" type="library" id="appengine" />
1516
</dependencies>
1617
<bundleActivator>org.restlet.engine.internal.Activator</bundleActivator>
1718
<source edition="android">

modules/org.restlet/src/org/restlet/engine/Engine.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static Thread createThreadWithLocalVariables(
156156
.getCurrent();
157157
final Response currentResponse = Response.getCurrent();
158158

159-
return new Thread(new Runnable() {
159+
Runnable r = new Runnable() {
160160

161161
@Override
162162
public void run() {
@@ -174,7 +174,13 @@ public void run() {
174174
}
175175
}
176176

177-
}, name);
177+
};
178+
179+
// [ifndef gae] instruction
180+
return new Thread(r, name);
181+
// [ifdef gae] instruction uncomment
182+
// return
183+
// com.google.appengine.api.ThreadManager.createThreadForCurrentRequest(r);
178184
}
179185

180186
// [ifndef gwt] method

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

Lines changed: 61 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -474,53 +474,43 @@ public static Reader getReader(
474474
final org.restlet.representation.WriterRepresentation representation)
475475
throws IOException {
476476
Reader result = null;
477-
if (Edition.CURRENT != Edition.GAE) {
478-
// [ifndef gae]
479-
final java.io.PipedWriter pipedWriter = new java.io.PipedWriter();
480-
481-
@SuppressWarnings("resource")
482-
java.io.PipedReader pipedReader = new java.io.PipedReader(
483-
pipedWriter);
484-
485-
// Gets a thread that will handle the task of continuously
486-
// writing the representation into the input side of the pipe
487-
Runnable task = new org.restlet.engine.util.ContextualRunnable() {
488-
public void run() {
477+
final java.io.PipedWriter pipedWriter = new java.io.PipedWriter();
478+
479+
@SuppressWarnings("resource")
480+
java.io.PipedReader pipedReader = new java.io.PipedReader(pipedWriter);
481+
482+
// Gets a thread that will handle the task of continuously
483+
// writing the representation into the input side of the pipe
484+
Runnable task = new org.restlet.engine.util.ContextualRunnable() {
485+
public void run() {
486+
try {
487+
representation.write(pipedWriter);
488+
pipedWriter.flush();
489+
} catch (IOException ioe) {
490+
Context.getCurrentLogger().log(Level.WARNING,
491+
"Error while writing to the piped reader.", ioe);
492+
} finally {
489493
try {
490-
representation.write(pipedWriter);
491-
pipedWriter.flush();
492-
} catch (IOException ioe) {
493-
Context.getCurrentLogger()
494-
.log(Level.WARNING,
495-
"Error while writing to the piped reader.",
496-
ioe);
497-
} finally {
498-
try {
499-
pipedWriter.close();
500-
} catch (IOException ioe2) {
501-
Context.getCurrentLogger().log(Level.WARNING,
502-
"Error while closing the pipe.", ioe2);
503-
}
494+
pipedWriter.close();
495+
} catch (IOException ioe2) {
496+
Context.getCurrentLogger().log(Level.WARNING,
497+
"Error while closing the pipe.", ioe2);
504498
}
505499
}
506-
};
507-
508-
org.restlet.Context context = org.restlet.Context.getCurrent();
509-
510-
if (context != null && context.getExecutorService() != null) {
511-
context.getExecutorService().execute(task);
512-
} else {
513-
Engine.createThreadWithLocalVariables(task, "Restlet-IoUtils")
514-
.start();
515500
}
501+
};
516502

517-
result = pipedReader;
518-
// [enddef]
503+
org.restlet.Context context = org.restlet.Context.getCurrent();
504+
505+
if (context != null && context.getExecutorService() != null) {
506+
context.getExecutorService().execute(task);
519507
} else {
520-
Context.getCurrentLogger()
521-
.log(Level.WARNING,
522-
"The GAE edition is unable to return a reader for a writer representation.");
508+
Engine.createThreadWithLocalVariables(task, "Restlet-IoUtils")
509+
.start();
523510
}
511+
512+
result = pipedReader;
513+
524514
return result;
525515

526516
}
@@ -597,55 +587,46 @@ public static InputStream getStream(Reader reader, CharacterSet characterSet) {
597587
public static InputStream getStream(final Representation representation) {
598588
InputStream result = null;
599589

600-
if (Edition.CURRENT != Edition.GAE) {
601-
// [ifndef gae]
602-
if (representation == null) {
603-
return null;
604-
}
605-
606-
final PipeStream pipe = new PipeStream();
607-
final java.io.OutputStream os = pipe.getOutputStream();
590+
if (representation == null) {
591+
return null;
592+
}
608593

609-
// Creates a thread that will handle the task of continuously
610-
// writing the representation into the input side of the pipe
611-
Runnable task = new org.restlet.engine.util.ContextualRunnable() {
612-
public void run() {
594+
final PipeStream pipe = new PipeStream();
595+
final java.io.OutputStream os = pipe.getOutputStream();
596+
597+
// Creates a thread that will handle the task of continuously
598+
// writing the representation into the input side of the pipe
599+
Runnable task = new org.restlet.engine.util.ContextualRunnable() {
600+
public void run() {
601+
try {
602+
representation.write(os);
603+
os.flush();
604+
} catch (IOException ioe) {
605+
Context.getCurrentLogger().log(Level.WARNING,
606+
"Error while writing to the piped input stream.",
607+
ioe);
608+
} finally {
613609
try {
614-
representation.write(os);
615-
os.flush();
616-
} catch (IOException ioe) {
617-
Context.getCurrentLogger()
618-
.log(Level.WARNING,
619-
"Error while writing to the piped input stream.",
620-
ioe);
621-
} finally {
622-
try {
623-
os.close();
624-
} catch (IOException ioe2) {
625-
Context.getCurrentLogger().log(Level.WARNING,
626-
"Error while closing the pipe.", ioe2);
627-
}
610+
os.close();
611+
} catch (IOException ioe2) {
612+
Context.getCurrentLogger().log(Level.WARNING,
613+
"Error while closing the pipe.", ioe2);
628614
}
629615
}
630-
};
631-
632-
org.restlet.Context context = org.restlet.Context.getCurrent();
633-
634-
if (context != null && context.getExecutorService() != null) {
635-
context.getExecutorService().execute(task);
636-
} else {
637-
Engine.createThreadWithLocalVariables(task, "Restlet-IoUtils")
638-
.start();
639616
}
617+
};
640618

641-
result = pipe.getInputStream();
642-
// [enddef]
619+
org.restlet.Context context = org.restlet.Context.getCurrent();
620+
621+
if (context != null && context.getExecutorService() != null) {
622+
context.getExecutorService().execute(task);
643623
} else {
644-
Context.getCurrentLogger()
645-
.log(Level.WARNING,
646-
"The GAE edition is unable to get an InputStream out of an OutputRepresentation.");
624+
Engine.createThreadWithLocalVariables(task, "Restlet-IoUtils")
625+
.start();
647626
}
648627

628+
result = pipe.getInputStream();
629+
649630
return result;
650631
}
651632

0 commit comments

Comments
 (0)