You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2021/03/12 07:44:34 UTC
[cxf] branch master updated: cxf-testutils: throw exception on
server starup; fix pmd warnings
This is an automated email from the ASF dual-hosted git repository.
buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 0d47c86 cxf-testutils: throw exception on server starup; fix pmd warnings
0d47c86 is described below
commit 0d47c86fce89c3709cca97f44904b6b24a5c2021
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Fri Mar 12 10:43:33 2021 +0300
cxf-testutils: throw exception on server starup; fix pmd warnings
---
.../AnonymousComplexTypeImpl.java | 3 +-
.../cxf/greeter_control/AbstractGreeterImpl.java | 14 +++----
.../apache/cxf/greeter_control/ControlImpl.java | 3 +-
.../greeter_control/FaultThrowingInterceptor.java | 2 +-
.../testutil/common/AbstractTestServerBase.java | 8 ++--
.../testutil/common/EmbeddedJMSBrokerLauncher.java | 48 +++++++---------------
.../apache/cxf/testutil/common/ServerLauncher.java | 21 +++-------
7 files changed, 32 insertions(+), 67 deletions(-)
diff --git a/testutils/src/main/java/org/apache/cxf/anonymous_complex_type/AnonymousComplexTypeImpl.java b/testutils/src/main/java/org/apache/cxf/anonymous_complex_type/AnonymousComplexTypeImpl.java
index be2fb70..edf2d9f 100644
--- a/testutils/src/main/java/org/apache/cxf/anonymous_complex_type/AnonymousComplexTypeImpl.java
+++ b/testutils/src/main/java/org/apache/cxf/anonymous_complex_type/AnonymousComplexTypeImpl.java
@@ -53,7 +53,6 @@ public class AnonymousComplexTypeImpl implements AnonymousComplexType {
String name = refSplitName.getSplitName().getName();
SplitNameResponse.Names names = new SplitNameResponse.Names();
int pos = name.indexOf(' ');
- SplitNameResponse response = null;
if (pos > 0) {
names.setFirst(name.substring(0, pos));
names.setSecond(name.substring(pos + 1));
@@ -63,7 +62,7 @@ public class AnonymousComplexTypeImpl implements AnonymousComplexType {
}
- response = new SplitNameResponse();
+ SplitNameResponse response = new SplitNameResponse();
response.setNames(names);
RefSplitNameResponse refResponse = new RefSplitNameResponse();
refResponse.setSplitNameResponse(response);
diff --git a/testutils/src/main/java/org/apache/cxf/greeter_control/AbstractGreeterImpl.java b/testutils/src/main/java/org/apache/cxf/greeter_control/AbstractGreeterImpl.java
index 8396846..c93deaa 100644
--- a/testutils/src/main/java/org/apache/cxf/greeter_control/AbstractGreeterImpl.java
+++ b/testutils/src/main/java/org/apache/cxf/greeter_control/AbstractGreeterImpl.java
@@ -20,6 +20,7 @@
package org.apache.cxf.greeter_control;
import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.xml.ws.AsyncHandler;
@@ -41,7 +42,7 @@ public class AbstractGreeterImpl implements Greeter {
private long delay;
private String lastOnewayArg;
private boolean throwAlways;
- private boolean useLastOnewayArg;
+ private AtomicBoolean useLastOnewayArg = new AtomicBoolean();
private int pingMeCount;
public long getDelay() {
@@ -58,10 +59,8 @@ public class AbstractGreeterImpl implements Greeter {
}
}
- public void useLastOnewayArg(Boolean use) {
- synchronized (this) {
- useLastOnewayArg = use;
- }
+ public void useLastOnewayArg(boolean use) {
+ useLastOnewayArg.set(use);
}
public void setThrowAlways(boolean t) {
@@ -77,10 +76,7 @@ public class AbstractGreeterImpl implements Greeter {
// ignore
}
}
- String result = null;
- synchronized (this) {
- result = useLastOnewayArg ? lastOnewayArg : arg0.toUpperCase();
- }
+ String result = useLastOnewayArg.get() ? lastOnewayArg : arg0.toUpperCase();
LOG.fine("returning: " + result);
return result;
}
diff --git a/testutils/src/main/java/org/apache/cxf/greeter_control/ControlImpl.java b/testutils/src/main/java/org/apache/cxf/greeter_control/ControlImpl.java
index 95ec3b4..f35c8aa 100644
--- a/testutils/src/main/java/org/apache/cxf/greeter_control/ControlImpl.java
+++ b/testutils/src/main/java/org/apache/cxf/greeter_control/ControlImpl.java
@@ -114,7 +114,6 @@ public class ControlImpl implements Control {
public void setFaultLocation(FaultLocation fl) {
List<Interceptor<? extends Message>> interceptors = greeterBus.getInInterceptors();
- FaultThrowingInterceptor fi = null;
for (Interceptor<? extends Message> i : interceptors) {
if (i instanceof FaultThrowingInterceptor) {
interceptors.remove(i);
@@ -127,7 +126,7 @@ public class ControlImpl implements Control {
return;
}
- fi = new FaultThrowingInterceptor(fl.getPhase());
+ FaultThrowingInterceptor fi = new FaultThrowingInterceptor(fl.getPhase());
if (null != fl.getBefore() && !"".equals(fl.getBefore())) {
fi.addBefore(fl.getBefore());
}
diff --git a/testutils/src/main/java/org/apache/cxf/greeter_control/FaultThrowingInterceptor.java b/testutils/src/main/java/org/apache/cxf/greeter_control/FaultThrowingInterceptor.java
index 26278e9..2b9ae5b 100644
--- a/testutils/src/main/java/org/apache/cxf/greeter_control/FaultThrowingInterceptor.java
+++ b/testutils/src/main/java/org/apache/cxf/greeter_control/FaultThrowingInterceptor.java
@@ -51,7 +51,7 @@ public class FaultThrowingInterceptor extends AbstractPhaseInterceptor<Message>
if (MessageUtils.isRequestor(message)) {
return;
}
- String msg = null;
+ final String msg;
synchronized (MESSAGE_FORMAT) {
msg = MESSAGE_FORMAT.format(new Object[] {getPhase()});
}
diff --git a/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractTestServerBase.java b/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractTestServerBase.java
index c3d4289..7b53c76 100644
--- a/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractTestServerBase.java
+++ b/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractTestServerBase.java
@@ -31,7 +31,7 @@ public abstract class AbstractTestServerBase {
* servants and publish endpoints etc.
*
*/
- protected abstract void run();
+ protected abstract void run() throws Exception;
protected Logger getLog() {
return LogUtils.getLogger(this.getClass());
@@ -59,7 +59,7 @@ public abstract class AbstractTestServerBase {
return ret;
}
- public void start() {
+ public void start() throws Exception {
try {
System.out.println("running server");
run();
@@ -73,8 +73,8 @@ public abstract class AbstractTestServerBase {
System.out.println("stopping bus");
tearDown();
} catch (Throwable ex) {
- ex.printStackTrace();
startFailed();
+ throw ex;
} finally {
if (verify(getLog())) {
System.out.println("server passed");
@@ -82,7 +82,6 @@ public abstract class AbstractTestServerBase {
System.out.println(ServerLauncher.SERVER_FAILED);
}
System.out.println("server stopped");
- System.exit(0);
}
}
@@ -102,7 +101,6 @@ public abstract class AbstractTestServerBase {
protected void startFailed() {
System.out.println(ServerLauncher.SERVER_FAILED);
- System.exit(-1);
}
/**
diff --git a/testutils/src/main/java/org/apache/cxf/testutil/common/EmbeddedJMSBrokerLauncher.java b/testutils/src/main/java/org/apache/cxf/testutil/common/EmbeddedJMSBrokerLauncher.java
index c1333c9..eb6b28f 100644
--- a/testutils/src/main/java/org/apache/cxf/testutil/common/EmbeddedJMSBrokerLauncher.java
+++ b/testutils/src/main/java/org/apache/cxf/testutil/common/EmbeddedJMSBrokerLauncher.java
@@ -39,17 +39,14 @@ import org.apache.cxf.wsdl.WSDLManager;
public class EmbeddedJMSBrokerLauncher extends AbstractBusTestServerBase {
public static final String PORT = allocatePort(EmbeddedJMSBrokerLauncher.class);
- String brokerUrl1;
BrokerService broker;
String brokerName;
+ private final String brokerUrl1;
public EmbeddedJMSBrokerLauncher() {
- this(null);
+ this("tcp://localhost:" + PORT);
}
public EmbeddedJMSBrokerLauncher(String url) {
- if (url == null) {
- url = "tcp://localhost:" + PORT;
- }
brokerUrl1 = url;
}
public void setBrokerName(String s) {
@@ -59,17 +56,9 @@ public class EmbeddedJMSBrokerLauncher extends AbstractBusTestServerBase {
public String getBrokerURL() {
return brokerUrl1;
}
+
public String getEncodedBrokerURL() {
- StringBuilder b = new StringBuilder(brokerUrl1.length());
- for (int x = 0; x < brokerUrl1.length(); x++) {
- char c = brokerUrl1.charAt(x);
- if (c == '?') {
- b.append("%3F");
- } else {
- b.append(c);
- }
- }
- return b.toString();
+ return brokerUrl1.replace("?", "%3F");
}
public void updateWsdl(Bus b, URL wsdlLocation) {
@@ -167,25 +156,21 @@ public class EmbeddedJMSBrokerLauncher extends AbstractBusTestServerBase {
}
//START SNIPPET: broker
- public final void run() {
- try {
- broker = new BrokerService();
- broker.setPersistent(false);
- broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
- broker.setTmpDataDirectory(new File("./target"));
- broker.setUseJmx(false);
- if (brokerName != null) {
- broker.setBrokerName(brokerName);
- }
- broker.addConnector(brokerUrl1);
- broker.start();
- } catch (Exception e) {
- e.printStackTrace();
+ public final void run() throws Exception {
+ broker = new BrokerService();
+ broker.setPersistent(false);
+ broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
+ broker.setTmpDataDirectory(new File("./target"));
+ broker.setUseJmx(false);
+ if (brokerName != null) {
+ broker.setBrokerName(brokerName);
}
+ broker.addConnector(brokerUrl1);
+ broker.start();
}
//END SNIPPET: broker
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
try {
String url = null;
if (args.length > 0) {
@@ -193,9 +178,6 @@ public class EmbeddedJMSBrokerLauncher extends AbstractBusTestServerBase {
}
EmbeddedJMSBrokerLauncher s = new EmbeddedJMSBrokerLauncher(url);
s.start();
- } catch (Exception ex) {
- ex.printStackTrace();
- System.exit(-1);
} finally {
System.out.println("done!");
}
diff --git a/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java b/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java
index 8247ea2..56d5a56 100644
--- a/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java
+++ b/testutils/src/main/java/org/apache/cxf/testutil/common/ServerLauncher.java
@@ -25,7 +25,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
-import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -51,13 +50,15 @@ public class ServerLauncher {
private static final boolean DEBUG = false;
+ private static final String JAVA_EXE =
+ System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
+
boolean serverPassed;
final String className;
private boolean inProcess = DEFAULT_IN_PROCESS;
private AbstractTestServerBase inProcessServer;
- private final String javaExe;
private Process process;
private boolean serverIsReady;
private boolean serverIsStopped;
@@ -73,13 +74,11 @@ public class ServerLauncher {
public ServerLauncher(AbstractTestServerBase b) {
inProcess = true;
inProcessServer = b;
- javaExe = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
className = null;
}
public ServerLauncher(String theClassName, boolean inprocess) {
inProcess = inprocess;
className = theClassName;
- javaExe = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
}
public ServerLauncher(String theClassName, Map<String, String> p, String[] args) {
this(theClassName, p, args, false);
@@ -89,7 +88,6 @@ public class ServerLauncher {
properties = p;
serverArgs = args;
inProcess = inprocess;
- javaExe = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
}
private boolean waitForServerToStop() {
@@ -208,14 +206,7 @@ public class ServerLauncher {
}
} else {
- List<String> cmd;
- try {
- cmd = getCommand();
- } catch (URISyntaxException e1) {
- IOException ex = new IOException();
- ex.initCause(e1);
- throw ex;
- }
+ List<String> cmd = getCommand();
LOG.fine("CMD: " + cmd);
if (DEBUG) {
@@ -343,10 +334,10 @@ public class ServerLauncher {
}
}
- private List<String> getCommand() throws URISyntaxException {
+ private List<String> getCommand() {
List<String> cmd = new ArrayList<>();
- cmd.add(javaExe);
+ cmd.add(JAVA_EXE);
if (null != properties) {
for (Map.Entry<String, String> entry : properties.entrySet()) {