From 61fdc04e9c26114fbbe968d3de0d9aace59b702c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=CC=88rg=20Prante?=
Date: Wed, 17 Jul 2019 22:53:14 +0200
Subject: [PATCH] make XML-RPC tests compile and run under Java 8
---
build.gradle | 8 +-
gradle.properties | 3 +-
.../netty/http/server/ServerResponse.java | 4 -
netty-http-xmlrpc-client/build.gradle | 3 +-
.../xmlrpc/client/XmlRpcSunHttpTransport.java | 6 +-
.../xmlrpc/client/XmlRpcTransportImpl.java | 22 +-
.../xmlrpc/client/XmlRpcClient.properties | 1 +
.../client/test/AuthenticationTest.java | 49 +-
.../http/xmlrpc/client/test/BaseTest.java | 324 ++++-----
.../http/xmlrpc/client/test/ClientIpTest.java | 65 +-
.../xmlrpc/client/test/ClientProvider.java | 4 +-
.../client/test/ClientProviderImpl.java | 12 +-
.../xmlrpc/client/test/CommonsProvider.java | 1 +
.../xmlrpc/client/test/CustomTypesTest.java | 53 +-
.../xmlrpc/client/test/DynamicProxyTest.java | 27 +-
.../http/xmlrpc/client/test/JiraTest.java | 133 ++--
.../client/test/LiteTransportProvider.java | 30 +-
.../test/LocalStreamTransportProvider.java | 36 +-
.../client/test/LocalTransportProvider.java | 37 +-
.../http/xmlrpc/client/test/MetadataTest.java | 61 +-
.../http/xmlrpc/client/test/ParserTest.java | 40 +-
.../xmlrpc/client/test/ScalabilityTest.java | 234 +++----
.../xmlrpc/client/test/SerializerTest.java | 205 +++---
.../client/test/ServletWebServerProvider.java | 32 +-
.../client/test/SunHttpTransportProvider.java | 1 +
.../xmlrpc/client/test/WebServerProvider.java | 80 ++-
.../xmlrpc/client/test/XmlRpcTestCase.java | 31 +-
.../src/test/resources/logging.properties | 5 +
.../client/test/AuthenticationTest.properties | 1 +
.../xmlrpc/client/test/BaseTest.properties | 1 +
.../client/test/DynamicProxyTest.properties | 1 +
.../xmlrpc/client/test/JiraTest.properties | 5 +
.../xmlrpc/servlet/XmlRpcServlet.properties | 1 +
.../http/xmlrpc/server/XmlRpcErrorLogger.java | 5 +-
.../xmlrpc/server/XmlRpcStreamServer.java | 49 +-
.../netty/http/xmlrpc/servlet/Connection.java | 100 +--
.../servlet/HttpServletRequestImpl.java | 34 +-
.../servlet/HttpServletResponseImpl.java | 12 +-
.../xmlrpc/servlet/ServletConnection.java | 17 +-
.../http/xmlrpc/servlet/ServletWebServer.java | 92 ++-
.../netty/http/xmlrpc/servlet/ThreadPool.java | 236 ++++---
.../netty/http/xmlrpc/servlet/WebServer.java | 654 +++++++++---------
settings.gradle | 8 +-
43 files changed, 1286 insertions(+), 1437 deletions(-)
create mode 100644 netty-http-xmlrpc-client/src/main/resources/org/xbib/netty/http/xmlrpc/client/XmlRpcClient.properties
create mode 100644 netty-http-xmlrpc-client/src/test/resources/logging.properties
create mode 100644 netty-http-xmlrpc-client/src/test/resources/org/xbib/netty/http/xmlrpc/client/test/AuthenticationTest.properties
create mode 100644 netty-http-xmlrpc-client/src/test/resources/org/xbib/netty/http/xmlrpc/client/test/BaseTest.properties
create mode 100644 netty-http-xmlrpc-client/src/test/resources/org/xbib/netty/http/xmlrpc/client/test/DynamicProxyTest.properties
create mode 100644 netty-http-xmlrpc-client/src/test/resources/org/xbib/netty/http/xmlrpc/client/test/JiraTest.properties
create mode 100644 netty-http-xmlrpc-client/src/test/resources/org/xbib/netty/http/xmlrpc/servlet/XmlRpcServlet.properties
diff --git a/build.gradle b/build.gradle
index 183afbe..f890d8d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,9 +19,11 @@ subprojects {
}
dependencies {
- testImplementation "org.junit.jupiter:junit-jupiter-api:${project.property('junit.version')}"
- testImplementation "org.junit.jupiter:junit-jupiter-params:${project.property('junit.version')}"
- testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${project.property('junit.version')}"
+ testCompile "org.junit.jupiter:junit-jupiter-api:${project.property('junit.version')}"
+ testCompile "org.junit.jupiter:junit-jupiter-params:${project.property('junit.version')}"
+ testCompile "org.junit.jupiter:junit-jupiter-engine:${project.property('junit.version')}"
+ testCompile "org.junit.vintage:junit-vintage-engine:${project.property('junit.version')}"
+ testCompile "junit:junit:${project.property('junit4.version')}"
asciidoclet "org.asciidoctor:asciidoclet:${project.property('asciidoclet.version')}"
}
diff --git a/gradle.properties b/gradle.properties
index 8398494..cc9dda8 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,6 @@
group = org.xbib
name = netty-http
-version = 4.1.36.6
+version = 4.1.36.7
# main packages
netty.version = 4.1.36.Final
@@ -23,6 +23,7 @@ commons-httpclient.version = 3.1
# test packages
junit.version = 5.4.2
+junit4.version = 4.12
conscrypt.version = 2.0.0
jackson.version = 2.8.11.1
asciidoclet.version = 1.5.4
diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerResponse.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerResponse.java
index 33cca57..8dea0d8 100644
--- a/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerResponse.java
+++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/ServerResponse.java
@@ -43,10 +43,6 @@ public interface ServerResponse {
void write(ChunkedInput chunkedInput);
- /**
- * Convenience methods.
- */
-
static void write(ServerResponse serverResponse, int status) {
write(serverResponse, HttpResponseStatus.valueOf(status));
}
diff --git a/netty-http-xmlrpc-client/build.gradle b/netty-http-xmlrpc-client/build.gradle
index b2214fb..2fbcb31 100644
--- a/netty-http-xmlrpc-client/build.gradle
+++ b/netty-http-xmlrpc-client/build.gradle
@@ -2,6 +2,5 @@ dependencies {
compile project(":netty-http-xmlrpc-common")
compile "commons-httpclient:commons-httpclient:${project.property(('commons-httpclient.version'))}"
testCompile project(":netty-http-xmlrpc-servlet")
- testCompileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
-
+ testCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
\ No newline at end of file
diff --git a/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcSunHttpTransport.java b/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcSunHttpTransport.java
index 3f36c44..3dbbb99 100644
--- a/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcSunHttpTransport.java
+++ b/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcSunHttpTransport.java
@@ -17,7 +17,9 @@ import org.xml.sax.SAXException;
* {@link HttpURLConnection} class.
*/
public class XmlRpcSunHttpTransport extends XmlRpcHttpTransport {
+
private static final String userAgent = USER_AGENT + " (Sun HTTP Transport)";
+
private URLConnection conn;
/** Creates a new instance.
@@ -55,7 +57,7 @@ public class XmlRpcSunHttpTransport extends XmlRpcHttpTransport {
getURLConnection().setRequestProperty(pHeader, pValue);
}
- protected void close() throws XmlRpcClientException {
+ protected void close() {
final URLConnection c = getURLConnection();
if (c instanceof HttpURLConnection) {
((HttpURLConnection) c).disconnect();
@@ -69,7 +71,7 @@ public class XmlRpcSunHttpTransport extends XmlRpcHttpTransport {
protected InputStream getInputStream() throws XmlRpcException {
try {
URLConnection connection = getURLConnection();
- if ( connection instanceof HttpURLConnection ) {
+ if (connection instanceof HttpURLConnection ) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode < 200 || responseCode > 299) {
diff --git a/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcTransportImpl.java b/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcTransportImpl.java
index 9b012e2..4123d96 100644
--- a/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcTransportImpl.java
+++ b/netty-http-xmlrpc-client/src/main/java/org/xbib/netty/http/xmlrpc/client/XmlRpcTransportImpl.java
@@ -1,25 +1,7 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.xbib.netty.http.xmlrpc.client;
-
-/** Abstract base implementation of an {@link org.apache.xmlrpc.client.XmlRpcTransport}.
+/**
+ * Abstract base implementation of an {@link XmlRpcTransport}.
*/
public abstract class XmlRpcTransportImpl implements XmlRpcTransport {
private final XmlRpcClient client;
diff --git a/netty-http-xmlrpc-client/src/main/resources/org/xbib/netty/http/xmlrpc/client/XmlRpcClient.properties b/netty-http-xmlrpc-client/src/main/resources/org/xbib/netty/http/xmlrpc/client/XmlRpcClient.properties
new file mode 100644
index 0000000..5d23b60
--- /dev/null
+++ b/netty-http-xmlrpc-client/src/main/resources/org/xbib/netty/http/xmlrpc/client/XmlRpcClient.properties
@@ -0,0 +1 @@
+user.agent=Apache XML RPC
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/AuthenticationTest.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/AuthenticationTest.java
index dfd3c4e..c169553 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/AuthenticationTest.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/AuthenticationTest.java
@@ -5,7 +5,6 @@ import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfigImpl;
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
import org.xbib.netty.http.xmlrpc.common.XmlRpcHttpRequestConfig;
-import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequestConfig;
import org.xbib.netty.http.xmlrpc.server.AbstractReflectiveHandlerMapping;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
@@ -18,7 +17,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* Test case for supported authentication variants.
*/
public class AuthenticationTest extends XmlRpcTestCase {
+
private static final String PASSWORD = "98765432109876543210987654321098765432109876543210";
+
private static final String USER_NAME = "01234567890123456789012345678901234567890123456789"
+ "\u00C4\u00D6\u00DC\u00F6\u00FC\u00E4\u00DF";
@@ -26,9 +27,11 @@ public class AuthenticationTest extends XmlRpcTestCase {
* server.
*/
public interface Adder {
- /** Returns the sum of the given integers.
+
+ /**
+ * Returns the sum of the given integers.
*/
- public int add(int pNum1, int pNum2);
+ int add(int pNum1, int pNum2);
}
/** Implementation of {@link DynamicProxyTest.Adder}, which is used by
@@ -42,42 +45,33 @@ public class AuthenticationTest extends XmlRpcTestCase {
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
XmlRpcHandlerMapping mapping = getHandlerMapping("AuthenticationTest.properties");
- ((AbstractReflectiveHandlerMapping) mapping).setAuthenticationHandler(new AbstractReflectiveHandlerMapping.AuthenticationHandler(){
- public boolean isAuthorized(XmlRpcRequest pRequest)
- throws XmlRpcException {
- XmlRpcRequestConfig config = pRequest.getConfig();
- if (config instanceof XmlRpcHttpRequestConfig) {
- XmlRpcHttpRequestConfig httpRequestConfig = (XmlRpcHttpRequestConfig) config;
- return USER_NAME.equals(httpRequestConfig.getBasicUserName())
- && PASSWORD.equals(httpRequestConfig.getBasicPassword());
- }
- return true;
+ ((AbstractReflectiveHandlerMapping) mapping).setAuthenticationHandler(pRequest -> {
+ XmlRpcRequestConfig config = pRequest.getConfig();
+ if (config instanceof XmlRpcHttpRequestConfig) {
+ XmlRpcHttpRequestConfig httpRequestConfig = (XmlRpcHttpRequestConfig) config;
+ return USER_NAME.equals(httpRequestConfig.getBasicUserName())
+ && PASSWORD.equals(httpRequestConfig.getBasicPassword());
}
+ return true;
});
return mapping;
}
- protected XmlRpcClientConfigImpl getConfig(ClientProvider pProvider)
- throws Exception {
+ protected XmlRpcClientConfigImpl getConfig(ClientProvider pProvider) throws Exception {
XmlRpcClientConfigImpl config = super.getConfig(pProvider);
config.setBasicUserName(USER_NAME);
config.setBasicPassword(PASSWORD);
return config;
}
- private ClientFactory getClientFactory(ClientProvider pProvider) throws Exception {
- XmlRpcClient client = pProvider.getClient();
- client.setConfig(getConfig(pProvider));
- return new ClientFactory(client);
- }
-
- /** Tests calling the {@link Adder#add(int,int)} method
+ /** T
+ * ests calling the {@link Adder#add(int,int)} method
* by using an object, which has been created by the
* {@link ClientFactory}.
*/
public void testAdderCall() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testAdderCall(providers[i]);
+ for (ClientProvider provider : providers) {
+ testAdderCall(provider);
}
}
@@ -86,4 +80,11 @@ public class AuthenticationTest extends XmlRpcTestCase {
Adder adder = (Adder) factory.newInstance(Adder.class);
assertEquals(6, adder.add(2, 4));
}
+
+ private ClientFactory getClientFactory(ClientProvider pProvider) throws Exception {
+ XmlRpcClient client = pProvider.getClient();
+ client.setConfig(getConfig(pProvider));
+ return new ClientFactory(client);
+ }
+
}
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/BaseTest.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/BaseTest.java
index 61cce2d..a8a8674 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/BaseTest.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/BaseTest.java
@@ -7,7 +7,6 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.TimeZone;
@@ -24,10 +23,6 @@ import org.xbib.netty.http.xmlrpc.common.XmlRpcInvocationException;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xml.sax.InputSource;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-
/**
* An abstract test case, to be implemented for the various
* transport classes.
@@ -129,8 +124,8 @@ public class BaseTest extends XmlRpcTestCase {
*/
public int byteArrayParam(byte[] pArg) {
int sum = 0;
- for (int i = 0; i < pArg.length; i++) {
- sum += pArg[i];
+ for (byte b : pArg) {
+ sum += b;
}
return sum;
}
@@ -151,11 +146,11 @@ public class BaseTest extends XmlRpcTestCase {
*/
public int objectArrayParam(Object[] pArg) {
int sum = 0;
- for (int i = 0; i < pArg.length; i++) {
- if (pArg[i] instanceof Number) {
- sum += ((Number) pArg[i]).intValue();
+ for (Object o : pArg) {
+ if (o instanceof Number) {
+ sum += ((Number) o).intValue();
} else {
- sum += Integer.parseInt((String) pArg[i]);
+ sum += Integer.parseInt((String) o);
}
}
return sum;
@@ -168,7 +163,7 @@ public class BaseTest extends XmlRpcTestCase {
public Object[] objectArrayResult(int pArg) {
Object[] result = new Object[pArg];
for (int i = 0; i < result.length; i++) {
- result[i] = new Integer(i);
+ result[i] = i;
}
return result;
}
@@ -177,13 +172,12 @@ public class BaseTest extends XmlRpcTestCase {
* @param pArg The map being iterated.
* @return Sum of keys, multiplied by their values.
*/
- public int mapParam(Map pArg) {
+ public int mapParam(Map pArg) {
int sum = 0;
- for (Iterator iter = pArg.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- String key = (String) entry.getKey();
- Integer value = (Integer) entry.getValue();
- sum += Integer.parseInt(key) * value.intValue();
+ for (Map.Entry entry : pArg.entrySet()) {
+ String key = entry.getKey();
+ Integer value = entry.getValue();
+ sum += Integer.parseInt(key) * value;
}
return sum;
}
@@ -193,10 +187,10 @@ public class BaseTest extends XmlRpcTestCase {
* @return Map with the keys "0".."pArg" and
* 0..pArg as values.
*/
- public Map mapResult(int pArg) {
- Map result = new HashMap();
+ public Map mapResult(int pArg) {
+ Map result = new HashMap<>();
for (int i = 0; i < pArg; i++) {
- result.put(Integer.toString(i), new Integer(i));
+ result.put(Integer.toString(i), i);
}
return result;
}
@@ -217,7 +211,7 @@ public class BaseTest extends XmlRpcTestCase {
}
private int count(Node pNode) {
if (INT_TAG.equals(pNode.getLocalName()) && INT_URI.equals(pNode.getNamespaceURI())) {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for (Node child = pNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE || child.getNodeType() == Node.CDATA_SECTION_NODE) {
sb.append(child.getNodeValue());
@@ -237,7 +231,7 @@ public class BaseTest extends XmlRpcTestCase {
/** Example of a Serializable instance.
*/
- public static class CalendarWrapper implements Serializable {
+ static class CalendarWrapper implements Serializable {
private static final long serialVersionUID = 8153663910532549627L;
final Calendar cal;
CalendarWrapper(Calendar pCalendar) {
@@ -255,7 +249,7 @@ public class BaseTest extends XmlRpcTestCase {
/** Returns midnight of the following day.
*/
- public Calendar calendarParam(Calendar pCal) {
+ Calendar calendarParam(Calendar pCal) {
Calendar cal = (Calendar) pCal.clone();
cal.add(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
@@ -282,96 +276,88 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testByteParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testByteParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testByteParam(provider);
}
}
private void testByteParam(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.byteParam";
- final Object[] params = new Object[]{new Byte((byte) 3)};
+ final Object[] params = new Object[]{(byte) 3};
XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Integer(6), result);
- boolean ok = false;
+ assertEquals(6, result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, returning a byte.
* @throws Exception The test failed.
*/
public void testByteResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testByteResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testByteResult(provider);
}
}
private void testByteResult(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.byteResult";
- final Object[] params = new Object[]{new Byte((byte) 3)};
+ final Object[] params = new Object[]{(byte) 3};
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Byte((byte) 6), result);
- boolean ok = false;
+ assertEquals((byte) 6, result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, passing a short value.
* @throws Exception The test failed.
*/
public void testShortParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testShortParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testShortParam(provider);
}
}
private void testShortParam(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.shortParam";
- final Object[] params = new Object[]{new Short((short) 4)};
+ final Object[] params = new Object[] { (short) 4 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Integer(8), result);
- boolean ok = false;
+ assertEquals(8, result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, returning a short value.
* @throws Exception The test failed.
*/
public void testShortResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testShortResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testShortResult(provider);
}
}
private void testShortResult(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.shortResult";
- final Object[] params = new Object[]{new Short((short) 4)};
+ final Object[] params = new Object[] { (short) 4 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Short((short) 8), result);
- boolean ok = false;
+ assertEquals((short) 8, result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, passing an
@@ -379,67 +365,63 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testIntParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testIntParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testIntParam(provider);
}
}
private void testIntParam(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.intParam";
- final Object[] params = new Object[]{new Integer(5)};
+ final Object[] params = new Object[] { 5 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getConfig(pProvider), methodName, params);
- assertEquals(new Integer(10), result);
+ assertEquals(10, result);
result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Integer(10), result);
+ assertEquals(10, result);
}
/** Test, whether we can invoke a method, passing a long value.
* @throws Exception The test failed.
*/
public void testLongParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testLongParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testLongParam(provider);
}
}
private void testLongParam(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.longParam";
- final Object[] params = new Object[]{new Long(6L)};
+ final Object[] params = new Object[] { 6L };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Integer(12), result);
- boolean ok = false;
+ assertEquals(12, result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, returning a long value.
* @throws Exception The test failed.
*/
public void testLongResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testLongResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testLongResult(provider);
}
}
private void testLongResult(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.longResult";
- final Object[] params = new Object[]{new Long(6L)};
+ final Object[] params = new Object[] { 6L };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Long(12L), result);
- boolean ok = false;
+ assertEquals(12L, result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, passing a
@@ -447,8 +429,8 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testStringParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testStringParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testStringParam(provider);
}
}
@@ -467,8 +449,8 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testNullableStringParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testNullableStringParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testNullableStringParam(provider);
}
}
@@ -483,13 +465,11 @@ public class BaseTest extends XmlRpcTestCase {
final Object[] nullParams = new Object[]{null};
result = client.execute(getExConfig(pProvider), methodName, nullParams);
assertEquals("", result);
- boolean ok = false;
try {
client.execute(getConfig(pProvider), methodName, nullParams);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, returning a
@@ -497,8 +477,8 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testNullableStringResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testNullableStringResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testNullableStringResult(provider);
}
}
@@ -512,62 +492,56 @@ public class BaseTest extends XmlRpcTestCase {
assertEquals("abcabc", result);
final Object[] nullParams = new Object[]{null};
result = client.execute(getExConfig(pProvider), methodName, nullParams);
- assertEquals(null, result);
- boolean ok = false;
+ assertNull(result);
try {
client.execute(getConfig(pProvider), methodName, nullParams);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, passing a float value.
* @throws Exception The test failed.
*/
public void testFloatParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testFloatParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testFloatParam(provider);
}
}
private void testFloatParam(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.floatParam";
- final Object[] params = new Object[]{new Float(0.4)};
+ final Object[] params = new Object[] { (float) 0.4 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(8, Math.round(((Double) result).doubleValue()*10));
- boolean ok = false;
+ assertEquals(8, Math.round((Double) result *10));
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, returning a float value.
* @throws Exception The test failed.
*/
public void testFloatResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testFloatResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testFloatResult(provider);
}
}
private void testFloatResult(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.floatResult";
- final Object[] params = new Object[]{new Float(0.4)};
+ final Object[] params = new Object[] { (float) 0.4 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Float(0.8), result);
- boolean ok = false;
+ assertEquals((float) 0.8, result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, passing a
@@ -575,19 +549,19 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testDoubleParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testDoubleParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testDoubleParam(provider);
}
}
private void testDoubleParam(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.doubleParam";
- final Object[] params = new Object[]{new Double(0.6)};
+ final Object[] params = new Object[] { 0.6 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getConfig(pProvider), methodName, params);
- assertEquals(new Double(1.2), result);
+ assertEquals(1.2, result);
result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Double(1.2), result);
+ assertEquals(1.2, result);
}
/** Test, whether we can invoke a method, returning a
@@ -595,19 +569,19 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testDoubleResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testDoubleResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testDoubleResult(provider);
}
}
private void testDoubleResult(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.doubleResult";
- final Object[] params = new Object[]{new Double(0.6)};
+ final Object[] params = new Object[]{ 0.6 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getConfig(pProvider), methodName, params);
- assertEquals(new Double(1.2), result);
+ assertEquals(1.2, result);
result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Double(1.2), result);
+ assertEquals(1.2, result);
}
/** Test, whether we can invoke a method, passing a
@@ -615,20 +589,20 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testByteArrayParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testByteArrayParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testByteArrayParam(provider);
}
}
private void testByteArrayParam(ClientProvider pProvider) throws Exception {
final byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
final String methodName = "Remote.byteArrayParam";
- final Object[] params = new Object[]{bytes};
+ final Object[] params = new Object[] { bytes };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getConfig(pProvider), methodName, params);
- assertEquals(new Integer(0+1+2+3+4+5+6+7+8+9), result);
+ assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, result);
result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Integer(0+1+2+3+4+5+6+7+8+9), result);
+ assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, result);
}
/** Test, whether we can invoke a method, returning a
@@ -636,15 +610,15 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testByteArrayResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testByteArrayResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testByteArrayResult(provider);
}
}
private void testByteArrayResult(ClientProvider pProvider) throws Exception {
final byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
final String methodName = "Remote.byteArrayResult";
- final Object[] params = new Object[]{new Integer(8)};
+ final Object[] params = new Object[] { 8 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getConfig(pProvider), methodName, params);
assertTrue(Arrays.equals(bytes, (byte[]) result));
@@ -657,14 +631,13 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testObjectArrayParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testObjectArrayParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testObjectArrayParam(provider);
}
}
private void testObjectArrayParam(ClientProvider pProvider) throws Exception {
- final Object[] objects = new Object[]{new Byte((byte) 1), new Short((short) 2),
- new Integer(3), new Long(4), "5"};
+ final Object[] objects = new Object[]{(byte) 1, (short) 2, 3, 4L, "5"};
final String methodName = "Remote.objectArrayParam";
final Object[] params = new Object[]{objects};
final XmlRpcClient client = pProvider.getClient();
@@ -676,7 +649,7 @@ public class BaseTest extends XmlRpcTestCase {
}
assertTrue(ok);
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Integer(15), result);
+ assertEquals(15, result);
}
/** Test, whether we can invoke a method, returning an
@@ -684,16 +657,15 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testObjectArrayResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testObjectArrayResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testObjectArrayResult(provider);
}
}
private void testObjectArrayResult(ClientProvider pProvider) throws Exception {
- final Object[] objects = new Object[]{new Integer(0), new Integer(1),
- new Integer(2), new Integer(3)};
+ final Object[] objects = new Object[]{0, 1, 2, 3};
final String methodName = "Remote.objectArrayResult";
- final Object[] params = new Object[]{new Integer(4)};
+ final Object[] params = new Object[] { 4 };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getConfig(pProvider), methodName, params);
assertTrue(Arrays.equals(objects, (Object[]) result));
@@ -705,49 +677,50 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testMapParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testMapParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testMapParam(provider);
}
}
private void testMapParam(ClientProvider pProvider) throws Exception {
- final Map map = new HashMap();
- map.put("2", new Integer(3));
- map.put("3", new Integer(5));
+ final Map map = new HashMap<>();
+ map.put("2", 3);
+ map.put("3", 5);
final String methodName = "Remote.mapParam";
- final Object[] params = new Object[]{map};
+ final Object[] params = new Object[]{ map };
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getConfig(pProvider), methodName, params);
- assertEquals(new Integer(21), result);
+ assertEquals(21, result);
result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Integer(21), result);
+ assertEquals(21, result);
}
- private void checkMap(Map pResult) {
+ private void checkMap(Map pResult) {
assertEquals(4, pResult.size());
- assertEquals(new Integer(0), pResult.get("0"));
- assertEquals(new Integer(1), pResult.get("1"));
- assertEquals(new Integer(2), pResult.get("2"));
- assertEquals(new Integer(3), pResult.get("3"));
+ assertEquals(0, pResult.get("0"));
+ assertEquals(1, pResult.get("1"));
+ assertEquals(2, pResult.get("2"));
+ assertEquals(3, pResult.get("3"));
}
/** Test, whether we can invoke a method, returning a map.
* @throws Exception The test failed.
*/
public void testMapResult() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testMapResult(providers[i]);
+ for (ClientProvider provider : providers) {
+ testMapResult(provider);
}
}
+ @SuppressWarnings("unchecked")
private void testMapResult(ClientProvider pProvider) throws Exception {
final String methodName = "Remote.mapResult";
- final Object[] params = new Object[]{new Integer(4)};
+ final Object[] params = new Object[] { 4 };
final XmlRpcClient client = pProvider.getClient();
- Object result = client.execute(getConfig(pProvider), methodName, params);
- checkMap((Map) result);
- result = client.execute(getExConfig(pProvider), methodName, params);
- checkMap((Map) result);
+ Map result = (Map) client.execute(getConfig(pProvider), methodName, params);
+ checkMap(result);
+ result = (Map) client.execute(getExConfig(pProvider), methodName, params);
+ checkMap(result);
}
/** Test, whether we can invoke a method, passing a DOM
@@ -755,13 +728,15 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testNodeParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testNodeParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testNodeParam(provider);
}
}
private static final String ROOT_TAG = "root";
+
private static final String INT_TAG = "int";
+
private static final String INT_URI = "http://ws.apache.org/xmlrpc/namespaces/testNodeParam";
private void testNodeParam(ClientProvider pProvider) throws Exception {
@@ -782,13 +757,11 @@ public class BaseTest extends XmlRpcTestCase {
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
assertEquals(1 + 2 + 3 + 4 + 5, result);
- boolean ok = false;
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
/** Test, whether we can invoke a method, passing an instance of
@@ -796,8 +769,8 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testSerializableParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testSerializableParam(providers[i]);
+ for (ClientProvider provider : providers) {
+ testSerializableParam(provider);
}
}
@@ -809,43 +782,14 @@ public class BaseTest extends XmlRpcTestCase {
final Object[] params = new Object[]{new Remote.CalendarWrapper(cal)};
final XmlRpcClient client = pProvider.getClient();
Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(new Long(cal.getTime().getTime()), result);
- boolean ok = false;
+ assertEquals(cal.getTime().getTime(), result);
try {
client.execute(getConfig(pProvider), methodName, params);
} catch (XmlRpcExtensionException e) {
- ok = true;
+ fail();
}
- assertTrue(ok);
}
- /** Tests, whether we can invoke a method, passing an instance of
- * {@link Calendar} as a parameter.
- * @throws Exception The test failed.
- */
- public void testCalendarParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testCalendarParam(providers[i]);
- }
- }
-
- private void testCalendarParam(ClientProvider pProvider) throws Exception {
- final String methodName = "Remote.calendarParam";
- Calendar cal1 = newCalendarParam();
- Calendar cal2 = newCalendarResult();
- final Object[] params = new Object[]{cal1};
- final XmlRpcClient client = pProvider.getClient();
- Object result = client.execute(getExConfig(pProvider), methodName, params);
- assertEquals(cal2.getTime(), ((Calendar) result).getTime());
- boolean ok = false;
- try {
- client.execute(getConfig(pProvider), methodName, params);
- } catch (XmlRpcExtensionException e) {
- ok = true;
- }
- assertTrue(ok);
- }
-
private Calendar newCalendarResult() {
Calendar cal2 = Calendar.getInstance(TimeZone.getDefault());
cal2.set(2005, 5, 24, 0, 0, 0);
@@ -865,9 +809,9 @@ public class BaseTest extends XmlRpcTestCase {
* @throws Exception The test failed.
*/
public void testDateParam() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testDateParam(providers[i]);
- }
+ for (ClientProvider provider : providers) {
+ testDateParam(provider);
+ }
}
private void testDateParam(ClientProvider pProvider) throws Exception {
@@ -887,9 +831,9 @@ public class BaseTest extends XmlRpcTestCase {
* trapped by the client.
*/
public void testCatchNPE() throws Exception {
- for (int i = 0; i < providers.length; i++) {
- testCatchNPE(providers[i]);
- }
+ for (ClientProvider provider : providers) {
+ testCatchNPE(provider);
+ }
}
private void testCatchNPE(ClientProvider pProvider) throws Exception {
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientIpTest.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientIpTest.java
index 0a49318..a69c3a9 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientIpTest.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientIpTest.java
@@ -1,38 +1,18 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.xbib.netty.http.xmlrpc.client.test;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcHandler;
+import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
+import org.xbib.netty.http.xmlrpc.server.XmlRpcNoSuchHandlerException;
+import org.xbib.netty.http.xmlrpc.servlet.XmlRpcServlet;
+
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.XmlRpcHandler;
-import org.apache.xmlrpc.XmlRpcRequest;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
-import org.apache.xmlrpc.server.XmlRpcNoSuchHandlerException;
-import org.apache.xmlrpc.webserver.XmlRpcServlet;
-
-
/**
* Test case for reading the clients IP address.
*/
@@ -65,14 +45,16 @@ public class ClientIpTest extends XmlRpcTestCase {
* object.
*/
public static class ClientInfoServlet extends XmlRpcServlet {
+
private static final long serialVersionUID = 8210342625908021538L;
- private static ThreadLocal clientInfo = new ThreadLocal();
+
+ private static final ThreadLocal clientInfo = new ThreadLocal<>();
/**
* Returns the current threads. client info object.
*/
- public static ClientInfo getClientInfo() {
- return (ClientInfo) clientInfo.get();
+ static ClientInfo getClientInfo() {
+ return clientInfo.get();
}
public void doPost(HttpServletRequest pRequest,
@@ -102,20 +84,17 @@ public class ClientIpTest extends XmlRpcTestCase {
};
}
- protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
- XmlRpcException {
- final XmlRpcHandler handler = new XmlRpcHandler(){
- public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
- final ClientInfo clientInfo = ClientInfoServlet.getClientInfo();
- if (clientInfo == null) {
- return "";
- }
- final String ip = clientInfo.getIpAddress();
- if (ip == null) {
- return "";
- }
- return ip;
+ protected XmlRpcHandlerMapping getHandlerMapping() {
+ final XmlRpcHandler handler = pRequest -> {
+ final ClientInfo clientInfo = ClientInfoServlet.getClientInfo();
+ if (clientInfo == null) {
+ return "";
}
+ final String ip = clientInfo.getIpAddress();
+ if (ip == null) {
+ return "";
+ }
+ return ip;
};
return new XmlRpcHandlerMapping(){
public XmlRpcHandler getHandler(String pHandlerName)
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProvider.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProvider.java
index 53ee97b..260f370 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProvider.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProvider.java
@@ -4,6 +4,8 @@ import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfigImpl;
import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
+import java.io.IOException;
+
/** This interface allows to perform a unit test with various
* transports. Basically, the implementation creates the client,
* including the transport, and the server, if required.
@@ -27,5 +29,5 @@ public interface ClientProvider {
/** Performs a shutdown of the server.
*/
- void shutdown();
+ void shutdown() throws IOException;
}
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProviderImpl.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProviderImpl.java
index 521b6d8..c245cec 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProviderImpl.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/ClientProviderImpl.java
@@ -1,6 +1,5 @@
package org.xbib.netty.http.xmlrpc.client.test;
-
import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfigImpl;
import org.xbib.netty.http.xmlrpc.client.XmlRpcTransportFactory;
@@ -10,8 +9,11 @@ import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
/** Abstract base implementation of {@link ClientProvider}.
*/
public abstract class ClientProviderImpl implements ClientProvider {
+
protected final XmlRpcHandlerMapping mapping;
+ protected XmlRpcClientConfigImpl clientConfig;
+
protected abstract XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient);
/** Creates a new instance.
@@ -21,15 +23,17 @@ public abstract class ClientProviderImpl implements ClientProvider {
mapping = pMapping;
}
- protected XmlRpcServer getXmlRpcServer() throws Exception {
+ protected XmlRpcServer getXmlRpcServer() {
XmlRpcServer server = new XmlRpcServer();
server.setHandlerMapping(mapping);
return server;
}
public XmlRpcClientConfigImpl getConfig() throws Exception {
- XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
- return config;
+ if (clientConfig == null) {
+ clientConfig = new XmlRpcClientConfigImpl();
+ }
+ return clientConfig;
}
public XmlRpcClient getClient() {
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CommonsProvider.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CommonsProvider.java
index 01e9cca..2de3791 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CommonsProvider.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CommonsProvider.java
@@ -1,6 +1,7 @@
package org.xbib.netty.http.xmlrpc.client.test;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcCommonsTransport;
import org.xbib.netty.http.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.xbib.netty.http.xmlrpc.client.XmlRpcTransportFactory;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CustomTypesTest.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CustomTypesTest.java
index 208e926..2a764a7 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CustomTypesTest.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/CustomTypesTest.java
@@ -1,21 +1,3 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.xbib.netty.http.xmlrpc.client.test;
import java.io.IOException;
@@ -25,26 +7,25 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
-import org.apache.ws.commons.util.NamespaceContextImpl;
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.XmlRpcRequest;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-import org.apache.xmlrpc.client.XmlRpcClientRequestImpl;
-import org.apache.xmlrpc.common.TypeFactory;
-import org.apache.xmlrpc.common.TypeFactoryImpl;
-import org.apache.xmlrpc.common.XmlRpcController;
-import org.apache.xmlrpc.common.XmlRpcStreamConfig;
-import org.apache.xmlrpc.parser.DateParser;
-import org.apache.xmlrpc.parser.TypeParser;
-import org.apache.xmlrpc.serializer.DateSerializer;
-import org.apache.xmlrpc.serializer.TypeSerializer;
-import org.apache.xmlrpc.server.PropertyHandlerMapping;
-import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
-import org.apache.xmlrpc.server.XmlRpcServer;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcClientRequestImpl;
+import org.xbib.netty.http.xmlrpc.common.TypeFactory;
+import org.xbib.netty.http.xmlrpc.common.TypeFactoryImpl;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcController;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamConfig;
+import org.xbib.netty.http.xmlrpc.common.parser.DateParser;
+import org.xbib.netty.http.xmlrpc.common.parser.TypeParser;
+import org.xbib.netty.http.xmlrpc.common.serializer.DateSerializer;
+import org.xbib.netty.http.xmlrpc.common.serializer.TypeSerializer;
+import org.xbib.netty.http.xmlrpc.common.util.NamespaceContextImpl;
+import org.xbib.netty.http.xmlrpc.server.PropertyHandlerMapping;
+import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
+import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
import org.xml.sax.SAXException;
-
/**
* Test suite for working with custom types.
*/
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/DynamicProxyTest.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/DynamicProxyTest.java
index 1eec24a..80f4985 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/DynamicProxyTest.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/DynamicProxyTest.java
@@ -1,32 +1,13 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.xbib.netty.http.xmlrpc.client.test;
import java.io.IOException;
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.util.ClientFactory;
-import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.xbib.netty.http.xmlrpc.client.ClientFactory;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
+import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xml.sax.SAXException;
-
/** Test case for the {@link ClientFactory}.
*/
public class DynamicProxyTest extends XmlRpcTestCase {
diff --git a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/JiraTest.java b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/JiraTest.java
index 6eeb4ee..1d9d274 100644
--- a/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/JiraTest.java
+++ b/netty-http-xmlrpc-client/src/test/java/org/xbib/netty/http/xmlrpc/client/test/JiraTest.java
@@ -1,21 +1,3 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.xbib.netty.http.xmlrpc.client.test;
import java.io.IOException;
@@ -26,22 +8,22 @@ import java.io.Writer;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.client.TimingOutCallback;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
-import org.apache.xmlrpc.client.util.ClientFactory;
-import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
-import org.apache.xmlrpc.parser.XmlRpcResponseParser;
-import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
-import org.apache.xmlrpc.util.SAXParsers;
+import org.xbib.netty.http.xmlrpc.client.ClientFactory;
+import org.xbib.netty.http.xmlrpc.client.TimingOutCallback;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
+import org.xbib.netty.http.xmlrpc.client.XmlRpcHttpClientConfig;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
+import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestConfig;
+import org.xbib.netty.http.xmlrpc.common.parser.XmlRpcResponseParser;
+import org.xbib.netty.http.xmlrpc.common.util.SAXParsers;
+import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@@ -56,12 +38,12 @@ public class JiraTest extends XmlRpcTestCase {
/**
* Returns the reversed vector.
*/
- Vector reverse(Vector pVector);
+ Vector
*
* final int port = 8088;
- *
* XmlRpcServlet servlet = new XmlRpcServlet();
* ServletWebServer webServer = new ServletWebServer(servlet, port);
* webServer.start();
*
*/
public class ServletWebServer extends WebServer {
- /** This exception is thrown by the request handling classes,
- * advising the server, that it should return an error response.
- */
- public static class Exception extends IOException {
- private static final long serialVersionUID = 49879832748972394L;
- private final int statusCode;
- private final String description;
-
- /** Creates a new instance.
- * @param pStatusCode The HTTP status code being sent to the client.
- * @param pMessage The HTTP status message being sent to the client.
- * @param pDescription The error description being sent to the client
- * in the response body.
- */
- public Exception(int pStatusCode, String pMessage, String pDescription) {
- super(pMessage);
- statusCode = pStatusCode;
- description = pDescription;
- }
-
- public String getMessage() { return statusCode + " " + super.getMessage(); }
-
- /** Returns the error description. The server will send the description
- * as plain text in the response body.
- * @return The error description.
- */
- public String getDescription() { return description; }
-
- /** Returns the HTTP status code.
- * @return The status code.
- */
- public int getStatusCode() { return statusCode; }
- }
private final HttpServlet servlet;
@@ -91,22 +57,34 @@ public class ServletWebServer extends WebServer {
* @param pAddr The servers IP address.
* @throws ServletException Initializing the servlet failed.
*/
- public ServletWebServer(HttpServlet pServlet, int pPort, InetAddress pAddr)
- throws ServletException {
+ public ServletWebServer(HttpServlet pServlet, int pPort, InetAddress pAddr) throws ServletException {
super(pPort, pAddr);
servlet = pServlet;
- servlet.init(new ServletConfig(){
+ servlet.init(new ServletConfig() {
+
+ @Override
public String getServletName() { return servlet.getClass().getName(); }
+
+ @Override
public ServletContext getServletContext() {
throw new IllegalStateException("Context not available");
}
+
+ @Override
public String getInitParameter(String pArg0) {
return null;
}
+ @Override
public Enumeration getInitParameterNames() {
return new Enumeration(){
- public boolean hasMoreElements() { return false; }
+
+ @Override
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ @Override
public String nextElement() {
throw new NoSuchElementException();
}
@@ -122,4 +100,42 @@ public class ServletWebServer extends WebServer {
Socket pSocket) throws IOException {
return new ServletConnection(servlet, pSocket);
}
+
+ /** This exception is thrown by the request handling classes,
+ * advising the server, that it should return an error response.
+ */
+ public static class ServletWebServerException extends IOException {
+
+ private static final long serialVersionUID = 49879832748972394L;
+
+ private final int statusCode;
+
+ private final String description;
+
+ /** Creates a new instance.
+ * @param pStatusCode The HTTP status code being sent to the client.
+ * @param pMessage The HTTP status message being sent to the client.
+ * @param pDescription The error description being sent to the client
+ * in the response body.
+ */
+ ServletWebServerException(int pStatusCode, String pMessage, String pDescription) {
+ super(pMessage);
+ statusCode = pStatusCode;
+ description = pDescription;
+ }
+
+ public String getMessage() { return statusCode + " " + super.getMessage(); }
+
+ /** Returns the error description. The server will send the description
+ * as plain text in the response body.
+ * @return The error description.
+ */
+ public String getDescription() { return description; }
+
+ /** Returns the HTTP status code.
+ * @return The status code.
+ */
+ public int getStatusCode() { return statusCode; }
+ }
+
}
diff --git a/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/ThreadPool.java b/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/ThreadPool.java
index d13706d..b137e8d 100644
--- a/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/ThreadPool.java
+++ b/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/ThreadPool.java
@@ -2,6 +2,8 @@ package org.xbib.netty.http.xmlrpc.servlet;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/** Simple thread pool. A task is executed by obtaining a thread from
* the pool
@@ -11,50 +13,54 @@ public class ThreadPool {
/** A task, which may be interrupted, if the pool is shutting down.
*/
public interface InterruptableTask extends Runnable {
+
/** Interrupts the task.
* @throws Throwable Shutting down the task failed.
*/
void shutdown() throws Throwable;
}
- private class Poolable extends Thread implements Runnable{
+ private class Poolable extends Thread implements Runnable {
- private volatile boolean shuttingDown;
+ private final Logger logger = Logger.getLogger(Poolable.class.getName());
+
+ private volatile boolean shuttingDown;
private Runnable task;
Poolable(ThreadGroup pGroup, int pNum) {
- super(pGroup, pGroup.getName() + "-" + pNum);
- super.start();
- }
+ super(pGroup, pGroup.getName() + "-" + pNum);
+ super.start();
+ }
- @Override
- public void run() {
- while (!shuttingDown) {
- final Runnable t = getTask();
- if (t == null) {
- try {
- synchronized (this) {
- if (!shuttingDown && getTask() == null) {
- wait();
- }
- }
- } catch (InterruptedException e) {
- // Do nothing
- }
- } else {
- try {
- t.run();
- resetTask();
- repool(Poolable.this);
- } catch (Throwable e) {
- remove(Poolable.this);
- Poolable.this.shutdown();
- resetTask();
- }
- }
- }
- }
+ @Override
+ public void run() {
+ while (!shuttingDown) {
+ final Runnable t = getTask();
+ if (t == null) {
+ try {
+ synchronized (this) {
+ if (!shuttingDown && getTask() == null) {
+ wait();
+ }
+ }
+ } catch (InterruptedException e) {
+ // Do nothing
+ }
+ } else {
+ try {
+ t.run();
+ resetTask();
+ repool(Poolable.this);
+ } catch (Throwable e) {
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ remove(Poolable.this);
+ Poolable.this.shutdown();
+ resetTask();
+ }
+ }
+ }
+ }
synchronized void shutdown() {
shuttingDown = true;
@@ -88,7 +94,7 @@ public class ThreadPool {
}
}
- private final ThreadGroup threadGroup;
+ private final ThreadGroup threadGroup;
private final int maxSize;
@@ -101,66 +107,66 @@ public class ThreadPool {
private int num;
- /** Creates a new instance.
- * @param pMaxSize Maximum number of concurrent threads.
- * @param pName Thread group name.
- */
- public ThreadPool(int pMaxSize, String pName) {
- maxSize = pMaxSize;
- threadGroup = new ThreadGroup(pName);
- }
+ /** Creates a new instance.
+ * @param pMaxSize Maximum number of concurrent threads.
+ * @param pName Thread group name.
+ */
+ public ThreadPool(int pMaxSize, String pName) {
+ maxSize = pMaxSize;
+ threadGroup = new ThreadGroup(pName);
+ }
- private synchronized void remove(Poolable pPoolable) {
+ private synchronized void remove(Poolable pPoolable) {
runningThreads.remove(pPoolable);
waitingThreads.remove(pPoolable);
- }
+ }
- private void repool(Poolable pPoolable) {
- boolean discarding = false;
- Runnable task = null;
- Poolable poolable = null;
- synchronized (this) {
- if (runningThreads.remove(pPoolable)) {
- if (maxSize != 0 && runningThreads.size() + waitingThreads.size() >= maxSize) {
- discarding = true;
- } else {
- waitingThreads.add(pPoolable);
- if (waitingTasks.size() > 0) {
- task = waitingTasks.remove(waitingTasks.size() - 1);
- poolable = getPoolable(task, false);
- }
- }
- } else {
- discarding = true;
- }
- if (discarding) {
- remove(pPoolable);
- }
- }
- if (poolable != null) {
- poolable.start(task);
- }
- if (discarding) {
- pPoolable.shutdown();
- }
- }
+ private void repool(Poolable pPoolable) {
+ boolean discarding = false;
+ Runnable task = null;
+ Poolable poolable = null;
+ synchronized (this) {
+ if (runningThreads.remove(pPoolable)) {
+ if (maxSize != 0 && runningThreads.size() + waitingThreads.size() >= maxSize) {
+ discarding = true;
+ } else {
+ waitingThreads.add(pPoolable);
+ if (waitingTasks.size() > 0) {
+ task = waitingTasks.remove(waitingTasks.size() - 1);
+ poolable = getPoolable(task, false);
+ }
+ }
+ } else {
+ discarding = true;
+ }
+ if (discarding) {
+ remove(pPoolable);
+ }
+ }
+ if (poolable != null) {
+ poolable.start(task);
+ }
+ if (discarding) {
+ pPoolable.shutdown();
+ }
+ }
- /**
- * Starts a task immediately.
- * @param pTask The task being started.
- * @return True, if the task could be started immediately. False, if
- * the maxmimum number of concurrent tasks was exceeded.
- */
- public boolean startTask(Runnable pTask) {
- final Poolable poolable = getPoolable(pTask, false);
- if (poolable == null) {
- return false;
- }
- poolable.start(pTask);
- return true;
- }
+ /**
+ * Starts a task immediately.
+ * @param pTask The task being started.
+ * @return True, if the task could be started immediately. False, if
+ * the maxmimum number of concurrent tasks was exceeded.
+ */
+ public boolean startTask(Runnable pTask) {
+ final Poolable poolable = getPoolable(pTask, false);
+ if (poolable == null) {
+ return false;
+ }
+ poolable.start(pTask);
+ return true;
+ }
- private synchronized Poolable getPoolable(Runnable pTask, boolean pQueue) {
+ private synchronized Poolable getPoolable(Runnable pTask, boolean pQueue) {
if (maxSize != 0 && runningThreads.size() >= maxSize) {
if (pQueue) {
waitingTasks.add(pTask);
@@ -175,28 +181,28 @@ public class ThreadPool {
}
runningThreads.add(poolable);
return poolable;
- }
-
- /**
- * Adds a task for immediate or deferred execution.
- * @param pTask The task being added.
- * @return True, if the task was started immediately. False, if
- * the task will be executed later.
- * @deprecated No longer in use.
- */
- @Deprecated
- public boolean addTask(Runnable pTask) {
- final Poolable poolable = getPoolable(pTask, true);
- if (poolable != null) {
- poolable.start(pTask);
- return true;
- }
- return false;
- }
+ }
- /** Closes the pool.
- */
- public synchronized void shutdown() {
+ /**
+ * Adds a task for immediate or deferred execution.
+ * @param pTask The task being added.
+ * @return True, if the task was started immediately. False, if
+ * the task will be executed later.
+ * @deprecated No longer in use.
+ */
+ @Deprecated
+ public boolean addTask(Runnable pTask) {
+ final Poolable poolable = getPoolable(pTask, true);
+ if (poolable != null) {
+ poolable.start(pTask);
+ return true;
+ }
+ return false;
+ }
+
+ /** Closes the pool.
+ */
+ public synchronized void shutdown() {
while (!waitingThreads.isEmpty()) {
Poolable poolable = (Poolable) waitingThreads.remove(waitingThreads.size()-1);
poolable.shutdown();
@@ -205,15 +211,15 @@ public class ThreadPool {
Poolable poolable = (Poolable) runningThreads.remove(runningThreads.size()-1);
poolable.shutdown();
}
- }
+ }
- /** Returns the maximum number of concurrent threads.
- * @return Maximum number of threads.
- */
- public int getMaxThreads() { return maxSize; }
+ /** Returns the maximum number of concurrent threads.
+ * @return Maximum number of threads.
+ */
+ public int getMaxThreads() { return maxSize; }
- /** Returns the number of threads, which have actually been created,
+ /** Returns the number of threads, which have actually been created,
* as opposed to the number of currently running threads.
- */
+ */
public synchronized int getNumThreads() { return num; }
}
diff --git a/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/WebServer.java b/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/WebServer.java
index 9d9bfd6..241b26e 100644
--- a/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/WebServer.java
+++ b/netty-http-xmlrpc-servlet/src/main/java/org/xbib/netty/http/xmlrpc/servlet/WebServer.java
@@ -5,11 +5,9 @@ import org.xbib.netty.http.xmlrpc.server.XmlRpcStreamServer;
import java.io.IOException;
import java.io.InterruptedIOException;
-import java.net.BindException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
-import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
@@ -52,50 +50,9 @@ import java.util.StringTokenizer;
*/
public class WebServer implements Runnable {
- private class AddressMatcher {
+ protected ServerSocket serverSocket;
- private final int[] pattern;
-
- AddressMatcher(String pAddress) {
- try {
- pattern = new int[4];
- StringTokenizer st = new StringTokenizer(pAddress, ".");
- if (st.countTokens() != 4) {
- throw new IllegalArgumentException();
- }
- for (int i = 0; i < 4; i++) {
- String next = st.nextToken();
- if ("*".equals(next)) {
- pattern[i] = 256;
- } else {
- /* Note: *Not* pattern[i] = Integer.parseInt(next);
- * See XMLRPC-145
- */
- pattern[i] = (byte) Integer.parseInt(next);
- }
- }
- } catch (Exception e) {
- throw new IllegalArgumentException("\"" + pAddress
- + "\" does not represent a valid IP address");
- }
- }
-
- boolean matches(byte[] pAddress) {
- for (int i = 0; i < 4; i++) {
- if (pattern[i] > 255) {
- continue; // Wildcard
- }
- if (pattern[i] != pAddress[i]) {
- return false;
- }
- }
- return true;
- }
- }
-
- protected ServerSocket serverSocket;
-
- private Thread listener;
+ private final WebServerThread webServerThread;
private ThreadPool pool;
@@ -105,304 +62,335 @@ public class WebServer implements Runnable {
protected final XmlRpcStreamServer server = newXmlRpcStreamServer();
- protected XmlRpcStreamServer newXmlRpcStreamServer(){
- return new ConnectionServer();
- }
+ protected XmlRpcStreamServer newXmlRpcStreamServer(){
+ return new ConnectionServer();
+ }
- // Inputs to setupServerSocket()
- private InetAddress address;
- private int port;
-
- private boolean paranoid;
-
- static final String HTTP_11 = "HTTP/1.1";
- /** Creates a web server at the specified port number.
- * @param pPort Port number; 0 for a random port, choosen by the
- * operating system.
- */
- public WebServer(int pPort) {
- this(pPort, null);
- }
-
- /** Creates a web server at the specified port number and IP address.
- * @param pPort Port number; 0 for a random port, choosen by the
- * operating system.
- * @param pAddr Local IP address; null for all available IP addresses.
- */
- public WebServer(int pPort, InetAddress pAddr) {
- address = pAddr;
- port = pPort;
- }
-
- /**
- * Factory method to manufacture the server socket. Useful as a
- * hook method for subclasses to override when they desire
- * different flavor of socket (i.e. a SSLServerSocket).
- *
- * @param pPort Port number; 0 for a random port, choosen by the operating
- * system.
- * @param backlog
- * @param addr If null, binds to
- * INADDR_ANY, meaning that all network interfaces on
- * a multi-homed host will be listening.
- * @exception IOException Error creating listener socket.
- */
- protected ServerSocket createServerSocket(int pPort, int backlog, InetAddress addr)
- throws IOException {
- return new ServerSocket(pPort, backlog, addr);
- }
-
- /**
- * Initializes this server's listener socket with the specified
- * attributes, assuring that a socket timeout has been set. The
- * {@link #createServerSocket(int, int, InetAddress)} method can
- * be overridden to change the flavor of socket used.
- *
- * @see #createServerSocket(int, int, InetAddress)
- */
- private synchronized void setupServerSocket(int backlog) throws IOException {
- // Since we can't reliably set SO_REUSEADDR until JDK 1.4 is
- // the standard, try to (re-)open the server socket several
- // times. Some OSes (Linux and Solaris, for example), hold on
- // to listener sockets for a brief period of time for security
- // reasons before relinquishing their hold.
- for (int i = 1; ; i++) {
- try {
- serverSocket = createServerSocket(port, backlog, address);
- // A socket timeout must be set.
- if (serverSocket.getSoTimeout() <= 0) {
- serverSocket.setSoTimeout(4096);
- }
- return;
- } catch (BindException e) {
- if (i == 10) {
- throw e;
- } else {
- long waitUntil = System.currentTimeMillis() + 1000;
- for (;;) {
- long l = waitUntil - System.currentTimeMillis();
- if (l > 0) {
- try {
- Thread.sleep(l);
- } catch (InterruptedException ex) {
- }
- } else {
- break;
+ // Inputs to setupServerSocket()
+ private InetAddress address;
+
+ private int port;
+
+ private boolean paranoid;
+
+ static final String HTTP_11 = "HTTP/1.1";
+ /** Creates a web server at the specified port number.
+ * @param pPort Port number; 0 for a random port, choosen by the
+ * operating system.
+ */
+ public WebServer(int pPort) {
+ this(pPort, null);
+ }
+
+ /** Creates a web server at the specified port number and IP address.
+ * @param pPort Port number; 0 for a random port, choosen by the
+ * operating system.
+ * @param pAddr Local IP address; null for all available IP addresses.
+ */
+ public WebServer(int pPort, InetAddress pAddr) {
+ address = pAddr;
+ port = pPort;
+ webServerThread = new WebServerThread(this, "XML-RPC Weblistener");
+ }
+
+ /**
+ * Factory method to manufacture the server socket. Useful as a
+ * hook method for subclasses to override when they desire
+ * different flavor of socket (i.e. a SSLServerSocket).
+ *
+ * @param pPort Port number; 0 for a random port, choosen by the operating
+ * system.
+ * @param backlog
+ * @param addr If null, binds to
+ * INADDR_ANY, meaning that all network interfaces on
+ * a multi-homed host will be listening.
+ * @exception IOException Error creating listener socket.
+ */
+ protected ServerSocket createServerSocket(int pPort, int backlog, InetAddress addr)
+ throws IOException {
+ return new ServerSocket(pPort, backlog, addr);
+ }
+
+ /**
+ * Initializes this server's listener socket with the specified
+ * attributes, assuring that a socket timeout has been set. The
+ * {@link #createServerSocket(int, int, InetAddress)} method can
+ * be overridden to change the flavor of socket used.
+ *
+ * @see #createServerSocket(int, int, InetAddress)
+ */
+ private synchronized void setupServerSocket(int backlog) throws IOException {
+ serverSocket = createServerSocket(port, backlog, address);
+ // A socket timeout must be set.
+ if (serverSocket.getSoTimeout() <= 0) {
+ serverSocket.setSoTimeout(4096);
+ }
+ }
+
+ /**
+ * Spawns a new thread which binds this server to the port it's
+ * configured to accept connections on.
+ *
+ * @see #run()
+ * @throws IOException Binding the server socket failed.
+ */
+ public void start() throws IOException {
+ setupServerSocket(50);
+ // Not marked as daemon thread since run directly via main().
+ webServerThread.start();
+ }
+
+ /**
+ * Switch client filtering on/off.
+ * @param pParanoid True to enable filtering, false otherwise.
+ * @see #acceptClient(String)
+ * @see #denyClient(String)
+ */
+ public void setParanoid(boolean pParanoid) {
+ paranoid = pParanoid;
+ }
+
+ /**
+ * Returns the client filtering state.
+ * @return True, if client filtering is enabled, false otherwise.
+ * @see #acceptClient(String)
+ * @see #denyClient(String)
+ */
+ protected boolean isParanoid() {
+ return paranoid;
+ }
+
+ /** Add an IP address to the list of accepted clients. The parameter can
+ * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
+ * setParanoid(true) in order for this to have any effect.
+ * @param pAddress The IP address being enabled.
+ * @see #denyClient(String)
+ * @see #setParanoid(boolean)
+ * @throws IllegalArgumentException Parsing the address failed.
+ */
+ public void acceptClient(String pAddress) {
+ accept.add(new AddressMatcher(pAddress));
+ }
+
+ /**
+ * Add an IP address to the list of denied clients. The parameter can
+ * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
+ * setParanoid(true) in order for this to have any effect.
+ * @param pAddress The IP address being disabled.
+ * @see #acceptClient(String)
+ * @see #setParanoid(boolean)
+ * @throws IllegalArgumentException Parsing the address failed.
+ */
+ public void denyClient(String pAddress) {
+ deny.add(new AddressMatcher(pAddress));
+ }
+
+ /**
+ * Checks incoming connections to see if they should be allowed.
+ * If not in paranoid mode, always returns true.
+ *
+ * @param s The socket to inspect.
+ * @return Whether the connection should be allowed.
+ */
+ protected boolean allowConnection(Socket s) {
+ if (!paranoid) {
+ return true;
+ }
+ int l = deny.size();
+ byte[] addr = s.getInetAddress().getAddress();
+ for (int i = 0; i < l; i++) {
+ AddressMatcher match = deny.get(i);
+ if (match.matches(addr)) {
+ return false;
+ }
+ }
+ l = accept.size();
+ for (int i = 0; i < l; i++) {
+ AddressMatcher match = accept.get(i);
+ if (match.matches(addr)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected Runnable newTask(WebServer pServer, XmlRpcStreamServer pXmlRpcServer,
+ Socket pSocket) throws IOException {
+ return new Connection(pServer, pXmlRpcServer, pSocket);
+ }
+
+ /**
+ * Listens for client requests until stopped. Call {@link
+ * #start()} to invoke this method, and {@link #shutdown()} to
+ * break out of it.
+ *
+ * @throws RuntimeException Generally caused by either an
+ * UnknownHostException or BindException
+ * with the vanilla web server.
+ *
+ * @see #start()
+ * @see #shutdown()
+ */
+ @Override
+ public void run() {
+ pool = newThreadPool();
+ try {
+ while (!webServerThread.closed) {
+ if (serverSocket.isClosed()) {
+ break;
+ }
+ Socket socket = null;
+ try {
+ socket = serverSocket.accept();
+ socket.setTcpNoDelay(true);
+ if (allowConnection(socket)) {
+ // set read timeout to 1 seconds
+ socket.setSoTimeout(1000);
+ Runnable task = newTask(this, server, socket);
+ if (pool.startTask(task)) {
+ socket = null;
+ } else {
+ log("Maximum load of " + pool.getMaxThreads()
+ + " exceeded, rejecting client");
}
- }
- }
- }
- }
- }
-
- /**
- * Spawns a new thread which binds this server to the port it's
- * configured to accept connections on.
- *
- * @see #run()
- * @throws IOException Binding the server socket failed.
- */
- public void start() throws IOException {
- setupServerSocket(50);
-
- // The listener reference is released upon shutdown().
- if (listener == null) {
- listener = new Thread(this, "XML-RPC Weblistener");
- // Not marked as daemon thread since run directly via main().
- listener.start();
- }
- }
-
- /**
- * Switch client filtering on/off.
- * @param pParanoid True to enable filtering, false otherwise.
- * @see #acceptClient(String)
- * @see #denyClient(String)
- */
- public void setParanoid(boolean pParanoid) {
- paranoid = pParanoid;
- }
+ }
+ } catch (InterruptedIOException e) {
+ //
+ } catch (Throwable t) {
+ log(t);
+ throw new RuntimeException(t);
+ } finally {
+ if (socket != null) {
+ try {
+ log("closing client socket");
+ socket.close();
+ } catch (Throwable ignore) {
- /**
- * Returns the client filtering state.
- * @return True, if client filtering is enabled, false otherwise.
- * @see #acceptClient(String)
- * @see #denyClient(String)
- */
- protected boolean isParanoid() {
- return paranoid;
- }
-
- /** Add an IP address to the list of accepted clients. The parameter can
- * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
- * setParanoid(true) in order for this to have any effect.
- * @param pAddress The IP address being enabled.
- * @see #denyClient(String)
- * @see #setParanoid(boolean)
- * @throws IllegalArgumentException Parsing the address failed.
- */
- public void acceptClient(String pAddress) {
- accept.add(new AddressMatcher(pAddress));
- }
-
- /**
- * Add an IP address to the list of denied clients. The parameter can
- * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
- * setParanoid(true) in order for this to have any effect.
- * @param pAddress The IP address being disabled.
- * @see #acceptClient(String)
- * @see #setParanoid(boolean)
- * @throws IllegalArgumentException Parsing the address failed.
- */
- public void denyClient(String pAddress) {
- deny.add(new AddressMatcher(pAddress));
- }
-
- /**
- * Checks incoming connections to see if they should be allowed.
- * If not in paranoid mode, always returns true.
- *
- * @param s The socket to inspect.
- * @return Whether the connection should be allowed.
- */
- protected boolean allowConnection(Socket s) {
- if (!paranoid) {
- return true;
- }
-
- int l = deny.size();
- byte[] addr = s.getInetAddress().getAddress();
- for (int i = 0; i < l; i++) {
- AddressMatcher match = deny.get(i);
- if (match.matches(addr))
- {
- return false;
- }
- }
- l = accept.size();
- for (int i = 0; i < l; i++) {
- AddressMatcher match = accept.get(i);
- if (match.matches(addr)) {
- return true;
- }
- }
- return false;
- }
-
- protected Runnable newTask(WebServer pServer, XmlRpcStreamServer pXmlRpcServer,
- Socket pSocket) throws IOException {
- return new Connection(pServer, pXmlRpcServer, pSocket);
- }
-
- /**
- * Listens for client requests until stopped. Call {@link
- * #start()} to invoke this method, and {@link #shutdown()} to
- * break out of it.
- *
- * @throws RuntimeException Generally caused by either an
- * UnknownHostException or BindException
- * with the vanilla web server.
- *
- * @see #start()
- * @see #shutdown()
- */
- @Override
- public void run() {
- pool = newThreadPool();
- try {
- while (listener != null) {
- try {
- Socket socket = serverSocket.accept();
- try {
- socket.setTcpNoDelay(true);
- } catch (SocketException socketOptEx) {
- log(socketOptEx);
- }
-
- try {
- if (allowConnection(socket)) {
- // set read timeout to 30 seconds
- socket.setSoTimeout(30000);
- Runnable task = newTask(this, server, socket);
- if (pool.startTask(task)) {
- socket = null;
- } else {
- log("Maximum load of " + pool.getMaxThreads()
- + " exceeded, rejecting client");
- }
- }
- } finally {
- if (socket != null) { try { socket.close(); } catch (Throwable ignore) {} }
- }
- } catch (InterruptedIOException checkState) {
- // Timeout while waiting for a client (from
- // SO_TIMEOUT)...try again if still listening.
- } catch (Throwable t) {
- log(t);
- }
- }
- } finally {
- if (serverSocket != null) {
- try {
- serverSocket.close();
- } catch (IOException e) {
- log(e);
- }
- }
-
- // Shutdown our Runner-based threads
- pool.shutdown();
- }
- }
+ }
+ }
+ }
+ }
+ } finally {
+ pool.shutdown();
+ if (serverSocket != null && !serverSocket.isClosed()) {
+ try {
+ log("closing server socket");
+ serverSocket.close();
+ } catch (IOException e) {
+ log(e);
+ }
+ }
+ }
+ }
protected ThreadPool newThreadPool() {
return new ThreadPool(server.getMaxThreads(), "XML-RPC");
}
-
- /**
- * Stop listening on the server port. Shutting down our {@link
- * #listener} effectively breaks it out of its {@link #run()}
- * loop.
- *
- * @see #run()
- */
- public synchronized void shutdown() {
- // Stop accepting client connections
- if (listener != null) {
- Thread l = listener;
- listener = null;
- l.interrupt();
- if (pool != null) {
- pool.shutdown();
+
+ /**
+ * Stop listening on the server port.
+ * Shutting down our {@link #webServerThread} effectively breaks it out of its {@link #run()} loop.
+ *
+ * @see #run()
+ */
+ public synchronized void shutdown() throws IOException {
+ webServerThread.closed = true;
+ webServerThread.interrupt();
+ // wait for server socket down
+ while (serverSocket != null && !serverSocket.isClosed()) {
+ try {
+ Thread.sleep(25L);
+ } catch (InterruptedException e) {
+ //
}
- }
- }
-
- /** Returns the port, on which the web server is running.
- * This method may be invoked after {@link #start()} only.
- * @return Servers port number
- */
- public int getPort() { return serverSocket.getLocalPort(); }
+ }
+ serverSocket = null;
+ try {
+ Thread.sleep(25L);
+ } catch (InterruptedException e) {
+ //
+ }
+ log("shutdown complete");
+ }
- /** Logs an error.
- * @param pError The error being logged.
- */
- public void log(Throwable pError) {
- final String msg = pError.getMessage() == null ? pError.getClass().getName() : pError.getMessage();
- server.getErrorLogger().log(msg, pError);
- }
+ public boolean isShutDown() {
+ return serverSocket.isClosed();
+ }
- /** Logs a message.
- * @param pMessage The being logged.
- */
- public void log(String pMessage) {
+ /** Returns the port, on which the web server is running.
+ * This method may be invoked after {@link #start()} only.
+ * @return Servers port number
+ */
+ public int getPort() {
+ return serverSocket.getLocalPort();
+ }
+
+ /** Logs an error.
+ * @param pError The error being logged.
+ */
+ public void log(Throwable pError) {
+ String msg = pError.getMessage() == null ? pError.getClass().getName() : pError.getMessage();
+ server.getErrorLogger().log(msg, pError);
+ }
+
+ /** Logs a message.
+ * @param pMessage The being logged.
+ */
+ public void log(String pMessage) {
server.getErrorLogger().log(pMessage);
- }
+ }
+
+ /** Returns the {@link XmlRpcServer}.
+ * @return The server object.
+ */
+ public XmlRpcStreamServer getXmlRpcServer() {
+ return server;
+ }
+
+ private class WebServerThread extends Thread {
+ volatile boolean closed = false;
+
+ WebServerThread(Runnable runnable, String name) {
+ super(runnable, name);
+ }
+ }
+
+ private class AddressMatcher {
+
+ private final int[] pattern;
+
+ AddressMatcher(String pAddress) {
+ try {
+ pattern = new int[4];
+ StringTokenizer st = new StringTokenizer(pAddress, ".");
+ if (st.countTokens() != 4) {
+ throw new IllegalArgumentException();
+ }
+ for (int i = 0; i < 4; i++) {
+ String next = st.nextToken();
+ if ("*".equals(next)) {
+ pattern[i] = 256;
+ } else {
+ pattern[i] = (byte) Integer.parseInt(next);
+ }
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException("\"" + pAddress
+ + "\" does not represent a valid IP address");
+ }
+ }
+
+ boolean matches(byte[] pAddress) {
+ for (int i = 0; i < 4; i++) {
+ if (pattern[i] > 255) {
+ continue; // Wildcard
+ }
+ if (pattern[i] != pAddress[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
- /** Returns the {@link XmlRpcServer}.
- * @return The server object.
- */
- public XmlRpcStreamServer getXmlRpcServer() {
- return server;
- }
}
diff --git a/settings.gradle b/settings.gradle
index b6d4758..d1add36 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -3,7 +3,7 @@ include 'netty-http-client'
include 'netty-http-server'
include 'netty-http-server-reactive'
include 'netty-http-server-rest'
-//include 'netty-http-xmlrpc-common'
-//include 'netty-http-xmlrpc-server'
-//include 'netty-http-xmlrpc-servlet'
-//include 'netty-http-xmlrpc-client'
+include 'netty-http-xmlrpc-common'
+include 'netty-http-xmlrpc-server'
+include 'netty-http-xmlrpc-servlet'
+include 'netty-http-xmlrpc-client'