Author: ningjiang Date: Thu Oct 27 12:27:42 2011 New Revision: 1189716 URL: http://svn.apache.org/viewvc?rev=1189716&view=rev Log: Merged revisions 1189704 via svnmerge from https://svn.apache.org/repos/asf/camel/branches/camel-2.8.x
................ r1189704 | ningjiang | 2011-10-27 19:08:21 +0800 (Thu, 27 Oct 2011) | 9 lines Merged revisions 1189693 via svnmerge from https://svn.apache.org/repos/asf/camel/trunk ........ r1189693 | ningjiang | 2011-10-27 17:50:09 +0800 (Thu, 27 Oct 2011) | 1 line CAMEL-4581 fix the NPE issue of stream endpoint ........ ................ Modified: camel/branches/camel-2.7.x/ (props changed) camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java Propchange: camel/branches/camel-2.7.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Oct 27 12:27:42 2011 @@ -1,2 +1,2 @@ -/camel/branches/camel-2.8.x:1170965,1171400,1174571,1175323,1176329,1176787,1177397,1177946,1177949,1180598,1187226 -/camel/trunk:1146608,1146903,1147216,1170956,1171396,1174565,1175321,1176274,1176781-1176782,1177394,1177945,1177948,1180597,1187221 +/camel/branches/camel-2.8.x:1170965,1171400,1174571,1175323,1176329,1176787,1177397,1177946,1177949,1180598,1187226,1189704 +/camel/trunk:1146608,1146903,1147216,1170956,1171396,1174565,1175321,1176274,1176781-1176782,1177394,1177945,1177948,1180597,1187221,1189693 Propchange: camel/branches/camel-2.7.x/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Thu Oct 27 12:27:42 2011 @@ -1 +1 @@ -/camel/branches/camel-2.8.x:1-1146127,1146608,1146653,1146771,1146903,1147216,1170965-1171083,1171085-1171400,1174571,1175323,1176329,1176787,1177397,1177946,1177949,1180598,1187226 +/camel/branches/camel-2.8.x:1-1146127,1146608,1146653,1146771,1146903,1147216,1170965-1171083,1171085-1171400,1174571,1175323,1176329,1176787,1177397,1177946,1177949,1180598,1187226,1189704 Modified: camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java?rev=1189716&r1=1189715&r2=1189716&view=diff ============================================================================== --- camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java (original) +++ camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java Thu Oct 27 12:27:42 2011 @@ -40,6 +40,7 @@ public class StreamEndpoint extends Defa private long promptDelay; private long initialPromptDelay = 2000; private int groupLines; + private Charset charset; public StreamEndpoint(String endpointUri, Component component) throws Exception { super(endpointUri, component); @@ -151,11 +152,19 @@ public class StreamEndpoint extends Defa public void setGroupLines(int groupLines) { this.groupLines = groupLines; } + + public Charset getCharset() { + return charset; + } // Implementations //------------------------------------------------------------------------- - Charset getCharset() { + protected void doStart() throws Exception { + charset = loadCharset(); + } + + Charset loadCharset() { if (encoding == null) { encoding = Charset.defaultCharset().name(); if (LOG.isDebugEnabled()) { Modified: camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java?rev=1189716&r1=1189715&r2=1189716&view=diff ============================================================================== --- camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java (original) +++ camel/branches/camel-2.7.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java Thu Oct 27 12:27:42 2011 @@ -45,8 +45,6 @@ public class StreamProducer extends Defa private static final String TYPES = "out,err,file,header,url"; private static final String INVALID_URI = "Invalid uri, valid form: 'stream:{" + TYPES + "}'"; private static final List<String> TYPES_LIST = Arrays.asList(TYPES.split(",")); - private OutputStream outputStream = System.out; - private boolean isSystemStream; private StreamEndpoint endpoint; private String uri; @@ -56,16 +54,10 @@ public class StreamProducer extends Defa validateUri(uri); } - @Override - public void doStop() throws Exception { - closeStream(); - super.doStop(); - } - public void process(Exchange exchange) throws Exception { delay(endpoint.getDelay()); - - isSystemStream = false; + OutputStream outputStream = System.out; + boolean isSystemStream = false; if ("out".equals(uri)) { isSystemStream = true; outputStream = System.out; @@ -80,8 +72,8 @@ public class StreamProducer extends Defa outputStream = resolveStreamFromUrl(); } - writeToStream(exchange); - closeStream(); + writeToStream(outputStream, exchange); + closeStream(outputStream, isSystemStream); } private OutputStream resolveStreamFromUrl() throws IOException { @@ -122,7 +114,7 @@ public class StreamProducer extends Defa Thread.sleep(ms); } - private void writeToStream(Exchange exchange) throws IOException, CamelExchangeException { + private void writeToStream(OutputStream outputStream, Exchange exchange) throws IOException, CamelExchangeException { Object body = exchange.getIn().getBody(); // if not a string then try as byte array first @@ -150,12 +142,11 @@ public class StreamProducer extends Defa bw.flush(); } - private void closeStream() throws Exception { + private void closeStream(OutputStream outputStream, boolean isSystemStream) throws Exception { // important: do not close the writer on a standard system.out etc. if (outputStream != null && !isSystemStream) { outputStream.close(); } - outputStream = null; } private void validateUri(String uri) throws Exception {
