make XML-RPC tests compile and run under Java 8
This commit is contained in:
parent
81b1aad724
commit
61fdc04e9c
43 changed files with 1286 additions and 1437 deletions
|
@ -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')}"
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
}
|
|
@ -17,7 +17,9 @@ import org.xml.sax.SAXException;
|
|||
* {@link HttpURLConnection} class.
|
||||
*/
|
||||
public class XmlRpcSunHttpTransport extends XmlRpcHttpTransport {
|
||||
|
||||
private static final String userAgent = USER_AGENT + " (Sun HTTP Transport)";
|
||||
|
||||
private URLConnection conn;
|
||||
|
||||
/** Creates a new instance.
|
||||
|
@ -55,7 +57,7 @@ public class XmlRpcSunHttpTransport extends XmlRpcHttpTransport {
|
|||
getURLConnection().setRequestProperty(pHeader, pValue);
|
||||
}
|
||||
|
||||
protected void close() throws XmlRpcClientException {
|
||||
protected void close() {
|
||||
final URLConnection c = getURLConnection();
|
||||
if (c instanceof HttpURLConnection) {
|
||||
((HttpURLConnection) c).disconnect();
|
||||
|
@ -69,7 +71,7 @@ public class XmlRpcSunHttpTransport extends XmlRpcHttpTransport {
|
|||
protected InputStream getInputStream() throws XmlRpcException {
|
||||
try {
|
||||
URLConnection connection = getURLConnection();
|
||||
if ( connection instanceof HttpURLConnection ) {
|
||||
if (connection instanceof HttpURLConnection ) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||
int responseCode = httpConnection.getResponseCode();
|
||||
if (responseCode < 200 || responseCode > 299) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
user.agent=Apache XML RPC
|
|
@ -5,7 +5,6 @@ import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
|
|||
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfigImpl;
|
||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcHttpRequestConfig;
|
||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequestConfig;
|
||||
import org.xbib.netty.http.xmlrpc.server.AbstractReflectiveHandlerMapping;
|
||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
|
||||
|
@ -18,7 +17,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
* Test case for supported authentication variants.
|
||||
*/
|
||||
public class AuthenticationTest extends XmlRpcTestCase {
|
||||
|
||||
private static final String PASSWORD = "98765432109876543210987654321098765432109876543210";
|
||||
|
||||
private static final String USER_NAME = "01234567890123456789012345678901234567890123456789"
|
||||
+ "\u00C4\u00D6\u00DC\u00F6\u00FC\u00E4\u00DF";
|
||||
|
||||
|
@ -26,9 +27,11 @@ public class AuthenticationTest extends XmlRpcTestCase {
|
|||
* server.
|
||||
*/
|
||||
public interface Adder {
|
||||
/** Returns the sum of the given integers.
|
||||
|
||||
/**
|
||||
* Returns the sum of the given integers.
|
||||
*/
|
||||
public int add(int pNum1, int pNum2);
|
||||
int add(int pNum1, int pNum2);
|
||||
}
|
||||
|
||||
/** Implementation of {@link DynamicProxyTest.Adder}, which is used by
|
||||
|
@ -42,42 +45,33 @@ public class AuthenticationTest extends XmlRpcTestCase {
|
|||
|
||||
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
|
||||
XmlRpcHandlerMapping mapping = getHandlerMapping("AuthenticationTest.properties");
|
||||
((AbstractReflectiveHandlerMapping) mapping).setAuthenticationHandler(new AbstractReflectiveHandlerMapping.AuthenticationHandler(){
|
||||
public boolean isAuthorized(XmlRpcRequest pRequest)
|
||||
throws XmlRpcException {
|
||||
XmlRpcRequestConfig config = pRequest.getConfig();
|
||||
if (config instanceof XmlRpcHttpRequestConfig) {
|
||||
XmlRpcHttpRequestConfig httpRequestConfig = (XmlRpcHttpRequestConfig) config;
|
||||
return USER_NAME.equals(httpRequestConfig.getBasicUserName())
|
||||
&& PASSWORD.equals(httpRequestConfig.getBasicPassword());
|
||||
}
|
||||
return true;
|
||||
((AbstractReflectiveHandlerMapping) mapping).setAuthenticationHandler(pRequest -> {
|
||||
XmlRpcRequestConfig config = pRequest.getConfig();
|
||||
if (config instanceof XmlRpcHttpRequestConfig) {
|
||||
XmlRpcHttpRequestConfig httpRequestConfig = (XmlRpcHttpRequestConfig) config;
|
||||
return USER_NAME.equals(httpRequestConfig.getBasicUserName())
|
||||
&& PASSWORD.equals(httpRequestConfig.getBasicPassword());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return mapping;
|
||||
}
|
||||
|
||||
protected XmlRpcClientConfigImpl getConfig(ClientProvider pProvider)
|
||||
throws Exception {
|
||||
protected XmlRpcClientConfigImpl getConfig(ClientProvider pProvider) throws Exception {
|
||||
XmlRpcClientConfigImpl config = super.getConfig(pProvider);
|
||||
config.setBasicUserName(USER_NAME);
|
||||
config.setBasicPassword(PASSWORD);
|
||||
return config;
|
||||
}
|
||||
|
||||
private ClientFactory getClientFactory(ClientProvider pProvider) throws Exception {
|
||||
XmlRpcClient client = pProvider.getClient();
|
||||
client.setConfig(getConfig(pProvider));
|
||||
return new ClientFactory(client);
|
||||
}
|
||||
|
||||
/** Tests calling the {@link Adder#add(int,int)} method
|
||||
/** T
|
||||
* ests calling the {@link Adder#add(int,int)} method
|
||||
* by using an object, which has been created by the
|
||||
* {@link ClientFactory}.
|
||||
*/
|
||||
public void testAdderCall() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testAdderCall(providers[i]);
|
||||
for (ClientProvider provider : providers) {
|
||||
testAdderCall(provider);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,4 +80,11 @@ public class AuthenticationTest extends XmlRpcTestCase {
|
|||
Adder adder = (Adder) factory.newInstance(Adder.class);
|
||||
assertEquals(6, adder.add(2, 4));
|
||||
}
|
||||
|
||||
private ClientFactory getClientFactory(ClientProvider pProvider) throws Exception {
|
||||
XmlRpcClient client = pProvider.getClient();
|
||||
client.setConfig(getConfig(pProvider));
|
||||
return new ClientFactory(client);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,20 +589,20 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testByteArrayParam() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testByteArrayParam(providers[i]);
|
||||
for (ClientProvider provider : providers) {
|
||||
testByteArrayParam(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void testByteArrayParam(ClientProvider pProvider) throws Exception {
|
||||
final byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
final String methodName = "Remote.byteArrayParam";
|
||||
final Object[] params = new Object[]{bytes};
|
||||
final Object[] params = new Object[] { bytes };
|
||||
final XmlRpcClient client = pProvider.getClient();
|
||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
||||
assertEquals(new Integer(0+1+2+3+4+5+6+7+8+9), result);
|
||||
assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, result);
|
||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
||||
assertEquals(new Integer(0+1+2+3+4+5+6+7+8+9), result);
|
||||
assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, result);
|
||||
}
|
||||
|
||||
/** Test, whether we can invoke a method, returning a
|
||||
|
@ -636,15 +610,15 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testByteArrayResult() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testByteArrayResult(providers[i]);
|
||||
for (ClientProvider provider : providers) {
|
||||
testByteArrayResult(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void testByteArrayResult(ClientProvider pProvider) throws Exception {
|
||||
final byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
|
||||
final String methodName = "Remote.byteArrayResult";
|
||||
final Object[] params = new Object[]{new Integer(8)};
|
||||
final Object[] params = new Object[] { 8 };
|
||||
final XmlRpcClient client = pProvider.getClient();
|
||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
||||
assertTrue(Arrays.equals(bytes, (byte[]) result));
|
||||
|
@ -657,14 +631,13 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testObjectArrayParam() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testObjectArrayParam(providers[i]);
|
||||
for (ClientProvider provider : providers) {
|
||||
testObjectArrayParam(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void testObjectArrayParam(ClientProvider pProvider) throws Exception {
|
||||
final Object[] objects = new Object[]{new Byte((byte) 1), new Short((short) 2),
|
||||
new Integer(3), new Long(4), "5"};
|
||||
final Object[] objects = new Object[]{(byte) 1, (short) 2, 3, 4L, "5"};
|
||||
final String methodName = "Remote.objectArrayParam";
|
||||
final Object[] params = new Object[]{objects};
|
||||
final XmlRpcClient client = pProvider.getClient();
|
||||
|
@ -676,7 +649,7 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
}
|
||||
assertTrue(ok);
|
||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
||||
assertEquals(new Integer(15), result);
|
||||
assertEquals(15, result);
|
||||
}
|
||||
|
||||
/** Test, whether we can invoke a method, returning an
|
||||
|
@ -684,16 +657,15 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testObjectArrayResult() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testObjectArrayResult(providers[i]);
|
||||
for (ClientProvider provider : providers) {
|
||||
testObjectArrayResult(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void testObjectArrayResult(ClientProvider pProvider) throws Exception {
|
||||
final Object[] objects = new Object[]{new Integer(0), new Integer(1),
|
||||
new Integer(2), new Integer(3)};
|
||||
final Object[] objects = new Object[]{0, 1, 2, 3};
|
||||
final String methodName = "Remote.objectArrayResult";
|
||||
final Object[] params = new Object[]{new Integer(4)};
|
||||
final Object[] params = new Object[] { 4 };
|
||||
final XmlRpcClient client = pProvider.getClient();
|
||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
||||
assertTrue(Arrays.equals(objects, (Object[]) result));
|
||||
|
@ -705,49 +677,50 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testMapParam() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testMapParam(providers[i]);
|
||||
for (ClientProvider provider : providers) {
|
||||
testMapParam(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void testMapParam(ClientProvider pProvider) throws Exception {
|
||||
final Map map = new HashMap();
|
||||
map.put("2", new Integer(3));
|
||||
map.put("3", new Integer(5));
|
||||
final Map<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 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,43 +782,14 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
final Object[] params = new Object[]{new Remote.CalendarWrapper(cal)};
|
||||
final XmlRpcClient client = pProvider.getClient();
|
||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
||||
assertEquals(new Long(cal.getTime().getTime()), result);
|
||||
boolean ok = false;
|
||||
assertEquals(cal.getTime().getTime(), result);
|
||||
try {
|
||||
client.execute(getConfig(pProvider), methodName, params);
|
||||
} catch (XmlRpcExtensionException e) {
|
||||
ok = true;
|
||||
fail();
|
||||
}
|
||||
assertTrue(ok);
|
||||
}
|
||||
|
||||
/** Tests, whether we can invoke a method, passing an instance of
|
||||
* {@link Calendar} as a parameter.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testCalendarParam() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testCalendarParam(providers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void testCalendarParam(ClientProvider pProvider) throws Exception {
|
||||
final String methodName = "Remote.calendarParam";
|
||||
Calendar cal1 = newCalendarParam();
|
||||
Calendar cal2 = newCalendarResult();
|
||||
final Object[] params = new Object[]{cal1};
|
||||
final XmlRpcClient client = pProvider.getClient();
|
||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
||||
assertEquals(cal2.getTime(), ((Calendar) result).getTime());
|
||||
boolean ok = false;
|
||||
try {
|
||||
client.execute(getConfig(pProvider), methodName, params);
|
||||
} catch (XmlRpcExtensionException e) {
|
||||
ok = true;
|
||||
}
|
||||
assertTrue(ok);
|
||||
}
|
||||
|
||||
private Calendar newCalendarResult() {
|
||||
Calendar cal2 = Calendar.getInstance(TimeZone.getDefault());
|
||||
cal2.set(2005, 5, 24, 0, 0, 0);
|
||||
|
@ -865,9 +809,9 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testDateParam() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testDateParam(providers[i]);
|
||||
}
|
||||
for (ClientProvider provider : providers) {
|
||||
testDateParam(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void testDateParam(ClientProvider pProvider) throws Exception {
|
||||
|
@ -887,9 +831,9 @@ public class BaseTest extends XmlRpcTestCase {
|
|||
* trapped by the client.
|
||||
*/
|
||||
public void testCatchNPE() throws Exception {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
testCatchNPE(providers[i]);
|
||||
}
|
||||
for (ClientProvider provider : providers) {
|
||||
testCatchNPE(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private void testCatchNPE(ClientProvider pProvider) throws Exception {
|
||||
|
|
|
@ -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,20 +84,17 @@ public class ClientIpTest extends XmlRpcTestCase {
|
|||
};
|
||||
}
|
||||
|
||||
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
|
||||
XmlRpcException {
|
||||
final XmlRpcHandler handler = new XmlRpcHandler(){
|
||||
public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
|
||||
final ClientInfo clientInfo = ClientInfoServlet.getClientInfo();
|
||||
if (clientInfo == null) {
|
||||
return "";
|
||||
}
|
||||
final String ip = clientInfo.getIpAddress();
|
||||
if (ip == null) {
|
||||
return "";
|
||||
}
|
||||
return ip;
|
||||
protected XmlRpcHandlerMapping getHandlerMapping() {
|
||||
final XmlRpcHandler handler = pRequest -> {
|
||||
final ClientInfo clientInfo = ClientInfoServlet.getClientInfo();
|
||||
if (clientInfo == null) {
|
||||
return "";
|
||||
}
|
||||
final String ip = clientInfo.getIpAddress();
|
||||
if (ip == null) {
|
||||
return "";
|
||||
}
|
||||
return ip;
|
||||
};
|
||||
return new XmlRpcHandlerMapping(){
|
||||
public XmlRpcHandler getHandler(String pHandlerName)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
@ -98,50 +59,48 @@ public class ScalabilityTest extends TestCase {
|
|||
}
|
||||
|
||||
private void initServletWebServer() throws Exception {
|
||||
servlet = new XmlRpcServlet(){
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,104 +27,100 @@ 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 {
|
||||
private final XmlRpcClient client;
|
||||
private final XmlRpcClient client;
|
||||
|
||||
/** Creates a new instance.
|
||||
*/
|
||||
public SerializerTest() {
|
||||
client = new XmlRpcClient();
|
||||
client.setTransportFactory(new XmlRpcSunHttpTransportFactory(client));
|
||||
}
|
||||
/** Creates a new instance.
|
||||
*/
|
||||
public SerializerTest() {
|
||||
client = new XmlRpcClient();
|
||||
client.setTransportFactory(new XmlRpcSunHttpTransportFactory(client));
|
||||
}
|
||||
|
||||
protected XmlRpcClientConfigImpl getConfig() {
|
||||
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
|
||||
return config;
|
||||
}
|
||||
protected XmlRpcClientConfigImpl getConfig() {
|
||||
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
|
||||
return config;
|
||||
}
|
||||
|
||||
protected XmlRpcStreamRequestConfig getExConfig() {
|
||||
XmlRpcClientConfigImpl config = getConfig();
|
||||
config.setEnabledForExtensions(true);
|
||||
return config;
|
||||
}
|
||||
protected XmlRpcStreamRequestConfig getExConfig() {
|
||||
XmlRpcClientConfigImpl config = getConfig();
|
||||
config.setEnabledForExtensions(true);
|
||||
return config;
|
||||
}
|
||||
|
||||
protected String writeRequest(XmlRpcStreamRequestConfig pConfig, XmlRpcRequest pRequest)
|
||||
throws SAXException {
|
||||
protected String writeRequest(XmlRpcStreamRequestConfig pConfig, XmlRpcRequest pRequest)
|
||||
throws SAXException {
|
||||
client.setConfig((XmlRpcClientConfig) pConfig);
|
||||
return XmlRpcTestCase.writeRequest(client, pRequest);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test serialization of a byte parameter.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testByteParam() throws Exception {
|
||||
XmlRpcStreamRequestConfig config = getExConfig();
|
||||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteParam", new Object[]{new Byte((byte)3)});
|
||||
String got = writeRequest(config, request);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">"
|
||||
+ "<methodName>byteParam</methodName><params><param><value><ex:i1>3</ex:i1></value></param></params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
/** Test serialization of a byte parameter.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testByteParam() throws Exception {
|
||||
XmlRpcStreamRequestConfig config = getExConfig();
|
||||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteParam", new Object[] { (byte) 3} );
|
||||
String got = writeRequest(config, request);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">"
|
||||
+ "<methodName>byteParam</methodName><params><param><value><ex:i1>3</ex:i1></value></param></params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
|
||||
/** Test serialization of an integer parameter.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testIntParam() throws Exception {
|
||||
XmlRpcStreamRequestConfig config = getConfig();
|
||||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "intParam", new Object[]{new Integer(3)});
|
||||
String got = writeRequest(config, request);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall>"
|
||||
+ "<methodName>intParam</methodName><params><param><value><i4>3</i4></value></param></params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
/** Test serialization of an integer parameter.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testIntParam() throws Exception {
|
||||
XmlRpcStreamRequestConfig config = getConfig();
|
||||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "intParam", new Object[] { 3 } );
|
||||
String got = writeRequest(config, request);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall>"
|
||||
+ "<methodName>intParam</methodName><params><param><value><i4>3</i4></value></param></params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
|
||||
/** Test serialization of a byte array.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testByteArrayParam() throws Exception {
|
||||
byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
XmlRpcStreamRequestConfig config = getConfig();
|
||||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteArrayParam", new Object[]{bytes});
|
||||
String got = writeRequest(config, request);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall>"
|
||||
+ "<methodName>byteArrayParam</methodName><params><param><value><base64>AAECAwQFBgcICQ==</base64></value></param></params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
/** Test serialization of a byte array.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testByteArrayParam() throws Exception {
|
||||
byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
XmlRpcStreamRequestConfig config = getConfig();
|
||||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteArrayParam", new Object[]{ bytes });
|
||||
String got = writeRequest(config, request);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall>"
|
||||
+ "<methodName>byteArrayParam</methodName><params><param><value><base64>AAECAwQFBgcICQ==</base64></value></param></params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
|
||||
/** Test serialization of a map.
|
||||
* @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 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\"?>"
|
||||
+ "<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>"
|
||||
+ "</struct></value></param></params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
/** Test serialization of a map.
|
||||
* @throws Exception The test failed.
|
||||
*/
|
||||
public void testMapParam() throws Exception {
|
||||
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\"?>"
|
||||
+ "<methodCall><methodName>mapParam</methodName>"
|
||||
+ "<params><param><value><struct>"
|
||||
+ "<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);
|
||||
}
|
||||
|
||||
/** Tests serialization of a calendar instance.
|
||||
*/
|
||||
/** Tests serialization of a calendar instance.
|
||||
*/
|
||||
public void testCalendarParam() throws Exception {
|
||||
TimeZone tz = TimeZone.getTimeZone("GMT");
|
||||
Calendar cal1 = Calendar.getInstance(tz);
|
||||
|
@ -136,12 +133,12 @@ public class SerializerTest extends TestCase {
|
|||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "dateParam", new Object[]{cal1, cal2.getTime()});
|
||||
String got = writeRequest(config, request);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">"
|
||||
+ "<methodName>dateParam</methodName><params>"
|
||||
+ "<param><value><ex:dateTime>1933-06-12T11:07:21.311Z</ex:dateTime></value></param>"
|
||||
+ "<param><value><dateTime.iso8601>19330612T11:07:21</dateTime.iso8601></value></param>"
|
||||
+ "</params></methodCall>";
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">"
|
||||
+ "<methodName>dateParam</methodName><params>"
|
||||
+ "<param><value><ex:dateTime>1933-06-12T11:07:21.311Z</ex:dateTime></value></param>"
|
||||
+ "<param><value><dateTime.iso8601>19330612T11:07:21</dateTime.iso8601></value></param>"
|
||||
+ "</params></methodCall>";
|
||||
assertEquals(expect, got);
|
||||
}
|
||||
|
||||
|
@ -149,23 +146,23 @@ 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);
|
||||
String expect =
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">"
|
||||
+ "<methodName>integerKeyMap</methodName><params>"
|
||||
+ "<param><value><struct><member>"
|
||||
+ "<name><value><i4>1</i4></value></name>"
|
||||
+ "<value>one</value></member>"
|
||||
+ "</struct></value></param>"
|
||||
+ "</params></methodCall>";
|
||||
"<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
||||
+ "<methodCall xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">"
|
||||
+ "<methodName>integerKeyMap</methodName><params>"
|
||||
+ "<param><value><struct><member>"
|
||||
+ "<name><value><i4>1</i4></value></name>"
|
||||
+ "<value>one</value></member>"
|
||||
+ "</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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
protected final XmlRpcServlet servlet;
|
||||
|
||||
private final boolean contentLength;
|
||||
private final int port;
|
||||
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Creates a new instance of {@link XmlRpcServlet}.
|
||||
|
@ -40,18 +44,22 @@ public class ServletWebServerProvider extends ClientProviderImpl {
|
|||
contentLength = pContentLength;
|
||||
servlet = newXmlRpcServlet();
|
||||
webServer = new ServletWebServer(servlet, 0);
|
||||
XmlRpcServer server = servlet.getXmlRpcServletServer();
|
||||
server.setHandlerMapping(mapping);
|
||||
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
|
||||
serverConfig.setEnabledForExtensions(true);
|
||||
serverConfig.setContentLengthOptional(!contentLength);
|
||||
serverConfig.setEnabledForExceptions(true);
|
||||
webServer.start();
|
||||
port = webServer.getPort();
|
||||
try {
|
||||
XmlRpcServer server = servlet.getXmlRpcServletServer();
|
||||
server.setHandlerMapping(mapping);
|
||||
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
|
||||
serverConfig.setEnabledForExtensions(true);
|
||||
serverConfig.setContentLengthOptional(!contentLength);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -6,53 +6,57 @@ 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 final boolean contentLength;
|
||||
|
||||
/** Creates a new instance.
|
||||
* @param pMapping The test servers handler mapping.
|
||||
*/
|
||||
protected WebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
|
||||
super(pMapping);
|
||||
contentLength = pContentLength;
|
||||
}
|
||||
private WebServer webServer;
|
||||
|
||||
public final XmlRpcClientConfigImpl getConfig() throws Exception {
|
||||
initWebServer();
|
||||
return getConfig(new URL("http://127.0.0.1:" + webServer.getPort() + "/"));
|
||||
}
|
||||
private final boolean contentLength;
|
||||
|
||||
protected XmlRpcClientConfigImpl getConfig(URL pServerURL) throws Exception {
|
||||
XmlRpcClientConfigImpl config = super.getConfig();
|
||||
config.setServerURL(pServerURL);
|
||||
config.setContentLengthOptional(!contentLength);
|
||||
return config;
|
||||
}
|
||||
|
||||
protected void initWebServer() throws Exception {
|
||||
if (!isActive) {
|
||||
XmlRpcServer server = webServer.getXmlRpcServer();
|
||||
server.setHandlerMapping(mapping);
|
||||
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
|
||||
serverConfig.setEnabledForExtensions(true);
|
||||
serverConfig.setContentLengthOptional(!contentLength);
|
||||
serverConfig.setEnabledForExceptions(true);
|
||||
webServer.start();
|
||||
isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
public XmlRpcServer getServer() {
|
||||
return webServer.getXmlRpcServer();
|
||||
/** Creates a new instance.
|
||||
* @param pMapping The test servers handler mapping.
|
||||
*/
|
||||
WebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
|
||||
super(pMapping);
|
||||
contentLength = pContentLength;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
webServer.shutdown();
|
||||
public final XmlRpcClientConfigImpl getConfig() throws Exception {
|
||||
initWebServer();
|
||||
return getConfig(new URL("http://localhost:" + webServer.getPort() + "/"));
|
||||
}
|
||||
|
||||
protected XmlRpcClientConfigImpl getConfig(URL pServerURL) throws Exception {
|
||||
XmlRpcClientConfigImpl config = super.getConfig();
|
||||
config.setServerURL(pServerURL);
|
||||
config.setContentLengthOptional(!contentLength);
|
||||
return config;
|
||||
}
|
||||
|
||||
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();
|
||||
serverConfig.setEnabledForExtensions(true);
|
||||
serverConfig.setContentLengthOptional(!contentLength);
|
||||
serverConfig.setEnabledForExceptions(true);
|
||||
webServer.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlRpcServer getServer() {
|
||||
return webServer.getXmlRpcServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() throws IOException {
|
||||
webServer.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
org.xbib.netty.http.xmlrpc.client.test.AuthenticationTest$Adder=org.xbib.netty.http.xmlrpc.client.test.AuthenticationTest$AdderImpl
|
|
@ -0,0 +1 @@
|
|||
Remote=org.xbib.netty.http.xmlrpc.client.test.BaseTest$Remote
|
|
@ -0,0 +1 @@
|
|||
org.xbib.netty.http.xmlrpc.client.test.DynamicProxyTest$Adder=org.xbib.netty.http.xmlrpc.client.test.DynamicProxyTest$AdderImpl
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
Remote=org.xbib.netty.http.xmlrpc.client.test.BaseTest$Remote
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,41 +135,36 @@ public class Connection implements ThreadPool.InterruptableTask, ServerStreamCon
|
|||
*/
|
||||
private RequestData getRequestConfig() throws IOException {
|
||||
requestData = new RequestData(this);
|
||||
if (headers != null) {
|
||||
headers.clear();
|
||||
}
|
||||
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
|
||||
StringTokenizer tokens = new StringTokenizer(line);
|
||||
String method = tokens.nextToken();
|
||||
if (!"POST".equalsIgnoreCase(method)) {
|
||||
throw new BadRequestException(requestData, method);
|
||||
if (line != null) {
|
||||
StringTokenizer tokens = new StringTokenizer(line);
|
||||
String method = tokens.nextToken();
|
||||
if (!"POST".equalsIgnoreCase(method)) {
|
||||
throw new BadRequestException(requestData, method);
|
||||
}
|
||||
requestData.setMethod(method);
|
||||
tokens.nextToken(); // Skip URI
|
||||
String httpVersion = tokens.nextToken();
|
||||
requestData.setHttpVersion(httpVersion);
|
||||
requestData.setKeepAlive(serverConfig.isKeepAliveEnabled()
|
||||
&& WebServer.HTTP_11.equals(httpVersion));
|
||||
}
|
||||
requestData.setMethod(method);
|
||||
tokens.nextToken(); // Skip URI
|
||||
String httpVersion = tokens.nextToken();
|
||||
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);
|
||||
}
|
||||
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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -5,27 +5,31 @@ 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;
|
||||
|
||||
private boolean shuttingDown;
|
||||
|
||||
/** Creates a new instance.
|
||||
* @param pServlet The servlet, which ought to handle the request.
|
||||
* @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();
|
||||
|
|
|
@ -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(){
|
||||
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; }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.xbib.netty.http.xmlrpc.servlet;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/** Simple thread pool. A task is executed by obtaining a thread from
|
||||
* the pool
|
||||
|
@ -11,50 +13,54 @@ public class ThreadPool {
|
|||
/** A task, which may be interrupted, if the pool is shutting down.
|
||||
*/
|
||||
public interface InterruptableTask extends Runnable {
|
||||
|
||||
/** Interrupts the task.
|
||||
* @throws Throwable Shutting down the task failed.
|
||||
*/
|
||||
void shutdown() throws Throwable;
|
||||
}
|
||||
|
||||
private class Poolable extends Thread implements Runnable{
|
||||
private class Poolable extends Thread implements Runnable {
|
||||
|
||||
private volatile boolean shuttingDown;
|
||||
private final Logger logger = Logger.getLogger(Poolable.class.getName());
|
||||
|
||||
private volatile boolean shuttingDown;
|
||||
|
||||
private Runnable task;
|
||||
|
||||
Poolable(ThreadGroup pGroup, int pNum) {
|
||||
super(pGroup, pGroup.getName() + "-" + pNum);
|
||||
super.start();
|
||||
}
|
||||
super(pGroup, pGroup.getName() + "-" + pNum);
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!shuttingDown) {
|
||||
final Runnable t = getTask();
|
||||
if (t == null) {
|
||||
try {
|
||||
synchronized (this) {
|
||||
if (!shuttingDown && getTask() == null) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// Do nothing
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
t.run();
|
||||
resetTask();
|
||||
repool(Poolable.this);
|
||||
} catch (Throwable e) {
|
||||
remove(Poolable.this);
|
||||
Poolable.this.shutdown();
|
||||
resetTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
while (!shuttingDown) {
|
||||
final Runnable t = getTask();
|
||||
if (t == null) {
|
||||
try {
|
||||
synchronized (this) {
|
||||
if (!shuttingDown && getTask() == null) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// Do nothing
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
t.run();
|
||||
resetTask();
|
||||
repool(Poolable.this);
|
||||
} catch (Throwable e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
remove(Poolable.this);
|
||||
Poolable.this.shutdown();
|
||||
resetTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void shutdown() {
|
||||
shuttingDown = true;
|
||||
|
@ -88,7 +94,7 @@ public class ThreadPool {
|
|||
}
|
||||
}
|
||||
|
||||
private final ThreadGroup threadGroup;
|
||||
private final ThreadGroup threadGroup;
|
||||
|
||||
private final int maxSize;
|
||||
|
||||
|
@ -101,66 +107,66 @@ public class ThreadPool {
|
|||
private int num;
|
||||
|
||||
|
||||
/** Creates a new instance.
|
||||
* @param pMaxSize Maximum number of concurrent threads.
|
||||
* @param pName Thread group name.
|
||||
*/
|
||||
public ThreadPool(int pMaxSize, String pName) {
|
||||
maxSize = pMaxSize;
|
||||
threadGroup = new ThreadGroup(pName);
|
||||
}
|
||||
/** Creates a new instance.
|
||||
* @param pMaxSize Maximum number of concurrent threads.
|
||||
* @param pName Thread group name.
|
||||
*/
|
||||
public ThreadPool(int pMaxSize, String pName) {
|
||||
maxSize = pMaxSize;
|
||||
threadGroup = new ThreadGroup(pName);
|
||||
}
|
||||
|
||||
private synchronized void remove(Poolable pPoolable) {
|
||||
private synchronized void remove(Poolable pPoolable) {
|
||||
runningThreads.remove(pPoolable);
|
||||
waitingThreads.remove(pPoolable);
|
||||
}
|
||||
}
|
||||
|
||||
private void repool(Poolable pPoolable) {
|
||||
boolean discarding = false;
|
||||
Runnable task = null;
|
||||
Poolable poolable = null;
|
||||
synchronized (this) {
|
||||
if (runningThreads.remove(pPoolable)) {
|
||||
if (maxSize != 0 && runningThreads.size() + waitingThreads.size() >= maxSize) {
|
||||
discarding = true;
|
||||
} else {
|
||||
waitingThreads.add(pPoolable);
|
||||
if (waitingTasks.size() > 0) {
|
||||
task = waitingTasks.remove(waitingTasks.size() - 1);
|
||||
poolable = getPoolable(task, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
discarding = true;
|
||||
}
|
||||
if (discarding) {
|
||||
remove(pPoolable);
|
||||
}
|
||||
}
|
||||
if (poolable != null) {
|
||||
poolable.start(task);
|
||||
}
|
||||
if (discarding) {
|
||||
pPoolable.shutdown();
|
||||
}
|
||||
}
|
||||
private void repool(Poolable pPoolable) {
|
||||
boolean discarding = false;
|
||||
Runnable task = null;
|
||||
Poolable poolable = null;
|
||||
synchronized (this) {
|
||||
if (runningThreads.remove(pPoolable)) {
|
||||
if (maxSize != 0 && runningThreads.size() + waitingThreads.size() >= maxSize) {
|
||||
discarding = true;
|
||||
} else {
|
||||
waitingThreads.add(pPoolable);
|
||||
if (waitingTasks.size() > 0) {
|
||||
task = waitingTasks.remove(waitingTasks.size() - 1);
|
||||
poolable = getPoolable(task, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
discarding = true;
|
||||
}
|
||||
if (discarding) {
|
||||
remove(pPoolable);
|
||||
}
|
||||
}
|
||||
if (poolable != null) {
|
||||
poolable.start(task);
|
||||
}
|
||||
if (discarding) {
|
||||
pPoolable.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a task immediately.
|
||||
* @param pTask The task being started.
|
||||
* @return True, if the task could be started immediately. False, if
|
||||
* the maxmimum number of concurrent tasks was exceeded.
|
||||
*/
|
||||
public boolean startTask(Runnable pTask) {
|
||||
final Poolable poolable = getPoolable(pTask, false);
|
||||
if (poolable == null) {
|
||||
return false;
|
||||
}
|
||||
poolable.start(pTask);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Starts a task immediately.
|
||||
* @param pTask The task being started.
|
||||
* @return True, if the task could be started immediately. False, if
|
||||
* the maxmimum number of concurrent tasks was exceeded.
|
||||
*/
|
||||
public boolean startTask(Runnable pTask) {
|
||||
final Poolable poolable = getPoolable(pTask, false);
|
||||
if (poolable == null) {
|
||||
return false;
|
||||
}
|
||||
poolable.start(pTask);
|
||||
return true;
|
||||
}
|
||||
|
||||
private synchronized Poolable getPoolable(Runnable pTask, boolean pQueue) {
|
||||
private synchronized Poolable getPoolable(Runnable pTask, boolean pQueue) {
|
||||
if (maxSize != 0 && runningThreads.size() >= maxSize) {
|
||||
if (pQueue) {
|
||||
waitingTasks.add(pTask);
|
||||
|
@ -175,28 +181,28 @@ public class ThreadPool {
|
|||
}
|
||||
runningThreads.add(poolable);
|
||||
return poolable;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a task for immediate or deferred execution.
|
||||
* @param pTask The task being added.
|
||||
* @return True, if the task was started immediately. False, if
|
||||
* the task will be executed later.
|
||||
* @deprecated No longer in use.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean addTask(Runnable pTask) {
|
||||
final Poolable poolable = getPoolable(pTask, true);
|
||||
if (poolable != null) {
|
||||
poolable.start(pTask);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Adds a task for immediate or deferred execution.
|
||||
* @param pTask The task being added.
|
||||
* @return True, if the task was started immediately. False, if
|
||||
* the task will be executed later.
|
||||
* @deprecated No longer in use.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean addTask(Runnable pTask) {
|
||||
final Poolable poolable = getPoolable(pTask, true);
|
||||
if (poolable != null) {
|
||||
poolable.start(pTask);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Closes the pool.
|
||||
*/
|
||||
public synchronized void shutdown() {
|
||||
/** Closes the pool.
|
||||
*/
|
||||
public synchronized void shutdown() {
|
||||
while (!waitingThreads.isEmpty()) {
|
||||
Poolable poolable = (Poolable) waitingThreads.remove(waitingThreads.size()-1);
|
||||
poolable.shutdown();
|
||||
|
@ -205,15 +211,15 @@ public class ThreadPool {
|
|||
Poolable poolable = (Poolable) runningThreads.remove(runningThreads.size()-1);
|
||||
poolable.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the maximum number of concurrent threads.
|
||||
* @return Maximum number of threads.
|
||||
*/
|
||||
public int getMaxThreads() { return maxSize; }
|
||||
/** Returns the maximum number of concurrent threads.
|
||||
* @return Maximum number of threads.
|
||||
*/
|
||||
public int getMaxThreads() { return maxSize; }
|
||||
|
||||
/** Returns the number of threads, which have actually been created,
|
||||
/** Returns the number of threads, which have actually been created,
|
||||
* as opposed to the number of currently running threads.
|
||||
*/
|
||||
*/
|
||||
public synchronized int getNumThreads() { return num; }
|
||||
}
|
||||
|
|
|
@ -5,11 +5,9 @@ import org.xbib.netty.http.xmlrpc.server.XmlRpcStreamServer;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.BindException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
@ -52,50 +50,9 @@ import java.util.StringTokenizer;
|
|||
*/
|
||||
public class WebServer implements Runnable {
|
||||
|
||||
private class AddressMatcher {
|
||||
protected ServerSocket serverSocket;
|
||||
|
||||
private final int[] pattern;
|
||||
|
||||
AddressMatcher(String pAddress) {
|
||||
try {
|
||||
pattern = new int[4];
|
||||
StringTokenizer st = new StringTokenizer(pAddress, ".");
|
||||
if (st.countTokens() != 4) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String next = st.nextToken();
|
||||
if ("*".equals(next)) {
|
||||
pattern[i] = 256;
|
||||
} else {
|
||||
/* Note: *Not* pattern[i] = Integer.parseInt(next);
|
||||
* See XMLRPC-145
|
||||
*/
|
||||
pattern[i] = (byte) Integer.parseInt(next);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("\"" + pAddress
|
||||
+ "\" does not represent a valid IP address");
|
||||
}
|
||||
}
|
||||
|
||||
boolean matches(byte[] pAddress) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (pattern[i] > 255) {
|
||||
continue; // Wildcard
|
||||
}
|
||||
if (pattern[i] != pAddress[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected ServerSocket serverSocket;
|
||||
|
||||
private Thread listener;
|
||||
private final WebServerThread webServerThread;
|
||||
|
||||
private ThreadPool pool;
|
||||
|
||||
|
@ -105,304 +62,335 @@ public class WebServer implements Runnable {
|
|||
|
||||
protected final XmlRpcStreamServer server = newXmlRpcStreamServer();
|
||||
|
||||
protected XmlRpcStreamServer newXmlRpcStreamServer(){
|
||||
return new ConnectionServer();
|
||||
}
|
||||
protected XmlRpcStreamServer newXmlRpcStreamServer(){
|
||||
return new ConnectionServer();
|
||||
}
|
||||
|
||||
// Inputs to setupServerSocket()
|
||||
private InetAddress address;
|
||||
private int port;
|
||||
// Inputs to setupServerSocket()
|
||||
private InetAddress address;
|
||||
|
||||
private boolean paranoid;
|
||||
private int port;
|
||||
|
||||
static final String HTTP_11 = "HTTP/1.1";
|
||||
/** Creates a web server at the specified port number.
|
||||
* @param pPort Port number; 0 for a random port, choosen by the
|
||||
* operating system.
|
||||
*/
|
||||
public WebServer(int pPort) {
|
||||
this(pPort, null);
|
||||
}
|
||||
private boolean paranoid;
|
||||
|
||||
/** Creates a web server at the specified port number and IP address.
|
||||
* @param pPort Port number; 0 for a random port, choosen by the
|
||||
* operating system.
|
||||
* @param pAddr Local IP address; null for all available IP addresses.
|
||||
*/
|
||||
public WebServer(int pPort, InetAddress pAddr) {
|
||||
address = pAddr;
|
||||
port = pPort;
|
||||
}
|
||||
static final String HTTP_11 = "HTTP/1.1";
|
||||
/** Creates a web server at the specified port number.
|
||||
* @param pPort Port number; 0 for a random port, choosen by the
|
||||
* operating system.
|
||||
*/
|
||||
public WebServer(int pPort) {
|
||||
this(pPort, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to manufacture the server socket. Useful as a
|
||||
* hook method for subclasses to override when they desire
|
||||
* different flavor of socket (i.e. a <code>SSLServerSocket</code>).
|
||||
*
|
||||
* @param pPort Port number; 0 for a random port, choosen by the operating
|
||||
* system.
|
||||
* @param backlog
|
||||
* @param addr If <code>null</code>, binds to
|
||||
* <code>INADDR_ANY</code>, meaning that all network interfaces on
|
||||
* a multi-homed host will be listening.
|
||||
* @exception IOException Error creating listener socket.
|
||||
*/
|
||||
protected ServerSocket createServerSocket(int pPort, int backlog, InetAddress addr)
|
||||
throws IOException {
|
||||
return new ServerSocket(pPort, backlog, addr);
|
||||
}
|
||||
/** Creates a web server at the specified port number and IP address.
|
||||
* @param pPort Port number; 0 for a random port, choosen by the
|
||||
* operating system.
|
||||
* @param pAddr Local IP address; null for all available IP addresses.
|
||||
*/
|
||||
public WebServer(int pPort, InetAddress pAddr) {
|
||||
address = pAddr;
|
||||
port = pPort;
|
||||
webServerThread = new WebServerThread(this, "XML-RPC Weblistener");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this server's listener socket with the specified
|
||||
* attributes, assuring that a socket timeout has been set. The
|
||||
* {@link #createServerSocket(int, int, InetAddress)} method can
|
||||
* be overridden to change the flavor of socket used.
|
||||
*
|
||||
* @see #createServerSocket(int, int, InetAddress)
|
||||
*/
|
||||
private synchronized void setupServerSocket(int backlog) throws IOException {
|
||||
// Since we can't reliably set SO_REUSEADDR until JDK 1.4 is
|
||||
// the standard, try to (re-)open the server socket several
|
||||
// times. Some OSes (Linux and Solaris, for example), hold on
|
||||
// to listener sockets for a brief period of time for security
|
||||
// reasons before relinquishing their hold.
|
||||
for (int i = 1; ; i++) {
|
||||
try {
|
||||
serverSocket = createServerSocket(port, backlog, address);
|
||||
// A socket timeout must be set.
|
||||
if (serverSocket.getSoTimeout() <= 0) {
|
||||
serverSocket.setSoTimeout(4096);
|
||||
}
|
||||
return;
|
||||
} catch (BindException e) {
|
||||
if (i == 10) {
|
||||
throw e;
|
||||
} else {
|
||||
long waitUntil = System.currentTimeMillis() + 1000;
|
||||
for (;;) {
|
||||
long l = waitUntil - System.currentTimeMillis();
|
||||
if (l > 0) {
|
||||
try {
|
||||
Thread.sleep(l);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
/**
|
||||
* Factory method to manufacture the server socket. Useful as a
|
||||
* hook method for subclasses to override when they desire
|
||||
* different flavor of socket (i.e. a <code>SSLServerSocket</code>).
|
||||
*
|
||||
* @param pPort Port number; 0 for a random port, choosen by the operating
|
||||
* system.
|
||||
* @param backlog
|
||||
* @param addr If <code>null</code>, binds to
|
||||
* <code>INADDR_ANY</code>, meaning that all network interfaces on
|
||||
* a multi-homed host will be listening.
|
||||
* @exception IOException Error creating listener socket.
|
||||
*/
|
||||
protected ServerSocket createServerSocket(int pPort, int backlog, InetAddress addr)
|
||||
throws IOException {
|
||||
return new ServerSocket(pPort, backlog, addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this server's listener socket with the specified
|
||||
* attributes, assuring that a socket timeout has been set. The
|
||||
* {@link #createServerSocket(int, int, InetAddress)} method can
|
||||
* be overridden to change the flavor of socket used.
|
||||
*
|
||||
* @see #createServerSocket(int, int, InetAddress)
|
||||
*/
|
||||
private synchronized void setupServerSocket(int backlog) throws IOException {
|
||||
serverSocket = createServerSocket(port, backlog, address);
|
||||
// A socket timeout must be set.
|
||||
if (serverSocket.getSoTimeout() <= 0) {
|
||||
serverSocket.setSoTimeout(4096);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a new thread which binds this server to the port it's
|
||||
* configured to accept connections on.
|
||||
*
|
||||
* @see #run()
|
||||
* @throws IOException Binding the server socket failed.
|
||||
*/
|
||||
public void start() throws IOException {
|
||||
setupServerSocket(50);
|
||||
// Not marked as daemon thread since run directly via main().
|
||||
webServerThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch client filtering on/off.
|
||||
* @param pParanoid True to enable filtering, false otherwise.
|
||||
* @see #acceptClient(String)
|
||||
* @see #denyClient(String)
|
||||
*/
|
||||
public void setParanoid(boolean pParanoid) {
|
||||
paranoid = pParanoid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client filtering state.
|
||||
* @return True, if client filtering is enabled, false otherwise.
|
||||
* @see #acceptClient(String)
|
||||
* @see #denyClient(String)
|
||||
*/
|
||||
protected boolean isParanoid() {
|
||||
return paranoid;
|
||||
}
|
||||
|
||||
/** Add an IP address to the list of accepted clients. The parameter can
|
||||
* contain '*' as wildcard character, e.g. "192.168.*.*". You must call
|
||||
* setParanoid(true) in order for this to have any effect.
|
||||
* @param pAddress The IP address being enabled.
|
||||
* @see #denyClient(String)
|
||||
* @see #setParanoid(boolean)
|
||||
* @throws IllegalArgumentException Parsing the address failed.
|
||||
*/
|
||||
public void acceptClient(String pAddress) {
|
||||
accept.add(new AddressMatcher(pAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an IP address to the list of denied clients. The parameter can
|
||||
* contain '*' as wildcard character, e.g. "192.168.*.*". You must call
|
||||
* setParanoid(true) in order for this to have any effect.
|
||||
* @param pAddress The IP address being disabled.
|
||||
* @see #acceptClient(String)
|
||||
* @see #setParanoid(boolean)
|
||||
* @throws IllegalArgumentException Parsing the address failed.
|
||||
*/
|
||||
public void denyClient(String pAddress) {
|
||||
deny.add(new AddressMatcher(pAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks incoming connections to see if they should be allowed.
|
||||
* If not in paranoid mode, always returns true.
|
||||
*
|
||||
* @param s The socket to inspect.
|
||||
* @return Whether the connection should be allowed.
|
||||
*/
|
||||
protected boolean allowConnection(Socket s) {
|
||||
if (!paranoid) {
|
||||
return true;
|
||||
}
|
||||
int l = deny.size();
|
||||
byte[] addr = s.getInetAddress().getAddress();
|
||||
for (int i = 0; i < l; i++) {
|
||||
AddressMatcher match = deny.get(i);
|
||||
if (match.matches(addr)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
l = accept.size();
|
||||
for (int i = 0; i < l; i++) {
|
||||
AddressMatcher match = accept.get(i);
|
||||
if (match.matches(addr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Runnable newTask(WebServer pServer, XmlRpcStreamServer pXmlRpcServer,
|
||||
Socket pSocket) throws IOException {
|
||||
return new Connection(pServer, pXmlRpcServer, pSocket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for client requests until stopped. Call {@link
|
||||
* #start()} to invoke this method, and {@link #shutdown()} to
|
||||
* break out of it.
|
||||
*
|
||||
* @throws RuntimeException Generally caused by either an
|
||||
* <code>UnknownHostException</code> or <code>BindException</code>
|
||||
* with the vanilla web server.
|
||||
*
|
||||
* @see #start()
|
||||
* @see #shutdown()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
pool = newThreadPool();
|
||||
try {
|
||||
while (!webServerThread.closed) {
|
||||
if (serverSocket.isClosed()) {
|
||||
break;
|
||||
}
|
||||
Socket socket = null;
|
||||
try {
|
||||
socket = serverSocket.accept();
|
||||
socket.setTcpNoDelay(true);
|
||||
if (allowConnection(socket)) {
|
||||
// set read timeout to 1 seconds
|
||||
socket.setSoTimeout(1000);
|
||||
Runnable task = newTask(this, server, socket);
|
||||
if (pool.startTask(task)) {
|
||||
socket = null;
|
||||
} else {
|
||||
log("Maximum load of " + pool.getMaxThreads()
|
||||
+ " exceeded, rejecting client");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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) {
|
||||
|
||||
/**
|
||||
* Spawns a new thread which binds this server to the port it's
|
||||
* configured to accept connections on.
|
||||
*
|
||||
* @see #run()
|
||||
* @throws IOException Binding the server socket failed.
|
||||
*/
|
||||
public void start() throws IOException {
|
||||
setupServerSocket(50);
|
||||
|
||||
// The listener reference is released upon shutdown().
|
||||
if (listener == null) {
|
||||
listener = new Thread(this, "XML-RPC Weblistener");
|
||||
// Not marked as daemon thread since run directly via main().
|
||||
listener.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch client filtering on/off.
|
||||
* @param pParanoid True to enable filtering, false otherwise.
|
||||
* @see #acceptClient(String)
|
||||
* @see #denyClient(String)
|
||||
*/
|
||||
public void setParanoid(boolean pParanoid) {
|
||||
paranoid = pParanoid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client filtering state.
|
||||
* @return True, if client filtering is enabled, false otherwise.
|
||||
* @see #acceptClient(String)
|
||||
* @see #denyClient(String)
|
||||
*/
|
||||
protected boolean isParanoid() {
|
||||
return paranoid;
|
||||
}
|
||||
|
||||
/** Add an IP address to the list of accepted clients. The parameter can
|
||||
* contain '*' as wildcard character, e.g. "192.168.*.*". You must call
|
||||
* setParanoid(true) in order for this to have any effect.
|
||||
* @param pAddress The IP address being enabled.
|
||||
* @see #denyClient(String)
|
||||
* @see #setParanoid(boolean)
|
||||
* @throws IllegalArgumentException Parsing the address failed.
|
||||
*/
|
||||
public void acceptClient(String pAddress) {
|
||||
accept.add(new AddressMatcher(pAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an IP address to the list of denied clients. The parameter can
|
||||
* contain '*' as wildcard character, e.g. "192.168.*.*". You must call
|
||||
* setParanoid(true) in order for this to have any effect.
|
||||
* @param pAddress The IP address being disabled.
|
||||
* @see #acceptClient(String)
|
||||
* @see #setParanoid(boolean)
|
||||
* @throws IllegalArgumentException Parsing the address failed.
|
||||
*/
|
||||
public void denyClient(String pAddress) {
|
||||
deny.add(new AddressMatcher(pAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks incoming connections to see if they should be allowed.
|
||||
* If not in paranoid mode, always returns true.
|
||||
*
|
||||
* @param s The socket to inspect.
|
||||
* @return Whether the connection should be allowed.
|
||||
*/
|
||||
protected boolean allowConnection(Socket s) {
|
||||
if (!paranoid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int l = deny.size();
|
||||
byte[] addr = s.getInetAddress().getAddress();
|
||||
for (int i = 0; i < l; i++) {
|
||||
AddressMatcher match = deny.get(i);
|
||||
if (match.matches(addr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
l = accept.size();
|
||||
for (int i = 0; i < l; i++) {
|
||||
AddressMatcher match = accept.get(i);
|
||||
if (match.matches(addr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Runnable newTask(WebServer pServer, XmlRpcStreamServer pXmlRpcServer,
|
||||
Socket pSocket) throws IOException {
|
||||
return new Connection(pServer, pXmlRpcServer, pSocket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for client requests until stopped. Call {@link
|
||||
* #start()} to invoke this method, and {@link #shutdown()} to
|
||||
* break out of it.
|
||||
*
|
||||
* @throws RuntimeException Generally caused by either an
|
||||
* <code>UnknownHostException</code> or <code>BindException</code>
|
||||
* with the vanilla web server.
|
||||
*
|
||||
* @see #start()
|
||||
* @see #shutdown()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
pool = newThreadPool();
|
||||
try {
|
||||
while (listener != null) {
|
||||
try {
|
||||
Socket socket = serverSocket.accept();
|
||||
try {
|
||||
socket.setTcpNoDelay(true);
|
||||
} catch (SocketException socketOptEx) {
|
||||
log(socketOptEx);
|
||||
}
|
||||
|
||||
try {
|
||||
if (allowConnection(socket)) {
|
||||
// set read timeout to 30 seconds
|
||||
socket.setSoTimeout(30000);
|
||||
Runnable task = newTask(this, server, socket);
|
||||
if (pool.startTask(task)) {
|
||||
socket = null;
|
||||
} else {
|
||||
log("Maximum load of " + pool.getMaxThreads()
|
||||
+ " exceeded, rejecting client");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (socket != null) { try { socket.close(); } catch (Throwable ignore) {} }
|
||||
}
|
||||
} catch (InterruptedIOException checkState) {
|
||||
// Timeout while waiting for a client (from
|
||||
// SO_TIMEOUT)...try again if still listening.
|
||||
} catch (Throwable t) {
|
||||
log(t);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (serverSocket != null) {
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown our Runner-based threads
|
||||
pool.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
pool.shutdown();
|
||||
if (serverSocket != null && !serverSocket.isClosed()) {
|
||||
try {
|
||||
log("closing server socket");
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ThreadPool newThreadPool() {
|
||||
return new ThreadPool(server.getMaxThreads(), "XML-RPC");
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop listening on the server port. Shutting down our {@link
|
||||
* #listener} effectively breaks it out of its {@link #run()}
|
||||
* loop.
|
||||
*
|
||||
* @see #run()
|
||||
*/
|
||||
public synchronized void shutdown() {
|
||||
// Stop accepting client connections
|
||||
if (listener != null) {
|
||||
Thread l = listener;
|
||||
listener = null;
|
||||
l.interrupt();
|
||||
if (pool != null) {
|
||||
pool.shutdown();
|
||||
/**
|
||||
* Stop listening on the server port.
|
||||
* Shutting down our {@link #webServerThread} effectively breaks it out of its {@link #run()} loop.
|
||||
*
|
||||
* @see #run()
|
||||
*/
|
||||
public synchronized void shutdown() throws IOException {
|
||||
webServerThread.closed = true;
|
||||
webServerThread.interrupt();
|
||||
// wait for server socket down
|
||||
while (serverSocket != null && !serverSocket.isClosed()) {
|
||||
try {
|
||||
Thread.sleep(25L);
|
||||
} catch (InterruptedException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
serverSocket = null;
|
||||
try {
|
||||
Thread.sleep(25L);
|
||||
} catch (InterruptedException e) {
|
||||
//
|
||||
}
|
||||
log("shutdown complete");
|
||||
}
|
||||
|
||||
/** 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 boolean isShutDown() {
|
||||
return serverSocket.isClosed();
|
||||
}
|
||||
|
||||
/** Logs an error.
|
||||
* @param pError The error being logged.
|
||||
*/
|
||||
public void log(Throwable pError) {
|
||||
final String msg = pError.getMessage() == null ? pError.getClass().getName() : pError.getMessage();
|
||||
server.getErrorLogger().log(msg, pError);
|
||||
}
|
||||
/** Returns the port, on which the web server is running.
|
||||
* This method may be invoked after {@link #start()} only.
|
||||
* @return Servers port number
|
||||
*/
|
||||
public int getPort() {
|
||||
return serverSocket.getLocalPort();
|
||||
}
|
||||
|
||||
/** Logs a message.
|
||||
* @param pMessage The being logged.
|
||||
*/
|
||||
public void log(String pMessage) {
|
||||
/** Logs an error.
|
||||
* @param pError The error being logged.
|
||||
*/
|
||||
public void log(Throwable pError) {
|
||||
String msg = pError.getMessage() == null ? pError.getClass().getName() : pError.getMessage();
|
||||
server.getErrorLogger().log(msg, pError);
|
||||
}
|
||||
|
||||
/** Logs a message.
|
||||
* @param pMessage The being logged.
|
||||
*/
|
||||
public void log(String pMessage) {
|
||||
server.getErrorLogger().log(pMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the {@link XmlRpcServer}.
|
||||
* @return The server object.
|
||||
*/
|
||||
public XmlRpcStreamServer getXmlRpcServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
private class WebServerThread extends Thread {
|
||||
volatile boolean closed = false;
|
||||
|
||||
WebServerThread(Runnable runnable, String name) {
|
||||
super(runnable, name);
|
||||
}
|
||||
}
|
||||
|
||||
private class AddressMatcher {
|
||||
|
||||
private final int[] pattern;
|
||||
|
||||
AddressMatcher(String pAddress) {
|
||||
try {
|
||||
pattern = new int[4];
|
||||
StringTokenizer st = new StringTokenizer(pAddress, ".");
|
||||
if (st.countTokens() != 4) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String next = st.nextToken();
|
||||
if ("*".equals(next)) {
|
||||
pattern[i] = 256;
|
||||
} else {
|
||||
pattern[i] = (byte) Integer.parseInt(next);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("\"" + pAddress
|
||||
+ "\" does not represent a valid IP address");
|
||||
}
|
||||
}
|
||||
|
||||
boolean matches(byte[] pAddress) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (pattern[i] > 255) {
|
||||
continue; // Wildcard
|
||||
}
|
||||
if (pattern[i] != pAddress[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the {@link XmlRpcServer}.
|
||||
* @return The server object.
|
||||
*/
|
||||
public XmlRpcStreamServer getXmlRpcServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue