From ec60f10e620a9e12383cdc9ef2cbff2f762e4161 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Tue, 13 Feb 2024 14:11:17 +0400 Subject: [PATCH] [RM-84612] Corrected after review --- build.gradle | 2 -- .../com/exactpro/th2/hand/HandServer.java | 3 ++- .../th2/hand/services/HandBaseService.java | 20 ++----------------- .../th2/hand/services/HandRuntimeException.kt | 19 ++++++++++++++++++ 4 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 src/main/kotlin/com/exactpro/th2/hand/services/HandRuntimeException.kt diff --git a/build.gradle b/build.gradle index 7879e11..70edc56 100644 --- a/build.gradle +++ b/build.gradle @@ -211,8 +211,6 @@ jar { archivesBaseName = applicationName manifest { attributes('Specification-Title': 'TH2 Hand') - attributes('Main-Class': 'com.exactpro.th2.hand.Application') - attributes("Class-Path": configurations.compileClasspath.collect { "lib/" + it.getName() }.join(' ')) attributes( 'Created-By': "${System.getProperty('java.version')} (${System.getProperty('java.vendor')})", 'Specification-Title': '', diff --git a/src/main/java/com/exactpro/th2/hand/HandServer.java b/src/main/java/com/exactpro/th2/hand/HandServer.java index 22a8098..c539352 100644 --- a/src/main/java/com/exactpro/th2/hand/HandServer.java +++ b/src/main/java/com/exactpro/th2/hand/HandServer.java @@ -66,7 +66,7 @@ public void start() throws IOException { server.start(); LOGGER.info("Server started, listening on port {}", server.getPort()); } else { - throw new IllegalStateException(getClass().getSimpleName() + " was started once"); + throw new IllegalStateException(getClass().getSimpleName() + " is already started"); } } @@ -94,6 +94,7 @@ public void close() throws InterruptedException { Thread thread = watcher.get(); if (thread != null && !thread.isInterrupted()) { thread.interrupt(); + thread.join(30_000); } } } \ No newline at end of file diff --git a/src/main/java/com/exactpro/th2/hand/services/HandBaseService.java b/src/main/java/com/exactpro/th2/hand/services/HandBaseService.java index 993686d..444a81b 100644 --- a/src/main/java/com/exactpro/th2/hand/services/HandBaseService.java +++ b/src/main/java/com/exactpro/th2/hand/services/HandBaseService.java @@ -92,18 +92,13 @@ public void dispose() { } } - /** - * @throws RhConfigurationException - */ - @SuppressWarnings("JavadocDeclaration") @Override public RhSessionID register(RhTargetServer targetServer) { try { String sessionId = messageHandler.getRhConnectionManager().createSessionHandler(targetServer.getTarget()).getId(); return RhSessionID.newBuilder().setId(sessionId).setSessionAlias(messageHandler.getConfig().getSessionAlias()).build(); } catch (RhConfigurationException e) { - sneakyThrow(e); - return null; + throw new HandRuntimeException(e.getMessage(), e); } } @@ -123,17 +118,12 @@ public Empty unregister(RhSessionID input, Map properties) { return unregister(input); } - /** - * @throws IOException - */ - @SuppressWarnings("JavadocDeclaration") @Override public RhBatchResponse executeRhActionsBatch(RhActionsBatch request) { try { return messageHandler.handleActionsBatchRequest(request); } catch (IOException e) { - sneakyThrow(e); - return null; + throw new HandRuntimeException(e.getMessage(), e); } } @@ -141,10 +131,4 @@ public RhBatchResponse executeRhActionsBatch(RhActionsBatch request) { public RhBatchResponse executeRhActionsBatch(RhActionsBatch input, Map properties) { return executeRhActionsBatch(input); } - - // This hack is used to avoid wrapping cause error - private static void sneakyThrow(Throwable e) throws E { - //noinspection unchecked - throw (E) e; - } } \ No newline at end of file diff --git a/src/main/kotlin/com/exactpro/th2/hand/services/HandRuntimeException.kt b/src/main/kotlin/com/exactpro/th2/hand/services/HandRuntimeException.kt new file mode 100644 index 0000000..8d72729 --- /dev/null +++ b/src/main/kotlin/com/exactpro/th2/hand/services/HandRuntimeException.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2024 Exactpro (Exactpro Systems Limited) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.exactpro.th2.hand.services + +class HandRuntimeException(message: String, cause: Throwable) : RuntimeException(message, cause) \ No newline at end of file