make XML-RPC tests compile and run under Java 8

This commit is contained in:
Jörg Prante 2019-07-17 22:53:14 +02:00
parent 81b1aad724
commit 61fdc04e9c
43 changed files with 1286 additions and 1437 deletions

View file

@ -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')}"
}

View file

@ -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

View file

@ -43,10 +43,6 @@ public interface ServerResponse {
void write(ChunkedInput<ByteBuf> chunkedInput);
/**
* Convenience methods.
*/
static void write(ServerResponse serverResponse, int status) {
write(serverResponse, HttpResponseStatus.valueOf(status));
}

View file

@ -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'
}

View file

@ -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();

View file

@ -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;

View file

@ -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,9 +45,7 @@ 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 {
((AbstractReflectiveHandlerMapping) mapping).setAuthenticationHandler(pRequest -> {
XmlRpcRequestConfig config = pRequest.getConfig();
if (config instanceof XmlRpcHttpRequestConfig) {
XmlRpcHttpRequestConfig httpRequestConfig = (XmlRpcHttpRequestConfig) config;
@ -52,32 +53,25 @@ public class AuthenticationTest extends XmlRpcTestCase {
&& 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);
}
}

View file

@ -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<String, Integer> 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<String, Integer> 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<String, Integer> mapResult(int pArg) {
Map<String, Integer> 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,8 +589,8 @@ 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);
}
}
@ -626,9 +600,9 @@ public class BaseTest extends XmlRpcTestCase {
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<String, Integer> map = new HashMap<>();
map.put("2", 3);
map.put("3", 5);
final String methodName = "Remote.mapParam";
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<String, Object> 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<String, Object> result = (Map<String, Object>) client.execute(getConfig(pProvider), methodName, params);
checkMap(result);
result = (Map<String, Object>) 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,41 +782,12 @@ 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() {
@ -865,8 +809,8 @@ 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);
}
}
@ -887,8 +831,8 @@ 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);
}
}

View file

