CAMEL-9157: JMX - Add dataformat as mbean category
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9765d562 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9765d562 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9765d562 Branch: refs/heads/master Commit: 9765d5624f2835fa51a5831334d76238f384d504 Parents: 0a991ea Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Sep 24 13:20:16 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Sep 24 13:20:16 2015 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/spi/DataFormat.java | 3 +- .../dataformat/barcode/BarcodeDataFormat.java | 204 +++++++------------ .../dataformat/base64/Base64DataFormat.java | 13 +- .../bindy/BindyAbstractDataFormat.java | 13 +- .../camel/component/boon/BoonDataFormat.java | 14 +- .../converter/crypto/CryptoDataFormat.java | 13 +- .../camel/dataformat/csv/CsvDataFormat.java | 44 ++-- .../cxf/jaxrs/DataFormatProviderTest.java | 12 +- .../dataformat/flatpack/FlatpackDataFormat.java | 14 +- .../dataformat/AbstractXmlDataFormat.java | 12 +- .../camel/component/ical/ICalDataFormat.java | 13 +- .../camel/dataformat/jibx/JibxDataFormat.java | 13 +- .../camel/dataformat/rss/RssDataFormat.java | 19 +- .../component/syslog/SyslogDataFormat.java | 13 +- .../tagsoup/TidyMarkupDataFormat.java | 75 ++----- .../dataformat/tarfile/TarFileDataFormat.java | 13 +- 16 files changed, 254 insertions(+), 234 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java b/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java index 86ed336..ad76316 100644 --- a/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java +++ b/camel-core/src/main/java/org/apache/camel/spi/DataFormat.java @@ -21,7 +21,6 @@ import java.io.OutputStream; import org.apache.camel.Exchange; import org.apache.camel.Message; -import org.apache.camel.Service; /** * Represents a @@ -32,7 +31,7 @@ import org.apache.camel.Service; * * @version */ -public interface DataFormat extends Service { +public interface DataFormat { // TODO: DataFormats should extends Service like the others http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java b/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java index 1dd5f9b..0f6ea37 100644 --- a/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java +++ b/components/camel-barcode/src/main/java/org/apache/camel/dataformat/barcode/BarcodeDataFormat.java @@ -14,17 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.camel.dataformat.barcode; import java.io.BufferedInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.EnumMap; import java.util.Map; - import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat; @@ -34,54 +30,48 @@ import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatReader; import com.google.zxing.MultiFormatWriter; import com.google.zxing.Result; -import com.google.zxing.WriterException; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.datamatrix.encoder.SymbolShapeHint; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; - import org.apache.camel.Exchange; -import org.apache.camel.NoTypeConversionAvailableException; -import org.apache.camel.TypeConversionException; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ExchangeHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * {@link DataFormat} to create (encode) and + * {@link DataFormat} to create (encode) and * read (decode) barcodes. For more info about * the available barcodes have a look at:<br/><br/> - * + * <p/> * https://github.com/zxing/zxing - * */ -public class BarcodeDataFormat implements DataFormat { +public class BarcodeDataFormat extends ServiceSupport implements DataFormat { /** * Logger. */ private static final Logger LOG = LoggerFactory.getLogger(BarcodeDataFormat.class); - + /** * The bean for the default parameters. */ private BarcodeParameters params; - + /** * The encoding hint map, used for writing a barcode. */ - private final Map<EncodeHintType, Object> writerHintMap = - new EnumMap<EncodeHintType, Object>(EncodeHintType.class); - + private final Map<EncodeHintType, Object> writerHintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class); + /** * The decoding hint map, used for reading a barcode. */ - private final Map<DecodeHintType, Object> readerHintMap = - new EnumMap<DecodeHintType, Object>(DecodeHintType.class); - + private final Map<DecodeHintType, Object> readerHintMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class); + /** * Create instance with default parameters. @@ -90,11 +80,11 @@ public class BarcodeDataFormat implements DataFormat { this.setDefaultParameters(); this.optimizeHints(); } - + /** - * Create instance with custom {@link BarcodeFormat}. The other + * Create instance with custom {@link BarcodeFormat}. The other * values are default. - * + * * @param format the barcode format */ public BarcodeDataFormat(final BarcodeFormat format) { @@ -104,11 +94,11 @@ public class BarcodeDataFormat implements DataFormat { } /** - * Create instance with custom height and width. The other + * Create instance with custom height and width. The other * values are default. - * + * * @param height the image height - * @param width the image width + * @param width the image width */ public BarcodeDataFormat(final int width, final int height) { this.setDefaultParameters(); @@ -118,9 +108,9 @@ public class BarcodeDataFormat implements DataFormat { } /** - * Create instance with custom {@link BarcodeImageType}. The other + * Create instance with custom {@link BarcodeImageType}. The other * values are default. - * + * * @param type the type (format) of the image. e.g. PNG */ public BarcodeDataFormat(final BarcodeImageType type) { @@ -128,18 +118,17 @@ public class BarcodeDataFormat implements DataFormat { this.params.setType(type); this.optimizeHints(); } - + /** - * Create instance with custom height, width and image type. The other + * Create instance with custom height, width and image type. The other * values are default. - * + * * @param height the image height - * @param width the image width - * @param type the type (format) of the image. e.g. PNG + * @param width the image width + * @param type the type (format) of the image. e.g. PNG * @param format the barcode format */ - public BarcodeDataFormat(final int width, final int height - , final BarcodeImageType type, final BarcodeFormat format) { + public BarcodeDataFormat(final int width, final int height, final BarcodeImageType type, final BarcodeFormat format) { this.setDefaultParameters(); this.params.setHeight(height); this.params.setWidth(width); @@ -147,41 +136,30 @@ public class BarcodeDataFormat implements DataFormat { this.params.setFormat(format); this.optimizeHints(); } - + /** * Marshall a {@link String} payload to a code image. - * - * @param exchange - * @param graph - * @param stream - * @throws Exception */ @Override - public void marshal(final Exchange exchange, final Object graph - , final OutputStream stream) throws Exception { + public void marshal(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { this.printImage(exchange, graph, stream); } /** * Unmarshall a code image to a {@link String} payload. - * - * @param exchange - * @param stream - * @return - * @throws Exception */ @Override public Object unmarshal(final Exchange exchange, final InputStream stream) throws Exception { return this.readImage(exchange, stream); } - + /** * Sets the default parameters. */ protected final void setDefaultParameters() { this.params = new BarcodeParameters(); } - + /** * Sets hints optimized for different barcode types. */ @@ -195,145 +173,102 @@ public class BarcodeDataFormat implements DataFormat { // only for QR code. AZTEC uses zxing's default error correction 33%. if (format.equals(BarcodeFormat.QR_CODE.toString())) { - this.writerHintMap - .put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + this.writerHintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); } if (format.equals(BarcodeFormat.DATA_MATRIX.toString())) { - this.writerHintMap - .put(EncodeHintType.DATA_MATRIX_SHAPE - , SymbolShapeHint.FORCE_SQUARE); + this.writerHintMap.put(EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE); } - + // reader hints this.readerHintMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); } - + /** * Writes the image file to the output stream. - * - * @param graph the object graph + * + * @param graph the object graph * @param exchange the camel exchange - * @param stream the output stream - * @throws WriterException - * @throws UnsupportedEncodingException - * @throws IOException - * @throws org.apache.camel.NoTypeConversionAvailableException + * @param stream the output stream */ - private void printImage(final Exchange exchange, final Object graph, final OutputStream stream) - throws WriterException, UnsupportedEncodingException, IOException, TypeConversionException, - NoTypeConversionAvailableException { - + private void printImage(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { final String payload = ExchangeHelper .convertToMandatoryType(exchange, String.class, graph); final MultiFormatWriter writer = new MultiFormatWriter(); // set values final String type = this.params.getType().toString(); - + // create code image final BitMatrix matrix = writer.encode( payload, - this.params.getFormat(), - this.params.getWidth(), - this.params.getHeight(), + this.params.getFormat(), + this.params.getWidth(), + this.params.getHeight(), writerHintMap); - + // write image back to stream MatrixToImageWriter.writeToStream(matrix, type, stream); } - + /** * Reads the message from a code. - * - * @param exchange - * @param stream - * @return - * @throws Exception */ - private String readImage(final Exchange exchange, final InputStream stream) - throws Exception { + private String readImage(final Exchange exchange, final InputStream stream) throws Exception { final MultiFormatReader reader = new MultiFormatReader(); final BufferedInputStream in = exchange.getContext() .getTypeConverter() .mandatoryConvertTo(BufferedInputStream.class, stream); - final BinaryBitmap bitmap = new BinaryBitmap( - new HybridBinarizer( - new BufferedImageLuminanceSource(ImageIO.read(in)))); + final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(in)))); final Result result = reader.decode(bitmap, readerHintMap); - + // write the found barcode format into the header - exchange.getOut() - .setHeader(Barcode.BARCODE_FORMAT, result.getBarcodeFormat()); - + exchange.getOut().setHeader(Barcode.BARCODE_FORMAT, result.getBarcodeFormat()); + return result.getText(); } - + /** * Adds a new hint value to writer (encode) hint map. - * - * @param hintType - * @param value */ - public final void addToHintMap(final EncodeHintType hintType - , final Object value) { + public final void addToHintMap(final EncodeHintType hintType, final Object value) { this.writerHintMap.put(hintType, value); - LOG.info( - String.format("Added '%s' with value '%s' to writer hint map." - , hintType.toString(), value.toString())); + LOG.info(String.format("Added '%s' with value '%s' to writer hint map.", hintType.toString(), value.toString())); } - + /** * Adds a new hint value to reader (decode) hint map. - * - * @param hintType - * @param value */ - public final void addToHintMap(final DecodeHintType hintType - , final Object value) { + public final void addToHintMap(final DecodeHintType hintType, final Object value) { this.readerHintMap.put(hintType, value); } - + /** * Removes a hint from writer (encode) hint map. - * - * @param hintType */ public final void removeFromHintMap(final EncodeHintType hintType) { if (this.writerHintMap.containsKey(hintType)) { this.writerHintMap.remove(hintType); - LOG.info( - String.format("Removed '%s' from writer hint map." - , hintType.toString())); + LOG.info(String.format("Removed '%s' from writer hint map.", hintType.toString())); } else { - LOG.warn( - String.format("Could not find encode hint type '%s' in " - + "writer hint map.", hintType.toString())); + LOG.warn(String.format("Could not find encode hint type '%s' in writer hint map.", hintType.toString())); } } - + /** * Removes a hint from reader (decode) hint map. - * - * @param hintType */ public final void removeFromHintMap(final DecodeHintType hintType) { if (this.readerHintMap.containsKey(hintType)) { this.readerHintMap.remove(hintType); - LOG.info( - String.format("Removed '%s' from reader hint map." - , hintType.toString())); + LOG.info(String.format("Removed '%s' from reader hint map.", hintType.toString())); } else { - LOG.warn( - String.format("Could not find decode hint type '%s' in" - + " reader hint map.", hintType.toString())); + LOG.warn(String.format("Could not find decode hint type '%s' in reader hint map.", hintType.toString())); } } /** * The (default) parameters. - * - * @return */ public final BarcodeParameters getParams() { return params; @@ -341,8 +276,6 @@ public class BarcodeDataFormat implements DataFormat { /** * The writer (encode) hint map. - * - * @return */ public final Map<EncodeHintType, Object> getWriterHintMap() { return writerHintMap; @@ -350,29 +283,38 @@ public class BarcodeDataFormat implements DataFormat { /** * The reader (decode) hint map. - * - * @return */ public final Map<DecodeHintType, Object> getReaderHintMap() { return readerHintMap; } - + // these set method is used for BarcodeDataFormat XML DSL public void setBarcodeImageType(BarcodeImageType type) { this.params.setType(type); this.optimizeHints(); } - + public void setBarcodeFormat(BarcodeFormat format) { this.params.setFormat(format); this.optimizeHints(); } - + public void setWidth(Integer width) { this.params.setWidth(width); } - + public void setHeight(Integer height) { this.params.setHeight(height); } + + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java b/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java index fc30303..4b9ee75 100644 --- a/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java +++ b/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java @@ -21,13 +21,14 @@ import java.io.OutputStream; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ExchangeHelper; import org.apache.camel.util.IOHelper; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64InputStream; import org.apache.commons.codec.binary.Base64OutputStream; -public class Base64DataFormat implements DataFormat { +public class Base64DataFormat extends ServiceSupport implements DataFormat { private int lineLength = Base64.MIME_CHUNK_SIZE; private byte[] lineSeparator = {'\r', '\n'}; @@ -91,4 +92,14 @@ public class Base64DataFormat implements DataFormat { public void setUrlSafe(boolean urlSafe) { this.urlSafe = urlSafe; } + + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java index a4365e3..b01e6d7 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java @@ -21,8 +21,9 @@ import java.util.List; import java.util.Map; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; -public abstract class BindyAbstractDataFormat implements DataFormat { +public abstract class BindyAbstractDataFormat extends ServiceSupport implements DataFormat { private String locale; private BindyAbstractFactory modelFactory; private Class<?> classType; @@ -84,4 +85,14 @@ public abstract class BindyAbstractDataFormat implements DataFormat { return models; } } + + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-boon/src/main/java/org/apache/camel/component/boon/BoonDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-boon/src/main/java/org/apache/camel/component/boon/BoonDataFormat.java b/components/camel-boon/src/main/java/org/apache/camel/component/boon/BoonDataFormat.java index dfea3b1..24fbc42 100644 --- a/components/camel-boon/src/main/java/org/apache/camel/component/boon/BoonDataFormat.java +++ b/components/camel-boon/src/main/java/org/apache/camel/component/boon/BoonDataFormat.java @@ -26,6 +26,7 @@ import java.util.HashMap; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ChildServiceSupport; import org.apache.camel.util.IOHelper; import org.boon.json.JsonFactory; import org.boon.json.ObjectMapper; @@ -36,7 +37,7 @@ import org.boon.json.ObjectMapper; * href="http://richardhightower.github.io/site/Boon/">Boon</a> to marshal to * and from JSON. */ -public class BoonDataFormat implements DataFormat { +public class BoonDataFormat extends ChildServiceSupport implements DataFormat { private final ObjectMapper objectMapper; private Class<?> unmarshalType; @@ -81,6 +82,16 @@ public class BoonDataFormat implements DataFormat { return result; } + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } + // Properties // ------------------------------------------------------------------------- @@ -95,4 +106,5 @@ public class BoonDataFormat implements DataFormat { public ObjectMapper getObjectMapper() { return this.objectMapper; } + } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java index 711b3df..dd1d2c4 100644 --- a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java +++ b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java @@ -35,6 +35,7 @@ import static javax.crypto.Cipher.ENCRYPT_MODE; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ExchangeHelper; import org.apache.camel.util.IOHelper; import org.slf4j.Logger; @@ -67,7 +68,7 @@ import org.slf4j.LoggerFactory; * <li>http://en.wikipedia.org/wiki/HMAC</li> * </ul> */ -public class CryptoDataFormat implements DataFormat { +public class CryptoDataFormat extends ServiceSupport implements DataFormat { public static final String KEY = "CamelCryptoKey"; @@ -173,6 +174,16 @@ public class CryptoDataFormat implements DataFormat { return unmarshalled; } + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } + private void inlineInitVector(OutputStream outputStream, byte[] iv) throws IOException { if (inline) { if (iv == null) { http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java index c75aa54..3437a3f 100644 --- a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java +++ b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java @@ -22,6 +22,7 @@ import java.util.Arrays; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.QuoteMode; @@ -34,7 +35,7 @@ import org.apache.commons.csv.QuoteMode; * Autogeneration can be disabled. In this case, only the fields defined in * csvConfig are written on the output. */ -public class CsvDataFormat implements DataFormat { +public class CsvDataFormat extends ServiceSupport implements DataFormat { // CSV format options private CSVFormat format = CSVFormat.DEFAULT; private boolean commentMarkerDisabled; @@ -72,19 +73,24 @@ public class CsvDataFormat implements DataFormat { } public void marshal(Exchange exchange, Object object, OutputStream outputStream) throws Exception { - if (marshaller == null) { - marshaller = CsvMarshaller.create(getActiveFormat(), this); - } marshaller.marshal(exchange, object, outputStream); } public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception { - if (unmarshaller == null) { - unmarshaller = CsvUnmarshaller.create(getActiveFormat(), this); - } return unmarshaller.unmarshal(exchange, inputStream); } + @Override + protected void doStart() throws Exception { + marshaller = CsvMarshaller.create(getActiveFormat(), this); + unmarshaller = CsvUnmarshaller.create(getActiveFormat(), this); + } + + @Override + protected void doStop() throws Exception { + // noop + } + CSVFormat getActiveFormat() { CSVFormat answer = format; @@ -151,11 +157,6 @@ public class CsvDataFormat implements DataFormat { return answer; } - private void reset() { - marshaller = null; - unmarshaller = null; - } - //region Getters/Setters /** @@ -179,7 +180,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setFormat(CSVFormat format) { this.format = (format == null) ? CSVFormat.DEFAULT : format; - reset(); return this; } @@ -228,7 +228,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setCommentMarkerDisabled(boolean commentMarkerDisabled) { this.commentMarkerDisabled = commentMarkerDisabled; - reset(); return this; } @@ -252,7 +251,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setCommentMarker(Character commentMarker) { this.commentMarker = commentMarker; - reset(); return this; } @@ -276,7 +274,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setDelimiter(Character delimiter) { this.delimiter = delimiter; - reset(); return this; } @@ -298,7 +295,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setEscapeDisabled(boolean escapeDisabled) { this.escapeDisabled = escapeDisabled; - reset(); return this; } @@ -322,7 +318,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setEscape(Character escape) { this.escape = escape; - reset(); return this; } @@ -344,7 +339,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setHeaderDisabled(boolean headerDisabled) { this.headerDisabled = headerDisabled; - reset(); return this; } @@ -368,7 +362,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setHeader(String[] header) { this.header = Arrays.copyOf(header, header.length); - reset(); return this; } @@ -392,7 +385,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setAllowMissingColumnNames(Boolean allowMissingColumnNames) { this.allowMissingColumnNames = allowMissingColumnNames; - reset(); return this; } @@ -416,7 +408,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setIgnoreEmptyLines(Boolean ignoreEmptyLines) { this.ignoreEmptyLines = ignoreEmptyLines; - reset(); return this; } @@ -440,7 +431,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setIgnoreSurroundingSpaces(Boolean ignoreSurroundingSpaces) { this.ignoreSurroundingSpaces = ignoreSurroundingSpaces; - reset(); return this; } @@ -462,7 +452,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setNullStringDisabled(boolean nullStringDisabled) { this.nullStringDisabled = nullStringDisabled; - reset(); return this; } @@ -486,7 +475,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setNullString(String nullString) { this.nullString = nullString; - reset(); return this; } @@ -508,7 +496,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setQuoteDisabled(boolean quoteDisabled) { this.quoteDisabled = quoteDisabled; - reset(); return this; } @@ -532,7 +519,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setQuote(Character quote) { this.quote = quote; - reset(); return this; } @@ -556,7 +542,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setQuoteMode(QuoteMode quoteMode) { this.quoteMode = quoteMode; - reset(); return this; } @@ -578,7 +563,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setRecordSeparatorDisabled(boolean recordSeparatorDisabled) { this.recordSeparatorDisabled = recordSeparatorDisabled; - reset(); return this; } @@ -602,7 +586,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setRecordSeparator(String recordSeparator) { this.recordSeparator = recordSeparator; - reset(); return this; } @@ -626,7 +609,6 @@ public class CsvDataFormat implements DataFormat { */ public CsvDataFormat setSkipHeaderRecord(Boolean skipHeaderRecord) { this.skipHeaderRecord = skipHeaderRecord; - reset(); return this; } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DataFormatProviderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DataFormatProviderTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DataFormatProviderTest.java index b369448..dcdb23e 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DataFormatProviderTest.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/DataFormatProviderTest.java @@ -27,6 +27,7 @@ import javax.ws.rs.core.MediaType; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.jaxrs.impl.MetadataMap; import org.junit.Assert; @@ -112,7 +113,7 @@ public class DataFormatProviderTest extends Assert { } } - private static class TestDataFormat implements DataFormat { + private static class TestDataFormat extends ServiceSupport implements DataFormat { @Override public void marshal(Exchange ex, Object obj, OutputStream os) throws Exception { @@ -125,6 +126,15 @@ public class DataFormatProviderTest extends Assert { return new Book(IOUtils.readStringFromStream(is)); } + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } } } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java b/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java index c8f0e46..a2bb9bc 100644 --- a/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java +++ b/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java @@ -36,6 +36,7 @@ import net.sf.flatpack.writer.Writer; import org.apache.camel.Exchange; import org.apache.camel.component.flatpack.DataSetList; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.IOHelper; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ResourceHelper; @@ -55,7 +56,7 @@ import org.slf4j.LoggerFactory; * * @version */ -public class FlatpackDataFormat implements DataFormat { +public class FlatpackDataFormat extends ServiceSupport implements DataFormat { private static final Logger LOG = LoggerFactory.getLogger(FlatpackDataFormat.class); private ParserFactory parserFactory = DefaultParserFactory.getInstance(); private char delimiter = ','; @@ -110,6 +111,17 @@ public class FlatpackDataFormat implements DataFormat { } } + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + + } + // Properties //------------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-groovy/src/main/java/org/apache/camel/groovy/dataformat/AbstractXmlDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/main/java/org/apache/camel/groovy/dataformat/AbstractXmlDataFormat.java b/components/camel-groovy/src/main/java/org/apache/camel/groovy/dataformat/AbstractXmlDataFormat.java index 428615d..8ec6087 100644 --- a/components/camel-groovy/src/main/java/org/apache/camel/groovy/dataformat/AbstractXmlDataFormat.java +++ b/components/camel-groovy/src/main/java/org/apache/camel/groovy/dataformat/AbstractXmlDataFormat.java @@ -19,6 +19,7 @@ package org.apache.camel.groovy.dataformat; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.camel.support.ServiceSupport; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -31,7 +32,7 @@ import org.slf4j.LoggerFactory; /** * Common attributes and methods for XmlParser and XmlSlurper usage. */ -public abstract class AbstractXmlDataFormat implements DataFormat { +public abstract class AbstractXmlDataFormat extends ServiceSupport implements DataFormat { private static final Logger LOG = LoggerFactory.getLogger(AbstractXmlDataFormat.class); private static final ErrorHandler DEFAULT_HANDLER = new DefaultErrorHandler(); @@ -90,4 +91,13 @@ public abstract class AbstractXmlDataFormat implements DataFormat { } + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-ical/src/main/java/org/apache/camel/component/ical/ICalDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-ical/src/main/java/org/apache/camel/component/ical/ICalDataFormat.java b/components/camel-ical/src/main/java/org/apache/camel/component/ical/ICalDataFormat.java index 0448c74..1db789b 100644 --- a/components/camel-ical/src/main/java/org/apache/camel/component/ical/ICalDataFormat.java +++ b/components/camel-ical/src/main/java/org/apache/camel/component/ical/ICalDataFormat.java @@ -25,11 +25,12 @@ import net.fortuna.ical4j.model.Calendar; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; /** * Bridge ICal data format to camel world. */ -public class ICalDataFormat implements DataFormat { +public class ICalDataFormat extends ServiceSupport implements DataFormat { /** * Class responsible for writing out calendar instances. @@ -72,4 +73,14 @@ public class ICalDataFormat implements DataFormat { return builder.build(stream); } + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-jibx/src/main/java/org/apache/camel/dataformat/jibx/JibxDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-jibx/src/main/java/org/apache/camel/dataformat/jibx/JibxDataFormat.java b/components/camel-jibx/src/main/java/org/apache/camel/dataformat/jibx/JibxDataFormat.java index 3ba125f..2727a89 100644 --- a/components/camel-jibx/src/main/java/org/apache/camel/dataformat/jibx/JibxDataFormat.java +++ b/components/camel-jibx/src/main/java/org/apache/camel/dataformat/jibx/JibxDataFormat.java @@ -21,6 +21,7 @@ import java.io.OutputStream; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ObjectHelper; import org.jibx.runtime.BindingDirectory; import org.jibx.runtime.IBindingFactory; @@ -28,7 +29,7 @@ import org.jibx.runtime.IMarshallingContext; import org.jibx.runtime.IUnmarshallingContext; import org.jibx.runtime.JiBXException; -public class JibxDataFormat implements DataFormat { +public class JibxDataFormat extends ServiceSupport implements DataFormat { private Class<?> unmarshallClass; private String bindingName; @@ -57,6 +58,16 @@ public class JibxDataFormat implements DataFormat { return unmarshallingContext.unmarshalDocument(stream, null); } + + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } public Class<?> getUnmarshallClass() { return unmarshallClass; } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java b/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java index 4e7688a..f74666e 100644 --- a/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java +++ b/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import com.sun.syndication.feed.synd.SyndFeed; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ExchangeHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,21 +39,27 @@ import org.slf4j.LoggerFactory; * Uses <a href="https://rome.dev.java.net/">ROME</a> for RSS parsing. * <p/> */ -public class RssDataFormat implements DataFormat { +public class RssDataFormat extends ServiceSupport implements DataFormat { protected static final Logger LOG = LoggerFactory.getLogger(RssDataFormat.class); public void marshal(Exchange exchange, Object body, OutputStream out) throws Exception { SyndFeed feed = ExchangeHelper.convertToMandatoryType(exchange, SyndFeed.class, body); String xml = RssConverter.feedToXml(feed); - if (xml != null) { - out.write(xml.getBytes()); - } else { - LOG.debug("Cannot marshal RSS feed to XML."); - } + out.write(xml.getBytes()); } public Object unmarshal(Exchange exchange, InputStream in) throws Exception { String xml = ExchangeHelper.convertToMandatoryType(exchange, String.class, in); return RssConverter.xmlToFeed(xml); } + + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogDataFormat.java b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogDataFormat.java index 399d8ab..84860cb 100644 --- a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogDataFormat.java +++ b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogDataFormat.java @@ -22,9 +22,10 @@ import java.util.Date; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ExchangeHelper; -public class SyslogDataFormat implements DataFormat { +public class SyslogDataFormat extends ServiceSupport implements DataFormat { @Override public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception { @@ -71,4 +72,14 @@ public class SyslogDataFormat implements DataFormat { return message; } + + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-tagsoup/src/main/java/org/apache/camel/dataformat/tagsoup/TidyMarkupDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-tagsoup/src/main/java/org/apache/camel/dataformat/tagsoup/TidyMarkupDataFormat.java b/components/camel-tagsoup/src/main/java/org/apache/camel/dataformat/tagsoup/TidyMarkupDataFormat.java index 546607f..e5a8250 100644 --- a/components/camel-tagsoup/src/main/java/org/apache/camel/dataformat/tagsoup/TidyMarkupDataFormat.java +++ b/components/camel-tagsoup/src/main/java/org/apache/camel/dataformat/tagsoup/TidyMarkupDataFormat.java @@ -28,6 +28,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXSource; +import org.apache.camel.support.ServiceSupport; import org.w3c.dom.Node; import org.xml.sax.ContentHandler; @@ -45,7 +46,6 @@ import org.ccil.cowan.tagsoup.XMLWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * Dataformat for TidyMarkup (aka Well formed HTML in XML form.. may or may not * be XHTML) This dataformat is intended to convert bad HTML from a site (or @@ -53,7 +53,7 @@ import org.slf4j.LoggerFactory; * xpath'ed on. * */ -public class TidyMarkupDataFormat implements DataFormat { +public class TidyMarkupDataFormat extends ServiceSupport implements DataFormat { /* * Our Logger @@ -114,8 +114,6 @@ public class TidyMarkupDataFormat implements DataFormat { /** * Unmarshal the data - * - * @throws Exception */ public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception { @@ -184,9 +182,6 @@ public class TidyMarkupDataFormat implements DataFormat { /** * Create the tagSoup Parser - * - * @return - * @throws CamelException */ protected XMLReader createTagSoupParser() throws CamelException { XMLReader reader = new Parser(); @@ -230,24 +225,6 @@ public class TidyMarkupDataFormat implements DataFormat { return reader; } - /** - * @param htmlSchema - * the htmlSchema to set - */ - public void setParsingSchema(Schema schema) { - this.parsingSchema = schema; - } - - /** - * @return the htmlSchema - */ - public Schema getParsingSchema() { - if (parsingSchema == null) { - this.parsingSchema = new HTMLSchema(); - } - return parsingSchema; - } - protected ContentHandler createContentHandler(Writer w) { XMLWriter xmlWriter = new XMLWriter(w); @@ -268,64 +245,56 @@ public class TidyMarkupDataFormat implements DataFormat { } - /** - * @param parserFeatures - * the parserFeatures to set - */ + public void setParsingSchema(Schema schema) { + this.parsingSchema = schema; + } + + public Schema getParsingSchema() { + if (parsingSchema == null) { + this.parsingSchema = new HTMLSchema(); + } + return parsingSchema; + } + public void setParserFeatures(Map<String, Boolean> parserFeatures) { this.parserFeatures = parserFeatures; } - /** - * @return the parserFeatures - */ public Map<String, Boolean> getParserFeatures() { return parserFeatures; } - /** - * @param parserPropeties - * the parserPropeties to set - */ public void setParserPropeties(Map<String, Object> parserPropeties) { this.parserPropeties = parserPropeties; } - /** - * @return the parserPropeties - */ public Map<String, Object> getParserPropeties() { return parserPropeties; } - /** - * @param method - * the method to set - */ public void setMethod(String method) { this.method = method; } - /** - * @return the method - */ public String getMethod() { return method; } - /** - * @return the dataObjectType - */ public Class<?> getDataObjectType() { return dataObjectType; } - /** - * @param dataObjectType - * the dataObjectType to set - */ public void setDataObjectType(Class<?> dataObjectType) { this.dataObjectType = dataObjectType; } + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } } http://git-wip-us.apache.org/repos/asf/camel/blob/9765d562/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java b/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java index 754d932..d994cf2 100644 --- a/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java +++ b/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; +import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.IOHelper; import org.apache.camel.util.StringHelper; import org.apache.commons.compress.archivers.ArchiveStreamFactory; @@ -38,7 +39,7 @@ import static org.apache.camel.Exchange.FILE_NAME; * Tar file data format. * Based on ZipFileDataFormat from camel-zipfile component */ -public class TarFileDataFormat implements DataFormat { +public class TarFileDataFormat extends ServiceSupport implements DataFormat { private boolean usingIterator; public void setUsingIterator(boolean usingIterator) { @@ -108,4 +109,14 @@ public class TarFileDataFormat implements DataFormat { } } } + + @Override + protected void doStart() throws Exception { + // noop + } + + @Override + protected void doStop() throws Exception { + // noop + } }