Issue #2807. Added MalformedDataException for VAA decoding.

Former-commit-id: 4a3a56abe6 [formerly 8391b1098e] [formerly 8f8a6cb90e [formerly 085c10211b1fa397ca54b8d4d316055f9225db0c]]
Former-commit-id: 8f8a6cb90e
Former-commit-id: 1f8d00e033
This commit is contained in:
Slav Korolev 2014-03-10 12:31:57 -04:00
parent 3a66c42d37
commit d1fbf15b5d
3 changed files with 45 additions and 29 deletions

View file

@ -46,9 +46,13 @@
<bean ref="vaaDecoder" method="decode" />
<to uri="direct-vm:indexAlert" />
</pipeline>
<doCatch>
<exception>com.raytheon.uf.common.dataplugin.exception.MalformedDataException</exception>
<to uri="direct-vm:logFailureAsInfo" />
</doCatch>
<doCatch>
<exception>java.lang.Throwable</exception>
<to uri="log:vaa?level=ERROR"/>
<to uri="direct-vm:logFailedData"/>
</doCatch>
</doTry>
</pipeline>

View file

@ -19,11 +19,13 @@
**/
package com.raytheon.uf.edex.plugin.vaa;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.raytheon.edex.esb.Headers;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.exception.MalformedDataException;
import com.raytheon.uf.common.dataplugin.vaa.VAARecord;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -39,6 +41,7 @@ import com.raytheon.uf.edex.plugin.vaa.decoder.VAAParser;
* ------------ ---------- ----------- --------------------------
* Nov 04, 2009 3267 jkorman Initial creation
* Nov 26, 2013 2582 njensen Cleanup
* Mar 10, 2014 2807 skorolev Added MalformedDataException for VAA decoding.
*
* </pre>
*
@ -63,7 +66,8 @@ public class VAADecoder {
* @param headers
* @return
*/
public PluginDataObject[] decode(byte[] data, Headers headers) {
public PluginDataObject[] decode(byte[] data, Headers headers)
throws MalformedDataException, IOException {
String traceId = null;
@ -77,26 +81,22 @@ public class VAADecoder {
if (data != null && data.length > 0) {
List<PluginDataObject> obsList = new ArrayList<PluginDataObject>();
try {
VAAParser parser = new VAAParser(data, traceId, headers);
for (VAARecord record : parser) {
if (record != null) {
// overwrite will only happen if a correction is issued
// within the same minute as the original
record.setOverwriteAllowed(true);
obsList.add(record);
}
}
} catch (Exception e) {
logger.error(traceId + "-Error in decode", e);
} finally {
if ((obsList != null) && (obsList.size() > 0)) {
decodedData = obsList.toArray(new PluginDataObject[obsList
.size()]);
} else {
decodedData = new PluginDataObject[0];
VAAParser parser = new VAAParser(data, traceId, headers);
for (VAARecord record : parser) {
if (record != null) {
// overwrite will only happen if a correction is issued
// within the same minute as the original
record.setOverwriteAllowed(true);
obsList.add(record);
}
}
if ((obsList != null) && (obsList.size() > 0)) {
decodedData = obsList.toArray(new PluginDataObject[obsList
.size()]);
} else {
decodedData = new PluginDataObject[0];
}
} else {
logger.info(traceId + "- No data in file");
decodedData = new PluginDataObject[0];

View file

@ -19,6 +19,7 @@
**/
package com.raytheon.uf.edex.plugin.vaa.decoder;
import java.io.IOException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -29,6 +30,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.raytheon.edex.esb.Headers;
import com.raytheon.uf.common.dataplugin.exception.MalformedDataException;
import com.raytheon.uf.common.dataplugin.vaa.VAARecord;
import com.raytheon.uf.common.dataplugin.vaa.VAASubPart;
import com.raytheon.uf.common.pointdata.spatial.SurfaceObsLocation;
@ -47,6 +49,7 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
* Nov 26, 2013 2582 njensen Cleanup
* Feb 11, 2014 2763 skorolev Made LFCR correction of input data.
* Mar 10, 2014 2807 skorolev Added MalformedDataException for VAA decoding.
*
* </pre>
*
@ -96,12 +99,14 @@ public class VAAParser implements Iterable<VAARecord> {
private final List<VAARecord> records = new ArrayList<VAARecord>();
/**
*
* @param message
* @param wmoHeader
* @param pdd
* @param traceId
* @param headers
* @throws MalformedDataException
* @throws IOException
*/
public VAAParser(byte[] message, String traceId, Headers headers) {
public VAAParser(byte[] message, String traceId, Headers headers)
throws MalformedDataException, IOException {
this.traceId = traceId;
byte[] msg = correctLFCR(message);
wmoHeader = new WMOHeader(msg, headers);
@ -150,10 +155,11 @@ public class VAAParser implements Iterable<VAARecord> {
*
* @param message
* Raw message data.
* @param traceId
* Trace id for this data.
* @param headers
* @throws MalformedDataException
*/
private void setData(byte[] message, Headers headers) {
private void setData(byte[] message, Headers headers)
throws MalformedDataException {
List<InternalReport> reports = InternalReport.identifyMessage(message,
headers);
@ -240,8 +246,11 @@ public class VAAParser implements Iterable<VAARecord> {
default: {
}
} // switch
}// for
if (vaa.getDataTime() == null) {
throw new MalformedDataException(
"VAA product does not have a date time group");
}
records.add(vaa);
}
@ -475,8 +484,11 @@ public class VAAParser implements Iterable<VAARecord> {
/**
*
* @param args
* @throws MalformedDataException
* @throws IOException
*/
public static final void main(String[] args) {
public static final void main(String[] args) throws MalformedDataException,
IOException {
String msg1 = "\u0001\r\r\n738\r\r\nFVXX20 KNES 041708 CAA"
+ "\r\r\nVA ADVISORY" + "\r\r\nDTG: 20091104/1708Z"