Avoid throws Exception where possible - Phase III

This commit is contained in:
Gary Russell
2019-03-07 16:53:48 -05:00
committed by Artem Bilan
parent b138ab80f8
commit 78199dca9b
42 changed files with 297 additions and 219 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,7 +83,7 @@ public class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa
}
@Override
public Message<?> fromSyslog(Message<?> message) throws Exception {
public Message<?> fromSyslog(Message<?> message) {
Map<String, ?> map = this.transformer.doTransform(message);
Map<String, Object> out = new HashMap<String, Object>();
for (Entry<String, ?> entry : map.entrySet()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,5 +29,6 @@ import org.springframework.messaging.Message;
@FunctionalInterface
public interface MessageConverter {
Message<?> fromSyslog(Message<?> syslog) throws Exception;
Message<?> fromSyslog(Message<?> syslog);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.integration.syslog;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
@@ -61,13 +62,18 @@ public class RFC5424MessageConverter extends DefaultMessageConverter {
@SuppressWarnings("unchecked")
@Override
public Message<?> fromSyslog(Message<?> message) throws Exception {
public Message<?> fromSyslog(Message<?> message) {
boolean isMap = message.getPayload() instanceof Map;
Map<String, ?> map;
Object originalContent;
if (!isMap) {
Assert.isInstanceOf(byte[].class, message.getPayload(), "Only byte[] and Map payloads are supported");
map = this.parser.parse(new String(((byte[]) message.getPayload()), this.charset), 0, false);
try {
map = this.parser.parse(new String(((byte[]) message.getPayload()), this.charset), 0, false);
}
catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
originalContent = message.getPayload();
}
else {

View File

@@ -215,7 +215,7 @@ public class SyslogReceivingChannelAdapterParserTests {
public static class PassThruConverter implements MessageConverter {
@Override
public Message<?> fromSyslog(Message<?> syslog) throws Exception {
public Message<?> fromSyslog(Message<?> syslog) {
return syslog;
}