@ -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> 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,10 +84,8 @@ public class ClientIpTest extends XmlRpcTestCase {
};
}
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
XmlRpcException {
final XmlRpcHandler handler = new XmlRpcHandler(){
public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
protected XmlRpcHandlerMapping getHandlerMapping() {
final XmlRpcHandler handler = pRequest -> {
final ClientInfo clientInfo = ClientInfoServlet.getClientInfo();
if (clientInfo == null) {
return "";
@ -115,7 +95,6 @@ public class ClientIpTest extends XmlRpcTestCase {
return "";
}
return ip;
}
};
return new XmlRpcHandlerMapping(){
public XmlRpcHandler getHandler(String pHandlerName)

View file

@ -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;
}

View file

@ -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() {

View file

@ -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;

View file

@ -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.
*/

View file

@ -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 {

View file

@ -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<Object> reverse(Vector<Object> pVector);
/**
* Returns the same hashtable, but doubles the
* values.
*/
Hashtable doubledValues(Hashtable pMap);
Hashtable<Object, Object> doubledValues(Hashtable<Object, Object> pMap);
/**
* Returns the same properties, but doubles the
* values.
@ -73,22 +55,21 @@ public class JiraTest extends XmlRpcTestCase {
* Handler for {@link JiraTest#testXMLRPC89()}
*/
public static class XMLRPC89HandlerImpl implements XMLRPC89Handler {
public Vector reverse(Vector pVector) {
Vector result = new Vector(pVector.size());
public Vector<Object> reverse(Vector<Object> pVector) {
Vector<Object> result = new Vector<>(pVector.size());
result.addAll(pVector);
Collections.reverse(result);
return result;
}
public Hashtable doubledValues(Hashtable pMap) {
final Hashtable result;
public Hashtable<Object, Object> doubledValues(Hashtable<Object, Object> pMap) {
final Hashtable<Object, Object> result;
if (pMap instanceof Properties) {
result = new Properties();
} else {
result = new Hashtable();
result = new Hashtable<>();
}
result.putAll(pMap);
for (Iterator iter = result.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
for (Map.Entry<Object, Object> entry : result.entrySet()) {
Object value = entry.getValue();
final Integer i;
if (pMap instanceof Properties) {
@ -96,7 +77,7 @@ public class JiraTest extends XmlRpcTestCase {
} else {
i = (Integer) value;
}
Integer iDoubled = new Integer(i.intValue()*2);
Integer iDoubled = i * 2;
if (pMap instanceof Properties) {
entry.setValue(iDoubled.toString());
} else {
@ -120,19 +101,19 @@ public class JiraTest extends XmlRpcTestCase {
* XMLRPC-89</a>
*/
public void testXMLRPC89() throws Exception {
for (int i = 0; i < providers.length; i++) {
testXMLRPC89Vector(providers[i]);
testXMLRPC89Hashtable(providers[i]);
testXMLRPC89Properties(providers[i]);
for (ClientProvider provider : providers) {
testXMLRPC89Vector(provider);
testXMLRPC89Hashtable(provider);
testXMLRPC89Properties(provider);
}
}
private void testXMLRPC89Vector(ClientProvider pProvider) throws Exception {
Vector values = new Vector();
Vector<Object> values = new Vector<>();
for (int i = 0; i < 3; i++) {
values.add(new Integer(i));
values.add(i);
}
Vector params = new Vector();
Vector<Object> params = new Vector<>();
params.add(values);
XmlRpcClient client = pProvider.getClient();
client.setConfig(getConfig(pProvider));
@ -141,20 +122,20 @@ public class JiraTest extends XmlRpcTestCase {
assertNotNull(result);
assertEquals(3, result.length);
for (int i = 0; i < 3; i++) {
assertEquals(new Integer(2-i), result[i]);
assertEquals(2 - i, result[i]);
}
ClientFactory factory = new ClientFactory(client);
XMLRPC89Handler handler = (XMLRPC89Handler) factory.newInstance(XMLRPC89Handler.class);
Vector resultVector = handler.reverse(values);
Vector<Object> resultVector = handler.reverse(values);
assertNotNull(resultVector);
assertEquals(3, resultVector.size());
for (int i = 0; i < 3; i++) {
assertEquals(new Integer(2-i), resultVector.get(i));
assertEquals(2 - i, resultVector.get(i));
}
}
private void verifyXMLRPC89Hashtable(Map pMap) {
private void verifyXMLRPC89Hashtable(Map<Object, Object> pMap) {
assertNotNull(pMap);
assertEquals(3, pMap.size());
for (int i = 0; i < 3; i++) {
@ -163,23 +144,24 @@ public class JiraTest extends XmlRpcTestCase {
}
}
@SuppressWarnings("unchecked")
private void testXMLRPC89Hashtable(ClientProvider pProvider) throws Exception {
Hashtable values = new Hashtable();
Hashtable<Object, Object> values = new Hashtable<>();
for (int i = 0; i < 3; i++) {
values.put(String.valueOf(i), new Integer(i));
values.put(String.valueOf(i), i);
}
XmlRpcClient client = pProvider.getClient();
client.setConfig(getConfig(pProvider));
Object res = client.execute(XMLRPC89Handler.class.getName() + ".doubledValues", new Object[]{values});
verifyXMLRPC89Hashtable((Map) res);
Map<Object, Object> res = (Map<Object, Object>) client.execute(XMLRPC89Handler.class.getName() + ".doubledValues", new Object[]{values});
verifyXMLRPC89Hashtable(res);
ClientFactory factory = new ClientFactory(client);
XMLRPC89Handler handler = (XMLRPC89Handler) factory.newInstance(XMLRPC89Handler.class);
Hashtable result = handler.doubledValues(values);
Hashtable<Object, Object> result = handler.doubledValues(values);
verifyXMLRPC89Hashtable(result);
}
private void verifyXMLRPC89Properties(Map pMap) {
private void verifyXMLRPC89Properties(Map<Object, Object> pMap) {
assertNotNull(pMap);
assertEquals(3, pMap.size());
for (int i = 0; i < 3; i++) {
@ -188,6 +170,7 @@ public class JiraTest extends XmlRpcTestCase {
}
}
@SuppressWarnings("unchecked")
private void testXMLRPC89Properties(ClientProvider pProvider) throws Exception {
Properties values = new Properties();
for (int i = 0; i < 3; i++) {
@ -195,19 +178,20 @@ public class JiraTest extends XmlRpcTestCase {
}
XmlRpcClient client = pProvider.getClient();
client.setConfig(getConfig(pProvider));
Object res = client.execute(XMLRPC89Handler.class.getName() + ".doubledPropertyValues", new Object[]{values});
verifyXMLRPC89Properties((Map) res);
Map<Object, Object> res = (Map<Object, Object>) client.execute(XMLRPC89Handler.class.getName() + ".doubledPropertyValues", new Object[]{values});
verifyXMLRPC89Properties(res);
ClientFactory factory = new ClientFactory(client);
XMLRPC89Handler handler = (XMLRPC89Handler) factory.newInstance(XMLRPC89Handler.class);
Properties result = handler.doubledPropertyValues(values);
verifyXMLRPC89Properties(result);
}
/** Handler for XMLRPC-96
/**
* Handler for XMLRPC-96
*/
public static class XMLRPC96Handler {
/** Returns the "Hello, world!" string.
/**
* Returns the "Hello, world!" string.
*/
public String getHelloWorld() {
return "Hello, world!";
@ -219,8 +203,8 @@ public class JiraTest extends XmlRpcTestCase {
* XMLRPC-96</a>
*/
public void testXMLRPC96() throws Exception {
for (int i = 0; i < providers.length; i++) {
testXMLRPC96(providers[i]);
for (ClientProvider provider : providers) {
testXMLRPC96(provider);
}
}
@ -238,8 +222,8 @@ public class JiraTest extends XmlRpcTestCase {
* XMLRPC-112</a>
*/
public void testXMLRPC112() throws Exception {
for (int i = 0; i < providers.length; i++) {
testXMLRPC112(providers[i]);
for (ClientProvider provider : providers) {
testXMLRPC112(provider);
}
}
@ -248,8 +232,8 @@ public class JiraTest extends XmlRpcTestCase {
* XMLRPC-113</a>
*/
public void testXMLRPC113() throws Exception {
for (int i = 0; i < providers.length; i++) {
testXMLRPC113(providers[i]);
for (ClientProvider provider : providers) {
testXMLRPC113(provider);
}
}
@ -306,7 +290,7 @@ public class JiraTest extends XmlRpcTestCase {
XMLRPC113Handler handler = (XMLRPC113Handler) new ClientFactory(client).newInstance(XMLRPC113Handler.class);
for (int i = 0; i < 5; i++) {
try {
client.execute(XMLRPC113Handler.class.getName() + ".throwCode", new Object[]{new Integer(i)});
client.execute(XMLRPC113Handler.class.getName() + ".throwCode", new Object[] { i });
fail("Excpected exception");
} catch (XmlRpcException e) {
assertEquals(i, e.code);
@ -336,8 +320,8 @@ public class JiraTest extends XmlRpcTestCase {
* XMLRPC-115</a>
*/
public void testXMLRPC115() throws Exception {
for (int i = 0; i < providers.length; i++) {
testXMLRPC115(providers[i]);
for (ClientProvider provider : providers) {
testXMLRPC115(provider);
}
}
@ -352,7 +336,7 @@ public class JiraTest extends XmlRpcTestCase {
conn.setRequestMethod("POST");
conn.setRequestProperty("content-type", "text/xml");
OutputStream ostream = conn.getOutputStream();
Writer w = new OutputStreamWriter(ostream, "UTF-8");
Writer w = new OutputStreamWriter(ostream, StandardCharsets.UTF_8);
w.write("<methodCall><methodName>" + XMLRPC115Handler.class.getName() + ".ping"
+ "</methodName></methodCall>");
w.close();
@ -372,8 +356,8 @@ public class JiraTest extends XmlRpcTestCase {
* XMLRPC-119</a>
*/
public void testXMLRPC119() throws Exception {
for (int i = 0; i < providers.length; i++) {
testXMLRPC119(providers[i]);
for (ClientProvider provider : providers) {
testXMLRPC119(provider);
}
}
@ -383,7 +367,7 @@ public class JiraTest extends XmlRpcTestCase {
/** Returns a string with a length of "num" Kilobytes.
*/
public String getString(int pSize) {
StringBuffer sb = new StringBuffer(pSize*1024);
StringBuilder sb = new StringBuilder(pSize*1024);
for (int i = 0; i < pSize*1024; i++) {
sb.append('&');
}
@ -395,7 +379,8 @@ public class JiraTest extends XmlRpcTestCase {
XmlRpcClient client = pProvider.getClient();
client.setConfig(getConfig(pProvider));
for (int i = 0; i < 100; i+= 10) {
String s = (String) client.execute(XMLRPC119Handler.class.getName() + ".getString", new Object[]{new Integer(i)});
String s = (String) client.execute(XMLRPC119Handler.class.getName() + ".getString",
new Object[] { i });
assertEquals(i*1024, s.length());
}
}

View file

@ -1,31 +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 org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcLiteHttpTransportFactory;
import org.apache.xmlrpc.client.XmlRpcTransportFactory;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
import org.xbib.netty.http.xmlrpc.client.XmlRpcLiteHttpTransport;
import org.xbib.netty.http.xmlrpc.client.XmlRpcLiteHttpTransportFactory;
import org.xbib.netty.http.xmlrpc.client.XmlRpcTransportFactory;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
/** Provider for testing the
* {@link org.apache.xmlrpc.client.XmlRpcLiteHttpTransport}.
* {@link XmlRpcLiteHttpTransport}.
*/
public class LiteTransportProvider extends WebServerProvider {
/** Creates a new instance.

View file

@ -1,33 +1,15 @@
/*
* 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.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcLocalStreamTransportFactory;
import org.apache.xmlrpc.client.XmlRpcTransportFactory;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcLocalStreamServer;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
import org.xbib.netty.http.xmlrpc.client.XmlRpcLocalStreamTransport;
import org.xbib.netty.http.xmlrpc.client.XmlRpcLocalStreamTransportFactory;
import org.xbib.netty.http.xmlrpc.client.XmlRpcTransportFactory;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xbib.netty.http.xmlrpc.server.XmlRpcLocalStreamServer;
import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
/** Implementation of {@link org.apache.xmlrpc.test.BaseTest}
* for testing the {@link org.apache.xmlrpc.client.XmlRpcLocalStreamTransport}.
/** Implementation of {@link BaseTest}
* for testing the {@link XmlRpcLocalStreamTransport}.
*/
public class LocalStreamTransportProvider extends LocalTransportProvider {
private XmlRpcLocalStreamServer server;

View file

@ -1,33 +1,16 @@
/*
* 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.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcLocalTransportFactory;
import org.apache.xmlrpc.client.XmlRpcTransportFactory;
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.XmlRpcLocalTransport;
import org.xbib.netty.http.xmlrpc.client.XmlRpcLocalTransportFactory;
import org.xbib.netty.http.xmlrpc.client.XmlRpcTransportFactory;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
/** Implementation of {@link org.apache.xmlrpc.test.BaseTest}
* for testing the {@link org.apache.xmlrpc.client.XmlRpcLocalTransport}.
/**
* Implementation of {@link BaseTest}
* for testing the {@link XmlRpcLocalTransport}.
*/
public class LocalTransportProvider extends ClientProviderImpl {
private XmlRpcServer server;

View file

@ -1,42 +1,23 @@
/*
* 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.xbib.netty.http.xmlrpc.client.XmlRpcClient;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfig;
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
import org.xbib.netty.http.xmlrpc.server.PropertyHandlerMapping;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xbib.netty.http.xmlrpc.server.XmlRpcSystemImpl;
import java.text.Collator;
import java.util.Arrays;
import java.util.Locale;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfig;
import org.apache.xmlrpc.metadata.XmlRpcSystemImpl;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
/**
* Test class for the introspection stuff.
*/
public class MetadataTest extends XmlRpcTestCase {
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
XmlRpcException {
@Override
protected XmlRpcHandlerMapping getHandlerMapping() throws XmlRpcException {
PropertyHandlerMapping mapping = new PropertyHandlerMapping();
mapping.addHandler("Adder", AuthenticationTest.AdderImpl.class);
XmlRpcSystemImpl.addSystemHandler(mapping);
@ -47,8 +28,8 @@ public class MetadataTest extends XmlRpcTestCase {
* Test, whether the actual handlers are working.
*/
public void testAdder() throws Exception {
for (int i = 0; i < providers.length; i++) {
testAdder(providers[i]);
for (ClientProvider provider : providers) {
testAdder(provider);
}
}
@ -56,16 +37,16 @@ public class MetadataTest extends XmlRpcTestCase {
XmlRpcClient client = pProvider.getClient();
XmlRpcClientConfig config = getConfig(pProvider);
client.setConfig(config);
Object o = client.execute("Adder.add", new Object[]{new Integer(3), new Integer(5)});
assertEquals(new Integer(8), o);
Object o = client.execute("Adder.add", new Object[]{3, 5});
assertEquals(8, o);
}
/**
* Test for system.listMethods.
*/
public void testListMethods() throws Exception {
for (int i = 0; i < providers.length; i++) {
testListMethods(providers[i]);
for (ClientProvider provider : providers) {
testListMethods(provider);
}
}
@ -87,8 +68,8 @@ public class MetadataTest extends XmlRpcTestCase {
* Test for system.methodHelp.
*/
public void testMethodHelp() throws Exception {
for (int i = 0; i < providers.length; i++) {
testMethodHelp(providers[i]);
for (ClientProvider provider : providers) {
testMethodHelp(provider);
}
}
@ -97,15 +78,15 @@ public class MetadataTest extends XmlRpcTestCase {
XmlRpcClientConfig config = getConfig(pProvider);
client.setConfig(config);
String help = (String) client.execute("system.methodHelp", new Object[]{"Adder.add"});
assertEquals("Invokes the method org.apache.xmlrpc.test.AuthenticationTest$AdderImpl.add(int, int).", help);
assertEquals("Invokes the method org.xbib.netty.http.xmlrpc.client.test.AuthenticationTest$AdderImpl.add(int, int).", help);
}
/**
* Test for system.methodSignature.
*/
public void testMethodSignature() throws Exception {
for (int i = 0; i < providers.length; i++) {
testMethodSignature(providers[i]);
for (ClientProvider provider : providers) {
testMethodSignature(provider);
}
}

View file

@ -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,17 +8,17 @@ import java.util.TimeZone;
import junit.framework.TestCase;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.apache.xmlrpc.parser.DateParser;
import org.apache.xmlrpc.parser.XmlRpcRequestParser;
import org.apache.xmlrpc.parser.XmlRpcResponseParser;
import org.apache.xmlrpc.util.SAXParsers;
import org.apache.xmlrpc.util.XmlRpcDateTimeFormat;
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.XmlRpcHttpRequestConfigImpl;
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamConfig;
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.xbib.netty.http.xmlrpc.common.parser.DateParser;
import org.xbib.netty.http.xmlrpc.common.parser.XmlRpcRequestParser;
import org.xbib.netty.http.xmlrpc.common.parser.XmlRpcResponseParser;
import org.xbib.netty.http.xmlrpc.common.util.SAXParsers;
import org.xbib.netty.http.xmlrpc.common.util.XmlRpcDateTimeFormat;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

View file

@ -1,45 +1,31 @@
/*
* 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 java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
import org.apache.xmlrpc.util.ThreadPool;
import org.apache.xmlrpc.webserver.ServletWebServer;
import org.apache.xmlrpc.webserver.WebServer;
import org.apache.xmlrpc.webserver.XmlRpcServlet;
import junit.framework.TestCase;
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.server.PropertyHandlerMapping;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xbib.netty.http.xmlrpc.servlet.ServletWebServer;
import org.xbib.netty.http.xmlrpc.servlet.ThreadPool;
import org.xbib.netty.http.xmlrpc.servlet.WebServer;
import org.xbib.netty.http.xmlrpc.servlet.XmlRpcServlet;
/**
* Tests the frameworks scalability.
*/
public class ScalabilityTest extends TestCase {
private static final Logger logger = Logger.getLogger(ScalabilityTest.class.getName());
/**
* Primitive handler class
*/
@ -52,43 +38,18 @@ public class ScalabilityTest extends TestCase {
}
}
private class MyServletWebServer extends ServletWebServer {
protected ThreadPool pool;
MyServletWebServer(HttpServlet pServlet, int pPort)
throws ServletException {
super(pServlet, pPort);
}
public ThreadPool newThreadPool(){
pool = new ThreadPool(getXmlRpcServer().getMaxThreads(), "XML-RPC"){
};
return pool;
}
int getNumThreads() {
return pool.getNumThreads();
}
}
private class MyWebServer extends WebServer {
protected ThreadPool pool;
MyWebServer(int pPort) {
super(pPort);
}
public ThreadPool newThreadPool(){
pool = new ThreadPool(getXmlRpcServer().getMaxThreads(), "XML-RPC"){
};
return pool;
}
int getNumThreads() {
return pool.getNumThreads();
}
}
private static final int BASE = 1;
private static final Integer THREE = new Integer(3);
private static final Integer FIVE = new Integer(5);
private static final Integer EIGHT = new Integer(8);
private static final Integer THREE = 3;
private static final Integer FIVE = 5;
private static final Integer EIGHT = 8;
private XmlRpcServlet servlet;
private MyServletWebServer server;
private MyWebServer webServer;
private XmlRpcHandlerMapping newXmlRpcHandlerMapping() throws XmlRpcException {
@ -99,49 +60,47 @@ public class ScalabilityTest extends TestCase {
private void initServletWebServer() throws Exception {
servlet = new XmlRpcServlet() {
private static final long serialVersionUID = -2040521497373327817L;
protected XmlRpcHandlerMapping newXmlRpcHandlerMapping()
throws XmlRpcException {
@Override
protected XmlRpcHandlerMapping newXmlRpcHandlerMapping() throws XmlRpcException {
return ScalabilityTest.this.newXmlRpcHandlerMapping();
}
};
server = new MyServletWebServer(servlet, 0);
server = new MyServletWebServer(servlet, 8080);
server.getXmlRpcServer().setMaxThreads(25);
server.start();
}
private void shutdownServletWebServer() {
private void shutdownServletWebServer() throws IOException {
server.shutdown();
}
private void initWebServer() throws Exception {
webServer = new MyWebServer(0);
webServer = new MyWebServer(8080);
webServer.getXmlRpcServer().setHandlerMapping(newXmlRpcHandlerMapping());
webServer.getXmlRpcServer().setMaxThreads(25);
webServer.start();
}
private void shutdownWebServer() {
private void shutdownWebServer() throws IOException {
webServer.shutdown();
}
/**
* Runs the test with a single client.
* Runs the servlet test with a single client.
*/
public void testSingleClient() throws Exception {
public void testSingleServletClient() throws Exception {
initServletWebServer();
boolean ok = false;
try {
long now = System.currentTimeMillis();
servlet.getXmlRpcServletServer().setMaxThreads(1);
new Client(100*BASE, server.getPort()).run();
System.out.println("Single client: " + (System.currentTimeMillis()-now) + ", " + server.getNumThreads());
shutdownServletWebServer();
ok = true;
new MyClient(100 * BASE, server.getPort()).run();
logger.log(Level.INFO,
"Single servlet client: " + (System.currentTimeMillis() - now) + ", " + server.getNumThreads());
} finally {
if (!ok) { try { shutdownServletWebServer(); } catch (Throwable t) {} }
shutdownServletWebServer();
}
}
@ -150,38 +109,14 @@ public class ScalabilityTest extends TestCase {
*/
public void testSingleWebServerClient() throws Exception {
initWebServer();
boolean ok = false;
try {
long now = System.currentTimeMillis();
webServer.getXmlRpcServer().setMaxThreads(1);
new Client(100*BASE, webServer.getPort()).run();
System.out.println("Single client: " + (System.currentTimeMillis()-now) + ", " + webServer.getNumThreads());
shutdownWebServer();
ok = true;
new MyClient(100 * BASE, webServer.getPort()).run();
logger.log(Level.INFO,
"Single web server client: " + (System.currentTimeMillis( ) -now) + ", " + webServer.getNumThreads());
} finally {
if (!ok) { try { shutdownWebServer(); } catch (Throwable t) {} }
}
}
private static class Client implements Runnable {
private final int iterations;
private final int port;
Client(int pIterations, int pPort) {
iterations = pIterations;
port = pPort;
}
public void run() {
try {
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:" + port + "/"));
client.setConfig(config);
for (int i = 0; i < iterations; i++) {
assertEquals(EIGHT, client.execute("Adder.add", new Object[]{THREE, FIVE}));
}
} catch (Throwable t) {
t.printStackTrace();
}
shutdownWebServer();
}
}
@ -190,23 +125,90 @@ public class ScalabilityTest extends TestCase {
*/
public void testTenClient() throws Exception {
initServletWebServer();
boolean ok = false;
try {
final Thread[] threads = new Thread[10];
servlet.getXmlRpcServletServer().setMaxThreads(10);
long now = System.currentTimeMillis();
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(new Client(10*BASE, server.getPort()));
threads[i] = new Thread(new MyClient(10 * BASE, server.getPort()));
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
for (Thread thread : threads) {
thread.join();
}
System.out.println("Ten clients: " + (System.currentTimeMillis() - now) + ", " + server.getNumThreads());
logger.log(Level.INFO, "Ten clients: " + (System.currentTimeMillis() - now) + ", " + server.getNumThreads());
shutdownServletWebServer();
ok = false;
} finally {
if (!ok) { try { shutdownServletWebServer(); } catch (Throwable t) {} }
shutdownServletWebServer();
}
}
private static class MyClient implements Runnable {
private final int iterations;
private final int port;
MyClient(int pIterations, int pPort) {
iterations = pIterations;
port = pPort;
}
@Override
public void run() {
int i = 0;
try {
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://localhost:" + port + "/"));
client.setConfig(config);
for (i = 0; i < iterations; i++) {
assertEquals(EIGHT, client.execute("Adder.add", new Object[] {
THREE, FIVE
}));
}
} catch (Throwable t) {
throw new RuntimeException("i=" + i, t);
}
}
}
private class MyServletWebServer extends ServletWebServer {
ThreadPool pool;
MyServletWebServer(HttpServlet pServlet, int pPort) throws ServletException {
super(pServlet, pPort);
}
@Override
public ThreadPool newThreadPool(){
pool = new ThreadPool(getXmlRpcServer().getMaxThreads(), "XML-RPC");
return pool;
}
int getNumThreads() {
return pool.getNumThreads();
}
}
private class MyWebServer extends WebServer {
ThreadPool pool;
MyWebServer(int pPort) {
super(pPort);
}
@Override
public ThreadPool newThreadPool(){
pool = new ThreadPool(getXmlRpcServer().getMaxThreads(), "XML-RPC");
return pool;
}
int getNumThreads() {
return pool.getNumThreads();
}
}
}

View file

@ -3,6 +3,7 @@ package org.xbib.netty.http.xmlrpc.client.test;
import java.io.StringReader;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
@ -26,9 +27,6 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** A test case for the various serializers.
*/
public class SerializerTest extends TestCase {
@ -63,7 +61,7 @@ public class SerializerTest extends TestCase {
*/
public void testByteParam() throws Exception {
XmlRpcStreamRequestConfig config = getExConfig();
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteParam", new Object[]{new Byte((byte)3)});
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteParam", new Object[] { (byte) 3} );
String got = writeRequest(config, request);
String expect =
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
@ -77,7 +75,7 @@ public class SerializerTest extends TestCase {
*/
public void testIntParam() throws Exception {
XmlRpcStreamRequestConfig config = getConfig();
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "intParam", new Object[]{new Integer(3)});
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "intParam", new Object[] { 3 } );
String got = writeRequest(config, request);
String expect =
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
@ -105,19 +103,18 @@ public class SerializerTest extends TestCase {
* @throws Exception The test failed.
*/
public void testMapParam() throws Exception {
final Map map = new HashMap();
map.put("2", new Integer(3));
map.put("3", new Integer(5));
final Map<String, Integer> map = new LinkedHashMap<>();
map.put("2", 3);
map.put("3", 5);
final Object[] params = new Object[]{map};
XmlRpcStreamRequestConfig config = getConfig();
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "mapParam", params);
String got = writeRequest(config, request);
String expect =
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
String expect = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
+ "<methodCall><methodName>mapParam</methodName>"
+ "<params><param><value><struct>"
+ "<member><name>3</name><value><i4>5</i4></value></member>"
+ "<member><name>2</name><value><i4>3</i4></value></member>"
+ "<member><name>3</name><value><i4>5</i4></value></member>"
+ "</struct></value></param></params></methodCall>";
assertEquals(expect, got);
}
@ -149,9 +146,10 @@ public class SerializerTest extends TestCase {
* Test for XMLRPC-127: Is it possible to transmit a
* map with integers as the keys?
*/
@SuppressWarnings("unchecked")
public void testIntegerKeyMap() throws Exception {
Map map = new HashMap();
map.put(new Integer(1), "one");
Map<Integer, String> map = new HashMap<>();
map.put(1, "one");
XmlRpcStreamRequestConfig config = getExConfig();
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "integerKeyMap", new Object[]{map});
String got = writeRequest(config, request);
@ -165,7 +163,6 @@ public class SerializerTest extends TestCase {
+ "</struct></value></param>"
+ "</params></methodCall>";
assertEquals(expect, got);
XmlRpcServer server = new XmlRpcServer();
XmlRpcServerConfigImpl serverConfig = new XmlRpcServerConfigImpl();
serverConfig.setEnabledForExtensions(true);
@ -178,10 +175,10 @@ public class SerializerTest extends TestCase {
xr.setContentHandler(parser);
xr.parse(new InputSource(new StringReader(expect)));
assertEquals("integerKeyMap", parser.getMethodName());
List params = parser.getParams();
List<Object> params = parser.getParams();
assertEquals(1, params.size());
Map paramMap = (Map) params.get(0);
Map<Object, Object> paramMap = (Map) params.get(0);
assertEquals(1, paramMap.size());
assertEquals("one", paramMap.get(new Integer(1)));
assertEquals("one", paramMap.get(1));
}
}

View file

@ -18,10 +18,14 @@ import java.net.URL;
* A provider class for testing the {@link ServletWebServer}.
*/
public class ServletWebServerProvider extends ClientProviderImpl {
protected final ServletWebServer webServer;
protected final XmlRpcServlet servlet;
private final boolean contentLength;
private final int port;
private int port;
/**
* Creates a new instance of {@link XmlRpcServlet}.
@ -40,6 +44,7 @@ public class ServletWebServerProvider extends ClientProviderImpl {
contentLength = pContentLength;
servlet = newXmlRpcServlet();
webServer = new ServletWebServer(servlet, 0);
try {
XmlRpcServer server = servlet.getXmlRpcServletServer();
server.setHandlerMapping(mapping);
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
@ -48,10 +53,13 @@ public class ServletWebServerProvider extends ClientProviderImpl {
serverConfig.setEnabledForExceptions(true);
webServer.start();
port = webServer.getPort();
} catch (Exception e) {
webServer.shutdown();
}
}
public final XmlRpcClientConfigImpl getConfig() throws Exception {
return getConfig(new URL("http://127.0.0.1:" + port + "/"));
return getConfig(new URL("http://localhost:" + port + "/"));
}
protected XmlRpcClientConfigImpl getConfig(URL pServerURL) throws Exception {
@ -69,7 +77,7 @@ public class ServletWebServerProvider extends ClientProviderImpl {
return servlet.getXmlRpcServletServer();
}
public void shutdown() {
public void shutdown() throws IOException {
webServer.shutdown();
}
}

View file

@ -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.XmlRpcSunHttpTransport;
import org.xbib.netty.http.xmlrpc.client.XmlRpcSunHttpTransportFactory;
import org.xbib.netty.http.xmlrpc.client.XmlRpcTransportFactory;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;

View file

@ -6,26 +6,28 @@ import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
import org.xbib.netty.http.xmlrpc.server.XmlRpcServerConfigImpl;
import org.xbib.netty.http.xmlrpc.servlet.WebServer;
import java.io.IOException;
import java.net.URL;
/** Abstract base class for providers, which require a webserver.
*/
public abstract class WebServerProvider extends ClientProviderImpl {
protected final WebServer webServer = new WebServer(0);
private boolean isActive;
private WebServer webServer;
private final boolean contentLength;
/** Creates a new instance.
* @param pMapping The test servers handler mapping.
*/
protected WebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
WebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
super(pMapping);
contentLength = pContentLength;
}
public final XmlRpcClientConfigImpl getConfig() throws Exception {
initWebServer();
return getConfig(new URL("http://127.0.0.1:" + webServer.getPort() + "/"));
return getConfig(new URL("http://localhost:" + webServer.getPort() + "/"));
}
protected XmlRpcClientConfigImpl getConfig(URL pServerURL) throws Exception {
@ -35,8 +37,9 @@ public abstract class WebServerProvider extends ClientProviderImpl {
return config;
}
protected void initWebServer() throws Exception {
if (!isActive) {
private void initWebServer() throws Exception {
if (webServer == null || webServer.isShutDown()) {
webServer = new WebServer(0);
XmlRpcServer server = webServer.getXmlRpcServer();
server.setHandlerMapping(mapping);
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
@ -44,15 +47,16 @@ public abstract class WebServerProvider extends ClientProviderImpl {
serverConfig.setContentLengthOptional(!contentLength);
serverConfig.setEnabledForExceptions(true);
webServer.start();
isActive = true;
}
}
@Override
public XmlRpcServer getServer() {
return webServer.getXmlRpcServer();
}
public void shutdown() {
@Override
public void shutdown() throws IOException {
webServer.shutdown();
}
}

View file

@ -3,6 +3,7 @@ package org.xbib.netty.http.xmlrpc.client.test;
import java.io.IOException;
import java.io.StringWriter;
import junit.framework.TestCase;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfig;
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfigImpl;
@ -18,6 +19,8 @@ import org.xbib.netty.http.xmlrpc.server.PropertyHandlerMapping;
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
import org.xml.sax.SAXException;
import javax.servlet.ServletException;
/**
* Abstract base class for deriving test cases.
*/
@ -31,14 +34,14 @@ public abstract class XmlRpcTestCase extends TestCase {
return pProvider.getConfig();
}
protected XmlRpcClientConfig getExConfig(ClientProvider pProvider) throws Exception {
XmlRpcClientConfig getExConfig(ClientProvider pProvider) throws Exception {
XmlRpcClientConfigImpl config = getConfig(pProvider);
config.setEnabledForExtensions(true);
config.setEnabledForExceptions(true);
return config;
}
protected XmlRpcHandlerMapping getHandlerMapping(String pResource) throws IOException, XmlRpcException {
XmlRpcHandlerMapping getHandlerMapping(String pResource) throws IOException, XmlRpcException {
PropertyHandlerMapping mapping = new PropertyHandlerMapping();
mapping.setVoidMethodEnabled(true);
mapping.load(getClass().getClassLoader(), getClass().getResource(pResource));
@ -49,27 +52,29 @@ public abstract class XmlRpcTestCase extends TestCase {
protected ClientProvider[] initProviders(XmlRpcHandlerMapping pMapping) throws ServletException, IOException {
return new ClientProvider[]{
new LocalTransportProvider(pMapping),
new LocalStreamTransportProvider(pMapping),
new LiteTransportProvider(pMapping, true),
// new LiteTransportProvider(mapping, false), Doesn't support HTTP/1.1
new SunHttpTransportProvider(pMapping, true),
new SunHttpTransportProvider(pMapping, false),
new CommonsProvider(pMapping),
new ServletWebServerProvider(pMapping, true),
new ServletWebServerProvider(pMapping, false)
//new LocalStreamTransportProvider(pMapping),
//new LiteTransportProvider(pMapping, true),
//// new LiteTransportProvider(mapping, false), Doesn't support HTTP/1.1
//new SunHttpTransportProvider(pMapping, true),
//new SunHttpTransportProvider(pMapping, false),
//new CommonsProvider(pMapping),
//new ServletWebServerProvider(pMapping, true),
//new ServletWebServerProvider(pMapping, false)
};
}
@Override
public void setUp() throws Exception {
if (providers == null) {
providers = initProviders(getHandlerMapping());
}
}
public void tearDown() throws Exception {
@Override
public void tearDown() throws IOException {
if (providers != null) {
for (int i = 0; i < providers.length; i++) {
providers[i].shutdown();
for (ClientProvider provider : providers) {
provider.shutdown();
}
}
}

View file

@ -0,0 +1,5 @@
handlers = java.util.logging.ConsoleHandler
.level = FINE
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %1$tFT%1$tT.%1$tL%1$tz [%4$-11s] [%3$s] %5$s %6$s%n

View file

@ -0,0 +1 @@
org.xbib.netty.http.xmlrpc.client.test.AuthenticationTest$Adder=org.xbib.netty.http.xmlrpc.client.test.AuthenticationTest$AdderImpl

View file

@ -0,0 +1 @@
Remote=org.xbib.netty.http.xmlrpc.client.test.BaseTest$Remote

View file

@ -0,0 +1 @@
org.xbib.netty.http.xmlrpc.client.test.DynamicProxyTest$Adder=org.xbib.netty.http.xmlrpc.client.test.DynamicProxyTest$AdderImpl

View file

@ -0,0 +1,5 @@
org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC89Handler=org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC89HandlerImpl
org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC96Handler=org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC96Handler
org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC113Handler=org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC113HandlerImpl
org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC115Handler=org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC115Handler
org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC119Handler=org.xbib.netty.http.xmlrpc.client.test.JiraTest$XMLRPC119Handler

View file

@ -0,0 +1 @@
Remote=org.xbib.netty.http.xmlrpc.client.test.BaseTest$Remote

View file

@ -8,19 +8,20 @@ import java.util.logging.Logger;
* error logging.
*/
public class XmlRpcErrorLogger {
private static final Logger log = Logger.getLogger(XmlRpcErrorLogger.class.getName());
/**
* Called to log the given error.
*/
public void log(String pMessage, Throwable pThrowable) {
log.log(Level.SEVERE, pMessage, pThrowable);
log.log(Level.INFO, pMessage, pThrowable);
}
/**
* Called to log the given error message.
*/
public void log(String pMessage) {
log.log(Level.SEVERE, pMessage);
log.log(Level.INFO, pMessage);
}
}

View file

@ -5,8 +5,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@ -34,8 +32,6 @@ import org.xml.sax.XMLReader;
public abstract class XmlRpcStreamServer extends XmlRpcServer
implements XmlRpcStreamRequestProcessor {
private static final Logger log = Logger.getLogger(XmlRpcStreamServer.class.getName());
private XmlWriterFactory writerFactory = new DefaultXMLWriterFactory();
private static final XmlRpcErrorLogger theErrorLogger = new XmlRpcErrorLogger();
@ -173,17 +169,16 @@ public abstract class XmlRpcStreamServer extends XmlRpcServer
return false;
}
/** Returns, whether the
/** Processes a "connection". The "connection" is an opaque object, which is
/**
* Processes a "connection". The "connection" is an opaque object, which is
* being handled by the subclasses.
* @param pConfig The request configuration.
* @param pConnection The "connection" being processed.
* @throws XmlRpcException Processing the request failed.
*/
public void execute(XmlRpcStreamRequestConfig pConfig,
ServerStreamConnection pConnection)
@Override
public void execute(XmlRpcStreamRequestConfig pConfig, ServerStreamConnection pConnection)
throws XmlRpcException {
log.log(Level.FINE, "execute: ->");
try {
Object result;
Throwable error;
@ -195,13 +190,18 @@ public abstract class XmlRpcStreamServer extends XmlRpcServer
istream.close();
istream = null;
error = null;
log.log(Level.FINE, "execute: Request performed successfully");
} catch (Throwable t) {
logError(t);
result = null;
error = t;
} finally {
if (istream != null) { try { istream.close(); } catch (Throwable ignore) {} }
if (istream != null) {
try {
istream.close();
} catch (Throwable ignore) {
//
}
}
}
boolean contentLengthRequired = isContentLengthRequired(pConfig);
ByteArrayOutputStream baos;
@ -223,7 +223,13 @@ public abstract class XmlRpcStreamServer extends XmlRpcServer
ostream.close();
ostream = null;
} finally {
if (ostream != null) { try { ostream.close(); } catch (Throwable ignore) {} }
if (ostream != null) {
try {
ostream.close();
} catch (Throwable ignore) {
}
}
}
if (baos != null) {
OutputStream dest = getOutputStream(pConfig, pConnection, baos.size());
@ -232,18 +238,27 @@ public abstract class XmlRpcStreamServer extends XmlRpcServer
dest.close();
dest = null;
} finally {
if (dest != null) { try { dest.close(); } catch (Throwable ignore) {} }
if (dest != null) {
try {
dest.close();
} catch (Throwable ignore) {
}
}
}
}
pConnection.close();
pConnection = null;
} catch (IOException e) {
throw new XmlRpcException("I/O error while processing request: "
+ e.getMessage(), e);
throw new XmlRpcException("I/O error while processing request: " + e.getMessage(), e);
} finally {
if (pConnection != null) { try { pConnection.close(); } catch (Throwable ignore) {} }
if (pConnection != null) {
try {
pConnection.close(); } catch (Throwable ignore) {
}
}
}
log.log(Level.FINE, "execute: <-");
}
protected void logError(Throwable t) {

View file

@ -14,30 +14,40 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
/** Handler for a single clients connection. This implementation
/**
* Handler for a single clients connection. This implementation
* is able to do HTTP keepalive. In other words, it can serve
* multiple requests via a single, physical connection.
*/
public class Connection implements ThreadPool.InterruptableTask, ServerStreamConnection {
private static final String US_ASCII = "US-ASCII";
private static final Logger logger = Logger.getLogger(Connection.class.getName());
private static final byte[] ctype = toHTTPBytes("Content-Type: text/xml\r\n");
private static final byte[] clength = toHTTPBytes("Content-Length: ");
private static final byte[] newline = toHTTPBytes("\r\n");
private static final byte[] doubleNewline = toHTTPBytes("\r\n\r\n");
private static final byte[] conkeep = toHTTPBytes("Connection: Keep-Alive\r\n");
private static final byte[] conclose = toHTTPBytes("Connection: close\r\n");
private static final byte[] ok = toHTTPBytes(" 200 OK\r\n");
private static final byte[] serverName = toHTTPBytes("Server: Apache XML-RPC 1.0\r\n");
private static final byte[] wwwAuthenticate = toHTTPBytes("WWW-Authenticate: Basic realm=XML-RPC\r\n");
private static abstract class RequestException extends IOException {
@ -48,6 +58,7 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
super(pMessage);
requestData = pData;
}
RequestData getRequestData() { return requestData; }
}
@ -109,10 +120,12 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
* Closing the input stream must not occur, because
* that would close the whole socket. So we suppress it.
*/
public void close() throws IOException {
@Override
public void close() {
}
};
output = new BufferedOutputStream(socket.getOutputStream());
headers = new LinkedHashMap<>();
}
/** Returns the connections request configuration by
@ -122,30 +135,24 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
*/
private RequestData getRequestConfig() throws IOException {
requestData = new RequestData(this);
if (headers != null) {
headers.clear();
}
firstByte = true;
XmlRpcHttpServerConfig serverConfig = (XmlRpcHttpServerConfig) server.getConfig();
requestData.setBasicEncoding(serverConfig.getBasicEncoding());
requestData.setContentLengthOptional(serverConfig.isContentLengthOptional());
requestData.setEnabledForExtensions(serverConfig.isEnabledForExtensions());
requestData.setEnabledForExceptions(serverConfig.isEnabledForExceptions());
// reset user authentication
String line = readLine();
if (line == null && firstByte) {
return null;
}
// Netscape sends an extra \n\r after bodypart, swallow it
if (line != null && line.length() == 0) {
line = readLine();
if (line == null || line.length() == 0) {
return null;
}
}
// tokenize first line of HTTP request
if (line != null) {
StringTokenizer tokens = new StringTokenizer(line);
String method = tokens.nextToken();
if (!"POST".equalsIgnoreCase(method)) {
@ -157,6 +164,7 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
requestData.setHttpVersion(httpVersion);
requestData.setKeepAlive(serverConfig.isKeepAliveEnabled()
&& WebServer.HTTP_11.equals(httpVersion));
}
do {
line = readLine();
if (line != null) {
@ -166,7 +174,7 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
requestData.setContentLength(Integer.parseInt(cLength.trim()));
} else if (lineLower.startsWith("connection:")) {
requestData.setKeepAlive(serverConfig.isKeepAliveEnabled()
&& lineLower.indexOf("keep-alive") > -1);
&& lineLower.contains("keep-alive"));
} else if (lineLower.startsWith("authorization:")) {
String credentials = line.substring("authorization:".length());
HttpUtil.parseAuthorization(requestData, credentials);
@ -180,13 +188,13 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
}
}
while (line != null && line.length() != 0);
return requestData;
}
@Override
public void run() {
try {
for (int i = 0; ; i++) {
while (true) {
RequestData data = getRequestConfig();
if (data == null) {
break;
@ -203,16 +211,28 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
writeErrorHeader(e.requestData, e, -1);
output.flush();
} catch (IOException e1) {
/* Ignore me */
logger.log(Level.WARNING, e1.getMessage(), e1);
}
} catch (Throwable t) {
if (!shuttingDown) {
webServer.log(t);
}
} finally {
try { output.close(); } catch (Throwable ignore) {}
try { input.close(); } catch (Throwable ignore) {}
try { socket.close(); } catch (Throwable ignore) {}
try {
output.close();
} catch (Throwable ignore) {
//
}
try {
input.close();
} catch (Throwable ignore) {
//
}
try {
socket.close();
} catch (Throwable ignore) {
//
}
}
}
@ -243,7 +263,7 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
throw new IOException("HTTP Header too long");
}
}
return new String(buffer, 0, count, US_ASCII);
return new String(buffer, 0, count, StandardCharsets.US_ASCII);
}
/** Writes the response header and the response to the
@ -365,12 +385,11 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
* Sets a response header value.
*/
public void setResponseHeader(String pHeader, String[] pValue) {
if (headers != null) {
headers.put(pHeader, pValue);
}
}
public OutputStream newOutputStream() throws IOException {
@Override
public OutputStream newOutputStream() {
boolean useContentLength;
useContentLength = !requestData.isEnabledForExtensions()
|| !((XmlRpcHttpRequestConfig) requestData).isContentLengthOptional();
@ -381,7 +400,8 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
}
}
public InputStream newInputStream() throws IOException {
@Override
public InputStream newInputStream() {
int contentLength = requestData.getContentLength();
if (contentLength == -1) {
return input;
@ -390,9 +410,11 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
}
}
public void close() throws IOException {
@Override
public void close() {
}
@Override
public void shutdown() throws Throwable {
shuttingDown = true;
socket.close();

View file

@ -131,19 +131,18 @@ public class HttpServletRequestImpl implements HttpServletRequest {
void readHttpHeaders() throws IOException {
byte[] buffer = new byte[2048];
String line = readLine(buffer);
StringTokenizer tokens =
line != null ? new StringTokenizer(line) : null;
StringTokenizer tokens = line != null ? new StringTokenizer(line) : null;
if (tokens == null || !tokens.hasMoreTokens()) {
throw new ServletWebServer.Exception(400, "Bad Request", "Unable to parse requests first line (should" +
throw new ServletWebServer.ServletWebServerException(400, "Bad Request", "Unable to parse requests first line (should" +
" be 'METHOD uri HTTP/version', was empty.");
}
method = tokens.nextToken();
if (!"POST".equalsIgnoreCase(method)) {
throw new ServletWebServer.Exception(400, "Bad Request", "Expected 'POST' method, got " +
throw new ServletWebServer.ServletWebServerException(400, "Bad Request", "Expected 'POST' method, got " +
method);
}
if (!tokens.hasMoreTokens()) {
throw new ServletWebServer.Exception(400, "Bad Request", "Unable to parse requests first line (should" +
throw new ServletWebServer.ServletWebServerException(400, "Bad Request", "Unable to parse requests first line (should" +
" be 'METHOD uri HTTP/version', was: " + line);
}
String u = tokens.nextToken();
@ -155,26 +154,23 @@ public class HttpServletRequestImpl implements HttpServletRequest {
uri = u;
queryString = null;
}
String httpVersion;
if (tokens.hasMoreTokens()) {
String v = tokens.nextToken().toUpperCase();
if (tokens.hasMoreTokens()) {
throw new ServletWebServer.Exception(400, "Bad Request", "Unable to parse requests first line (should" +
" be 'METHOD uri HTTP/version', was: " + line);
throw new ServletWebServer.ServletWebServerException(400, "Bad Request",
"Unable to parse requests first line (should" + " be 'METHOD uri HTTP/version', was: " + line);
} else {
int index = v.indexOf('/');
if (index == -1) {
throw new ServletWebServer.Exception(400, "Bad Request", "Unable to parse requests first line (should" +
" be 'METHOD uri HTTP/version', was: " + line);
throw new ServletWebServer.ServletWebServerException(400, "Bad Request",
"Unable to parse requests first line (should" + " be 'METHOD uri HTTP/version', was: " + line);
}
protocol = v.substring(0, index).toUpperCase();
httpVersion = v.substring(index + 1);
}
} else {
httpVersion = "1.0";
protocol = "HTTP";
}
for (;;) {
while (true) {
line = HttpUtil.readLine(istream, buffer);
if (line.length() == 0) {
break;
@ -183,8 +179,8 @@ public class HttpServletRequestImpl implements HttpServletRequest {
if (off > 0) {
addHeader(line.substring(0, off), line.substring(off + 1).trim());
} else {
throw new ServletWebServer.Exception(400, "Bad Request", "Unable to parse header line: " +
line);
throw new ServletWebServer.ServletWebServerException(400, "Bad Request",
"Unable to parse header line: " + line);
}
}
contentBytesRemaining = getIntHeader("content-length");
@ -196,7 +192,7 @@ public class HttpServletRequestImpl implements HttpServletRequest {
return null;
}
if (res == pBuffer.length && pBuffer[pBuffer.length - 1] != '\n') {
throw new ServletWebServer.Exception(400, "Bad Request",
throw new ServletWebServer.ServletWebServerException(400, "Bad Request",
"maximum header size of " + pBuffer.length + " characters exceeded");
}
return new String(pBuffer, 0, res, StandardCharsets.US_ASCII);
@ -242,7 +238,7 @@ public class HttpServletRequestImpl implements HttpServletRequest {
public String getHeader(String pHeader) {
String key = pHeader.toLowerCase();
String[] strings = headers.get(key);
return strings != null ? strings[0] : null;
return strings != null && strings.length > 0 ? strings[0] : null;
}
@Override
@ -253,7 +249,9 @@ public class HttpServletRequestImpl implements HttpServletRequest {
@Override
public Enumeration<String> getHeaders(String pHeader) {
String key = pHeader.toLowerCase();
return Collections.enumeration(Arrays.asList(headers.get(key)));
String[] values = headers.get(key);
return values != null && values.length > 0 ?
Collections.enumeration(Arrays.asList(values)) : Collections.emptyEnumeration();
}
@Override

View file

@ -28,8 +28,6 @@ public class HttpServletResponseImpl implements HttpServletResponse {
static final int BUFFER_SIZE = 8192;
private final Socket socket;
private final OutputStream ostream;
private final Map<String, String[]> headers = new HashMap<>();
@ -50,9 +48,8 @@ public class HttpServletResponseImpl implements HttpServletResponse {
* @param pSocket The clients socket.
* @throws IOException Accessing the sockets output stream failed.
*/
public HttpServletResponseImpl(Socket pSocket) throws IOException {
socket = pSocket;
ostream = socket.getOutputStream();
HttpServletResponseImpl(Socket pSocket) throws IOException {
ostream = pSocket.getOutputStream();
}
@Override
@ -79,7 +76,7 @@ public class HttpServletResponseImpl implements HttpServletResponse {
public String getHeader(String pHeader) {
String key = pHeader.toLowerCase();
String[] strings = headers.get(key);
return strings != null ? strings[0] : null;
return strings != null && strings.length > 0 ? strings[0] : null;
}
@Override
@ -125,8 +122,7 @@ public class HttpServletResponseImpl implements HttpServletResponse {
sendError(pStatusCode, pMessage, null);
}
protected void sendError(int pStatusCode, String pMessage, String pDescription)
throws IOException {
protected void sendError(int pStatusCode, String pMessage, String pDescription) throws IOException {
if (isCommitted()) {
throw new IllegalStateException("Can't send an error message, if the response has already been committed.");
}

View file

@ -5,15 +5,19 @@ import java.net.Socket;
import javax.servlet.http.HttpServlet;
/** {@link ServletWebServer ServletWebServer's}
* {@link ThreadPool.Task} for handling a single
/** {@link ServletWebServer ServletWebServer's} {@link Runnable} for handling a single
* servlet connection.
*/
public class ServletConnection implements ThreadPool.InterruptableTask {
private final HttpServlet servlet;
private final Socket socket;
private final HttpServletRequestImpl request;
private final HttpServletResponseImpl response;
private boolean shuttingDown;
/** Creates a new instance.
@ -21,11 +25,11 @@ public class ServletConnection implements ThreadPool.InterruptableTask {
* @param pSocket The socket, to which the client is connected.
* @throws IOException
*/
public ServletConnection(HttpServlet pServlet, Socket pSocket) throws IOException {
ServletConnection(HttpServlet pServlet, Socket pSocket) throws IOException {
servlet = pServlet;
socket = pSocket;
request = new HttpServletRequestImpl(socket);
response = new HttpServletResponseImpl(socket);
request = new HttpServletRequestImpl(pSocket);
response = new HttpServletResponseImpl(pSocket);
}
@Override
@ -40,6 +44,7 @@ public class ServletConnection implements ThreadPool.InterruptableTask {
}
}
@Override
public void shutdown() throws Throwable {
shuttingDown = true;
socket.close();

View file

@ -29,46 +29,12 @@ import javax.servlet.http.HttpServlet;
* <code>org/apache/xmlrpc/server/webserver/XmlRpcServlet.properties</code>.</p>
* <pre>
* final int port = 8088;
*
* XmlRpcServlet servlet = new XmlRpcServlet();
* ServletWebServer webServer = new ServletWebServer(servlet, port);
* webServer.start();
* </pre>
*/
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() {
@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<String> getInitParameterNames() {
return new Enumeration<String>(){
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; }
}
}

View file

@ -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,6 +13,7 @@ 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.
*/
@ -19,6 +22,8 @@ public class ThreadPool {
private class Poolable extends Thread implements Runnable {
private final Logger logger = Logger.getLogger(Poolable.class.getName());
private volatile boolean shuttingDown;
private Runnable task;
@ -48,6 +53,7 @@ public class ThreadPool {
resetTask();
repool(Poolable.this);
} catch (Throwable e) {
logger.log(Level.SEVERE, e.getMessage(), e);
remove(Poolable.this);
Poolable.this.shutdown();
resetTask();

View file

@ -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 {
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;
@ -111,6 +68,7 @@ public class WebServer implements Runnable {
// Inputs to setupServerSocket()
private InetAddress address;
private int port;
private boolean paranoid;
@ -132,6 +90,7 @@ public class WebServer implements Runnable {
public WebServer(int pPort, InetAddress pAddr) {
address = pAddr;
port = pPort;
webServerThread = new WebServerThread(this, "XML-RPC Weblistener");
}
/**
@ -161,38 +120,11 @@ public class WebServer implements Runnable {
* @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;
}
}
}
}
}
}
/**
@ -204,13 +136,8 @@ public class WebServer implements Runnable {
*/
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();
}
webServerThread.start();
}
/**
@ -269,13 +196,11 @@ public class WebServer implements Runnable {
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))
{
if (match.matches(addr)) {
return false;
}
}
@ -310,19 +235,17 @@ public class WebServer implements Runnable {
public void run() {
pool = newThreadPool();
try {
while (listener != null) {
try {
Socket socket = serverSocket.accept();
try {
socket.setTcpNoDelay(true);
} catch (SocketException socketOptEx) {
log(socketOptEx);
while (!webServerThread.closed) {
if (serverSocket.isClosed()) {
break;
}
Socket socket = null;
try {
socket = serverSocket.accept();
socket.setTcpNoDelay(true);
if (allowConnection(socket)) {
// set read timeout to 30 seconds
socket.setSoTimeout(30000);
// set read timeout to 1 seconds
socket.setSoTimeout(1000);
Runnable task = newTask(this, server, socket);
if (pool.startTask(task)) {
socket = null;
@ -331,27 +254,32 @@ public class WebServer implements Runnable {
+ " 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 (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) {
}
}
}
}
} finally {
if (serverSocket != null) {
pool.shutdown();
if (serverSocket != null && !serverSocket.isClosed()) {
try {
log("closing server socket");
serverSocket.close();
} catch (IOException e) {
log(e);
}
}
// Shutdown our Runner-based threads
pool.shutdown();
}
}
@ -360,35 +288,48 @@ public class WebServer implements Runnable {
}
/**
* Stop listening on the server port. Shutting down our {@link
* #listener} effectively breaks it out of its {@link #run()}
* loop.
* 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() {
// Stop accepting client connections
if (listener != null) {
Thread l = listener;
listener = null;
l.interrupt();
if (pool != null) {
pool.shutdown();
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) {
//
}
}
serverSocket = null;
try {
Thread.sleep(25L);
} catch (InterruptedException e) {
//
}
log("shutdown complete");
}
public boolean isShutDown() {
return serverSocket.isClosed();
}
/** 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(); }
public int getPort() {
return serverSocket.getLocalPort();
}
/** 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();
String msg = pError.getMessage() == null ? pError.getClass().getName() : pError.getMessage();
server.getErrorLogger().log(msg, pError);
}
@ -405,4 +346,51 @@ public class WebServer implements Runnable {
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;
}
}
}

View file

@ -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'