Skip to content

Commit 9b6a2cc

Browse files
authored
Merge pull request #412 from okue/refactor-spring-boot
NON-ISSUE Refactoring line-bot-spring-boot
2 parents 7fef4ce + 4b30f32 commit 9b6a2cc

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/interceptor/LineBotServerInterceptor.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,24 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
5050
return true;
5151
}
5252

53-
HandlerMethod hm = (HandlerMethod) handler;
54-
MethodParameter[] methodParameters = hm.getMethodParameters();
53+
final HandlerMethod hm = (HandlerMethod) handler;
54+
final MethodParameter[] methodParameters = hm.getMethodParameters();
55+
5556
for (MethodParameter methodParameter : methodParameters) {
56-
if (methodParameter.getParameterAnnotation(LineBotMessages.class) != null) {
57-
try {
58-
CallbackRequest callbackRequest = lineBotCallbackRequestParser.handle(request);
59-
LineBotServerArgumentProcessor.setValue(request, callbackRequest);
60-
return true;
61-
} catch (LineBotCallbackException e) {
62-
log.info("LINE Bot callback exception: {}", e.getMessage());
63-
response.sendError(HttpStatus.BAD_REQUEST.value());
64-
try (PrintWriter writer = response.getWriter()) {
65-
writer.println(e.getMessage());
66-
}
67-
return false;
57+
if (methodParameter.getParameterAnnotation(LineBotMessages.class) == null) {
58+
continue;
59+
}
60+
try {
61+
final CallbackRequest callbackRequest = lineBotCallbackRequestParser.handle(request);
62+
LineBotServerArgumentProcessor.setValue(request, callbackRequest);
63+
return true;
64+
} catch (LineBotCallbackException e) {
65+
log.info("LINE Bot callback exception: {}", e.getMessage());
66+
response.sendError(HttpStatus.BAD_REQUEST.value());
67+
try (PrintWriter writer = response.getWriter()) {
68+
writer.println(e.getMessage());
6869
}
70+
return false;
6971
}
7072
}
7173
return true;
@@ -78,7 +80,6 @@ public void postHandle(HttpServletRequest request, HttpServletResponse response,
7880

7981
@Override
8082
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
81-
Exception ex)
82-
throws Exception {
83+
Exception ex) throws Exception {
8384
}
8485
}

line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/support/LineMessageHandlerSupport.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ private HandlerMethod getMethodHandlerMethodFunction(Object consumer, Method met
133133
final Type type = method.getGenericParameterTypes()[0];
134134

135135
final Predicate<Event> predicate = new EventPredicate(type);
136-
return new HandlerMethod(predicate, consumer, method,
137-
getPriority(mapping, type));
136+
return new HandlerMethod(predicate, consumer, method, getPriority(mapping, type));
138137
}
139138

140139
private int getPriority(final EventMapping mapping, final Type type) {
@@ -234,7 +233,6 @@ public boolean test(final Event event) {
234233
}
235234

236235
private static boolean filterByType(final Class<?> clazz, final Object content) {
237-
238236
return clazz.isAssignableFrom(content.getClass());
239237
}
240238

line-bot-spring-boot/src/main/java/com/linecorp/bot/spring/boot/support/ReplyByReturnValueConsumer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private void acceptResult(final Object returnValue) {
9393
if (returnValue instanceof Message) {
9494
reply(singletonList((Message) returnValue));
9595
} else if (returnValue instanceof List) {
96-
List<?> returnValueAsList = (List<?>) returnValue;
96+
final List<?> returnValueAsList = (List<?>) returnValue;
9797

9898
if (returnValueAsList.isEmpty()) {
9999
return;
@@ -118,6 +118,7 @@ private void logging(final BotApiResponse botApiResponse, final Throwable throwa
118118
}
119119
}
120120

121+
@SuppressWarnings("unchecked")
121122
@VisibleForTesting
122123
static List<Message> checkListContents(final List<?> list) {
123124
for (int i = 0; i < list.size(); ++i) {
@@ -128,8 +129,6 @@ static List<Message> checkListContents(final List<?> list) {
128129
item.getClass());
129130
}
130131

131-
@SuppressWarnings("unchecked")
132-
final List<Message> messageList = (List<Message>) list;
133-
return messageList;
132+
return (List<Message>) list;
134133
}
135134
}

0 commit comments

Comments
 (0)