drop xmlrpc code
This commit is contained in:
parent
61fdc04e9c
commit
3d944e417e
191 changed files with 0 additions and 15383 deletions
|
@ -1,6 +0,0 @@
|
||||||
dependencies {
|
|
||||||
compile project(":netty-http-xmlrpc-common")
|
|
||||||
compile "commons-httpclient:commons-httpclient:${project.property(('commons-httpclient.version'))}"
|
|
||||||
testCompile project(":netty-http-xmlrpc-servlet")
|
|
||||||
testCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A callback interface for an asynchronous XML-RPC call.
|
|
||||||
*/
|
|
||||||
public interface AsyncCallback {
|
|
||||||
/** Call went ok, handle result.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @param pResult The result object, which was returned by the server.
|
|
||||||
*/
|
|
||||||
public void handleResult(XmlRpcRequest pRequest, Object pResult);
|
|
||||||
|
|
||||||
/** Something went wrong, handle error.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @param pError The error being thrown.
|
|
||||||
*/
|
|
||||||
public void handleError(XmlRpcRequest pRequest, Throwable pError);
|
|
||||||
}
|
|
|
@ -1,139 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeConverter;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeConverterFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeConverterFactoryImpl;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcInvocationException;
|
|
||||||
|
|
||||||
import java.lang.reflect.Proxy;
|
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The {@link ClientFactory} is a useful tool for simplifying the
|
|
||||||
* use of Apache XML-RPC. The rough idea is as follows: All XML-RPC
|
|
||||||
* handlers are implemented as interfaces. The server uses the actual
|
|
||||||
* implementation. The client uses the {@link ClientFactory} to
|
|
||||||
* obtain an implementation, which is based on running XML-RPC calls.</p>
|
|
||||||
*/
|
|
||||||
public class ClientFactory {
|
|
||||||
|
|
||||||
private final XmlRpcClient client;
|
|
||||||
|
|
||||||
private final TypeConverterFactory typeConverterFactory;
|
|
||||||
|
|
||||||
private boolean objectMethodLocal;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pClient A fully configured XML-RPC client, which is
|
|
||||||
* used internally to perform XML-RPC calls.
|
|
||||||
* @param pTypeConverterFactory Creates instances of {@link TypeConverterFactory},
|
|
||||||
* which are used to transform the result object in its target representation.
|
|
||||||
*/
|
|
||||||
public ClientFactory(XmlRpcClient pClient, TypeConverterFactory pTypeConverterFactory) {
|
|
||||||
typeConverterFactory = pTypeConverterFactory;
|
|
||||||
client = pClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a new instance. Shortcut for
|
|
||||||
* <pre>
|
|
||||||
* new ClientFactory(pClient, new TypeConverterFactoryImpl());
|
|
||||||
* </pre>
|
|
||||||
* @param pClient A fully configured XML-RPC client, which is
|
|
||||||
* used internally to perform XML-RPC calls.
|
|
||||||
* @see TypeConverterFactoryImpl
|
|
||||||
*/
|
|
||||||
public ClientFactory(XmlRpcClient pClient) {
|
|
||||||
this(pClient, new TypeConverterFactoryImpl());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the factories client.
|
|
||||||
*/
|
|
||||||
public XmlRpcClient getClient() {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns, whether a method declared by the {@link Object
|
|
||||||
* Object class} is performed by the local object, rather than
|
|
||||||
* by the server. Defaults to true.
|
|
||||||
*/
|
|
||||||
public boolean isObjectMethodLocal() {
|
|
||||||
return objectMethodLocal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets, whether a method declared by the {@link Object
|
|
||||||
* Object class} is performed by the local object, rather than
|
|
||||||
* by the server. Defaults to true.
|
|
||||||
*/
|
|
||||||
public void setObjectMethodLocal(boolean pObjectMethodLocal) {
|
|
||||||
objectMethodLocal = pObjectMethodLocal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an object, which is implementing the given interface.
|
|
||||||
* The objects methods are internally calling an XML-RPC server
|
|
||||||
* by using the factories client; shortcut for
|
|
||||||
* <pre>
|
|
||||||
* newInstance(Thread.currentThread().getContextClassLoader(),
|
|
||||||
* pClass)
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public Object newInstance(Class<?> pClass) {
|
|
||||||
return newInstance(Thread.currentThread().getContextClassLoader(), pClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates an object, which is implementing the given interface.
|
|
||||||
* The objects methods are internally calling an XML-RPC server
|
|
||||||
* by using the factories client; shortcut for
|
|
||||||
* <pre>
|
|
||||||
* newInstance(pClassLoader, pClass, pClass.getName())
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public Object newInstance(ClassLoader pClassLoader, Class<?> pClass) {
|
|
||||||
return newInstance(pClassLoader, pClass, pClass.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates an object, which is implementing the given interface.
|
|
||||||
* The objects methods are internally calling an XML-RPC server
|
|
||||||
* by using the factories client.
|
|
||||||
* @param pClassLoader The class loader, which is being used for
|
|
||||||
* loading classes, if required.
|
|
||||||
* @param pClass Interface, which is being implemented.
|
|
||||||
* @param pRemoteName Handler name, which is being used when
|
|
||||||
* calling the server. This is used for composing the
|
|
||||||
* method name. For example, if <code>pRemoteName</code>
|
|
||||||
* is "Foo" and you want to invoke the method "bar" in
|
|
||||||
* the handler, then the full method name would be "Foo.bar".
|
|
||||||
*/
|
|
||||||
public Object newInstance(ClassLoader pClassLoader, final Class<?> pClass, final String pRemoteName) {
|
|
||||||
|
|
||||||
return Proxy.newProxyInstance(pClassLoader, new Class<?>[] { pClass }, (pProxy, pMethod, pArgs) -> {
|
|
||||||
if (isObjectMethodLocal() && pMethod.getDeclaringClass().equals(Object.class)) {
|
|
||||||
return pMethod.invoke(pProxy, pArgs);
|
|
||||||
}
|
|
||||||
final String methodName;
|
|
||||||
if (pRemoteName == null || pRemoteName.length() == 0) {
|
|
||||||
methodName = pMethod.getName();
|
|
||||||
} else {
|
|
||||||
methodName = pRemoteName + "." + pMethod.getName();
|
|
||||||
}
|
|
||||||
Object result;
|
|
||||||
try {
|
|
||||||
result = client.execute(methodName, pArgs);
|
|
||||||
} catch (XmlRpcInvocationException e) {
|
|
||||||
Throwable t = e.linkedException;
|
|
||||||
if (t instanceof RuntimeException) {
|
|
||||||
throw t;
|
|
||||||
}
|
|
||||||
Class<?>[] exceptionTypes = pMethod.getExceptionTypes();
|
|
||||||
for (Class<?> c : exceptionTypes) {
|
|
||||||
if (c.isAssignableFrom(t.getClass())) {
|
|
||||||
throw t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UndeclaredThrowableException(t);
|
|
||||||
}
|
|
||||||
TypeConverter typeConverter = typeConverterFactory.getTypeConverter(pMethod.getReturnType());
|
|
||||||
return typeConverter.convert(result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>A callback object that can wait up to a specified amount
|
|
||||||
* of time for the XML-RPC response. Suggested use is as follows:
|
|
||||||
* </p>
|
|
||||||
* <pre>
|
|
||||||
* // Wait for 10 seconds.
|
|
||||||
* TimingOutCallback callback = new TimingOutCallback(10 * 1000);
|
|
||||||
* XmlRpcClient client = new XmlRpcClient(url);
|
|
||||||
* client.executeAsync(methodName, aVector, callback);
|
|
||||||
* try {
|
|
||||||
* return callback.waitForResponse();
|
|
||||||
* } catch (TimeoutException e) {
|
|
||||||
* System.out.println("No response from server.");
|
|
||||||
* } catch (Exception e) {
|
|
||||||
* System.out.println("Server returned an error message.");
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public class TimingOutCallback implements AsyncCallback {
|
|
||||||
/** This exception is thrown, if the request times out.
|
|
||||||
*/
|
|
||||||
public static class TimeoutException extends XmlRpcException {
|
|
||||||
private static final long serialVersionUID = 4875266372372105081L;
|
|
||||||
|
|
||||||
/** Creates a new instance with the given error code and
|
|
||||||
* error message.
|
|
||||||
*/
|
|
||||||
public TimeoutException(int pCode, String message) {
|
|
||||||
super(pCode, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final long timeout;
|
|
||||||
private Object result;
|
|
||||||
private Throwable error;
|
|
||||||
private boolean responseSeen;
|
|
||||||
|
|
||||||
/** Waits the specified number of milliseconds for a response.
|
|
||||||
*/
|
|
||||||
public TimingOutCallback(long pTimeout) {
|
|
||||||
timeout = pTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called to wait for the response.
|
|
||||||
* @throws InterruptedException The thread was interrupted.
|
|
||||||
* @throws TimeoutException No response was received after waiting the specified time.
|
|
||||||
* @throws Throwable An error was returned by the server.
|
|
||||||
*/
|
|
||||||
public synchronized Object waitForResponse() throws Throwable {
|
|
||||||
if (!responseSeen) {
|
|
||||||
wait(timeout);
|
|
||||||
if (!responseSeen) {
|
|
||||||
throw new TimeoutException(0, "No response after waiting for " + timeout + " milliseconds.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (error != null) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void handleError(XmlRpcRequest pRequest, Throwable pError) {
|
|
||||||
responseSeen = true;
|
|
||||||
error = pError;
|
|
||||||
notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void handleResult(XmlRpcRequest pRequest, Object pResult) {
|
|
||||||
responseSeen = true;
|
|
||||||
result = pResult;
|
|
||||||
notify();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,246 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcConfig;
|
|
||||||
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.XmlRpcWorkerFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.XmlWriterFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The main access point of an XML-RPC client. This object serves mainly
|
|
||||||
* as an object factory. It is designed with singletons in mind: Basically,
|
|
||||||
* an application should be able to hold a single instance of
|
|
||||||
* <code>XmlRpcClient</code> in a static variable, unless you would be
|
|
||||||
* working with different factories.</p>
|
|
||||||
* <p>Until Apache XML-RPC 2.0, this object was used both as an object
|
|
||||||
* factory and as a place, where configuration details (server URL,
|
|
||||||
* suggested encoding, user credentials and the like) have been stored.
|
|
||||||
* In Apache XML-RPC 3.0, the configuration details has been moved to
|
|
||||||
* the {@link XmlRpcClientConfig} object.
|
|
||||||
* The configuration object is designed for being passed through the
|
|
||||||
* actual worker methods.</p>
|
|
||||||
* <p>A configured XmlRpcClient object is thread safe: In other words,
|
|
||||||
* the suggested use is, that you configure the client using
|
|
||||||
* {@link #setTransportFactory(XmlRpcTransportFactory)} and similar
|
|
||||||
* methods, store it in a field and never modify it again. Without
|
|
||||||
* modifications, the client may be used for an arbitrary number
|
|
||||||
* of concurrent requests.</p>
|
|
||||||
*/
|
|
||||||
public class XmlRpcClient extends XmlRpcController {
|
|
||||||
|
|
||||||
private XmlRpcTransportFactory transportFactory = XmlRpcClientDefaults.newTransportFactory(this);
|
|
||||||
|
|
||||||
private XmlRpcClientConfig config = XmlRpcClientDefaults.newXmlRpcClientConfig();
|
|
||||||
|
|
||||||
private XmlWriterFactory xmlWriterFactory = XmlRpcClientDefaults.newXmlWriterFactory();
|
|
||||||
|
|
||||||
protected XmlRpcWorkerFactory getDefaultXmlRpcWorkerFactory() {
|
|
||||||
return new XmlRpcClientWorkerFactory(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the clients default configuration. This configuration
|
|
||||||
* is used by the methods
|
|
||||||
* {@link #execute(String, List)},
|
|
||||||
* {@link #execute(String, Object[])}, and
|
|
||||||
* {@link #execute(XmlRpcRequest)}.
|
|
||||||
* You may overwrite this per request by using
|
|
||||||
* {@link #execute(XmlRpcClientConfig, String, List)},
|
|
||||||
* or {@link #execute(XmlRpcClientConfig, String, Object[])}.
|
|
||||||
* @param pConfig The default request configuration.
|
|
||||||
*/
|
|
||||||
public void setConfig(XmlRpcClientConfig pConfig) {
|
|
||||||
config = pConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the clients default configuration. This configuration
|
|
||||||
* is used by the methods
|
|
||||||
* {@link #execute(String, List)},
|
|
||||||
* {@link #execute(String, Object[])}.
|
|
||||||
* You may overwrite this per request by using
|
|
||||||
* {@link #execute(XmlRpcClientConfig, String, List)},
|
|
||||||
* or {@link #execute(XmlRpcClientConfig, String, Object[])}.
|
|
||||||
* @return The default request configuration.
|
|
||||||
*/
|
|
||||||
public XmlRpcConfig getConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the clients default configuration. Shortcut for
|
|
||||||
* <code>(XmlRpcClientConfig) getConfig()</code>.
|
|
||||||
* This configuration is used by the methods
|
|
||||||
* {@link #execute(String, List)},
|
|
||||||
* {@link #execute(String, Object[])}.
|
|
||||||
* You may overwrite this per request by using
|
|
||||||
* {@link #execute(XmlRpcClientConfig, String, List)}, or
|
|
||||||
* {@link #execute(XmlRpcClientConfig, String, Object[])}
|
|
||||||
* @return The default request configuration.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientConfig getClientConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the clients transport factory. The client will invoke the
|
|
||||||
* factory method {@link XmlRpcTransportFactory#getTransport()}
|
|
||||||
* for any request.
|
|
||||||
* @param pFactory The clients transport factory.
|
|
||||||
*/
|
|
||||||
public void setTransportFactory(XmlRpcTransportFactory pFactory) {
|
|
||||||
transportFactory = pFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the clients transport factory. The client will use this factory
|
|
||||||
* for invocation of {@link XmlRpcTransportFactory#getTransport()}
|
|
||||||
* for any request.
|
|
||||||
* @return The clients transport factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcTransportFactory getTransportFactory() {
|
|
||||||
return transportFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a request with the clients default configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @return The result object.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public Object execute(String pMethodName, Object[] pParams) throws XmlRpcException {
|
|
||||||
return execute(getClientConfig(), pMethodName, pParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a request with the given configuration.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @return The result object.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public Object execute(XmlRpcClientConfig pConfig, String pMethodName, Object[] pParams) throws XmlRpcException {
|
|
||||||
return execute(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a request with the clients default configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @return The result object.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public Object execute(String pMethodName, List<Object> pParams) throws XmlRpcException {
|
|
||||||
return execute(getClientConfig(), pMethodName, pParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a request with the given configuration.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @return The result object.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public Object execute(XmlRpcClientConfig pConfig, String pMethodName, List<Object> pParams) throws XmlRpcException {
|
|
||||||
return execute(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a request with the clients default configuration.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @return The result object.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
|
|
||||||
return getWorkerFactory().getWorker().execute(pRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs an asynchronous request with the clients default configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @param pCallback The callback being notified when the request is finished.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public void executeAsync(String pMethodName, Object[] pParams,
|
|
||||||
AsyncCallback pCallback) throws XmlRpcException {
|
|
||||||
executeAsync(getClientConfig(), pMethodName, pParams, pCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs an asynchronous request with the given configuration.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @param pCallback The callback being notified when the request is finished.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public void executeAsync(XmlRpcClientConfig pConfig,
|
|
||||||
String pMethodName, Object[] pParams,
|
|
||||||
AsyncCallback pCallback) throws XmlRpcException {
|
|
||||||
executeAsync(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams),
|
|
||||||
pCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs an asynchronous request with the clients default configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @param pCallback The callback being notified when the request is finished.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public void executeAsync(String pMethodName, List<Object> pParams,
|
|
||||||
AsyncCallback pCallback) throws XmlRpcException {
|
|
||||||
executeAsync(getClientConfig(), pMethodName, pParams, pCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs an asynchronous request with the given configuration.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pMethodName The method being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @param pCallback The callback being notified when the request is finished.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public void executeAsync(XmlRpcClientConfig pConfig,
|
|
||||||
String pMethodName, List<Object> pParams,
|
|
||||||
AsyncCallback pCallback) throws XmlRpcException {
|
|
||||||
executeAsync(new XmlRpcClientRequestImpl(pConfig, pMethodName, pParams), pCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a request with the clients default configuration.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @param pCallback The callback being notified when the request is finished.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public void executeAsync(XmlRpcRequest pRequest,
|
|
||||||
AsyncCallback pCallback) throws XmlRpcException {
|
|
||||||
XmlRpcClientWorker w = (XmlRpcClientWorker) getWorkerFactory().getWorker();
|
|
||||||
w.execute(pRequest, pCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the clients instance of
|
|
||||||
* {@link XmlWriterFactory}.
|
|
||||||
* @return A factory for creating instances.
|
|
||||||
*/
|
|
||||||
public XmlWriterFactory getXmlWriterFactory() {
|
|
||||||
return xmlWriterFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the clients instance of
|
|
||||||
* {@link XmlWriterFactory}.
|
|
||||||
* @param pFactory A factory for creating instances}.
|
|
||||||
*/
|
|
||||||
public void setXmlWriterFactory(XmlWriterFactory pFactory) {
|
|
||||||
xmlWriterFactory = pFactory;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequestConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface is being implemented by an Apache XML-RPC clients
|
|
||||||
* configuration object. Depending on the transport factory, a
|
|
||||||
* configuration object must implement additional methods. For
|
|
||||||
* example, an HTTP transport requires an instance of
|
|
||||||
* {@link XmlRpcHttpClientConfig}. A
|
|
||||||
* local transport requires an instance of
|
|
||||||
* {@link XmlRpcLocalClientConfig}.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcClientConfig extends XmlRpcRequestConfig {
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequestProcessor;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of a clients request configuration.
|
|
||||||
*/
|
|
||||||
public class XmlRpcClientConfigImpl extends XmlRpcHttpRequestConfigImpl
|
|
||||||
implements XmlRpcHttpClientConfig, XmlRpcLocalClientConfig, Cloneable, Serializable {
|
|
||||||
private static final long serialVersionUID = 4121131450507800889L;
|
|
||||||
private URL serverURL;
|
|
||||||
private XmlRpcRequestProcessor xmlRpcServer;
|
|
||||||
private String userAgent;
|
|
||||||
|
|
||||||
/** Creates a new client configuration with default settings.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientConfigImpl() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a clone of this client configuration.
|
|
||||||
* @return A clone of this configuration.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientConfigImpl cloneMe() {
|
|
||||||
try {
|
|
||||||
return (XmlRpcClientConfigImpl) clone();
|
|
||||||
} catch (CloneNotSupportedException e) {
|
|
||||||
throw new IllegalStateException("Unable to create my clone");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets the servers URL.
|
|
||||||
* @param pURL Servers URL
|
|
||||||
*/
|
|
||||||
public void setServerURL(URL pURL) {
|
|
||||||
serverURL = pURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getServerURL() { return serverURL; }
|
|
||||||
/** Returns the {@link XmlRpcRequestProcessor} being invoked.
|
|
||||||
* @param pServer Server object being invoked. This will typically
|
|
||||||
* be a singleton instance, but could as well create a new
|
|
||||||
* instance with any call.
|
|
||||||
*/
|
|
||||||
public void setXmlRpcServer(XmlRpcRequestProcessor pServer) {
|
|
||||||
xmlRpcServer = pServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcRequestProcessor getXmlRpcServer() { return xmlRpcServer; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the user agent header to use
|
|
||||||
* @return the http user agent header to set when doing xmlrpc requests
|
|
||||||
*/
|
|
||||||
public String getUserAgent() {
|
|
||||||
return userAgent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param pUserAgent the http user agent header to set when doing xmlrpc requests
|
|
||||||
*/
|
|
||||||
public void setUserAgent(String pUserAgent) {
|
|
||||||
userAgent = pUserAgent;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.DefaultXMLWriterFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.XmlWriterFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is responsible to provide default settings.
|
|
||||||
*/
|
|
||||||
public class XmlRpcClientDefaults {
|
|
||||||
|
|
||||||
private static final XmlWriterFactory xmlWriterFactory = new DefaultXMLWriterFactory();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new transport factory for the given client.
|
|
||||||
*/
|
|
||||||
public static XmlRpcTransportFactory newTransportFactory(XmlRpcClient pClient) {
|
|
||||||
try {
|
|
||||||
return new XmlRpcSun15HttpTransportFactory(pClient);
|
|
||||||
} catch (Throwable t1) {
|
|
||||||
try {
|
|
||||||
return new XmlRpcSun14HttpTransportFactory(pClient);
|
|
||||||
} catch (Throwable t2) {
|
|
||||||
return new XmlRpcSunHttpTransportFactory(pClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of {@link XmlRpcClientConfig}.
|
|
||||||
*/
|
|
||||||
public static XmlRpcClientConfig newXmlRpcClientConfig() {
|
|
||||||
return new XmlRpcClientConfigImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link XmlWriterFactory}.
|
|
||||||
*/
|
|
||||||
public static XmlWriterFactory newXmlWriterFactory() {
|
|
||||||
return xmlWriterFactory;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
|
|
||||||
/** <p>This is thrown by many of the client classes if an error occured processing
|
|
||||||
* and XML-RPC request or response due to client side processing..</p>
|
|
||||||
*/
|
|
||||||
public class XmlRpcClientException extends XmlRpcException {
|
|
||||||
private static final long serialVersionUID = 3545798797134608691L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an XmlRpcClientException with the given message and
|
|
||||||
* underlying cause exception.
|
|
||||||
*
|
|
||||||
* @param pMessage the message for this exception.
|
|
||||||
* @param pCause the cause of the exception.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientException(String pMessage, Throwable pCause) {
|
|
||||||
super(0, pMessage, pCause);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequestConfig;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of
|
|
||||||
* {@link XmlRpcRequest}.
|
|
||||||
*/
|
|
||||||
public class XmlRpcClientRequestImpl implements XmlRpcRequest {
|
|
||||||
|
|
||||||
private static final Object[] ZERO_PARAMS = new Object[0];
|
|
||||||
|
|
||||||
private final XmlRpcRequestConfig config;
|
|
||||||
|
|
||||||
private final String methodName;
|
|
||||||
|
|
||||||
private final Object[] params;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pMethodName The method name being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @throws NullPointerException One of the parameters is null.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientRequestImpl(XmlRpcRequestConfig pConfig,
|
|
||||||
String pMethodName, Object[] pParams) {
|
|
||||||
config = pConfig;
|
|
||||||
if (config == null) {
|
|
||||||
throw new NullPointerException("The request configuration must not be null.");
|
|
||||||
}
|
|
||||||
methodName = pMethodName;
|
|
||||||
if (methodName == null) {
|
|
||||||
throw new NullPointerException("The method name must not be null.");
|
|
||||||
}
|
|
||||||
params = pParams == null ? ZERO_PARAMS : pParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pMethodName The method name being performed.
|
|
||||||
* @param pParams The parameters.
|
|
||||||
* @throws NullPointerException The method name or the parameters are null.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientRequestImpl(XmlRpcRequestConfig pConfig,
|
|
||||||
String pMethodName, List<Object> pParams) {
|
|
||||||
this(pConfig, pMethodName, pParams == null ? null : pParams.toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMethodName() { return methodName; }
|
|
||||||
|
|
||||||
public int getParameterCount() { return params.length; }
|
|
||||||
|
|
||||||
public Object getParameter(int pIndex) { return params[pIndex]; }
|
|
||||||
|
|
||||||
public XmlRpcRequestConfig getConfig() { return config; }
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
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.XmlRpcWorker;
|
|
||||||
|
|
||||||
/** Object, which performs a request on the clients behalf.
|
|
||||||
* The client maintains a pool of workers. The main purpose of the
|
|
||||||
* pool is limitation of the maximum number of concurrent requests.
|
|
||||||
*/
|
|
||||||
public class XmlRpcClientWorker implements XmlRpcWorker {
|
|
||||||
private final XmlRpcClientWorkerFactory factory;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pFactory The factory, which is being notified, if
|
|
||||||
* the worker's ready.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientWorker(XmlRpcClientWorkerFactory pFactory) {
|
|
||||||
factory = pFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcController getController() {
|
|
||||||
return factory.getController();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Performs a synchronous request.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @return The requests result.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
public Object execute(XmlRpcRequest pRequest)
|
|
||||||
throws XmlRpcException {
|
|
||||||
try {
|
|
||||||
XmlRpcClient client = (XmlRpcClient) getController();
|
|
||||||
return client.getTransportFactory().getTransport().sendRequest(pRequest);
|
|
||||||
} finally {
|
|
||||||
factory.releaseWorker(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Thread newThread(Runnable pRunnable) {
|
|
||||||
Thread result = new Thread(pRunnable);
|
|
||||||
result.setDaemon(true);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Performs an synchronous request.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @param pCallback The callback being invoked, when the request is finished.
|
|
||||||
*/
|
|
||||||
public void execute(final XmlRpcRequest pRequest,
|
|
||||||
final AsyncCallback pCallback) {
|
|
||||||
Runnable runnable = new Runnable(){
|
|
||||||
public void run(){
|
|
||||||
Object result = null;
|
|
||||||
Throwable th = null;
|
|
||||||
try {
|
|
||||||
XmlRpcClient client = (XmlRpcClient) getController();
|
|
||||||
result = client.getTransportFactory().getTransport().sendRequest(pRequest);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
th = t;
|
|
||||||
}
|
|
||||||
factory.releaseWorker(XmlRpcClientWorker.this);
|
|
||||||
if (th == null) {
|
|
||||||
pCallback.handleResult(pRequest, result);
|
|
||||||
} else {
|
|
||||||
pCallback.handleError(pRequest, th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
newThread(runnable).start();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcWorker;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcWorkerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A worker factory for the client, creating instances of
|
|
||||||
* {@link XmlRpcClientWorker}.
|
|
||||||
*/
|
|
||||||
public class XmlRpcClientWorkerFactory extends XmlRpcWorkerFactory {
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pClient The factory controller.
|
|
||||||
*/
|
|
||||||
public XmlRpcClientWorkerFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a new worker instance.
|
|
||||||
* @return New instance of {@link XmlRpcClientWorker}.
|
|
||||||
*/
|
|
||||||
protected XmlRpcWorker newWorker() {
|
|
||||||
return new XmlRpcClientWorker(this);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,242 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.FilterOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.Credentials;
|
|
||||||
import org.apache.commons.httpclient.Header;
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.httpclient.HttpVersion;
|
|
||||||
import org.apache.commons.httpclient.URI;
|
|
||||||
import org.apache.commons.httpclient.URIException;
|
|
||||||
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
|
||||||
import org.apache.commons.httpclient.auth.AuthScope;
|
|
||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
|
||||||
import org.apache.commons.httpclient.params.HttpMethodParams;
|
|
||||||
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.XmlRpcStreamRequestConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.HttpUtil;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An HTTP transport factory, which is based on the Jakarta Commons HTTP Client.
|
|
||||||
*/
|
|
||||||
public class XmlRpcCommonsTransport extends XmlRpcHttpTransport {
|
|
||||||
/**
|
|
||||||
* Maximum number of allowed redirects.
|
|
||||||
*/
|
|
||||||
private static final int MAX_REDIRECT_ATTEMPTS = 100;
|
|
||||||
|
|
||||||
protected final HttpClient client;
|
|
||||||
private static final String userAgent = USER_AGENT + " (Jakarta Commons httpclient Transport)";
|
|
||||||
protected PostMethod method;
|
|
||||||
private int contentLength = -1;
|
|
||||||
private XmlRpcHttpClientConfig config;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pFactory The factory, which created this transport.
|
|
||||||
*/
|
|
||||||
public XmlRpcCommonsTransport(XmlRpcCommonsTransportFactory pFactory) {
|
|
||||||
super(pFactory.getClient(), userAgent);
|
|
||||||
HttpClient httpClient = pFactory.getHttpClient();
|
|
||||||
if (httpClient == null) {
|
|
||||||
httpClient = newHttpClient();
|
|
||||||
}
|
|
||||||
client = httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setContentLength(int pLength) {
|
|
||||||
contentLength = pLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected HttpClient newHttpClient() {
|
|
||||||
return new HttpClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException {
|
|
||||||
config = (XmlRpcHttpClientConfig) pRequest.getConfig();
|
|
||||||
method = newPostMethod(config);
|
|
||||||
super.initHttpHeaders(pRequest);
|
|
||||||
|
|
||||||
if (config.getConnectionTimeout() != 0)
|
|
||||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout());
|
|
||||||
|
|
||||||
if (config.getReplyTimeout() != 0)
|
|
||||||
client.getHttpConnectionManager().getParams().setSoTimeout(config.getReplyTimeout());
|
|
||||||
|
|
||||||
method.getParams().setVersion(HttpVersion.HTTP_1_1);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected PostMethod newPostMethod(XmlRpcHttpClientConfig pConfig) {
|
|
||||||
return new PostMethod(pConfig.getServerURL().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setRequestHeader(String pHeader, String pValue) {
|
|
||||||
method.setRequestHeader(new Header(pHeader, pValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isResponseGzipCompressed() {
|
|
||||||
Header h = method.getResponseHeader( "Content-Encoding" );
|
|
||||||
if (h == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return HttpUtil.isUsingGzipEncoding(h.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InputStream getInputStream() throws XmlRpcException {
|
|
||||||
try {
|
|
||||||
checkStatus(method);
|
|
||||||
return method.getResponseBodyAsStream();
|
|
||||||
} catch (HttpException e) {
|
|
||||||
throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setCredentials(XmlRpcHttpClientConfig pConfig) throws XmlRpcClientException {
|
|
||||||
String userName = pConfig.getBasicUserName();
|
|
||||||
if (userName != null) {
|
|
||||||
String enc = pConfig.getBasicEncoding();
|
|
||||||
if (enc == null) {
|
|
||||||
enc = XmlRpcStreamConfig.UTF8_ENCODING;
|
|
||||||
}
|
|
||||||
client.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, enc);
|
|
||||||
Credentials creds = new UsernamePasswordCredentials(userName, pConfig.getBasicPassword());
|
|
||||||
AuthScope scope = new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME);
|
|
||||||
client.getState().setCredentials(scope, creds);
|
|
||||||
client.getParams().setAuthenticationPreemptive(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void close() throws XmlRpcClientException {
|
|
||||||
method.releaseConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig) {
|
|
||||||
Header h = method.getResponseHeader( "Content-Encoding" );
|
|
||||||
if (h == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return HttpUtil.isUsingGzipEncoding(h.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isRedirectRequired() {
|
|
||||||
switch (method.getStatusCode()) {
|
|
||||||
case HttpStatus.SC_MOVED_TEMPORARILY:
|
|
||||||
case HttpStatus.SC_MOVED_PERMANENTLY:
|
|
||||||
case HttpStatus.SC_SEE_OTHER:
|
|
||||||
case HttpStatus.SC_TEMPORARY_REDIRECT:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void resetClientForRedirect()
|
|
||||||
throws XmlRpcException {
|
|
||||||
//get the location header to find out where to redirect to
|
|
||||||
Header locationHeader = method.getResponseHeader("location");
|
|
||||||
if (locationHeader == null) {
|
|
||||||
throw new XmlRpcException("Invalid redirect: Missing location header");
|
|
||||||
}
|
|
||||||
String location = locationHeader.getValue();
|
|
||||||
|
|
||||||
URI redirectUri = null;
|
|
||||||
URI currentUri = null;
|
|
||||||
try {
|
|
||||||
currentUri = method.getURI();
|
|
||||||
String charset = currentUri.getProtocolCharset();
|
|
||||||
redirectUri = new URI(location, true, charset);
|
|
||||||
method.setURI(redirectUri);
|
|
||||||
} catch (URIException ex) {
|
|
||||||
throw new XmlRpcException(ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
//And finally invalidate the actual authentication scheme
|
|
||||||
method.getHostAuthState().invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeRequest(final ReqWriter pWriter) throws XmlRpcException {
|
|
||||||
method.setRequestEntity(new RequestEntity(){
|
|
||||||
public boolean isRepeatable() { return true; }
|
|
||||||
public void writeRequest(OutputStream pOut) throws IOException {
|
|
||||||
try {
|
|
||||||
/* Make sure, that the socket is not closed by replacing it with our
|
|
||||||
* own BufferedOutputStream.
|
|
||||||
*/
|
|
||||||
OutputStream ostream;
|
|
||||||
if (isUsingByteArrayOutput(config)) {
|
|
||||||
// No need to buffer the output.
|
|
||||||
ostream = new FilterOutputStream(pOut){
|
|
||||||
public void close() throws IOException {
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
ostream = new BufferedOutputStream(pOut){
|
|
||||||
public void close() throws IOException {
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
pWriter.write(ostream);
|
|
||||||
} catch (XmlRpcException e) {
|
|
||||||
throw new XmlRpcIOException(e);
|
|
||||||
} catch (SAXException e) {
|
|
||||||
throw new XmlRpcIOException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public long getContentLength() { return contentLength; }
|
|
||||||
public String getContentType() { return "text/xml"; }
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
int redirectAttempts = 0;
|
|
||||||
for (;;) {
|
|
||||||
client.executeMethod(method);
|
|
||||||
if (!isRedirectRequired()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (redirectAttempts++ > MAX_REDIRECT_ATTEMPTS) {
|
|
||||||
throw new XmlRpcException("Too many redirects.");
|
|
||||||
}
|
|
||||||
resetClientForRedirect();
|
|
||||||
}
|
|
||||||
} catch (XmlRpcIOException e) {
|
|
||||||
Throwable t = e.getLinkedException();
|
|
||||||
if (t instanceof XmlRpcException) {
|
|
||||||
throw (XmlRpcException) t;
|
|
||||||
} else {
|
|
||||||
throw new XmlRpcException("Unexpected exception: " + t.getMessage(), t);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcException("I/O error while communicating with HTTP server: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check the status of the HTTP request and throw an XmlRpcHttpTransportException if it
|
|
||||||
* indicates that there is an error.
|
|
||||||
* @param pMethod the method that has been executed
|
|
||||||
* @throws XmlRpcHttpTransportException if the status of the method indicates that there is an error.
|
|
||||||
*/
|
|
||||||
private void checkStatus(HttpMethod pMethod) throws XmlRpcHttpTransportException {
|
|
||||||
final int status = pMethod.getStatusCode();
|
|
||||||
|
|
||||||
// All status codes except SC_OK are handled as errors. Perhaps some should require special handling (e.g., SC_UNAUTHORIZED)
|
|
||||||
if (status < 200 || status > 299) {
|
|
||||||
throw new XmlRpcHttpTransportException(status, pMethod.getStatusText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
|
|
||||||
|
|
||||||
/** An HTTP transport factory, which is based on the Jakarta Commons
|
|
||||||
* HTTP Client.
|
|
||||||
*/
|
|
||||||
public class XmlRpcCommonsTransportFactory extends XmlRpcTransportFactoryImpl {
|
|
||||||
private HttpClient httpClient;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pClient The client, which is controlling the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcCommonsTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() {
|
|
||||||
return new XmlRpcCommonsTransport(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Sets the factories {@link HttpClient}. By default, a new instance
|
|
||||||
* of {@link HttpClient} is created for any request.</p>
|
|
||||||
* <p>Reusing the {@link HttpClient} is required, if you want to preserve
|
|
||||||
* some state between requests. This applies, in particular, if you want
|
|
||||||
* to use cookies: In that case, create an instance of {@link HttpClient},
|
|
||||||
* give it to the factory, and use {@link HttpClient#getState()} to
|
|
||||||
* read or set cookies.
|
|
||||||
*/
|
|
||||||
public void setHttpClient(HttpClient pHttpClient) {
|
|
||||||
httpClient = pHttpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Returns the factories {@link HttpClient}. By default, a new instance
|
|
||||||
* of {@link HttpClient} is created for any request.</p>
|
|
||||||
* <p>Reusing the {@link HttpClient} is required, if you want to preserve
|
|
||||||
* some state between requests. This applies, in particular, if you want
|
|
||||||
* to use cookies: In that case, create an instance of {@link HttpClient},
|
|
||||||
* give it to the factory, and use {@link HttpClient#getState()} to
|
|
||||||
* read or set cookies.
|
|
||||||
*/
|
|
||||||
public HttpClient getHttpClient() {
|
|
||||||
return httpClient;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcHttpRequestConfig;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/** Extension of {@link XmlRpcClientConfig}
|
|
||||||
* for HTTP based transport. Provides details like server URL,
|
|
||||||
* user credentials, and so on.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcHttpClientConfig extends XmlRpcHttpRequestConfig {
|
|
||||||
/** Returns the HTTP servers URL.
|
|
||||||
* @return XML-RPC servers URL; for example, this may be the URL of a
|
|
||||||
* servlet
|
|
||||||
*/
|
|
||||||
URL getServerURL();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the user agent header to use
|
|
||||||
* @return the http user agent header to set when doing xmlrpc requests
|
|
||||||
*/
|
|
||||||
String getUserAgent();
|
|
||||||
}
|
|
|
@ -1,147 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.HttpUtil;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
|
|
||||||
/** Abstract base implementation of an HTTP transport. Base class for the
|
|
||||||
* concrete implementations, like {@link XmlRpcSunHttpTransport},
|
|
||||||
* or {@link XmlRpcCommonsTransport}.
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcHttpTransport extends XmlRpcStreamTransport {
|
|
||||||
protected class ByteArrayReqWriter implements ReqWriter {
|
|
||||||
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
ByteArrayReqWriter(XmlRpcRequest pRequest)
|
|
||||||
throws XmlRpcException, IOException, SAXException {
|
|
||||||
new ReqWriterImpl(pRequest).write(baos);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getContentLength() {
|
|
||||||
return baos.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(OutputStream pStream) throws IOException {
|
|
||||||
try {
|
|
||||||
baos.writeTo(pStream);
|
|
||||||
pStream.close();
|
|
||||||
pStream = null;
|
|
||||||
} finally {
|
|
||||||
if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The user agent string.
|
|
||||||
*/
|
|
||||||
public static final String USER_AGENT;
|
|
||||||
static {
|
|
||||||
final String p = "XmlRpcClient.properties";
|
|
||||||
final URL url = XmlRpcHttpTransport.class.getResource(p);
|
|
||||||
if (url == null) {
|
|
||||||
throw new IllegalStateException("Failed to locate resource: " + p);
|
|
||||||
}
|
|
||||||
InputStream stream = null;
|
|
||||||
try {
|
|
||||||
stream = url.openStream();
|
|
||||||
final Properties props = new Properties();
|
|
||||||
props.load(stream);
|
|
||||||
USER_AGENT = props.getProperty("user.agent");
|
|
||||||
if (USER_AGENT == null || USER_AGENT.trim().length() == 0) {
|
|
||||||
throw new IllegalStateException("The property user.agent is not set.");
|
|
||||||
}
|
|
||||||
stream.close();
|
|
||||||
stream = null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new UndeclaredThrowableException(e, "Failed to load resource " + url + ": " + e.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (stream != null) { try { stream.close(); } catch (Throwable t) { /* Ignore me */ } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String userAgent;
|
|
||||||
|
|
||||||
|
|
||||||
protected XmlRpcHttpTransport(XmlRpcClient pClient, String pUserAgent) {
|
|
||||||
super(pClient);
|
|
||||||
userAgent = pUserAgent;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getUserAgent() { return userAgent; }
|
|
||||||
|
|
||||||
protected abstract void setRequestHeader(String pHeader, String pValue);
|
|
||||||
|
|
||||||
protected void setCredentials(XmlRpcHttpClientConfig pConfig)
|
|
||||||
throws XmlRpcClientException {
|
|
||||||
String auth;
|
|
||||||
try {
|
|
||||||
auth = HttpUtil.encodeBasicAuthentication(pConfig.getBasicUserName(),
|
|
||||||
pConfig.getBasicPassword(),
|
|
||||||
pConfig.getBasicEncoding());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new XmlRpcClientException("Unsupported encoding: " + pConfig.getBasicEncoding(), e);
|
|
||||||
}
|
|
||||||
if (auth != null) {
|
|
||||||
setRequestHeader("Authorization", "Basic " + auth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setContentLength(int pLength) {
|
|
||||||
setRequestHeader("Content-Length", Integer.toString(pLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setCompressionHeaders(XmlRpcHttpClientConfig pConfig) {
|
|
||||||
if (pConfig.isGzipCompressing()) {
|
|
||||||
setRequestHeader("Content-Encoding", "gzip");
|
|
||||||
}
|
|
||||||
if (pConfig.isGzipRequesting()) {
|
|
||||||
setRequestHeader("Accept-Encoding", "gzip");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException {
|
|
||||||
XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
|
|
||||||
setRequestHeader("Content-Type", "text/xml");
|
|
||||||
if(config.getUserAgent() != null)
|
|
||||||
setRequestHeader("User-Agent", config.getUserAgent());
|
|
||||||
else
|
|
||||||
setRequestHeader("User-Agent", getUserAgent());
|
|
||||||
setCredentials(config);
|
|
||||||
setCompressionHeaders(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
|
|
||||||
initHttpHeaders(pRequest);
|
|
||||||
return super.sendRequest(pRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig pConfig) {
|
|
||||||
return !pConfig.isEnabledForExtensions()
|
|
||||||
|| !pConfig.isContentLengthOptional();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
|
|
||||||
throws XmlRpcException, IOException, SAXException {
|
|
||||||
final XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
|
|
||||||
if (isUsingByteArrayOutput(config)) {
|
|
||||||
ByteArrayReqWriter reqWriter = new ByteArrayReqWriter(pRequest);
|
|
||||||
setContentLength(reqWriter.getContentLength());
|
|
||||||
if (isCompressingRequest(config)) {
|
|
||||||
return new GzipReqWriter(reqWriter);
|
|
||||||
}
|
|
||||||
return reqWriter;
|
|
||||||
} else {
|
|
||||||
return super.newReqWriter(pRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown if the HTTP status code sent by the server
|
|
||||||
* indicates that the request could not be processed. In
|
|
||||||
* general, the 400 and 500 level HTTP status codes will
|
|
||||||
* result in an XmlRpcHttpTransportException being thrown.
|
|
||||||
*/
|
|
||||||
public class XmlRpcHttpTransportException extends XmlRpcException {
|
|
||||||
private static final long serialVersionUID = -6933992871198450027L;
|
|
||||||
|
|
||||||
private final int status;
|
|
||||||
private final String statusMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance with the specified HTTP status code
|
|
||||||
* and HTTP status message.
|
|
||||||
* @param pCode The HTTP status code
|
|
||||||
* @param pMessage The HTTP status message returned by the HTTP server
|
|
||||||
*/
|
|
||||||
public XmlRpcHttpTransportException(int pCode, String pMessage) {
|
|
||||||
this(pCode, pMessage, "HTTP server returned unexpected status: " + pMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new XmlRpcHttpTransportException with the specified HTTP status code,
|
|
||||||
* HTTP status message, and exception message.
|
|
||||||
* @param httpStatusCode the HTTP status code
|
|
||||||
* @param httpStatusMessage the HTTP status message returned by the HTTP server
|
|
||||||
* @param message the exception message.
|
|
||||||
*/
|
|
||||||
public XmlRpcHttpTransportException(int httpStatusCode, String httpStatusMessage, String message) {
|
|
||||||
super( message );
|
|
||||||
this.status = httpStatusCode;
|
|
||||||
this.statusMessage = httpStatusMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the HTTP status code that resulted in this exception.
|
|
||||||
* @return the HTTP status code that resulted in this exception.
|
|
||||||
*/
|
|
||||||
public int getStatusCode()
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the status message returned by the HTTP server.
|
|
||||||
* @return the status message returned by the HTTP server.
|
|
||||||
*/
|
|
||||||
public String getStatusMessage()
|
|
||||||
{
|
|
||||||
return statusMessage;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/** This is a subclass of {@link IOException}, which
|
|
||||||
* allows to attach a linked exception. Throwing this
|
|
||||||
* particular instance of {@link IOException} allows
|
|
||||||
* to catch it and throw the linked exception instead.
|
|
||||||
*/
|
|
||||||
public class XmlRpcIOException extends IOException {
|
|
||||||
private static final long serialVersionUID = -7704704099502077919L;
|
|
||||||
private final Throwable linkedException;
|
|
||||||
|
|
||||||
/** Creates a new instance of {@link XmlRpcIOException}
|
|
||||||
* with the given cause.
|
|
||||||
*/
|
|
||||||
public XmlRpcIOException(Throwable t) {
|
|
||||||
super(t.getMessage());
|
|
||||||
linkedException = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the linked exception, which is the actual
|
|
||||||
* cause for this exception.
|
|
||||||
*/
|
|
||||||
public Throwable getLinkedException() {
|
|
||||||
return linkedException;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A "light" HTTP transport implementation for Java 1.4.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLite14HttpTransport extends XmlRpcLiteHttpTransport {
|
|
||||||
private SSLSocketFactory sslSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pClient The client controlling this instance.
|
|
||||||
*/
|
|
||||||
public XmlRpcLite14HttpTransport(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the SSL Socket Factory to use for https connections.
|
|
||||||
*/
|
|
||||||
public SSLSocketFactory getSSLSocketFactory() {
|
|
||||||
return sslSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SSL Socket Factory to use for https connections.
|
|
||||||
*/
|
|
||||||
public void setSSLSocketFactory(SSLSocketFactory pSSLSocketFactory) {
|
|
||||||
sslSocketFactory = pSSLSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Socket newSocket(boolean pSSL, String pHostName, int pPort) throws UnknownHostException, IOException {
|
|
||||||
if (pSSL) {
|
|
||||||
SSLSocketFactory sslSockFactory = getSSLSocketFactory();
|
|
||||||
if (sslSockFactory == null) {
|
|
||||||
sslSockFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
|
|
||||||
}
|
|
||||||
return sslSockFactory.createSocket(pHostName, pPort);
|
|
||||||
} else {
|
|
||||||
return super.newSocket(pSSL, pHostName, pPort);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Java 1.4 specific factory for the lite HTTP transport,
|
|
||||||
* {@link XmlRpcLiteHttpTransport}.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLite14HttpTransportFactory extends XmlRpcLiteHttpTransportFactory {
|
|
||||||
private SSLSocketFactory sslSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pClient The client, which will invoke the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcLite14HttpTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the SSL Socket Factory to use for https connections.
|
|
||||||
*/
|
|
||||||
public SSLSocketFactory getSSLSocketFactory() {
|
|
||||||
return sslSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SSL Socket Factory to use for https connections.
|
|
||||||
*/
|
|
||||||
public void setSSLSocketFactory(SSLSocketFactory pSSLSocketFactory) {
|
|
||||||
sslSocketFactory = pSSLSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() {
|
|
||||||
XmlRpcLite14HttpTransport transport = new XmlRpcLite14HttpTransport(getClient());
|
|
||||||
transport.setSSLSocketFactory(sslSocketFactory);
|
|
||||||
return transport;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,260 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.ConnectException;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.HttpUtil;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.LimitedInputStream;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A "light" HTTP transport implementation.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLiteHttpTransport extends XmlRpcHttpTransport {
|
|
||||||
private static final String userAgent = USER_AGENT + " (Lite HTTP Transport)";
|
|
||||||
private boolean ssl;
|
|
||||||
private String hostname;
|
|
||||||
private String host;
|
|
||||||
private int port;
|
|
||||||
private String uri;
|
|
||||||
private Socket socket;
|
|
||||||
private OutputStream output;
|
|
||||||
private InputStream input;
|
|
||||||
private final Map<String, Object> headers = new HashMap<>();
|
|
||||||
private boolean responseGzipCompressed = false;
|
|
||||||
private XmlRpcHttpClientConfig config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pClient The client controlling this instance.
|
|
||||||
*/
|
|
||||||
public XmlRpcLiteHttpTransport(XmlRpcClient pClient) {
|
|
||||||
super(pClient, userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
|
|
||||||
config = (XmlRpcHttpClientConfig) pRequest.getConfig();
|
|
||||||
URL url = config.getServerURL();
|
|
||||||
ssl = "https".equals(url.getProtocol());
|
|
||||||
hostname = url.getHost();
|
|
||||||
int p = url.getPort();
|
|
||||||
port = p < 1 ? 80 : p;
|
|
||||||
String u = url.getFile();
|
|
||||||
uri = (u == null || "".equals(u)) ? "/" : u;
|
|
||||||
host = port == 80 ? hostname : hostname + ":" + port;
|
|
||||||
headers.put("Host", host);
|
|
||||||
return super.sendRequest(pRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
protected void setRequestHeader(String pHeader, String pValue) {
|
|
||||||
Object value = headers.get(pHeader);
|
|
||||||
if (value == null) {
|
|
||||||
headers.put(pHeader, pValue);
|
|
||||||
} else {
|
|
||||||
List<Object> list;
|
|
||||||
if (value instanceof String) {
|
|
||||||
list = new ArrayList<>();
|
|
||||||
list.add(value);
|
|
||||||
headers.put(pHeader, list);
|
|
||||||
} else {
|
|
||||||
list = (List) value;
|
|
||||||
}
|
|
||||||
list.add(pValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void close() throws XmlRpcClientException {
|
|
||||||
IOException e = null;
|
|
||||||
if (input != null) {
|
|
||||||
try {
|
|
||||||
input.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
e = ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (output != null) {
|
|
||||||
try {
|
|
||||||
output.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
if (e != null) {
|
|
||||||
e = ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (socket != null) {
|
|
||||||
try {
|
|
||||||
socket.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
if (e != null) {
|
|
||||||
e = ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e != null) {
|
|
||||||
throw new XmlRpcClientException("Failed to close connection: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private OutputStream getOutputStream() throws XmlRpcException {
|
|
||||||
try {
|
|
||||||
final int retries = 3;
|
|
||||||
final int delayMillis = 100;
|
|
||||||
|
|
||||||
for (int tries = 0; ; tries++) {
|
|
||||||
try {
|
|
||||||
socket = newSocket(ssl, hostname, port);
|
|
||||||
output = new BufferedOutputStream(socket.getOutputStream()){
|
|
||||||
/** Closing the output stream would close the whole socket, which we don't want,
|
|
||||||
* because the don't want until the request is processed completely.
|
|
||||||
* A close will later occur within
|
|
||||||
* {@link XmlRpcLiteHttpTransport#close()}.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
flush();
|
|
||||||
socket.shutdownOutput();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
} catch (ConnectException e) {
|
|
||||||
if (tries >= retries) {
|
|
||||||
throw new XmlRpcException("Failed to connect to "
|
|
||||||
+ hostname + ":" + port + ": " + e.getMessage(), e);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
Thread.sleep(delayMillis);
|
|
||||||
} catch (InterruptedException ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendRequestHeaders(output);
|
|
||||||
return output;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcException("Failed to open connection to "
|
|
||||||
+ hostname + ":" + port + ": " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Socket newSocket(boolean pSSL, String pHostName, int pPort) throws UnknownHostException, IOException {
|
|
||||||
if (pSSL) {
|
|
||||||
throw new IOException("Unable to create SSL connections, use the XmlRpcLite14HttpTransportFactory.");
|
|
||||||
}
|
|
||||||
return new Socket(pHostName, pPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] toHTTPBytes(String pValue) throws UnsupportedEncodingException {
|
|
||||||
return pValue.getBytes(StandardCharsets.US_ASCII);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendHeader(OutputStream pOut, String pKey, String pValue) throws IOException {
|
|
||||||
pOut.write(toHTTPBytes(pKey + ": " + pValue + "\r\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void sendRequestHeaders(OutputStream pOut) throws IOException {
|
|
||||||
pOut.write(("POST " + uri + " HTTP/1.0\r\n").getBytes(StandardCharsets.US_ASCII));
|
|
||||||
for (Object o : headers.entrySet()) {
|
|
||||||
Map.Entry<String, Object> entry = (Map.Entry) o;
|
|
||||||
String key = entry.getKey();
|
|
||||||
Object value = entry.getValue();
|
|
||||||
if (value instanceof String) {
|
|
||||||
sendHeader(pOut, key, (String) value);
|
|
||||||
} else {
|
|
||||||
List<Object> list = (List) value;
|
|
||||||
for (Object item : list) {
|
|
||||||
sendHeader(pOut, key, (String) item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pOut.write(toHTTPBytes("\r\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig) {
|
|
||||||
return responseGzipCompressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected InputStream getInputStream() throws XmlRpcException {
|
|
||||||
final byte[] buffer = new byte[2048];
|
|
||||||
try {
|
|
||||||
// If reply timeout specified, set the socket timeout accordingly
|
|
||||||
if (config.getReplyTimeout() != 0)
|
|
||||||
socket.setSoTimeout(config.getReplyTimeout());
|
|
||||||
input = new BufferedInputStream(socket.getInputStream());
|
|
||||||
// start reading server response headers
|
|
||||||
String line = HttpUtil.readLine(input, buffer);
|
|
||||||
StringTokenizer tokens = new StringTokenizer(line);
|
|
||||||
tokens.nextToken(); // Skip HTTP version
|
|
||||||
String statusCode = tokens.nextToken();
|
|
||||||
String statusMsg = tokens.nextToken("\n\r");
|
|
||||||
final int code;
|
|
||||||
try {
|
|
||||||
code = Integer.parseInt(statusCode);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new XmlRpcClientException("Server returned invalid status code: "
|
|
||||||
+ statusCode + " " + statusMsg, null);
|
|
||||||
}
|
|
||||||
if (code < 200 || code > 299) {
|
|
||||||
throw new XmlRpcHttpTransportException(code, statusMsg);
|
|
||||||
}
|
|
||||||
int contentLength = -1;
|
|
||||||
for (;;) {
|
|
||||||
line = HttpUtil.readLine(input, buffer);
|
|
||||||
if ("".equals(line)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
line = line.toLowerCase();
|
|
||||||
if (line.startsWith("content-length:")) {
|
|
||||||
contentLength = Integer.parseInt(line.substring("content-length:".length()).trim());
|
|
||||||
} else if (line.startsWith("content-encoding:")) {
|
|
||||||
responseGzipCompressed = HttpUtil.isUsingGzipEncoding(line.substring("content-encoding:".length()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
InputStream result;
|
|
||||||
if (contentLength == -1) {
|
|
||||||
result = input;
|
|
||||||
} else {
|
|
||||||
result = new LimitedInputStream(input, contentLength);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcClientException("Failed to read server response: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig pConfig) {
|
|
||||||
boolean result = super.isUsingByteArrayOutput(pConfig);
|
|
||||||
if (!result) {
|
|
||||||
throw new IllegalStateException("The Content-Length header is required with HTTP/1.0, and HTTP/1.1 is unsupported by the Lite HTTP Transport.");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void writeRequest(ReqWriter pWriter) throws XmlRpcException, IOException, SAXException {
|
|
||||||
pWriter.write(getOutputStream());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
/** Factory for the lite HTTP transport,
|
|
||||||
* {@link XmlRpcLiteHttpTransport}.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLiteHttpTransportFactory extends XmlRpcTransportFactoryImpl {
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pClient The client, which will invoke the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcLiteHttpTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() { return new XmlRpcLiteHttpTransport(getClient()); }
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequestProcessorFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of a client configuration for local rpc calls. Local
|
|
||||||
* rpc calls are mainly useful for testing, because you don't need
|
|
||||||
* a running server.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcLocalClientConfig extends XmlRpcClientConfig,
|
|
||||||
XmlRpcRequestProcessorFactory {
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.LocalStreamConnection;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestProcessor;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/** Another local transport for debugging and testing. This one is
|
|
||||||
* similar to the {@link XmlRpcLocalTransport},
|
|
||||||
* except that it adds request serialization. In other words, it is
|
|
||||||
* particularly well suited for development and testing of XML serialization
|
|
||||||
* and parsing.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLocalStreamTransport extends XmlRpcStreamTransport {
|
|
||||||
private final XmlRpcStreamRequestProcessor localServer;
|
|
||||||
private LocalStreamConnection conn;
|
|
||||||
private XmlRpcRequest request;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pClient The client, which is controlling the transport.
|
|
||||||
* @param pServer An instance of {@link XmlRpcStreamRequestProcessor}.
|
|
||||||
*/
|
|
||||||
public XmlRpcLocalStreamTransport(XmlRpcClient pClient,
|
|
||||||
XmlRpcStreamRequestProcessor pServer) {
|
|
||||||
super(pClient);
|
|
||||||
localServer = pServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig) {
|
|
||||||
return pConfig.isGzipRequesting();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void close() throws XmlRpcClientException {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InputStream getInputStream() throws XmlRpcException {
|
|
||||||
localServer.execute(conn.getConfig(), conn.getServerStreamConnection());
|
|
||||||
return new ByteArrayInputStream(conn.getResponse().toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
|
|
||||||
throws XmlRpcException, IOException, SAXException {
|
|
||||||
request = pRequest;
|
|
||||||
return super.newReqWriter(pRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeRequest(ReqWriter pWriter)
|
|
||||||
throws XmlRpcException, IOException, SAXException {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
pWriter.write(baos);
|
|
||||||
XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) request.getConfig();
|
|
||||||
conn = new LocalStreamConnection(config, new ByteArrayInputStream(baos.toByteArray()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestProcessor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Another local transport factory for debugging and testing. This one is
|
|
||||||
* similar to the {@link XmlRpcLocalTransportFactory},
|
|
||||||
* except that it adds request serialization. In other words, it is
|
|
||||||
* particularly well suited for development and testing of XML serialization
|
|
||||||
* and parsing.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLocalStreamTransportFactory extends XmlRpcStreamTransportFactory {
|
|
||||||
|
|
||||||
private final XmlRpcStreamRequestProcessor server;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pClient The client controlling the factory.
|
|
||||||
* @param pServer An instance of {@link XmlRpcStreamRequestProcessor}.
|
|
||||||
*/
|
|
||||||
public XmlRpcLocalStreamTransportFactory(XmlRpcClient pClient,
|
|
||||||
XmlRpcStreamRequestProcessor pServer) {
|
|
||||||
super(pClient);
|
|
||||||
server = pServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() {
|
|
||||||
return new XmlRpcLocalStreamTransport(getClient(), server);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeConverter;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeConverterFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcExtensionException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequestProcessor;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default implementation of a local transport.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLocalTransport extends XmlRpcTransportImpl {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pClient The client, which creates the transport.
|
|
||||||
*/
|
|
||||||
public XmlRpcLocalTransport(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private boolean isExtensionType(Object pObject) {
|
|
||||||
if (pObject == null) {
|
|
||||||
return true;
|
|
||||||
} else if (pObject instanceof Object[]) {
|
|
||||||
Object[] objects = (Object[]) pObject;
|
|
||||||
for (Object object : objects) {
|
|
||||||
if (isExtensionType(object)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else if (pObject instanceof Collection) {
|
|
||||||
for (Object o : ((Collection) pObject)) {
|
|
||||||
if (isExtensionType(o)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else if (pObject instanceof Map) {
|
|
||||||
Map<String, Object> map = (Map) pObject;
|
|
||||||
for (Object o : map.entrySet()) {
|
|
||||||
Map.Entry<String, Object> entry = (Map.Entry) o;
|
|
||||||
if (isExtensionType(entry.getKey()) || isExtensionType(entry.getValue())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return !(pObject instanceof Integer
|
|
||||||
|| pObject instanceof Date
|
|
||||||
|| pObject instanceof String
|
|
||||||
|| pObject instanceof byte[]
|
|
||||||
|| pObject instanceof Double);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
|
|
||||||
XmlRpcConfig config = pRequest.getConfig();
|
|
||||||
if (!config.isEnabledForExtensions()) {
|
|
||||||
for (int i = 0; i < pRequest.getParameterCount(); i++) {
|
|
||||||
if (isExtensionType(pRequest.getParameter(i))) {
|
|
||||||
throw new XmlRpcExtensionException("Parameter " + i + " has invalid type, if isEnabledForExtensions() == false");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final XmlRpcRequestProcessor server = ((XmlRpcLocalClientConfig) config).getXmlRpcServer();
|
|
||||||
Object result;
|
|
||||||
try {
|
|
||||||
result = server.execute(pRequest);
|
|
||||||
} catch (XmlRpcException t) {
|
|
||||||
throw t;
|
|
||||||
} catch (Throwable t) {
|
|
||||||
throw new XmlRpcClientException("Failed to invoke method " + pRequest.getMethodName()
|
|
||||||
+ ": " + t.getMessage(), t);
|
|
||||||
}
|
|
||||||
if (!config.isEnabledForExtensions()) {
|
|
||||||
if (isExtensionType(result)) {
|
|
||||||
throw new XmlRpcExtensionException("Result has invalid type, if isEnabledForExtensions() == false");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final TypeConverterFactory typeConverterFactory = server.getTypeConverterFactory();
|
|
||||||
final TypeConverter typeConverter = typeConverterFactory.getTypeConverter(result.getClass());
|
|
||||||
return typeConverter.backConvert(result);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>A transport factory being used for local XML-RPC calls. Local XML-RPC
|
|
||||||
* calls are mainly useful for development and unit testing: Both client
|
|
||||||
* and server are runing within the same JVM and communication is implemented
|
|
||||||
* in simple method invokcations.</p>
|
|
||||||
* <p>This class is thread safe and the returned instance of
|
|
||||||
* {@link XmlRpcTransport} will always return the
|
|
||||||
* same object, an instance of {@link XmlRpcLocalTransport}</p>
|
|
||||||
*/
|
|
||||||
public class XmlRpcLocalTransportFactory extends XmlRpcTransportFactoryImpl {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance, operated by the given client.
|
|
||||||
* @param pClient The client, which will invoke the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcLocalTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final XmlRpcTransport LOCAL_TRANSPORT = new XmlRpcLocalTransport(getClient());
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() { return LOCAL_TRANSPORT; }
|
|
||||||
}
|
|
|
@ -1,195 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
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.XmlRpcStreamRequestConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.XmlRpcResponseParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.XmlRpcWriter;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.SAXParsers;
|
|
||||||
import org.xml.sax.ContentHandler;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.XMLReader;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of a transport class, which is based on an output
|
|
||||||
* stream for sending the request and an input stream for receiving
|
|
||||||
* the response,
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcStreamTransport extends XmlRpcTransportImpl {
|
|
||||||
|
|
||||||
protected interface ReqWriter {
|
|
||||||
/**
|
|
||||||
* Writes the requests data to the given output stream.
|
|
||||||
* The method ensures, that the target is being closed.
|
|
||||||
*/
|
|
||||||
void write(OutputStream pStream) throws XmlRpcException, IOException, SAXException;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class ReqWriterImpl implements ReqWriter {
|
|
||||||
private final XmlRpcRequest request;
|
|
||||||
|
|
||||||
protected ReqWriterImpl(XmlRpcRequest pRequest) {
|
|
||||||
request = pRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the requests uncompressed XML data to the given
|
|
||||||
* output stream. Ensures, that the output stream is being
|
|
||||||
* closed.
|
|
||||||
*/
|
|
||||||
public void write(OutputStream pStream)
|
|
||||||
throws XmlRpcException, IOException, SAXException {
|
|
||||||
final XmlRpcStreamConfig config = (XmlRpcStreamConfig) request.getConfig();
|
|
||||||
try {
|
|
||||||
ContentHandler h = getClient().getXmlWriterFactory().getXmlWriter(config, pStream);
|
|
||||||
XmlRpcWriter xw = new XmlRpcWriter(config, h, getClient().getTypeFactory());
|
|
||||||
xw.write(request);
|
|
||||||
pStream.close();
|
|
||||||
pStream = null;
|
|
||||||
} finally {
|
|
||||||
if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class GzipReqWriter implements ReqWriter {
|
|
||||||
private final ReqWriter reqWriter;
|
|
||||||
protected GzipReqWriter(ReqWriter pReqWriter) {
|
|
||||||
reqWriter = pReqWriter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(OutputStream pStream) throws XmlRpcException, IOException, SAXException {
|
|
||||||
try {
|
|
||||||
GZIPOutputStream gStream = new GZIPOutputStream(pStream);
|
|
||||||
reqWriter.write(gStream);
|
|
||||||
pStream.close();
|
|
||||||
pStream = null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcException("Failed to write request: " + e.getMessage(), e);
|
|
||||||
} finally {
|
|
||||||
if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance on behalf of the given client.
|
|
||||||
*/
|
|
||||||
protected XmlRpcStreamTransport(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the connection and ensures, that all resources are being
|
|
||||||
* released.
|
|
||||||
*/
|
|
||||||
protected abstract void close() throws XmlRpcClientException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns, whether the response is gzip compressed.
|
|
||||||
* @param pConfig The clients configuration.
|
|
||||||
* @return Whether the response stream is gzip compressed.
|
|
||||||
*/
|
|
||||||
protected abstract boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the input stream, from which the response is
|
|
||||||
* being read.
|
|
||||||
*/
|
|
||||||
protected abstract InputStream getInputStream() throws XmlRpcException;
|
|
||||||
|
|
||||||
protected boolean isCompressingRequest(XmlRpcStreamRequestConfig pConfig) {
|
|
||||||
return pConfig.isEnabledForExtensions()
|
|
||||||
&& pConfig.isGzipCompressing();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of {@link ReqWriter}.
|
|
||||||
* @throws XmlRpcException Creating the instance failed.
|
|
||||||
* @throws IOException Creating the instance failed, because
|
|
||||||
* an {@link IOException} occurs.
|
|
||||||
* @throws SAXException Creating the instance failed, because
|
|
||||||
* the request could not be parsed.
|
|
||||||
*/
|
|
||||||
protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
|
|
||||||
throws XmlRpcException, IOException, SAXException {
|
|
||||||
ReqWriter reqWriter = new ReqWriterImpl(pRequest);
|
|
||||||
if (isCompressingRequest((XmlRpcStreamRequestConfig) pRequest.getConfig())) {
|
|
||||||
reqWriter = new GzipReqWriter(reqWriter);
|
|
||||||
}
|
|
||||||
return reqWriter;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void writeRequest(ReqWriter pWriter)
|
|
||||||
throws XmlRpcException, IOException, SAXException;
|
|
||||||
|
|
||||||
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
|
|
||||||
XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) pRequest.getConfig();
|
|
||||||
boolean closed = false;
|
|
||||||
try {
|
|
||||||
ReqWriter reqWriter = newReqWriter(pRequest);
|
|
||||||
writeRequest(reqWriter);
|
|
||||||
InputStream istream = getInputStream();
|
|
||||||
if (isResponseGzipCompressed(config)) {
|
|
||||||
istream = new GZIPInputStream(istream);
|
|
||||||
}
|
|
||||||
Object result = readResponse(config, istream);
|
|
||||||
closed = true;
|
|
||||||
close();
|
|
||||||
return result;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcException("Failed to read server's response: "
|
|
||||||
+ e.getMessage(), e);
|
|
||||||
} catch (SAXException e) {
|
|
||||||
Exception ex = e.getException();
|
|
||||||
if (ex instanceof XmlRpcException) {
|
|
||||||
throw (XmlRpcException) ex;
|
|
||||||
}
|
|
||||||
throw new XmlRpcException("Failed to generate request: "
|
|
||||||
+ e.getMessage(), e);
|
|
||||||
} finally {
|
|
||||||
if (!closed) { try { close(); } catch (Throwable ignore) {} }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XMLReader newXMLReader() throws XmlRpcException {
|
|
||||||
return SAXParsers.newXMLReader();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object readResponse(XmlRpcStreamRequestConfig pConfig, InputStream pStream) throws XmlRpcException {
|
|
||||||
InputSource isource = new InputSource(pStream);
|
|
||||||
XMLReader xr = newXMLReader();
|
|
||||||
XmlRpcResponseParser xp;
|
|
||||||
try {
|
|
||||||
xp = new XmlRpcResponseParser(pConfig, getClient().getTypeFactory());
|
|
||||||
xr.setContentHandler(xp);
|
|
||||||
xr.parse(isource);
|
|
||||||
} catch (SAXException e) {
|
|
||||||
throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
if (xp.isSuccess()) {
|
|
||||||
return xp.getResult();
|
|
||||||
}
|
|
||||||
Throwable t = xp.getErrorCause();
|
|
||||||
if (t == null) {
|
|
||||||
throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage());
|
|
||||||
}
|
|
||||||
if (t instanceof XmlRpcException) {
|
|
||||||
throw (XmlRpcException) t;
|
|
||||||
}
|
|
||||||
if (t instanceof RuntimeException) {
|
|
||||||
throw (RuntimeException) t;
|
|
||||||
}
|
|
||||||
throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage(), t);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract base implementation of a factory for stream transports.
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcStreamTransportFactory extends XmlRpcTransportFactoryImpl {
|
|
||||||
protected XmlRpcStreamTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of an HTTP transport in Java 1.4, based on the
|
|
||||||
* {@link java.net.HttpURLConnection} class. Adds support for the
|
|
||||||
* {@link SSLSocketFactory}.
|
|
||||||
*/
|
|
||||||
public class XmlRpcSun14HttpTransport extends XmlRpcSunHttpTransport {
|
|
||||||
private SSLSocketFactory sslSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pClient The client controlling this instance.
|
|
||||||
*/
|
|
||||||
public XmlRpcSun14HttpTransport(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the SSLSocketFactory used to create secure sockets.
|
|
||||||
* @param pSocketFactory The SSLSocketFactory to use.
|
|
||||||
*/
|
|
||||||
public void setSSLSocketFactory(SSLSocketFactory pSocketFactory) {
|
|
||||||
sslSocketFactory = pSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SSLSocketFactory used to create secure sockets.
|
|
||||||
*/
|
|
||||||
public SSLSocketFactory getSSLSocketFactory() {
|
|
||||||
return sslSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URLConnection newURLConnection(URL pURL) throws IOException {
|
|
||||||
final URLConnection conn = super.newURLConnection(pURL);
|
|
||||||
final SSLSocketFactory sslSockFactory = getSSLSocketFactory();
|
|
||||||
if ((sslSockFactory != null) && (conn instanceof HttpsURLConnection))
|
|
||||||
((HttpsURLConnection)conn).setSSLSocketFactory(sslSockFactory);
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of an HTTP transport factory in Java 1.4, based
|
|
||||||
* on the {@link java.net.HttpURLConnection} class.
|
|
||||||
*/
|
|
||||||
public class XmlRpcSun14HttpTransportFactory extends XmlRpcTransportFactoryImpl {
|
|
||||||
private SSLSocketFactory sslSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new factory, which creates transports for the given client.
|
|
||||||
* @param pClient The client, which is operating the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcSun14HttpTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the SSLSocketFactory to be used by transports.
|
|
||||||
* @param pSocketFactory The SSLSocketFactory to use.
|
|
||||||
*/
|
|
||||||
public void setSSLSocketFactory(SSLSocketFactory pSocketFactory) {
|
|
||||||
sslSocketFactory = pSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SSLSocketFactory to be used by transports.
|
|
||||||
*/
|
|
||||||
public SSLSocketFactory getSSLSocketFactory() {
|
|
||||||
return sslSocketFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() {
|
|
||||||
XmlRpcSun14HttpTransport transport = new XmlRpcSun14HttpTransport(getClient());
|
|
||||||
transport.setSSLSocketFactory(sslSocketFactory);
|
|
||||||
return transport;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of an HTTP transport in Java 1.4, based on the
|
|
||||||
* {@link java.net.HttpURLConnection} class. Adds support for the
|
|
||||||
* {@link Proxy} class.
|
|
||||||
*/
|
|
||||||
public class XmlRpcSun15HttpTransport extends XmlRpcSun14HttpTransport {
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pClient The client controlling this instance.
|
|
||||||
*/
|
|
||||||
public XmlRpcSun15HttpTransport(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Proxy proxy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the proxy to use.
|
|
||||||
*/
|
|
||||||
public void setProxy(Proxy pProxy) {
|
|
||||||
proxy = pProxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the proxy to use.
|
|
||||||
*/
|
|
||||||
public Proxy getProxy() {
|
|
||||||
return proxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initHttpHeaders(XmlRpcRequest pRequest)
|
|
||||||
throws XmlRpcClientException {
|
|
||||||
final XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
|
|
||||||
int connectionTimeout = config.getConnectionTimeout();
|
|
||||||
if (connectionTimeout > 0) {
|
|
||||||
getURLConnection().setConnectTimeout(connectionTimeout);
|
|
||||||
}
|
|
||||||
int replyTimeout = config.getReplyTimeout();
|
|
||||||
if (replyTimeout > 0) {
|
|
||||||
getURLConnection().setReadTimeout(replyTimeout);
|
|
||||||
}
|
|
||||||
super.initHttpHeaders(pRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URLConnection newURLConnection(URL pURL) throws IOException {
|
|
||||||
final Proxy prox = getProxy();
|
|
||||||
final URLConnection conn = prox == null ? pURL.openConnection() : pURL.openConnection(prox);
|
|
||||||
final SSLSocketFactory sslSockFactory = getSSLSocketFactory();
|
|
||||||
if (sslSockFactory != null && conn instanceof HttpsURLConnection) {
|
|
||||||
((HttpsURLConnection)conn).setSSLSocketFactory(sslSockFactory);
|
|
||||||
}
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Proxy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of an HTTP transport in Java 1.5, based on the
|
|
||||||
* {@link java.net.HttpURLConnection} class.
|
|
||||||
*/
|
|
||||||
public class XmlRpcSun15HttpTransportFactory extends XmlRpcSun14HttpTransportFactory {
|
|
||||||
private Proxy proxy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new factory, which creates transports for the given client.
|
|
||||||
* @param pClient The client, which is operating the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcSun15HttpTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the proxy to use.
|
|
||||||
* @param proxyHost The proxy hostname.
|
|
||||||
* @param proxyPort The proxy port number.
|
|
||||||
* @throws IllegalArgumentException if the proxyHost parameter is null or if
|
|
||||||
* the proxyPort parameter is outside the range of valid port values.
|
|
||||||
*/
|
|
||||||
public void setProxy(String proxyHost, int proxyPort) {
|
|
||||||
setProxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress(proxyHost,proxyPort)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the proxy to use.
|
|
||||||
* @param pProxy The proxy settings.
|
|
||||||
*/
|
|
||||||
public void setProxy(Proxy pProxy) {
|
|
||||||
proxy = pProxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() {
|
|
||||||
XmlRpcSun15HttpTransport transport = new XmlRpcSun15HttpTransport(getClient());
|
|
||||||
transport.setSSLSocketFactory(getSSLSocketFactory());
|
|
||||||
transport.setProxy(proxy);
|
|
||||||
return transport;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.HttpUtil;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of an HTTP transport, based on the
|
|
||||||
* {@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.
|
|
||||||
* @param pClient The client controlling this instance.
|
|
||||||
*/
|
|
||||||
public XmlRpcSunHttpTransport(XmlRpcClient pClient) {
|
|
||||||
super(pClient, userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URLConnection newURLConnection(URL pURL) throws IOException {
|
|
||||||
return pURL.openConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For use by subclasses.
|
|
||||||
*/
|
|
||||||
protected URLConnection getURLConnection() {
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
|
|
||||||
XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
|
|
||||||
try {
|
|
||||||
final URLConnection c = conn = newURLConnection(config.getServerURL());
|
|
||||||
c.setUseCaches(false);
|
|
||||||
c.setDoInput(true);
|
|
||||||
c.setDoOutput(true);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcException("Failed to create URLConnection: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return super.sendRequest(pRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setRequestHeader(String pHeader, String pValue) {
|
|
||||||
getURLConnection().setRequestProperty(pHeader, pValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void close() {
|
|
||||||
final URLConnection c = getURLConnection();
|
|
||||||
if (c instanceof HttpURLConnection) {
|
|
||||||
((HttpURLConnection) c).disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig) {
|
|
||||||
return HttpUtil.isUsingGzipEncoding(getURLConnection().getHeaderField("Content-Encoding"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InputStream getInputStream() throws XmlRpcException {
|
|
||||||
try {
|
|
||||||
URLConnection connection = getURLConnection();
|
|
||||||
if (connection instanceof HttpURLConnection ) {
|
|
||||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
|
||||||
int responseCode = httpConnection.getResponseCode();
|
|
||||||
if (responseCode < 200 || responseCode > 299) {
|
|
||||||
throw new XmlRpcHttpTransportException(responseCode, httpConnection.getResponseMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return connection.getInputStream();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new XmlRpcException("Failed to create input stream: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeRequest(ReqWriter pWriter) throws IOException, XmlRpcException, SAXException {
|
|
||||||
pWriter.write(getURLConnection().getOutputStream());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
/** Default implementation of a HTTP transport factory, based on the
|
|
||||||
* {@link java.net.HttpURLConnection} class.
|
|
||||||
*/
|
|
||||||
public class XmlRpcSunHttpTransportFactory extends XmlRpcTransportFactoryImpl {
|
|
||||||
/** Creates a new factory, which creates transports for the given client.
|
|
||||||
* @param pClient The client, which is operating the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcSunHttpTransportFactory(XmlRpcClient pClient) {
|
|
||||||
super(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcTransport getTransport() {
|
|
||||||
return new XmlRpcSunHttpTransport(getClient());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Interface from XML-RPC to an underlying transport, most likely based on HTTP.</p>
|
|
||||||
*/
|
|
||||||
public interface XmlRpcTransport {
|
|
||||||
|
|
||||||
/** Send an XML-RPC message. This method is called to send a message to the
|
|
||||||
* other party.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @return Result object, if invoking the remote method was successfull.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException;
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
/** Interface of an object creating instances of
|
|
||||||
* {@link XmlRpcTransport}. The implementation
|
|
||||||
* is typically based on singletons.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcTransportFactory {
|
|
||||||
/** Returns an instance of {@link XmlRpcTransport}. This may
|
|
||||||
* be a singleton, but the caller should not depend on that:
|
|
||||||
* A new instance may as well be created for any request.
|
|
||||||
* @return The configured transport.
|
|
||||||
*/
|
|
||||||
public XmlRpcTransport getTransport();
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract base implementation of an {@link XmlRpcTransportFactory}.
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcTransportFactoryImpl implements XmlRpcTransportFactory {
|
|
||||||
private final XmlRpcClient client;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pClient The client, which will invoke the factory.
|
|
||||||
*/
|
|
||||||
protected XmlRpcTransportFactoryImpl(XmlRpcClient pClient) {
|
|
||||||
client = pClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the client operating this factory.
|
|
||||||
* @return The client.
|
|
||||||
*/
|
|
||||||
public XmlRpcClient getClient() { return client; }
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract base implementation of an {@link XmlRpcTransport}.
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcTransportImpl implements XmlRpcTransport {
|
|
||||||
private final XmlRpcClient client;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pClient The client, which creates the transport.
|
|
||||||
*/
|
|
||||||
protected XmlRpcTransportImpl(XmlRpcClient pClient) {
|
|
||||||
client = pClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the client, which created this transport.
|
|
||||||
* @return The client.
|
|
||||||
*/
|
|
||||||
public XmlRpcClient getClient() { return client; }
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
user.agent=Apache XML RPC
|
|
|
@ -1,90 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.client.ClientFactory;
|
|
||||||
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.XmlRpcRequestConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.AbstractReflectiveHandlerMapping;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
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";
|
|
||||||
|
|
||||||
/** An interface, which is being implemented by the
|
|
||||||
* server.
|
|
||||||
*/
|
|
||||||
public interface Adder {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sum of the given integers.
|
|
||||||
*/
|
|
||||||
int add(int pNum1, int pNum2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implementation of {@link DynamicProxyTest.Adder}, which is used by
|
|
||||||
* the server.
|
|
||||||
*/
|
|
||||||
public static class AdderImpl implements Adder {
|
|
||||||
public int add(int pNum1, int pNum2) {
|
|
||||||
return pNum1 + pNum2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
|
|
||||||
XmlRpcHandlerMapping mapping = getHandlerMapping("AuthenticationTest.properties");
|
|
||||||
((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 {
|
|
||||||
XmlRpcClientConfigImpl config = super.getConfig(pProvider);
|
|
||||||
config.setBasicUserName(USER_NAME);
|
|
||||||
config.setBasicPassword(PASSWORD);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 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 (ClientProvider provider : providers) {
|
|
||||||
testAdderCall(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testAdderCall(ClientProvider pProvider) throws Exception {
|
|
||||||
ClientFactory factory = getClientFactory(pProvider);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,850 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.xbib.netty.http.xmlrpc.client.XmlRpcClient;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcExtensionException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcInvocationException;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An abstract test case, to be implemented for the various
|
|
||||||
* transport classes.
|
|
||||||
*/
|
|
||||||
public class BaseTest extends XmlRpcTestCase {
|
|
||||||
|
|
||||||
/** The remote class being invoked by the test case.
|
|
||||||
*/
|
|
||||||
public static class Remote {
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public int byteParam(byte pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public byte byteResult(byte pArg) { return (byte) (pArg*2); }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public int shortParam(short pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public short shortResult(short pArg) { return (short) (pArg*2); }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public int intParam(int pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public int longParam(long pArg) { return (int) (pArg*2); }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public long longResult(long pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public double floatParam(float pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public float floatResult(float pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public double doubleParam(double pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, multiplied by two.
|
|
||||||
* @param pArg The argument being doubled.
|
|
||||||
* @return The argument, multiplied by two.
|
|
||||||
*/
|
|
||||||
public double doubleResult(double pArg) { return pArg*2; }
|
|
||||||
/** Returns the argument, concatenated with itself.
|
|
||||||
* @param pArg The argument being concatenated.
|
|
||||||
* @return The argument, concatenated with itself.
|
|
||||||
*/
|
|
||||||
public String stringParam(String pArg) { return pArg+pArg; }
|
|
||||||
/**
|
|
||||||
* Throws a NullPointerException.
|
|
||||||
*/
|
|
||||||
public Object throwNPE() {
|
|
||||||
throw new NullPointerException();
|
|
||||||
}
|
|
||||||
/** Returns the argument, concatenated with itself.
|
|
||||||
* @param pArg The argument being concatenated.
|
|
||||||
* @return The argument, concatenated with itself.
|
|
||||||
*/
|
|
||||||
public String nullableStringParam(String pArg) {
|
|
||||||
if (pArg == null) {
|
|
||||||
pArg = "";
|
|
||||||
}
|
|
||||||
return pArg+pArg;
|
|
||||||
}
|
|
||||||
/** Returns the argument, concatenated with itself.
|
|
||||||
* @param pArg The argument being concatenated.
|
|
||||||
* @return The argument, concatenated with itself.
|
|
||||||
*/
|
|
||||||
public String nullableStringResult(String pArg) {
|
|
||||||
if (pArg == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return pArg+pArg;
|
|
||||||
}
|
|
||||||
/** Returns the sum of the bytes in the given byte array.
|
|
||||||
* @param pArg The array of bytes being added.
|
|
||||||
* @return Sum over the bytes in the array.
|
|
||||||
*/
|
|
||||||
public int byteArrayParam(byte[] pArg) {
|
|
||||||
int sum = 0;
|
|
||||||
for (byte b : pArg) {
|
|
||||||
sum += b;
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
/** Returns an array with the bytes 0..pArg.
|
|
||||||
* @param pArg Requestes byte array length.
|
|
||||||
* @return Byte array with 0..pArg.
|
|
||||||
*/
|
|
||||||
public byte[] byteArrayResult(int pArg) {
|
|
||||||
byte[] result = new byte[pArg];
|
|
||||||
for (int i = 0; i < result.length; i++) {
|
|
||||||
result[i] = (byte) i;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/** Returns the sum over the objects in the array.
|
|
||||||
* @param pArg Object array being added
|
|
||||||
* @return Sum over the objects in the array
|
|
||||||
*/
|
|
||||||
public int objectArrayParam(Object[] pArg) {
|
|
||||||
int sum = 0;
|
|
||||||
for (Object o : pArg) {
|
|
||||||
if (o instanceof Number) {
|
|
||||||
sum += ((Number) o).intValue();
|
|
||||||
} else {
|
|
||||||
sum += Integer.parseInt((String) o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
/** Returns an array of integers with the values
|
|
||||||
* 0..pArg.
|
|
||||||
* @param pArg Requested array length.
|
|
||||||
* @return Array of integers with the values 0..pArg
|
|
||||||
*/
|
|
||||||
public Object[] objectArrayResult(int pArg) {
|
|
||||||
Object[] result = new Object[pArg];
|
|
||||||
for (int i = 0; i < result.length; i++) {
|
|
||||||
result[i] = i;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/** Returns a sum over the entries in the map. Each
|
|
||||||
* key is multiplied with its value.
|
|
||||||
* @param pArg The map being iterated.
|
|
||||||
* @return Sum of keys, multiplied by their values.
|
|
||||||
*/
|
|
||||||
public int mapParam(Map<String, Integer> pArg) {
|
|
||||||
int sum = 0;
|
|
||||||
for (Map.Entry<String, Integer> entry : pArg.entrySet()) {
|
|
||||||
String key = entry.getKey();
|
|
||||||
Integer value = entry.getValue();
|
|
||||||
sum += Integer.parseInt(key) * value;
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
/** Returns a map with the stringified values 0..pArg as
|
|
||||||
* keys and the corresponding integers as values.
|
|
||||||
* @param pArg Requested map size.
|
|
||||||
* @return Map with the keys "0".."pArg" and
|
|
||||||
* 0..pArg as values.
|
|
||||||
*/
|
|
||||||
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), i);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/** Returns the sum of all "int" nodes in <code>pNode</code>.
|
|
||||||
* @param pNode The node being counted.
|
|
||||||
* @return The sum of the values of all "int" nodes.
|
|
||||||
*/
|
|
||||||
public int nodeParam(Node pNode) {
|
|
||||||
if (pNode.getNodeType() != Node.DOCUMENT_NODE) {
|
|
||||||
throw new IllegalStateException("Expected document node, got " + pNode);
|
|
||||||
}
|
|
||||||
Element e = ((Document) pNode).getDocumentElement();
|
|
||||||
if (!ROOT_TAG.equals(e.getLocalName()) || !INT_URI.equals(e.getNamespaceURI())) {
|
|
||||||
throw new IllegalStateException("Expected root element 'root', got "
|
|
||||||
+ new QName(e.getNamespaceURI(), e.getLocalName()));
|
|
||||||
}
|
|
||||||
return count(pNode);
|
|
||||||
}
|
|
||||||
private int count(Node pNode) {
|
|
||||||
if (INT_TAG.equals(pNode.getLocalName()) && INT_URI.equals(pNode.getNamespaceURI())) {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Integer.parseInt(sb.toString());
|
|
||||||
} else {
|
|
||||||
int result = 0;
|
|
||||||
for (Node child = pNode.getFirstChild(); child != null; child = child.getNextSibling()) {
|
|
||||||
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
result += count(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Example of a Serializable instance.
|
|
||||||
*/
|
|
||||||
static class CalendarWrapper implements Serializable {
|
|
||||||
private static final long serialVersionUID = 8153663910532549627L;
|
|
||||||
final Calendar cal;
|
|
||||||
CalendarWrapper(Calendar pCalendar) {
|
|
||||||
cal = pCalendar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the calendar value in milliseconds.
|
|
||||||
* @param pCal Calendar object
|
|
||||||
* @return <code>pCal.getTime().getTime()</code>.
|
|
||||||
*/
|
|
||||||
public long serializableParam(CalendarWrapper pCal) {
|
|
||||||
return pCal.cal.getTime().getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns midnight of the following day.
|
|
||||||
*/
|
|
||||||
Calendar calendarParam(Calendar pCal) {
|
|
||||||
Calendar cal = (Calendar) pCal.clone();
|
|
||||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
||||||
cal.set(Calendar.MINUTE, 0);
|
|
||||||
cal.set(Calendar.SECOND, 0);
|
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
|
||||||
return cal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns midnight of the following day.
|
|
||||||
*/
|
|
||||||
public Date dateParam(Date pDate) {
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(pDate);
|
|
||||||
return calendarParam(cal).getTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
|
|
||||||
return getHandlerMapping("BaseTest.properties");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a byte value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testByteParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testByteParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testByteParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.byteParam";
|
|
||||||
final Object[] params = new Object[]{(byte) 3};
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(6, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a byte.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testByteResult() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testByteResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testByteResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.byteResult";
|
|
||||||
final Object[] params = new Object[]{(byte) 3};
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals((byte) 6, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a short value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testShortParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testShortParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testShortParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.shortParam";
|
|
||||||
final Object[] params = new Object[] { (short) 4 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(8, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a short value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testShortResult() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testShortResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testShortResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.shortResult";
|
|
||||||
final Object[] params = new Object[] { (short) 4 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals((short) 8, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing an
|
|
||||||
* integer value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testIntParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testIntParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testIntParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.intParam";
|
|
||||||
final Object[] params = new Object[] { 5 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(10, result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
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 (ClientProvider provider : providers) {
|
|
||||||
testLongParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testLongParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.longParam";
|
|
||||||
final Object[] params = new Object[] { 6L };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(12, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a long value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testLongResult() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testLongResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testLongResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.longResult";
|
|
||||||
final Object[] params = new Object[] { 6L };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(12L, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a
|
|
||||||
* string value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testStringParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testStringParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testStringParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.stringParam";
|
|
||||||
final Object[] params = new Object[]{"abc"};
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals("abcabc", result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals("abcabc", result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a
|
|
||||||
* string value or null.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testNullableStringParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testNullableStringParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testNullableStringParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.nullableStringParam";
|
|
||||||
final Object[] params = new Object[]{"abc"};
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals("abcabc", result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals("abcabc", result);
|
|
||||||
final Object[] nullParams = new Object[]{null};
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, nullParams);
|
|
||||||
assertEquals("", result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, nullParams);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a
|
|
||||||
* string value or null.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testNullableStringResult() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testNullableStringResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testNullableStringResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.nullableStringResult";
|
|
||||||
final Object[] params = new Object[]{"abc"};
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals("abcabc", result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals("abcabc", result);
|
|
||||||
final Object[] nullParams = new Object[]{null};
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, nullParams);
|
|
||||||
assertNull(result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, nullParams);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a float value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testFloatParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testFloatParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testFloatParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.floatParam";
|
|
||||||
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 *10));
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a float value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testFloatResult() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testFloatResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testFloatResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.floatResult";
|
|
||||||
final Object[] params = new Object[] { (float) 0.4 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals((float) 0.8, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a
|
|
||||||
* double value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testDoubleParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testDoubleParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testDoubleParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.doubleParam";
|
|
||||||
final Object[] params = new Object[] { 0.6 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(1.2, result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(1.2, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a
|
|
||||||
* double value.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testDoubleResult() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testDoubleResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testDoubleResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.doubleResult";
|
|
||||||
final Object[] params = new Object[]{ 0.6 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(1.2, result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(1.2, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a
|
|
||||||
* byte array.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testByteArrayParam() throws Exception {
|
|
||||||
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 XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a
|
|
||||||
* byte array.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testByteArrayResult() throws Exception {
|
|
||||||
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[] { 8 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertTrue(Arrays.equals(bytes, (byte[]) result));
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertTrue(Arrays.equals(bytes, (byte[]) result));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing an
|
|
||||||
* object array.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testObjectArrayParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testObjectArrayParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testObjectArrayParam(ClientProvider pProvider) throws Exception {
|
|
||||||
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();
|
|
||||||
boolean ok = false;
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
ok = true;
|
|
||||||
}
|
|
||||||
assertTrue(ok);
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(15, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning an
|
|
||||||
* object array.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testObjectArrayResult() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testObjectArrayResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testObjectArrayResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final Object[] objects = new Object[]{0, 1, 2, 3};
|
|
||||||
final String methodName = "Remote.objectArrayResult";
|
|
||||||
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));
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertTrue(Arrays.equals(objects, (Object[]) result));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing a map.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testMapParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testMapParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testMapParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final Map<String, Integer> map = new HashMap<>();
|
|
||||||
map.put("2", 3);
|
|
||||||
map.put("3", 5);
|
|
||||||
final String methodName = "Remote.mapParam";
|
|
||||||
final Object[] params = new Object[]{ map };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(21, result);
|
|
||||||
result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(21, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkMap(Map<String, Object> pResult) {
|
|
||||||
assertEquals(4, pResult.size());
|
|
||||||
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 (ClientProvider provider : providers) {
|
|
||||||
testMapResult(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void testMapResult(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.mapResult";
|
|
||||||
final Object[] params = new Object[] { 4 };
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
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
|
|
||||||
* node as parameter.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testNodeParam() throws Exception {
|
|
||||||
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 {
|
|
||||||
final String xml =
|
|
||||||
"<" + ROOT_TAG + " xmlns='" + INT_URI +"'>" +
|
|
||||||
" <" + INT_TAG + ">1</" + INT_TAG + ">" +
|
|
||||||
" <" + INT_TAG + ">2</" + INT_TAG + ">" +
|
|
||||||
" <" + INT_TAG + ">3</" + INT_TAG + ">" +
|
|
||||||
" <" + INT_TAG + ">4</" + INT_TAG + ">" +
|
|
||||||
" <" + INT_TAG + ">5</" + INT_TAG + ">" +
|
|
||||||
"</" + ROOT_TAG + ">";
|
|
||||||
final String methodName = "Remote.nodeParam";
|
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
||||||
dbf.setValidating(false);
|
|
||||||
dbf.setNamespaceAware(true);
|
|
||||||
Document doc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
|
|
||||||
final Object[] params = new Object[]{doc};
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(1 + 2 + 3 + 4 + 5, result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, passing an instance of
|
|
||||||
* {@link Serializable} as a parameter.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testSerializableParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testSerializableParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testSerializableParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.serializableParam";
|
|
||||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
|
||||||
cal.set(2005, 5, 23, 8, 4, 0);
|
|
||||||
cal.set(Calendar.MILLISECOND, 5);
|
|
||||||
final Object[] params = new Object[]{new Remote.CalendarWrapper(cal)};
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(cal.getTime().getTime(), result);
|
|
||||||
try {
|
|
||||||
client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
} catch (XmlRpcExtensionException e) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Calendar newCalendarResult() {
|
|
||||||
Calendar cal2 = Calendar.getInstance(TimeZone.getDefault());
|
|
||||||
cal2.set(2005, 5, 24, 0, 0, 0);
|
|
||||||
cal2.set(Calendar.MILLISECOND, 0);
|
|
||||||
return cal2;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Calendar newCalendarParam() {
|
|
||||||
Calendar cal1 = Calendar.getInstance(TimeZone.getDefault());
|
|
||||||
cal1.set(2005, 5, 23, 8, 4, 0);
|
|
||||||
cal1.set(Calendar.MILLISECOND, 5);
|
|
||||||
return cal1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tests, whether we can invoke a method, passing an instance of
|
|
||||||
* {@link Date} as a parameter.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testDateParam() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testDateParam(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testDateParam(ClientProvider pProvider) throws Exception {
|
|
||||||
final String methodName = "Remote.dateParam";
|
|
||||||
Date date1 = newCalendarParam().getTime();
|
|
||||||
Calendar cal2 = newCalendarResult();
|
|
||||||
final Object[] params = new Object[]{date1};
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
Object result = client.execute(getExConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(cal2.getTime(), result);
|
|
||||||
result = client.execute(getConfig(pProvider), methodName, params);
|
|
||||||
assertEquals(cal2.getTime(), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests, whether a NullPointerException, thrown by the server, can be
|
|
||||||
* trapped by the client.
|
|
||||||
*/
|
|
||||||
public void testCatchNPE() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testCatchNPE(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testCatchNPE(ClientProvider pProvider) throws Exception {
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
final String methodName = "Remote.throwNPE";
|
|
||||||
try {
|
|
||||||
client.execute(getExConfig(pProvider), methodName, (Object[]) null);
|
|
||||||
} catch (XmlRpcInvocationException e) {
|
|
||||||
if (!(e.getCause() instanceof NullPointerException)) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,122 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for reading the clients IP address.
|
|
||||||
*/
|
|
||||||
public class ClientIpTest extends XmlRpcTestCase {
|
|
||||||
/**
|
|
||||||
* An object, which provides additional information
|
|
||||||
* about the client to the user.
|
|
||||||
*/
|
|
||||||
public static class ClientInfo {
|
|
||||||
private final String ipAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
*/
|
|
||||||
public ClientInfo(String pIpAddress) {
|
|
||||||
ipAddress = pIpAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the clients IP address.
|
|
||||||
*/
|
|
||||||
public String getIpAddress() {
|
|
||||||
return ipAddress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An extension of the {@link XmlRpcServlet}, which
|
|
||||||
* ensures the availability of a {@link ClientInfo}
|
|
||||||
* object.
|
|
||||||
*/
|
|
||||||
public static class ClientInfoServlet extends XmlRpcServlet {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 8210342625908021538L;
|
|
||||||
|
|
||||||
private static final ThreadLocal<ClientInfo> clientInfo = new ThreadLocal<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current threads. client info object.
|
|
||||||
*/
|
|
||||||
static ClientInfo getClientInfo() {
|
|
||||||
return clientInfo.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doPost(HttpServletRequest pRequest,
|
|
||||||
HttpServletResponse pResponse) throws IOException,
|
|
||||||
ServletException {
|
|
||||||
clientInfo.set(new ClientInfo(pRequest.getRemoteAddr()));
|
|
||||||
super.doPost(pRequest, pResponse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ClientIpTestProvider extends ServletWebServerProvider {
|
|
||||||
ClientIpTestProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength)
|
|
||||||
throws ServletException, IOException {
|
|
||||||
super(pMapping, pContentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcServlet newXmlRpcServlet() {
|
|
||||||
return new ClientInfoServlet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ClientProvider[] initProviders(XmlRpcHandlerMapping pMapping)
|
|
||||||
throws ServletException, IOException {
|
|
||||||
return new ClientProvider[]{
|
|
||||||
new ClientIpTestProvider(pMapping, false),
|
|
||||||
new ClientIpTestProvider(pMapping, true)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
throws XmlRpcNoSuchHandlerException, XmlRpcException {
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testClientIpAddress(ClientProvider pProvider) throws Exception {
|
|
||||||
final XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
final String ip = (String) client.execute("getIpAddress", new Object[]{});
|
|
||||||
assertEquals("127.0.0.1", ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test, whether we can invoke a method, returning a byte.
|
|
||||||
* @throws Exception The test failed.
|
|
||||||
*/
|
|
||||||
public void testClientIpAddress() throws Exception {
|
|
||||||
for (int i = 0; i < providers.length; i++) {
|
|
||||||
testClientIpAddress(providers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
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.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.
|
|
||||||
*/
|
|
||||||
public interface ClientProvider {
|
|
||||||
/** Returns the clients default configuration.
|
|
||||||
* @return The clients configuration.
|
|
||||||
* @throws Exception Creating the configuration failed.
|
|
||||||
*/
|
|
||||||
XmlRpcClientConfigImpl getConfig() throws Exception;
|
|
||||||
|
|
||||||
/** Returns a new client instance.
|
|
||||||
* @return A client being used for performing the test.
|
|
||||||
*/
|
|
||||||
XmlRpcClient getClient();
|
|
||||||
|
|
||||||
/** Returns the providers server instance.
|
|
||||||
* @return A server instance, which is being used for performing the test.
|
|
||||||
*/
|
|
||||||
XmlRpcServer getServer();
|
|
||||||
|
|
||||||
/** Performs a shutdown of the server.
|
|
||||||
*/
|
|
||||||
void shutdown() throws IOException;
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
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;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
|
|
||||||
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.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
*/
|
|
||||||
protected ClientProviderImpl(XmlRpcHandlerMapping pMapping) {
|
|
||||||
mapping = pMapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcServer getXmlRpcServer() {
|
|
||||||
XmlRpcServer server = new XmlRpcServer();
|
|
||||||
server.setHandlerMapping(mapping);
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcClientConfigImpl getConfig() throws Exception {
|
|
||||||
if (clientConfig == null) {
|
|
||||||
clientConfig = new XmlRpcClientConfigImpl();
|
|
||||||
}
|
|
||||||
return clientConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcClient getClient() {
|
|
||||||
XmlRpcClient client = new XmlRpcClient();
|
|
||||||
client.setTransportFactory(getTransportFactory(client));
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provider for testing the
|
|
||||||
* {@link XmlRpcCommonsTransport}.
|
|
||||||
*/
|
|
||||||
public class CommonsProvider extends WebServerProvider {
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
*/
|
|
||||||
public CommonsProvider(XmlRpcHandlerMapping pMapping) {
|
|
||||||
super(pMapping, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
|
|
||||||
return new XmlRpcCommonsTransportFactory(pClient);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.Format;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
public class CustomTypesTest extends XmlRpcTestCase {
|
|
||||||
/**
|
|
||||||
* Sample date converter
|
|
||||||
*/
|
|
||||||
public static class DateConverter {
|
|
||||||
/**
|
|
||||||
* Adds one day to the given date.
|
|
||||||
*/
|
|
||||||
public Date tomorrow(Date pDate) {
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(pDate);
|
|
||||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
return cal.getTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
|
|
||||||
PropertyHandlerMapping mapping = new PropertyHandlerMapping();
|
|
||||||
mapping.addHandler("DateConverter", DateConverter.class);
|
|
||||||
return mapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tests using a custom date format.
|
|
||||||
*/
|
|
||||||
public void testCustomDateFormat() throws Exception {
|
|
||||||
for (int i = 0; i < providers.length; i++) {
|
|
||||||
testCustomDateFormat(providers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeFactory getCustomDateTypeFactory(XmlRpcController pController, final Format pFormat) {
|
|
||||||
return new TypeFactoryImpl(pController){
|
|
||||||
private TypeSerializer dateSerializer = new DateSerializer(pFormat);
|
|
||||||
|
|
||||||
public TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName) {
|
|
||||||
if (DateSerializer.DATE_TAG.equals(pLocalName)) {
|
|
||||||
return new DateParser(pFormat);
|
|
||||||
} else {
|
|
||||||
return super.getParser(pConfig, pContext, pURI, pLocalName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException {
|
|
||||||
if (pObject instanceof Date) {
|
|
||||||
return dateSerializer;
|
|
||||||
} else {
|
|
||||||
return super.getSerializer(pConfig, pObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testCustomDateFormat(ClientProvider pProvider) throws Exception {
|
|
||||||
final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
XmlRpcClientConfigImpl config = getConfig(pProvider);
|
|
||||||
client.setConfig(config);
|
|
||||||
TypeFactory typeFactory = getCustomDateTypeFactory(client, format);
|
|
||||||
client.setTypeFactory(typeFactory);
|
|
||||||
Calendar cal1 = Calendar.getInstance();
|
|
||||||
XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "DateConverter.tomorrow", new Object[]{cal1.getTime()});
|
|
||||||
final String got = XmlRpcTestCase.writeRequest(client, request);
|
|
||||||
final String expect = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
|
|
||||||
+ "<methodCall><methodName>DateConverter.tomorrow</methodName>"
|
|
||||||
+ "<params><param><value><dateTime.iso8601>" + format.format(cal1.getTime())
|
|
||||||
+ "</dateTime.iso8601></value></param></params></methodCall>";
|
|
||||||
assertEquals(expect, got);
|
|
||||||
|
|
||||||
XmlRpcServer server = pProvider.getServer();
|
|
||||||
server.setTypeFactory(getCustomDateTypeFactory(server, format));
|
|
||||||
Date date = (Date) client.execute(request);
|
|
||||||
Calendar cal2 = Calendar.getInstance();
|
|
||||||
cal2.setTime(date);
|
|
||||||
cal1.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
assertEquals(cal1, cal2);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
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 {
|
|
||||||
/** An interface, which is being implemented by the
|
|
||||||
* server.
|
|
||||||
*/
|
|
||||||
public interface Adder {
|
|
||||||
/** Returns the sum of the given integers.
|
|
||||||
*/
|
|
||||||
public int add(int pNum1, int pNum2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Throws a SAXException.
|
|
||||||
*/
|
|
||||||
public Object parse(String pMessage) throws SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A void method; these are disabled without support for
|
|
||||||
* extensions, but enabled when extensions are on.
|
|
||||||
*/
|
|
||||||
public void ping();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implementation of {@link Adder}, which is used by
|
|
||||||
* the server.
|
|
||||||
*/
|
|
||||||
public static class AdderImpl implements Adder {
|
|
||||||
public int add(int pNum1, int pNum2) {
|
|
||||||
return pNum1 + pNum2;
|
|
||||||
}
|
|
||||||
public Object parse(String pMessage) throws SAXException {
|
|
||||||
throw new SAXException("Failed to parse message: " + pMessage);
|
|
||||||
}
|
|
||||||
public void ping() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
|
|
||||||
return getHandlerMapping("DynamicProxyTest.properties");
|
|
||||||
}
|
|
||||||
|
|
||||||
private ClientFactory getClientFactory(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
return new ClientFactory(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ClientFactory getExClientFactory(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getExConfig(pProvider));
|
|
||||||
return new ClientFactory(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tests 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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testAdderCall(ClientProvider pProvider) throws Exception {
|
|
||||||
ClientFactory factory = getClientFactory(pProvider);
|
|
||||||
Adder adder = (Adder) factory.newInstance(Adder.class);
|
|
||||||
assertEquals(6, adder.add(2, 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tests trapping a SAXException.
|
|
||||||
*/
|
|
||||||
public void testParseCall() throws Exception {
|
|
||||||
for (int i = 0; i < providers.length; i++) {
|
|
||||||
testParseCall(providers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testParseCall(ClientProvider pProvider) throws Exception {
|
|
||||||
ClientFactory factory = getExClientFactory(pProvider);
|
|
||||||
Adder adder = (Adder) factory.newInstance(Adder.class);
|
|
||||||
try {
|
|
||||||
adder.parse("foo");
|
|
||||||
fail("Expected SAXException");
|
|
||||||
} catch (SAXException e) {
|
|
||||||
// Ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests invoking a "void" method.
|
|
||||||
*/
|
|
||||||
public void testVoidMethod() throws Exception {
|
|
||||||
for (int i = 0; i < providers.length; i++) {
|
|
||||||
testVoidMethod(providers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testVoidMethod(ClientProvider pProvider) throws Exception {
|
|
||||||
ClientFactory factory = getExClientFactory(pProvider);
|
|
||||||
Adder adder = (Adder) factory.newInstance(Adder.class);
|
|
||||||
adder.ping();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,387 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
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.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for various jira issues.
|
|
||||||
*/
|
|
||||||
public class JiraTest extends XmlRpcTestCase {
|
|
||||||
/** Interface of the handler for {@link JiraTest#testXMLRPC89()}
|
|
||||||
*/
|
|
||||||
public interface XMLRPC89Handler {
|
|
||||||
/**
|
|
||||||
* Returns the reversed vector.
|
|
||||||
*/
|
|
||||||
Vector<Object> reverse(Vector<Object> pVector);
|
|
||||||
/**
|
|
||||||
* Returns the same hashtable, but doubles the
|
|
||||||
* values.
|
|
||||||
*/
|
|
||||||
Hashtable<Object, Object> doubledValues(Hashtable<Object, Object> pMap);
|
|
||||||
/**
|
|
||||||
* Returns the same properties, but doubles the
|
|
||||||
* values.
|
|
||||||
*/
|
|
||||||
Properties doubledPropertyValues(Properties pMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for {@link JiraTest#testXMLRPC89()}
|
|
||||||
*/
|
|
||||||
public static class XMLRPC89HandlerImpl implements XMLRPC89Handler {
|
|
||||||
public Vector<Object> reverse(Vector<Object> pVector) {
|
|
||||||
Vector<Object> result = new Vector<>(pVector.size());
|
|
||||||
result.addAll(pVector);
|
|
||||||
Collections.reverse(result);
|
|
||||||
return 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.putAll(pMap);
|
|
||||||
for (Map.Entry<Object, Object> entry : result.entrySet()) {
|
|
||||||
Object value = entry.getValue();
|
|
||||||
final Integer i;
|
|
||||||
if (pMap instanceof Properties) {
|
|
||||||
i = Integer.valueOf((String) value);
|
|
||||||
} else {
|
|
||||||
i = (Integer) value;
|
|
||||||
}
|
|
||||||
Integer iDoubled = i * 2;
|
|
||||||
if (pMap instanceof Properties) {
|
|
||||||
entry.setValue(iDoubled.toString());
|
|
||||||
} else {
|
|
||||||
entry.setValue(iDoubled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
public Properties doubledPropertyValues(Properties pProperties) {
|
|
||||||
return (Properties) doubledValues(pProperties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
|
|
||||||
XmlRpcException {
|
|
||||||
return getHandlerMapping("JiraTest.properties");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-89">
|
|
||||||
* XMLRPC-89</a>
|
|
||||||
*/
|
|
||||||
public void testXMLRPC89() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testXMLRPC89Vector(provider);
|
|
||||||
testXMLRPC89Hashtable(provider);
|
|
||||||
testXMLRPC89Properties(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testXMLRPC89Vector(ClientProvider pProvider) throws Exception {
|
|
||||||
Vector<Object> values = new Vector<>();
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
values.add(i);
|
|
||||||
}
|
|
||||||
Vector<Object> params = new Vector<>();
|
|
||||||
params.add(values);
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
Object res = client.execute(XMLRPC89Handler.class.getName() + ".reverse", params);
|
|
||||||
Object[] result = (Object[]) res;
|
|
||||||
assertNotNull(result);
|
|
||||||
assertEquals(3, result.length);
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
assertEquals(2 - i, result[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientFactory factory = new ClientFactory(client);
|
|
||||||
XMLRPC89Handler handler = (XMLRPC89Handler) factory.newInstance(XMLRPC89Handler.class);
|
|
||||||
Vector<Object> resultVector = handler.reverse(values);
|
|
||||||
assertNotNull(resultVector);
|
|
||||||
assertEquals(3, resultVector.size());
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
assertEquals(2 - i, resultVector.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyXMLRPC89Hashtable(Map<Object, Object> pMap) {
|
|
||||||
assertNotNull(pMap);
|
|
||||||
assertEquals(3, pMap.size());
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
Integer j = (Integer) pMap.get(String.valueOf(i));
|
|
||||||
assertEquals(i*2, j.intValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void testXMLRPC89Hashtable(ClientProvider pProvider) throws Exception {
|
|
||||||
Hashtable<Object, Object> values = new Hashtable<>();
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
values.put(String.valueOf(i), i);
|
|
||||||
}
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
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<Object, Object> result = handler.doubledValues(values);
|
|
||||||
verifyXMLRPC89Hashtable(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyXMLRPC89Properties(Map<Object, Object> pMap) {
|
|
||||||
assertNotNull(pMap);
|
|
||||||
assertEquals(3, pMap.size());
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
String j = (String) pMap.get(String.valueOf(i));
|
|
||||||
assertEquals(i*2, Integer.parseInt(j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void testXMLRPC89Properties(ClientProvider pProvider) throws Exception {
|
|
||||||
Properties values = new Properties();
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
values.put(String.valueOf(i), String.valueOf(i));
|
|
||||||
}
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
public static class XMLRPC96Handler {
|
|
||||||
/**
|
|
||||||
* Returns the "Hello, world!" string.
|
|
||||||
*/
|
|
||||||
public String getHelloWorld() {
|
|
||||||
return "Hello, world!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-96">
|
|
||||||
* XMLRPC-96</a>
|
|
||||||
*/
|
|
||||||
public void testXMLRPC96() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testXMLRPC96(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testXMLRPC96(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
String s = (String) client.execute(XMLRPC96Handler.class.getName() + ".getHelloWorld", new Object[0]);
|
|
||||||
assertEquals("Hello, world!", s);
|
|
||||||
s = (String) client.execute(XMLRPC96Handler.class.getName() + ".getHelloWorld", (Object[]) null);
|
|
||||||
assertEquals("Hello, world!", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-112">
|
|
||||||
* XMLRPC-112</a>
|
|
||||||
*/
|
|
||||||
public void testXMLRPC112() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testXMLRPC112(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-113">
|
|
||||||
* XMLRPC-113</a>
|
|
||||||
*/
|
|
||||||
public void testXMLRPC113() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testXMLRPC113(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void testXMLRPC112(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
TimingOutCallback toc = new TimingOutCallback(5000);
|
|
||||||
final String methodName = XMLRPC89Handler.class.getName() + ".reverse";
|
|
||||||
client.executeAsync(methodName, new Object[]{new Object[]{"1", "2", "3"}}, toc);
|
|
||||||
Object o;
|
|
||||||
try {
|
|
||||||
o = toc.waitForResponse();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw e;
|
|
||||||
} catch (Throwable t) {
|
|
||||||
throw new UndeclaredThrowableException(t);
|
|
||||||
}
|
|
||||||
checkXMLRPC112Result(o);
|
|
||||||
checkXMLRPC112Result(client.execute(methodName, new Object[]{new Object[]{"1", "2", "3"}}));
|
|
||||||
checkXMLRPC112Result(client.execute(methodName, new Object[]{new Object[]{"1", "2", "3"}}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkXMLRPC112Result(Object pObject) {
|
|
||||||
Object[] args = (Object[]) pObject;
|
|
||||||
assertEquals(3, args.length);
|
|
||||||
assertEquals("3", args[0]);
|
|
||||||
assertEquals("2", args[1]);
|
|
||||||
assertEquals("1", args[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler interface for {@link JiraTest#testXMLRPC113()}
|
|
||||||
*/
|
|
||||||
public interface XMLRPC113Handler {
|
|
||||||
/**
|
|
||||||
* Throws an {@link XmlRpcException} with the given error code.
|
|
||||||
*/
|
|
||||||
Object throwCode(int pCode) throws XmlRpcException;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for {@link JiraTest#testXMLRPC113()}
|
|
||||||
*/
|
|
||||||
public static class XMLRPC113HandlerImpl implements XMLRPC113Handler {
|
|
||||||
public Object throwCode(int pCode) throws XmlRpcException {
|
|
||||||
throw new XmlRpcException(pCode, "Message: " + pCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testXMLRPC113(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
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[] { i });
|
|
||||||
fail("Excpected exception");
|
|
||||||
} catch (XmlRpcException e) {
|
|
||||||
assertEquals(i, e.code);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
handler.throwCode(i);
|
|
||||||
} catch (XmlRpcException e) {
|
|
||||||
assertEquals(i, e.code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for {@link JiraTest#testXMLRPC115()}
|
|
||||||
*/
|
|
||||||
public static class XMLRPC115Handler {
|
|
||||||
/**
|
|
||||||
* Does nothing, just for checking, whether the server is alive.
|
|
||||||
*/
|
|
||||||
public Object[] ping() {
|
|
||||||
return new Object[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-115">
|
|
||||||
* XMLRPC-115</a>
|
|
||||||
*/
|
|
||||||
public void testXMLRPC115() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testXMLRPC115(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testXMLRPC115(ClientProvider pProvider) throws Exception {
|
|
||||||
if (pProvider instanceof SunHttpTransportProvider) {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
client.setConfig(getConfig(pProvider));
|
|
||||||
URL url = ((XmlRpcHttpClientConfig) client.getConfig()).getServerURL();
|
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
||||||
conn.setDoInput(true);
|
|
||||||
conn.setDoOutput(true);
|
|
||||||
conn.setRequestMethod("POST");
|
|
||||||
conn.setRequestProperty("content-type", "text/xml");
|
|
||||||
OutputStream ostream = conn.getOutputStream();
|
|
||||||
Writer w = new OutputStreamWriter(ostream, StandardCharsets.UTF_8);
|
|
||||||
w.write("<methodCall><methodName>" + XMLRPC115Handler.class.getName() + ".ping"
|
|
||||||
+ "</methodName></methodCall>");
|
|
||||||
w.close();
|
|
||||||
InputStream istream = conn.getInputStream();
|
|
||||||
XmlRpcResponseParser parser = new XmlRpcResponseParser((XmlRpcStreamRequestConfig) client.getClientConfig(), client.getTypeFactory());
|
|
||||||
XMLReader xr = SAXParsers.newXMLReader();
|
|
||||||
xr.setContentHandler(parser);
|
|
||||||
xr.parse(new InputSource(istream));
|
|
||||||
istream.close();
|
|
||||||
assertTrue(parser.getResult() instanceof Object[]);
|
|
||||||
assertEquals(0, ((Object[]) parser.getResult()).length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-119">
|
|
||||||
* XMLRPC-119</a>
|
|
||||||
*/
|
|
||||||
public void testXMLRPC119() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testXMLRPC119(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handler for XMLRPC-119
|
|
||||||
*/
|
|
||||||
public static class XMLRPC119Handler {
|
|
||||||
/** Returns a string with a length of "num" Kilobytes.
|
|
||||||
*/
|
|
||||||
public String getString(int pSize) {
|
|
||||||
StringBuilder sb = new StringBuilder(pSize*1024);
|
|
||||||
for (int i = 0; i < pSize*1024; i++) {
|
|
||||||
sb.append('&');
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testXMLRPC119(ClientProvider pProvider) throws Exception {
|
|
||||||
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[] { i });
|
|
||||||
assertEquals(i*1024, s.length());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
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 XmlRpcLiteHttpTransport}.
|
|
||||||
*/
|
|
||||||
public class LiteTransportProvider extends WebServerProvider {
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
* @param pContentLength Whether a Content-Length header is required.
|
|
||||||
*/
|
|
||||||
public LiteTransportProvider(XmlRpcHandlerMapping pMapping,
|
|
||||||
boolean pContentLength) {
|
|
||||||
super(pMapping, pContentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
|
|
||||||
return new XmlRpcLiteHttpTransportFactory(pClient);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
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 BaseTest}
|
|
||||||
* for testing the {@link XmlRpcLocalStreamTransport}.
|
|
||||||
*/
|
|
||||||
public class LocalStreamTransportProvider extends LocalTransportProvider {
|
|
||||||
private XmlRpcLocalStreamServer server;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
*/
|
|
||||||
public LocalStreamTransportProvider(XmlRpcHandlerMapping pMapping) {
|
|
||||||
super(pMapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
|
|
||||||
server = new XmlRpcLocalStreamServer();
|
|
||||||
XmlRpcLocalStreamTransportFactory factory
|
|
||||||
= new XmlRpcLocalStreamTransportFactory(pClient, server);
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcServer getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
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.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 BaseTest}
|
|
||||||
* for testing the {@link XmlRpcLocalTransport}.
|
|
||||||
*/
|
|
||||||
public class LocalTransportProvider extends ClientProviderImpl {
|
|
||||||
private XmlRpcServer server;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
*/
|
|
||||||
public LocalTransportProvider(XmlRpcHandlerMapping pMapping) {
|
|
||||||
super(pMapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
|
|
||||||
XmlRpcLocalTransportFactory factory = new XmlRpcLocalTransportFactory(pClient);
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcClientConfigImpl getConfig() throws Exception {
|
|
||||||
XmlRpcClientConfigImpl config = super.getConfig();
|
|
||||||
server = getXmlRpcServer();
|
|
||||||
config.setXmlRpcServer(server);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcServer getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() {
|
|
||||||
// Does nothing
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for the introspection stuff.
|
|
||||||
*/
|
|
||||||
public class MetadataTest extends XmlRpcTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected XmlRpcHandlerMapping getHandlerMapping() throws XmlRpcException {
|
|
||||||
PropertyHandlerMapping mapping = new PropertyHandlerMapping();
|
|
||||||
mapping.addHandler("Adder", AuthenticationTest.AdderImpl.class);
|
|
||||||
XmlRpcSystemImpl.addSystemHandler(mapping);
|
|
||||||
return mapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test, whether the actual handlers are working.
|
|
||||||
*/
|
|
||||||
public void testAdder() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testAdder(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testAdder(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
XmlRpcClientConfig config = getConfig(pProvider);
|
|
||||||
client.setConfig(config);
|
|
||||||
Object o = client.execute("Adder.add", new Object[]{3, 5});
|
|
||||||
assertEquals(8, o);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for system.listMethods.
|
|
||||||
*/
|
|
||||||
public void testListMethods() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testListMethods(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testListMethods(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
XmlRpcClientConfig config = getConfig(pProvider);
|
|
||||||
client.setConfig(config);
|
|
||||||
Object o = client.execute("system.listMethods", new Object[0]);
|
|
||||||
Object[] methodList = (Object[]) o;
|
|
||||||
Arrays.sort(methodList, Collator.getInstance(Locale.US));
|
|
||||||
assertEquals(4, methodList.length);
|
|
||||||
assertEquals("Adder.add", methodList[0]);
|
|
||||||
assertEquals("system.listMethods", methodList[1]);
|
|
||||||
assertEquals("system.methodHelp", methodList[2]);
|
|
||||||
assertEquals("system.methodSignature", methodList[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for system.methodHelp.
|
|
||||||
*/
|
|
||||||
public void testMethodHelp() throws Exception {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
testMethodHelp(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testMethodHelp(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
XmlRpcClientConfig config = getConfig(pProvider);
|
|
||||||
client.setConfig(config);
|
|
||||||
String help = (String) client.execute("system.methodHelp", new Object[]{"Adder.add"});
|
|
||||||
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 (ClientProvider provider : providers) {
|
|
||||||
testMethodSignature(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testMethodSignature(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClient client = pProvider.getClient();
|
|
||||||
XmlRpcClientConfig config = getConfig(pProvider);
|
|
||||||
client.setConfig(config);
|
|
||||||
Object[] signatures = (Object[]) client.execute("system.methodSignature", new Object[]{"Adder.add"});
|
|
||||||
assertEquals(signatures.length, 1);
|
|
||||||
Object[] signature = (Object[]) signatures[0];
|
|
||||||
assertEquals(3, signature.length);
|
|
||||||
assertEquals("int", signature[0]);
|
|
||||||
assertEquals("int", signature[1]);
|
|
||||||
assertEquals("int", signature[2]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,150 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
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.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;
|
|
||||||
import org.xml.sax.XMLReader;
|
|
||||||
|
|
||||||
|
|
||||||
/** Test for the various parsers.
|
|
||||||
*/
|
|
||||||
public class ParserTest extends TestCase {
|
|
||||||
private Object parseResponse(final String s) throws XmlRpcException, IOException, SAXException {
|
|
||||||
return parseResponse(new InputSource(new StringReader(s)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object parseResponse(InputSource isource) throws XmlRpcException,
|
|
||||||
IOException, SAXException {
|
|
||||||
XmlRpcStreamRequestConfig config = new XmlRpcClientConfigImpl();
|
|
||||||
XmlRpcClient client = new XmlRpcClient();
|
|
||||||
XmlRpcResponseParser parser = new XmlRpcResponseParser(config, client.getTypeFactory());
|
|
||||||
XMLReader xr = SAXParsers.newXMLReader();
|
|
||||||
xr.setContentHandler(parser);
|
|
||||||
xr.parse(isource);
|
|
||||||
Object o = parser.getResult();
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
private XmlRpcRequestParser parseRequest(final String s) throws XmlRpcException, IOException, SAXException {
|
|
||||||
XmlRpcStreamConfig config = new XmlRpcHttpRequestConfigImpl();
|
|
||||||
XmlRpcClient client = new XmlRpcClient();
|
|
||||||
XmlRpcRequestParser parser = new XmlRpcRequestParser(config, client.getTypeFactory());
|
|
||||||
XMLReader xr = SAXParsers.newXMLReader();
|
|
||||||
xr.setContentHandler(parser);
|
|
||||||
xr.parse(new InputSource(new StringReader(s)));
|
|
||||||
return parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tests, whether strings can be parsed with,
|
|
||||||
* or without, the "string" tag.
|
|
||||||
*/
|
|
||||||
public void testStringType() throws Exception {
|
|
||||||
final String[] strings = new String[]{
|
|
||||||
"3", "<string>3</string>",
|
|
||||||
" <string>3</string> "
|
|
||||||
};
|
|
||||||
for (int i = 0; i < strings.length; i++) {
|
|
||||||
final String s =
|
|
||||||
"<?xml version='1.0' encoding='UTF-8'?>\n"
|
|
||||||
+ "<methodResponse><params><param>\n"
|
|
||||||
+ "<value>" + strings[i] + "</value></param>\n"
|
|
||||||
+ "</params></methodResponse>\n";
|
|
||||||
Object o = parseResponse(s);
|
|
||||||
assertEquals("3", o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tests, whether nested arrays can be parsed.
|
|
||||||
*/
|
|
||||||
public void testNestedObjectArrays() throws Exception {
|
|
||||||
final String s =
|
|
||||||
"<?xml version='1.0' encoding='UTF-8'?>\n"
|
|
||||||
+ "<methodResponse><params><param>\n"
|
|
||||||
+ "<value><array><data><value><array>\n"
|
|
||||||
+ "<data><value>array</value>\n"
|
|
||||||
+ "<value>string</value></data></array>\n"
|
|
||||||
+ "</value></data></array></value></param>\n"
|
|
||||||
+ "</params></methodResponse>\n";
|
|
||||||
Object o = parseResponse(s);
|
|
||||||
assertTrue(o instanceof Object[]);
|
|
||||||
Object[] outer = (Object[]) o;
|
|
||||||
assertEquals(1, outer.length);
|
|
||||||
o = outer[0];
|
|
||||||
assertTrue(o instanceof Object[]);
|
|
||||||
Object[] inner = (Object[]) o;
|
|
||||||
assertEquals(2, inner.length);
|
|
||||||
assertEquals("array", inner[0]);
|
|
||||||
assertEquals("string", inner[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests, whether a request may omit the <params> tag.
|
|
||||||
*/
|
|
||||||
public void testOptionalParams() throws Exception {
|
|
||||||
final String s1 = "<methodResponse/>";
|
|
||||||
Object o1 = parseResponse(s1);
|
|
||||||
assertNull(o1);
|
|
||||||
|
|
||||||
final String s2 = "<methodResponse><params/></methodResponse>";
|
|
||||||
Object o2 = parseResponse(s2);
|
|
||||||
assertNull(o2);
|
|
||||||
|
|
||||||
final String s3 = "<methodCall><methodName>foo</methodName></methodCall>";
|
|
||||||
XmlRpcRequestParser p3 = parseRequest(s3);
|
|
||||||
assertEquals("foo", p3.getMethodName());
|
|
||||||
assertNull(p3.getParams());
|
|
||||||
|
|
||||||
final String s4 = "<methodCall><methodName>bar</methodName><params/></methodCall>";
|
|
||||||
XmlRpcRequestParser p4 = parseRequest(s4);
|
|
||||||
assertEquals("bar", p4.getMethodName());
|
|
||||||
assertNotNull(p4.getParams());
|
|
||||||
assertTrue(p4.getParams().size() == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for XMLRPC-140.
|
|
||||||
*/
|
|
||||||
public void testXMLRPC140() throws Exception {
|
|
||||||
DateParser parser = new DateParser(new XmlRpcDateTimeFormat(){
|
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
protected TimeZone getTimeZone() {
|
|
||||||
return TimeZone.getDefault();
|
|
||||||
}
|
|
||||||
}){
|
|
||||||
public void setResult(Object pObject){
|
|
||||||
try {
|
|
||||||
super.setResult((String) pObject);
|
|
||||||
} catch (SAXException e) {
|
|
||||||
throw new UndeclaredThrowableException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
parser.setResult("20070316T162808Z");
|
|
||||||
fail("Expected exception");
|
|
||||||
} catch (UndeclaredThrowableException e) {
|
|
||||||
SAXParseException spe = (SAXParseException) e.getUndeclaredThrowable();
|
|
||||||
ParseException pe = (ParseException) spe.getException();
|
|
||||||
assertEquals(11, pe.getErrorOffset());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,214 +0,0 @@
|
||||||
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 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
|
|
||||||
*/
|
|
||||||
public static class Adder {
|
|
||||||
/**
|
|
||||||
* Returns the sum of the numbers p1 and p2.
|
|
||||||
*/
|
|
||||||
public int add(int p1, int p2) {
|
|
||||||
return p1 + p2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int BASE = 1;
|
|
||||||
|
|
||||||
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 {
|
|
||||||
PropertyHandlerMapping mapping = new PropertyHandlerMapping();
|
|
||||||
mapping.addHandler("Adder", Adder.class);
|
|
||||||
return mapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initServletWebServer() throws Exception {
|
|
||||||
servlet = new XmlRpcServlet() {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -2040521497373327817L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected XmlRpcHandlerMapping newXmlRpcHandlerMapping() throws XmlRpcException {
|
|
||||||
return ScalabilityTest.this.newXmlRpcHandlerMapping();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
server = new MyServletWebServer(servlet, 8080);
|
|
||||||
server.getXmlRpcServer().setMaxThreads(25);
|
|
||||||
server.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shutdownServletWebServer() throws IOException {
|
|
||||||
server.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initWebServer() throws Exception {
|
|
||||||
webServer = new MyWebServer(8080);
|
|
||||||
webServer.getXmlRpcServer().setHandlerMapping(newXmlRpcHandlerMapping());
|
|
||||||
webServer.getXmlRpcServer().setMaxThreads(25);
|
|
||||||
webServer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shutdownWebServer() throws IOException {
|
|
||||||
webServer.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs the servlet test with a single client.
|
|
||||||
*/
|
|
||||||
public void testSingleServletClient() throws Exception {
|
|
||||||
initServletWebServer();
|
|
||||||
try {
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
servlet.getXmlRpcServletServer().setMaxThreads(1);
|
|
||||||
new MyClient(100 * BASE, server.getPort()).run();
|
|
||||||
logger.log(Level.INFO,
|
|
||||||
"Single servlet client: " + (System.currentTimeMillis() - now) + ", " + server.getNumThreads());
|
|
||||||
} finally {
|
|
||||||
shutdownServletWebServer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs the web server test with a single client.
|
|
||||||
*/
|
|
||||||
public void testSingleWebServerClient() throws Exception {
|
|
||||||
initWebServer();
|
|
||||||
try {
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
webServer.getXmlRpcServer().setMaxThreads(1);
|
|
||||||
new MyClient(100 * BASE, webServer.getPort()).run();
|
|
||||||
logger.log(Level.INFO,
|
|
||||||
"Single web server client: " + (System.currentTimeMillis( ) -now) + ", " + webServer.getNumThreads());
|
|
||||||
} finally {
|
|
||||||
shutdownWebServer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs the test with ten clients.
|
|
||||||
*/
|
|
||||||
public void testTenClient() throws Exception {
|
|
||||||
initServletWebServer();
|
|
||||||
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 MyClient(10 * BASE, server.getPort()));
|
|
||||||
threads[i].start();
|
|
||||||
}
|
|
||||||
for (Thread thread : threads) {
|
|
||||||
thread.join();
|
|
||||||
}
|
|
||||||
logger.log(Level.INFO, "Ten clients: " + (System.currentTimeMillis() - now) + ", " + server.getNumThreads());
|
|
||||||
shutdownServletWebServer();
|
|
||||||
} finally {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,184 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
|
||||||
|
|
||||||
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;
|
|
||||||
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientRequestImpl;
|
|
||||||
import org.xbib.netty.http.xmlrpc.client.XmlRpcSunHttpTransportFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeFactoryImpl;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcRequest;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.XmlRpcStreamRequestConfig;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.XmlRpcRequestParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcServerConfigImpl;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.XMLReader;
|
|
||||||
|
|
||||||
/** A test case for the various serializers.
|
|
||||||
*/
|
|
||||||
public class SerializerTest extends TestCase {
|
|
||||||
private final XmlRpcClient 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 XmlRpcStreamRequestConfig getExConfig() {
|
|
||||||
XmlRpcClientConfigImpl config = getConfig();
|
|
||||||
config.setEnabledForExtensions(true);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
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[] { (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[] { 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 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.
|
|
||||||
*/
|
|
||||||
public void testCalendarParam() throws Exception {
|
|
||||||
TimeZone tz = TimeZone.getTimeZone("GMT");
|
|
||||||
Calendar cal1 = Calendar.getInstance(tz);
|
|
||||||
cal1.set(1933, 5, 12, 11, 7, 21);
|
|
||||||
cal1.set(Calendar.MILLISECOND, 311);
|
|
||||||
Calendar cal2 = Calendar.getInstance(TimeZone.getDefault());
|
|
||||||
cal2.set(1933, 5, 12, 11, 7, 21);
|
|
||||||
cal2.set(Calendar.MILLISECOND, 311);
|
|
||||||
XmlRpcStreamRequestConfig config = getExConfig();
|
|
||||||
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>";
|
|
||||||
assertEquals(expect, got);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for XMLRPC-127: Is it possible to transmit a
|
|
||||||
* map with integers as the keys?
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testIntegerKeyMap() throws Exception {
|
|
||||||
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>";
|
|
||||||
assertEquals(expect, got);
|
|
||||||
XmlRpcServer server = new XmlRpcServer();
|
|
||||||
XmlRpcServerConfigImpl serverConfig = new XmlRpcServerConfigImpl();
|
|
||||||
serverConfig.setEnabledForExtensions(true);
|
|
||||||
server.setConfig(serverConfig);
|
|
||||||
XmlRpcRequestParser parser = new XmlRpcRequestParser(serverConfig, new TypeFactoryImpl(server));
|
|
||||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
|
||||||
spf.setValidating(false);
|
|
||||||
spf.setNamespaceAware(true);
|
|
||||||
XMLReader xr = spf.newSAXParser().getXMLReader();
|
|
||||||
xr.setContentHandler(parser);
|
|
||||||
xr.parse(new InputSource(new StringReader(expect)));
|
|
||||||
assertEquals("integerKeyMap", parser.getMethodName());
|
|
||||||
List<Object> params = parser.getParams();
|
|
||||||
assertEquals(1, params.size());
|
|
||||||
Map<Object, Object> paramMap = (Map) params.get(0);
|
|
||||||
assertEquals(1, paramMap.size());
|
|
||||||
assertEquals("one", paramMap.get(1));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
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.XmlRpcSunHttpTransportFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.client.XmlRpcTransportFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcServer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcServerConfigImpl;
|
|
||||||
import org.xbib.netty.http.xmlrpc.servlet.ServletWebServer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.servlet.XmlRpcServlet;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A provider class for testing the {@link ServletWebServer}.
|
|
||||||
*/
|
|
||||||
public class ServletWebServerProvider extends ClientProviderImpl {
|
|
||||||
|
|
||||||
protected final ServletWebServer webServer;
|
|
||||||
|
|
||||||
protected final XmlRpcServlet servlet;
|
|
||||||
|
|
||||||
private final boolean contentLength;
|
|
||||||
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of {@link XmlRpcServlet}.
|
|
||||||
*/
|
|
||||||
protected XmlRpcServlet newXmlRpcServlet() {
|
|
||||||
return new XmlRpcServlet();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
* @throws ServletException
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
protected ServletWebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) throws ServletException, IOException {
|
|
||||||
super(pMapping);
|
|
||||||
contentLength = pContentLength;
|
|
||||||
servlet = newXmlRpcServlet();
|
|
||||||
webServer = new ServletWebServer(servlet, 0);
|
|
||||||
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://localhost:" + port + "/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcClientConfigImpl getConfig(URL pServerURL) throws Exception {
|
|
||||||
XmlRpcClientConfigImpl config = super.getConfig();
|
|
||||||
config.setServerURL(pServerURL);
|
|
||||||
config.setContentLengthOptional(!contentLength);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
|
|
||||||
return new XmlRpcSunHttpTransportFactory(pClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlRpcServer getServer() {
|
|
||||||
return servlet.getXmlRpcServletServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() throws IOException {
|
|
||||||
webServer.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
/** Implementation of {@link BaseTest} for testing the
|
|
||||||
* {@link XmlRpcSunHttpTransport}.
|
|
||||||
*/
|
|
||||||
public class SunHttpTransportProvider extends WebServerProvider {
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
* @param pContentLength Number of bytes being transmitted.
|
|
||||||
*/
|
|
||||||
public SunHttpTransportProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
|
|
||||||
super(pMapping, pContentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
|
|
||||||
return new XmlRpcSunHttpTransportFactory(pClient);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.client.test;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.client.XmlRpcClientConfigImpl;
|
|
||||||
import org.xbib.netty.http.xmlrpc.server.XmlRpcHandlerMapping;
|
|
||||||
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 {
|
|
||||||
|
|
||||||
private WebServer webServer;
|
|
||||||
|
|
||||||
private final boolean contentLength;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMapping The test servers handler mapping.
|
|
||||||
*/
|
|
||||||
WebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
|
|
||||||
super(pMapping);
|
|
||||||
contentLength = pContentLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
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;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeConverterFactory;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.TypeConverterFactoryImpl;
|
|
||||||
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.serializer.XmlRpcWriter;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.XMLWriter;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.XMLWriterImpl;
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcTestCase extends TestCase {
|
|
||||||
|
|
||||||
protected ClientProvider[] providers;
|
|
||||||
|
|
||||||
protected abstract XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException;
|
|
||||||
|
|
||||||
protected XmlRpcClientConfigImpl getConfig(ClientProvider pProvider) throws Exception {
|
|
||||||
return pProvider.getConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
XmlRpcClientConfig getExConfig(ClientProvider pProvider) throws Exception {
|
|
||||||
XmlRpcClientConfigImpl config = getConfig(pProvider);
|
|
||||||
config.setEnabledForExtensions(true);
|
|
||||||
config.setEnabledForExceptions(true);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
XmlRpcHandlerMapping getHandlerMapping(String pResource) throws IOException, XmlRpcException {
|
|
||||||
PropertyHandlerMapping mapping = new PropertyHandlerMapping();
|
|
||||||
mapping.setVoidMethodEnabled(true);
|
|
||||||
mapping.load(getClass().getClassLoader(), getClass().getResource(pResource));
|
|
||||||
mapping.setTypeConverterFactory(getTypeConverterFactory());
|
|
||||||
return mapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
if (providers == null) {
|
|
||||||
providers = initProviders(getHandlerMapping());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tearDown() throws IOException {
|
|
||||||
if (providers != null) {
|
|
||||||
for (ClientProvider provider : providers) {
|
|
||||||
provider.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TypeConverterFactory getTypeConverterFactory() {
|
|
||||||
return new TypeConverterFactoryImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
static String writeRequest(XmlRpcClient pClient, XmlRpcRequest pRequest)
|
|
||||||
throws SAXException {
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
XMLWriter xw = new XMLWriterImpl();
|
|
||||||
xw.setEncoding("US-ASCII");
|
|
||||||
xw.setDeclarating(true);
|
|
||||||
xw.setIndenting(false);
|
|
||||||
xw.setWriter(sw);
|
|
||||||
XmlRpcWriter xrw = new XmlRpcWriter((XmlRpcStreamConfig) pClient.getConfig(), xw, pClient.getTypeFactory());
|
|
||||||
xrw.write(pRequest);
|
|
||||||
return sw.toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
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
|
|
|
@ -1 +0,0 @@
|
||||||
org.xbib.netty.http.xmlrpc.client.test.AuthenticationTest$Adder=org.xbib.netty.http.xmlrpc.client.test.AuthenticationTest$AdderImpl
|
|
|
@ -1 +0,0 @@
|
||||||
Remote=org.xbib.netty.http.xmlrpc.client.test.BaseTest$Remote
|
|
|
@ -1 +0,0 @@
|
||||||
org.xbib.netty.http.xmlrpc.client.test.DynamicProxyTest$Adder=org.xbib.netty.http.xmlrpc.client.test.DynamicProxyTest$AdderImpl
|
|
|
@ -1,5 +0,0 @@
|
||||||
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
|
|
|
@ -1 +0,0 @@
|
||||||
Remote=org.xbib.netty.http.xmlrpc.client.test.BaseTest$Remote
|
|
|
@ -1,75 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of {@link ServerStreamConnection}
|
|
||||||
*/
|
|
||||||
public class LocalStreamConnection {
|
|
||||||
private class LocalServerStreamConnection implements ServerStreamConnection {
|
|
||||||
public InputStream newInputStream() throws IOException {
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutputStream newOutputStream() throws IOException {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
|
||||||
response.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final InputStream request;
|
|
||||||
private final XmlRpcStreamRequestConfig config;
|
|
||||||
private final ByteArrayOutputStream response = new ByteArrayOutputStream();
|
|
||||||
private final ServerStreamConnection serverStreamConnection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance with the given request stream.
|
|
||||||
* @param pConfig config
|
|
||||||
* @param pRequest request
|
|
||||||
*/
|
|
||||||
public LocalStreamConnection(XmlRpcStreamRequestConfig pConfig,
|
|
||||||
InputStream pRequest) {
|
|
||||||
config = pConfig;
|
|
||||||
request = pRequest;
|
|
||||||
serverStreamConnection = new LocalServerStreamConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the request stream.
|
|
||||||
* @return stream
|
|
||||||
*/
|
|
||||||
public InputStream getRequest() {
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the request configuration.
|
|
||||||
* @return config
|
|
||||||
*/
|
|
||||||
public XmlRpcStreamRequestConfig getConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an output stream, to which the response
|
|
||||||
* may be written.
|
|
||||||
* @return response
|
|
||||||
*/
|
|
||||||
public ByteArrayOutputStream getResponse() {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the server connection.
|
|
||||||
* @return server connection
|
|
||||||
*/
|
|
||||||
public ServerStreamConnection getServerStreamConnection() {
|
|
||||||
return serverStreamConnection;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of an object, which is able to provide
|
|
||||||
* an XML stream, containing an XML-RPC request.
|
|
||||||
* Additionally, the object may also be used to
|
|
||||||
* write the response as an XML stream.
|
|
||||||
*/
|
|
||||||
public interface ServerStreamConnection {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the connection input stream.
|
|
||||||
* @return input stream
|
|
||||||
* @throws IOException if connection fails
|
|
||||||
*/
|
|
||||||
InputStream newInputStream() throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the connection output stream.
|
|
||||||
* @return output stream
|
|
||||||
* @throws IOException if connection fails
|
|
||||||
*/
|
|
||||||
OutputStream newOutputStream() throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the connection, and frees resources.
|
|
||||||
* @throws IOException if close fails
|
|
||||||
*/
|
|
||||||
void close() throws IOException;
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link TypeConverter} is used when actually calling the
|
|
||||||
* handler method or actually returning the result object. It's
|
|
||||||
* purpose is to convert a single parameter or the return value
|
|
||||||
* from a generic representation (for example an array of objects)
|
|
||||||
* to an alternative representation, which is actually used in
|
|
||||||
* the methods signature (for example {@link List}, or
|
|
||||||
* {@link Vector}.
|
|
||||||
*/
|
|
||||||
public interface TypeConverter {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true whether the {@link TypeConverter} is
|
|
||||||
* ready to handle the given object. If so,
|
|
||||||
* {@link #convert(Object)} may be called.
|
|
||||||
* @param pObject object
|
|
||||||
* @return true
|
|
||||||
*/
|
|
||||||
boolean isConvertable(Object pObject);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the given object into the required
|
|
||||||
* representation.
|
|
||||||
* @param pObject object
|
|
||||||
* @return object
|
|
||||||
*/
|
|
||||||
Object convert(Object pObject);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the given object into its generic
|
|
||||||
* representation.
|
|
||||||
* @param result result
|
|
||||||
* @return object
|
|
||||||
*/
|
|
||||||
Object backConvert(Object result);
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link TypeConverterFactory} is called for creating instances
|
|
||||||
* of {@link TypeConverter}.
|
|
||||||
*/
|
|
||||||
public interface TypeConverterFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of {@link TypeFactory}, which may be
|
|
||||||
* used to create instances of the given class.
|
|
||||||
* @param pClass class
|
|
||||||
* @return type converter
|
|
||||||
*/
|
|
||||||
TypeConverter getTypeConverter(Class<?> pClass);
|
|
||||||
}
|
|
|
@ -1,322 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of {@link TypeConverterFactory}.
|
|
||||||
*/
|
|
||||||
public class TypeConverterFactoryImpl implements TypeConverterFactory {
|
|
||||||
|
|
||||||
private static class IdentityTypeConverter implements TypeConverter {
|
|
||||||
|
|
||||||
private final Class<?> clazz;
|
|
||||||
|
|
||||||
IdentityTypeConverter(Class<?> pClass) {
|
|
||||||
clazz = pClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConvertable(Object pObject) {
|
|
||||||
return pObject == null || clazz.isAssignableFrom(pObject.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object backConvert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static abstract class ListTypeConverter implements TypeConverter {
|
|
||||||
|
|
||||||
private final Class<?> clazz;
|
|
||||||
|
|
||||||
ListTypeConverter(Class<?> pClass) {
|
|
||||||
clazz = pClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract List<Object> newList(int pSize);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConvertable(Object pObject) {
|
|
||||||
return pObject == null || pObject instanceof Object[] || pObject instanceof Collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public Object convert(Object pObject) {
|
|
||||||
if (pObject == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (clazz.isAssignableFrom(pObject.getClass())) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
if (pObject instanceof Object[]) {
|
|
||||||
Object[] objects = (Object[]) pObject;
|
|
||||||
List<Object> result = newList(objects.length);
|
|
||||||
result.addAll(Arrays.asList(objects));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
Collection<Object> collection = (Collection) pObject;
|
|
||||||
List<Object> result = newList(collection.size());
|
|
||||||
result.addAll(collection);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object backConvert(Object pObject) {
|
|
||||||
return ((List) pObject).toArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class PrimitiveTypeConverter implements TypeConverter {
|
|
||||||
|
|
||||||
private final Class<?> clazz;
|
|
||||||
|
|
||||||
PrimitiveTypeConverter(Class<?> pClass) {
|
|
||||||
clazz = pClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConvertable(Object pObject) {
|
|
||||||
return pObject != null && pObject.getClass().isAssignableFrom(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object backConvert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final TypeConverter voidTypeConverter = new IdentityTypeConverter(void.class);
|
|
||||||
private static final TypeConverter mapTypeConverter = new IdentityTypeConverter(Map.class);
|
|
||||||
private static final TypeConverter objectArrayTypeConverter = new IdentityTypeConverter(Object[].class);
|
|
||||||
private static final TypeConverter byteArrayTypeConverter = new IdentityTypeConverter(byte[].class);
|
|
||||||
private static final TypeConverter stringTypeConverter = new IdentityTypeConverter(String.class);
|
|
||||||
private static final TypeConverter booleanTypeConverter = new IdentityTypeConverter(Boolean.class);
|
|
||||||
private static final TypeConverter characterTypeConverter = new IdentityTypeConverter(Character.class);
|
|
||||||
private static final TypeConverter byteTypeConverter = new IdentityTypeConverter(Byte.class);
|
|
||||||
private static final TypeConverter shortTypeConverter = new IdentityTypeConverter(Short.class);
|
|
||||||
private static final TypeConverter integerTypeConverter = new IdentityTypeConverter(Integer.class);
|
|
||||||
private static final TypeConverter longTypeConverter = new IdentityTypeConverter(Long.class);
|
|
||||||
private static final TypeConverter bigDecimalTypeConverter = new IdentityTypeConverter(BigDecimal.class);
|
|
||||||
private static final TypeConverter bigIntegerTypeConverter = new IdentityTypeConverter(BigInteger.class);
|
|
||||||
private static final TypeConverter floatTypeConverter = new IdentityTypeConverter(Float.class);
|
|
||||||
private static final TypeConverter doubleTypeConverter = new IdentityTypeConverter(Double.class);
|
|
||||||
private static final TypeConverter dateTypeConverter = new IdentityTypeConverter(Date.class);
|
|
||||||
private static final TypeConverter calendarTypeConverter = new IdentityTypeConverter(Calendar.class);
|
|
||||||
private static final TypeConverter domTypeConverter = new IdentityTypeConverter(Document.class);
|
|
||||||
private static final TypeConverter primitiveBooleanTypeConverter = new PrimitiveTypeConverter(Boolean.class);
|
|
||||||
private static final TypeConverter primitiveCharTypeConverter = new PrimitiveTypeConverter(Character.class);
|
|
||||||
private static final TypeConverter primitiveByteTypeConverter = new PrimitiveTypeConverter(Byte.class);
|
|
||||||
private static final TypeConverter primitiveShortTypeConverter = new PrimitiveTypeConverter(Short.class);
|
|
||||||
private static final TypeConverter primitiveIntTypeConverter = new PrimitiveTypeConverter(Integer.class);
|
|
||||||
private static final TypeConverter primitiveLongTypeConverter = new PrimitiveTypeConverter(Long.class);
|
|
||||||
private static final TypeConverter primitiveFloatTypeConverter = new PrimitiveTypeConverter(Float.class);
|
|
||||||
private static final TypeConverter primitiveDoubleTypeConverter = new PrimitiveTypeConverter(Double.class);
|
|
||||||
|
|
||||||
private static final TypeConverter propertiesTypeConverter = new TypeConverter() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConvertable(Object pObject) {
|
|
||||||
return pObject == null || pObject instanceof Map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convert(Object pObject) {
|
|
||||||
if (pObject == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.putAll((Map) pObject);
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object backConvert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final TypeConverter hashTableTypeConverter = new TypeConverter() {
|
|
||||||
@Override
|
|
||||||
public boolean isConvertable(Object pObject) {
|
|
||||||
return pObject == null || pObject instanceof Map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public Object convert(Object pObject) {
|
|
||||||
if (pObject == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Hashtable<>((Map) pObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object backConvert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final TypeConverter listTypeConverter = new ListTypeConverter(List.class) {
|
|
||||||
@Override
|
|
||||||
protected List<Object> newList(int pSize) {
|
|
||||||
return new ArrayList<>(pSize);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final TypeConverter vectorTypeConverter = new ListTypeConverter(Vector.class) {
|
|
||||||
@Override
|
|
||||||
protected List<Object> newList(int pSize) {
|
|
||||||
return new Vector<>(pSize);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static class CastCheckingTypeConverter implements TypeConverter {
|
|
||||||
|
|
||||||
private final Class<?> clazz;
|
|
||||||
|
|
||||||
CastCheckingTypeConverter(Class<?> pClass) {
|
|
||||||
clazz = pClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConvertable(Object pObject) {
|
|
||||||
return pObject == null || clazz.isAssignableFrom(pObject.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object backConvert(Object pObject) {
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns a type converter for the given class.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public TypeConverter getTypeConverter(Class<?> pClass) {
|
|
||||||
if (void.class.equals(pClass)) {
|
|
||||||
return voidTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(boolean.class)) {
|
|
||||||
return primitiveBooleanTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(char.class)) {
|
|
||||||
return primitiveCharTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(byte.class)) {
|
|
||||||
return primitiveByteTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(short.class)) {
|
|
||||||
return primitiveShortTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(int.class)) {
|
|
||||||
return primitiveIntTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(long.class)) {
|
|
||||||
return primitiveLongTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(float.class)) {
|
|
||||||
return primitiveFloatTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(double.class)) {
|
|
||||||
return primitiveDoubleTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(String.class)) {
|
|
||||||
return stringTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Boolean.class)) {
|
|
||||||
return booleanTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Character.class)) {
|
|
||||||
return characterTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Byte.class)) {
|
|
||||||
return byteTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Short.class)) {
|
|
||||||
return shortTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Integer.class)) {
|
|
||||||
return integerTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Long.class)) {
|
|
||||||
return longTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(BigDecimal.class)) {
|
|
||||||
return bigDecimalTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(BigInteger.class)) {
|
|
||||||
return bigIntegerTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Float.class)) {
|
|
||||||
return floatTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Double.class)) {
|
|
||||||
return doubleTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Date.class)) {
|
|
||||||
return dateTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Calendar.class)) {
|
|
||||||
return calendarTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Object[].class)) {
|
|
||||||
return objectArrayTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(List.class)) {
|
|
||||||
return listTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Vector.class)) {
|
|
||||||
return vectorTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Map.class)) {
|
|
||||||
return mapTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Hashtable.class)) {
|
|
||||||
return hashTableTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Properties.class)) {
|
|
||||||
return propertiesTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(byte[].class)) {
|
|
||||||
return byteArrayTypeConverter;
|
|
||||||
}
|
|
||||||
if (pClass.isAssignableFrom(Document.class)) {
|
|
||||||
return domTypeConverter;
|
|
||||||
}
|
|
||||||
if (Serializable.class.isAssignableFrom(pClass)) {
|
|
||||||
return new CastCheckingTypeConverter(pClass);
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Invalid parameter or result type: " + pClass.getName());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.TypeParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.TypeSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.NamespaceContextImpl;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A type factory creates serializers or handlers, based on the object
|
|
||||||
* type.
|
|
||||||
*/
|
|
||||||
public interface TypeFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a serializer for the object <code>pObject</code>.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pObject The object being serialized.
|
|
||||||
* @return A serializer for <code>pObject</code>.
|
|
||||||
* @throws SAXException Creating the serializer failed.
|
|
||||||
*/
|
|
||||||
TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a parser for a parameter or result object.
|
|
||||||
* @param pConfig The request configuration.
|
|
||||||
* @param pContext A namespace context, for looking up prefix mappings.
|
|
||||||
* @param pURI The namespace URI of the element containing the parameter or result.
|
|
||||||
* @param pLocalName The local name of the element containing the parameter or result.
|
|
||||||
* @return The created parser.
|
|
||||||
*/
|
|
||||||
TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName);
|
|
||||||
}
|
|
|
@ -1,220 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.BigDecimalParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.BigIntegerParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.BooleanParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.ByteArrayParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.CalendarParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.DateParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.DoubleParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.FloatParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.I1Parser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.I2Parser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.I4Parser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.I8Parser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.MapParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.NullParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.ObjectArrayParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.StringParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.parser.TypeParser;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.BigDecimalSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.BigIntegerSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.BooleanSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.ByteArraySerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.CalendarSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.DateSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.DoubleSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.FloatSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.I1Serializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.I2Serializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.I4Serializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.I8Serializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.ListSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.MapSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.NullSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.ObjectArraySerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.StringSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.TypeSerializer;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.serializer.XmlRpcWriter;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.NamespaceContextImpl;
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.XmlRpcDateTimeDateFormat;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of a type factory.
|
|
||||||
*/
|
|
||||||
public class TypeFactoryImpl implements TypeFactory {
|
|
||||||
private static final TypeSerializer NULL_SERIALIZER = new NullSerializer();
|
|
||||||
private static final TypeSerializer STRING_SERIALIZER = new StringSerializer();
|
|
||||||
private static final TypeSerializer I4_SERIALIZER = new I4Serializer();
|
|
||||||
private static final TypeSerializer BOOLEAN_SERIALIZER = new BooleanSerializer();
|
|
||||||
private static final TypeSerializer DOUBLE_SERIALIZER = new DoubleSerializer();
|
|
||||||
private static final TypeSerializer BYTE_SERIALIZER = new I1Serializer();
|
|
||||||
private static final TypeSerializer SHORT_SERIALIZER = new I2Serializer();
|
|
||||||
private static final TypeSerializer LONG_SERIALIZER = new I8Serializer();
|
|
||||||
private static final TypeSerializer FLOAT_SERIALIZER = new FloatSerializer();
|
|
||||||
private static final TypeSerializer BIGDECIMAL_SERIALIZER = new BigDecimalSerializer();
|
|
||||||
private static final TypeSerializer BIGINTEGER_SERIALIZER = new BigIntegerSerializer();
|
|
||||||
private static final TypeSerializer CALENDAR_SERIALIZER = new CalendarSerializer();
|
|
||||||
|
|
||||||
private final XmlRpcController controller;
|
|
||||||
private DateSerializer dateSerializer;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pController The controller, which operates the type factory.
|
|
||||||
*/
|
|
||||||
public TypeFactoryImpl(XmlRpcController pController) {
|
|
||||||
controller = pController;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the controller, which operates the type factory.
|
|
||||||
* @return The controller
|
|
||||||
*/
|
|
||||||
public XmlRpcController getController() {
|
|
||||||
return controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException {
|
|
||||||
if (pObject == null) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return NULL_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("Null values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof String) {
|
|
||||||
return STRING_SERIALIZER;
|
|
||||||
} else if (pObject instanceof Byte) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return BYTE_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("Byte values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof Short) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return SHORT_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("Short values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof Integer) {
|
|
||||||
return I4_SERIALIZER;
|
|
||||||
} else if (pObject instanceof Long) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return LONG_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("Long values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof Boolean) {
|
|
||||||
return BOOLEAN_SERIALIZER;
|
|
||||||
} else if (pObject instanceof Float) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return FLOAT_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("Float values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof Double) {
|
|
||||||
return DOUBLE_SERIALIZER;
|
|
||||||
} else if (pObject instanceof Calendar) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return CALENDAR_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("Calendar values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof Date) {
|
|
||||||
if (dateSerializer == null) {
|
|
||||||
dateSerializer = new DateSerializer(new XmlRpcDateTimeDateFormat(){
|
|
||||||
private static final long serialVersionUID = 24345909123324234L;
|
|
||||||
protected TimeZone getTimeZone() {
|
|
||||||
return controller.getConfig().getTimeZone();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return dateSerializer;
|
|
||||||
} else if (pObject instanceof byte[]) {
|
|
||||||
return new ByteArraySerializer();
|
|
||||||
} else if (pObject instanceof Object[]) {
|
|
||||||
return new ObjectArraySerializer(this, pConfig);
|
|
||||||
} else if (pObject instanceof List) {
|
|
||||||
return new ListSerializer(this, pConfig);
|
|
||||||
} else if (pObject instanceof Map) {
|
|
||||||
return new MapSerializer(this, pConfig);
|
|
||||||
} else if (pObject instanceof Node) {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("DOM nodes aren't supported"));
|
|
||||||
} else if (pObject instanceof BigInteger) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return BIGINTEGER_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("BigInteger values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof BigDecimal) {
|
|
||||||
if (pConfig.isEnabledForExtensions()) {
|
|
||||||
return BIGDECIMAL_SERIALIZER;
|
|
||||||
} else {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("BigDecimal values aren't supported, if isEnabledForExtensions() == false"));
|
|
||||||
}
|
|
||||||
} else if (pObject instanceof Serializable) {
|
|
||||||
throw new SAXException(new XmlRpcExtensionException("Serializable objects aren't supported"));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName) {
|
|
||||||
if (XmlRpcWriter.EXTENSIONS_URI.equals(pURI)) {
|
|
||||||
if (!pConfig.isEnabledForExtensions()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (NullSerializer.NIL_TAG.equals(pLocalName)) {
|
|
||||||
return new NullParser();
|
|
||||||
} else if (I1Serializer.I1_TAG.equals(pLocalName)) {
|
|
||||||
return new I1Parser();
|
|
||||||
} else if (I2Serializer.I2_TAG.equals(pLocalName)) {
|
|
||||||
return new I2Parser();
|
|
||||||
} else if (I8Serializer.I8_TAG.equals(pLocalName)) {
|
|
||||||
return new I8Parser();
|
|
||||||
} else if (FloatSerializer.FLOAT_TAG.equals(pLocalName)) {
|
|
||||||
return new FloatParser();
|
|
||||||
} else if (BigDecimalSerializer.BIGDECIMAL_TAG.equals(pLocalName)) {
|
|
||||||
return new BigDecimalParser();
|
|
||||||
} else if (BigIntegerSerializer.BIGINTEGER_TAG.equals(pLocalName)) {
|
|
||||||
return new BigIntegerParser();
|
|
||||||
} else if (CalendarSerializer.CALENDAR_TAG.equals(pLocalName)) {
|
|
||||||
return new CalendarParser();
|
|
||||||
}
|
|
||||||
} else if ("".equals(pURI)) {
|
|
||||||
if (I4Serializer.INT_TAG.equals(pLocalName) || I4Serializer.I4_TAG.equals(pLocalName)) {
|
|
||||||
return new I4Parser();
|
|
||||||
} else if (BooleanSerializer.BOOLEAN_TAG.equals(pLocalName)) {
|
|
||||||
return new BooleanParser();
|
|
||||||
} else if (DoubleSerializer.DOUBLE_TAG.equals(pLocalName)) {
|
|
||||||
return new DoubleParser();
|
|
||||||
} else if (DateSerializer.DATE_TAG.equals(pLocalName)) {
|
|
||||||
return new DateParser(new XmlRpcDateTimeDateFormat(){
|
|
||||||
private static final long serialVersionUID = 7585237706442299067L;
|
|
||||||
protected TimeZone getTimeZone() {
|
|
||||||
return controller.getConfig().getTimeZone();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (ObjectArraySerializer.ARRAY_TAG.equals(pLocalName)) {
|
|
||||||
return new ObjectArrayParser(pConfig, pContext, this);
|
|
||||||
} else if (MapSerializer.STRUCT_TAG.equals(pLocalName)) {
|
|
||||||
return new MapParser(pConfig, pContext, this);
|
|
||||||
} else if (ByteArraySerializer.BASE_64_TAG.equals(pLocalName)) {
|
|
||||||
return new ByteArrayParser();
|
|
||||||
} else if (StringSerializer.STRING_TAG.equals(pLocalName)) {
|
|
||||||
return new StringParser();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
public interface XmlRpcConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns, whether support for extensions are enabled.
|
|
||||||
* By default, extensions are disabled and your client is
|
|
||||||
* interoperable with other XML-RPC implementations.
|
|
||||||
* Interoperable XML-RPC implementations are those, which
|
|
||||||
* are compliant to the
|
|
||||||
* <a href="http://www.xmlrpc.org/spec">XML-RPC Specification</a>.
|
|
||||||
* @return Whether extensions are enabled or not.
|
|
||||||
*/
|
|
||||||
boolean isEnabledForExtensions();
|
|
||||||
|
|
||||||
/** Returns the timezone, which is used to interpret date/time
|
|
||||||
* values. Defaults to {@link TimeZone#getDefault()}.
|
|
||||||
* @return time zone
|
|
||||||
*/
|
|
||||||
TimeZone getTimeZone();
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of {@link XmlRpcConfig}.
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcConfigImpl implements XmlRpcConfig, XmlRpcHttpConfig {
|
|
||||||
|
|
||||||
private boolean enabledForExtensions;
|
|
||||||
|
|
||||||
private boolean contentLengthOptional;
|
|
||||||
|
|
||||||
private String basicEncoding;
|
|
||||||
|
|
||||||
private String encoding;
|
|
||||||
|
|
||||||
private TimeZone timeZone = TimeZone.getDefault();
|
|
||||||
|
|
||||||
public boolean isEnabledForExtensions() { return enabledForExtensions; }
|
|
||||||
|
|
||||||
/** Sets, whether extensions are enabled. By default, the
|
|
||||||
* client or server is strictly compliant to the XML-RPC
|
|
||||||
* specification and extensions are disabled.
|
|
||||||
* @param pExtensions True to enable extensions, false otherwise.
|
|
||||||
*/
|
|
||||||
public void setEnabledForExtensions(boolean pExtensions) {
|
|
||||||
enabledForExtensions = pExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets the encoding for basic authentication.
|
|
||||||
* @param pEncoding The encoding; may be null, in which case
|
|
||||||
* UTF-8 is choosen.
|
|
||||||
*/
|
|
||||||
public void setBasicEncoding(String pEncoding) {
|
|
||||||
basicEncoding = pEncoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBasicEncoding() { return basicEncoding; }
|
|
||||||
|
|
||||||
/** Sets the requests encoding.
|
|
||||||
* @param pEncoding The requests encoding or null (default
|
|
||||||
* UTF-8).
|
|
||||||
*/
|
|
||||||
public void setEncoding(String pEncoding) {
|
|
||||||
encoding = pEncoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEncoding() { return encoding; }
|
|
||||||
|
|
||||||
public boolean isContentLengthOptional() {
|
|
||||||
return contentLengthOptional;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets, whether a "Content-Length" header may be
|
|
||||||
* omitted. The XML-RPC specification demands, that such
|
|
||||||
* a header be present.
|
|
||||||
* @param pContentLengthOptional True, if the content length may be omitted.
|
|
||||||
*/
|
|
||||||
public void setContentLengthOptional(boolean pContentLengthOptional) {
|
|
||||||
contentLengthOptional = pContentLengthOptional;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeZone getTimeZone() {
|
|
||||||
return timeZone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the timezone, which is used to interpret date/time
|
|
||||||
* values. Defaults to {@link TimeZone#getDefault()}.
|
|
||||||
* @param pTimeZone time zone
|
|
||||||
*/
|
|
||||||
public void setTimeZone(TimeZone pTimeZone) {
|
|
||||||
timeZone = pTimeZone;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class XmlRpcController {
|
|
||||||
|
|
||||||
private XmlRpcWorkerFactory workerFactory = getDefaultXmlRpcWorkerFactory();
|
|
||||||
|
|
||||||
private int maxThreads;
|
|
||||||
|
|
||||||
private TypeFactory typeFactory = new TypeFactoryImpl(this);
|
|
||||||
|
|
||||||
/** Creates the controllers default worker factory.
|
|
||||||
* @return The default factory for workers.
|
|
||||||
*/
|
|
||||||
protected abstract XmlRpcWorkerFactory getDefaultXmlRpcWorkerFactory();
|
|
||||||
|
|
||||||
/** Sets the maximum number of concurrent requests. This includes
|
|
||||||
* both synchronous and asynchronous requests.
|
|
||||||
* @param pMaxThreads Maximum number of threads or 0 to disable
|
|
||||||
* the limit.
|
|
||||||
*/
|
|
||||||
public void setMaxThreads(int pMaxThreads) {
|
|
||||||
maxThreads = pMaxThreads;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the maximum number of concurrent requests. This includes
|
|
||||||
* both synchronous and asynchronous requests.
|
|
||||||
* @return Maximum number of threads or 0 to disable
|
|
||||||
* the limit.
|
|
||||||
*/
|
|
||||||
public int getMaxThreads() {
|
|
||||||
return maxThreads;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets the clients worker factory.
|
|
||||||
* @param pFactory The factory being used to create workers.
|
|
||||||
*/
|
|
||||||
public void setWorkerFactory(XmlRpcWorkerFactory pFactory) {
|
|
||||||
workerFactory = pFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the clients worker factory.
|
|
||||||
* @return The factory being used to create workers.
|
|
||||||
*/
|
|
||||||
public XmlRpcWorkerFactory getWorkerFactory() {
|
|
||||||
return workerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the controllers default configuration.
|
|
||||||
* @return The default configuration.
|
|
||||||
*/
|
|
||||||
public abstract XmlRpcConfig getConfig();
|
|
||||||
|
|
||||||
/** Sets the type factory.
|
|
||||||
* @param pTypeFactory The type factory.
|
|
||||||
*/
|
|
||||||
public void setTypeFactory(TypeFactory pTypeFactory) {
|
|
||||||
typeFactory = pTypeFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the type factory.
|
|
||||||
* @return The type factory.
|
|
||||||
*/
|
|
||||||
public TypeFactory getTypeFactory() {
|
|
||||||
return typeFactory;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception is thrown by the XmlRpcClient, if an invocation of the
|
|
||||||
* remote method failed. Failure may have two reasons: The invocation
|
|
||||||
* failed on the remote side (for example, an exception was thrown within
|
|
||||||
* the server) or the communication with the server failed.
|
|
||||||
*/
|
|
||||||
public class XmlRpcException extends Exception {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3258693217049325618L;
|
|
||||||
|
|
||||||
/** The fault code of the exception. For servers based on this library, this
|
|
||||||
* will always be 0. (If there are predefined error codes, they should be in
|
|
||||||
* the XML-RPC spec.)
|
|
||||||
*/
|
|
||||||
public final int code;
|
|
||||||
|
|
||||||
/** If the transport was able to catch a remote exception
|
|
||||||
* (as is the case, if the local transport is used or if extensions
|
|
||||||
* are enabled and the server returned a serialized exception),
|
|
||||||
* then this field contains the trapped exception.
|
|
||||||
*/
|
|
||||||
public final Throwable linkedException;
|
|
||||||
|
|
||||||
/** Creates a new instance with the given error code and error message.
|
|
||||||
* @param pCode Error code.
|
|
||||||
* @param pMessage Detail message.
|
|
||||||
*/
|
|
||||||
public XmlRpcException(int pCode, String pMessage) {
|
|
||||||
this(pCode, pMessage, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a new instance with the given error message
|
|
||||||
* and cause.
|
|
||||||
* @param pMessage Detail message.
|
|
||||||
* @param pLinkedException The errors cause.
|
|
||||||
*/
|
|
||||||
public XmlRpcException(String pMessage, Throwable pLinkedException) {
|
|
||||||
this(0, pMessage, pLinkedException);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a new instance with the given error message
|
|
||||||
* and error code 0.
|
|
||||||
* @param pMessage Detail message.
|
|
||||||
*/
|
|
||||||
public XmlRpcException(String pMessage) {
|
|
||||||
this(0, pMessage, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a new instance with the given error code, error message
|
|
||||||
* and cause.
|
|
||||||
* @param pCode Error code.
|
|
||||||
* @param pMessage Detail message.
|
|
||||||
* @param pLinkedException The errors cause.
|
|
||||||
*/
|
|
||||||
public XmlRpcException(int pCode, String pMessage, Throwable pLinkedException) {
|
|
||||||
super(pMessage);
|
|
||||||
code = pCode;
|
|
||||||
linkedException = pLinkedException;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void printStackTrace(PrintStream pStream) {
|
|
||||||
super.printStackTrace(pStream);
|
|
||||||
if (linkedException != null) {
|
|
||||||
pStream.println("Caused by:");
|
|
||||||
linkedException.printStackTrace(pStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void printStackTrace(PrintWriter pWriter) {
|
|
||||||
super.printStackTrace(pWriter);
|
|
||||||
if (linkedException != null) {
|
|
||||||
pWriter.println("Caused by:");
|
|
||||||
linkedException.printStackTrace(pWriter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Throwable getCause() {
|
|
||||||
return linkedException;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception is thrown, if an attempt to use extensions
|
|
||||||
* is made, but extensions aren't explicitly enabled.
|
|
||||||
*/
|
|
||||||
public class XmlRpcExtensionException extends XmlRpcException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3617014169594311221L;
|
|
||||||
|
|
||||||
/** Creates a new instance with the given error message.
|
|
||||||
* @param pMessage The error message.
|
|
||||||
*/
|
|
||||||
public XmlRpcExtensionException(String pMessage) {
|
|
||||||
super(0, pMessage);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The XML-RPC server uses this interface to call a method of an RPC handler.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the request and returns the result object.
|
|
||||||
* @param pRequest The request being performed (method name and
|
|
||||||
* parameters.)
|
|
||||||
* @return The result object.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
Object execute(XmlRpcRequest pRequest) throws XmlRpcException;
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of a configuration for HTTP requests.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcHttpConfig extends XmlRpcStreamConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the encoding being used to convert the String "username:password"
|
|
||||||
* into bytes.
|
|
||||||
* @return Encoding being used for basic HTTP authentication credentials,
|
|
||||||
* or null, if the default encoding
|
|
||||||
* ({@link XmlRpcStreamRequestConfig#UTF8_ENCODING})
|
|
||||||
* is being used.
|
|
||||||
*/
|
|
||||||
String getBasicEncoding();
|
|
||||||
|
|
||||||
/** Returns, whether a "Content-Length" header may be
|
|
||||||
* omitted. The XML-RPC specification demands, that such
|
|
||||||
* a header be present.
|
|
||||||
* @return True, if the content length may be omitted.
|
|
||||||
*/
|
|
||||||
boolean isContentLengthOptional();
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extension for HTTP based transport. Provides details like server URL,
|
|
||||||
* user credentials, and so on.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcHttpRequestConfig extends XmlRpcStreamRequestConfig, XmlRpcHttpConfig {
|
|
||||||
|
|
||||||
/** Returns the user name being used for basic HTTP authentication.
|
|
||||||
* @return User name or null, if no basic HTTP authentication is being used.
|
|
||||||
*/
|
|
||||||
String getBasicUserName();
|
|
||||||
|
|
||||||
/** Returns the password being used for basic HTTP authentication.
|
|
||||||
* @return Password or null, if no basic HTTP authentication is beind used.
|
|
||||||
* @throws IllegalStateException A user name is configured, but no password.
|
|
||||||
*/
|
|
||||||
String getBasicPassword();
|
|
||||||
|
|
||||||
/** Return the connection timeout in milliseconds
|
|
||||||
* @return connection timeout in milliseconds or 0 if no set
|
|
||||||
*/
|
|
||||||
int getConnectionTimeout();
|
|
||||||
|
|
||||||
/** Return the reply timeout in milliseconds
|
|
||||||
* @return reply timeout in milliseconds or 0 if no set
|
|
||||||
*/
|
|
||||||
int getReplyTimeout();
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of a request configuration.
|
|
||||||
*/
|
|
||||||
public class XmlRpcHttpRequestConfigImpl extends XmlRpcConfigImpl implements
|
|
||||||
XmlRpcHttpRequestConfig {
|
|
||||||
|
|
||||||
private boolean gzipCompressing;
|
|
||||||
|
|
||||||
private boolean gzipRequesting;
|
|
||||||
|
|
||||||
private String basicUserName;
|
|
||||||
|
|
||||||
private String basicPassword;
|
|
||||||
|
|
||||||
private int connectionTimeout = 0;
|
|
||||||
|
|
||||||
private int replyTimeout = 0;
|
|
||||||
|
|
||||||
private boolean enabledForExceptions;
|
|
||||||
|
|
||||||
/** Sets, whether gzip compression is being used for
|
|
||||||
* transmitting the request.
|
|
||||||
* @param pCompressing True for enabling gzip compression,
|
|
||||||
* false otherwise.
|
|
||||||
* @see #setGzipRequesting(boolean)
|
|
||||||
*/
|
|
||||||
public void setGzipCompressing(boolean pCompressing) {
|
|
||||||
gzipCompressing = pCompressing;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGzipCompressing() {
|
|
||||||
return gzipCompressing;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets, whether gzip compression is requested for the
|
|
||||||
* response.
|
|
||||||
* @param pRequesting True for requesting gzip compression,
|
|
||||||
* false otherwise.
|
|
||||||
* @see #setGzipCompressing(boolean)
|
|
||||||
*/
|
|
||||||
public void setGzipRequesting(boolean pRequesting) {
|
|
||||||
gzipRequesting = pRequesting;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGzipRequesting() {
|
|
||||||
return gzipRequesting;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets the user name for basic authentication.
|
|
||||||
* @param pUser The user name.
|
|
||||||
*/
|
|
||||||
public void setBasicUserName(String pUser) {
|
|
||||||
basicUserName = pUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBasicUserName() { return basicUserName; }
|
|
||||||
|
|
||||||
/** Sets the password for basic authentication.
|
|
||||||
* @param pPassword The password.
|
|
||||||
*/
|
|
||||||
public void setBasicPassword(String pPassword) {
|
|
||||||
basicPassword = pPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBasicPassword() { return basicPassword; }
|
|
||||||
|
|
||||||
/** Set the connection timeout in milliseconds.
|
|
||||||
* @param pTimeout connection timeout, 0 to disable it
|
|
||||||
*/
|
|
||||||
public void setConnectionTimeout(int pTimeout) {
|
|
||||||
connectionTimeout = pTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionTimeout() {
|
|
||||||
return connectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Set the reply timeout in milliseconds.
|
|
||||||
* @param pTimeout reply timeout, 0 to disable it
|
|
||||||
*/
|
|
||||||
public void setReplyTimeout(int pTimeout) {
|
|
||||||
replyTimeout = pTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getReplyTimeout() {
|
|
||||||
return replyTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets, whether the response should contain a "faultCause" element
|
|
||||||
* in case of errors. The "faultCause" is an exception, which the
|
|
||||||
* server has trapped and written into a byte stream as a serializable
|
|
||||||
* object.
|
|
||||||
* @param pEnabledForExceptions enabled for exceptions
|
|
||||||
*/
|
|
||||||
public void setEnabledForExceptions(boolean pEnabledForExceptions) {
|
|
||||||
enabledForExceptions = pEnabledForExceptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabledForExceptions() {
|
|
||||||
return enabledForExceptions;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception is thrown, if the server catches an exception, which
|
|
||||||
* is thrown by the handler.
|
|
||||||
*/
|
|
||||||
public class XmlRpcInvocationException extends XmlRpcException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7439737967784966169L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance with the given error code, error message
|
|
||||||
* and cause.
|
|
||||||
* @param pCode code
|
|
||||||
* @param pMessage message
|
|
||||||
* @param pLinkedException exception
|
|
||||||
*/
|
|
||||||
public XmlRpcInvocationException(int pCode, String pMessage, Throwable pLinkedException) {
|
|
||||||
super(pCode, pMessage, pLinkedException);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance with the given error message and cause.
|
|
||||||
* @param pMessage message
|
|
||||||
* @param pLinkedException exception
|
|
||||||
*/
|
|
||||||
public XmlRpcInvocationException(String pMessage, Throwable pLinkedException) {
|
|
||||||
super(pMessage, pLinkedException);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception is thrown, if the clients or servers maximum
|
|
||||||
* number of concurrent threads is exceeded.
|
|
||||||
*/
|
|
||||||
public class XmlRpcLoadException extends XmlRpcException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 4050760511635272755L;
|
|
||||||
|
|
||||||
/** Creates a new instance.
|
|
||||||
* @param pMessage Error description.
|
|
||||||
*/
|
|
||||||
public XmlRpcLoadException(String pMessage) {
|
|
||||||
super(0, pMessage, null);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception must be thrown, if the user isn't authenticated.
|
|
||||||
*/
|
|
||||||
public class XmlRpcNotAuthorizedException extends XmlRpcException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3258410629709574201L;
|
|
||||||
|
|
||||||
/** Creates a new instance with the given error message.
|
|
||||||
* @param pMessage The error message.
|
|
||||||
*/
|
|
||||||
public XmlRpcNotAuthorizedException(String pMessage) {
|
|
||||||
super(0, pMessage);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface to an XML-RPC request made by a client.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcRequest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the request configuration.
|
|
||||||
* @return The request configuration.
|
|
||||||
*/
|
|
||||||
XmlRpcRequestConfig getConfig();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the requests method name.
|
|
||||||
* @return Name of the method being invoked.
|
|
||||||
*/
|
|
||||||
String getMethodName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of parameters.
|
|
||||||
* @return Number of parameters.
|
|
||||||
*/
|
|
||||||
int getParameterCount();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the parameter with index <code>pIndex</code>.
|
|
||||||
* @param pIndex Number between 0 and {@link #getParameterCount()}-1.
|
|
||||||
* @return Parameter being sent to the server.
|
|
||||||
*/
|
|
||||||
public Object getParameter(int pIndex);
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of a request configuration. Depending on
|
|
||||||
* the transport, implementations will also implement
|
|
||||||
* additional interfaces like
|
|
||||||
* {@link XmlRpcStreamRequestConfig}.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcRequestConfig extends XmlRpcConfig {
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of an object, which is able to process
|
|
||||||
* XML-RPC requests.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcRequestProcessor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processes the given request and returns a
|
|
||||||
* result object.
|
|
||||||
* @param pRequest request
|
|
||||||
* @return result
|
|
||||||
* @throws XmlRpcException Processing the request failed.
|
|
||||||
*/
|
|
||||||
Object execute(XmlRpcRequest pRequest) throws XmlRpcException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the request processors {@link TypeConverterFactory}.
|
|
||||||
* @return type converter factory
|
|
||||||
*/
|
|
||||||
TypeConverterFactory getTypeConverterFactory();
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of an object, which may be used
|
|
||||||
* to create instances of {@link XmlRpcRequestProcessor}.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcRequestProcessorFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link XmlRpcRequestProcessor} being invoked.
|
|
||||||
* @return Server object being invoked. This will typically
|
|
||||||
* be a singleton instance, but could as well create a new
|
|
||||||
* instance with any call.
|
|
||||||
*/
|
|
||||||
XmlRpcRequestProcessor getXmlRpcServer();
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of a configuration for a stream based transport.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcStreamConfig extends XmlRpcConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default encoding (UTF-8).
|
|
||||||
*/
|
|
||||||
String UTF8_ENCODING = "UTF-8";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the encoding being used for data encoding, when writing
|
|
||||||
* to a stream.
|
|
||||||
* @return Suggested encoding, or null, if the {@link #UTF8_ENCODING}
|
|
||||||
* is being used.
|
|
||||||
*/
|
|
||||||
String getEncoding();
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of a client configuration for a transport, which
|
|
||||||
* is implemented by writing to a stream.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcStreamRequestConfig extends XmlRpcStreamConfig, XmlRpcRequestConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the request stream is being compressed. Note,
|
|
||||||
* that the response stream may still be uncompressed.
|
|
||||||
* @return Whether to use Gzip compression or not. Defaults to false.
|
|
||||||
* @see #isGzipRequesting()
|
|
||||||
*/
|
|
||||||
boolean isGzipCompressing();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if compression is requested for the response stream.
|
|
||||||
* Note, that the request is stull uncompressed, unless
|
|
||||||
* {@link #isGzipCompressing()} is activated. Also note, that the
|
|
||||||
* server may still decide to send uncompressed data.
|
|
||||||
* @return Whether to use Gzip compression or not. Defaults to false.
|
|
||||||
* @see #isGzipCompressing()
|
|
||||||
*/
|
|
||||||
boolean isGzipRequesting();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the response should contain a "faultCause" element
|
|
||||||
* in case of errors. The "faultCause" is an exception, which the
|
|
||||||
* server has trapped and written into a byte stream as a serializable
|
|
||||||
* object.
|
|
||||||
* @return true if enabled for exceptions
|
|
||||||
*/
|
|
||||||
boolean isEnabledForExceptions();
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An instance of {@link XmlRpcRequestProcessor},
|
|
||||||
* which is processing an XML stream.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcStreamRequestProcessor extends XmlRpcRequestProcessor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads an XML-RPC request from the connection
|
|
||||||
* object and processes the request, writing the
|
|
||||||
* result to the same connection object.
|
|
||||||
* @param pConfig config
|
|
||||||
* @param pConnection connection
|
|
||||||
* @throws XmlRpcException Processing the request failed.
|
|
||||||
*/
|
|
||||||
void execute(XmlRpcStreamRequestConfig pConfig, ServerStreamConnection pConnection) throws XmlRpcException;
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An object, which executes requests on the controllers
|
|
||||||
* behalf. These objects are mainly used for controlling the
|
|
||||||
* clients or servers load, which is defined in terms of the
|
|
||||||
* number of currently active workers.
|
|
||||||
*/
|
|
||||||
public interface XmlRpcWorker {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the workers controller.
|
|
||||||
* @return The controller
|
|
||||||
*/
|
|
||||||
XmlRpcController getController();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a synchronous request. The client worker extends
|
|
||||||
* this interface with the ability to perform asynchronous
|
|
||||||
* requests.
|
|
||||||
* @param pRequest The request being performed.
|
|
||||||
* @return The requests result.
|
|
||||||
* @throws XmlRpcException Performing the request failed.
|
|
||||||
*/
|
|
||||||
Object execute(XmlRpcRequest pRequest) throws XmlRpcException;
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A factory for {@link XmlRpcWorker} instances.
|
|
||||||
*/
|
|
||||||
public abstract class XmlRpcWorkerFactory {
|
|
||||||
|
|
||||||
private final XmlRpcWorker singleton = newWorker();
|
|
||||||
|
|
||||||
private final XmlRpcController controller;
|
|
||||||
|
|
||||||
private final List<XmlRpcWorker> pool = new ArrayList<>();
|
|
||||||
|
|
||||||
private int numThreads;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
* @param pController The client controlling the factory.
|
|
||||||
*/
|
|
||||||
public XmlRpcWorkerFactory(XmlRpcController pController) {
|
|
||||||
controller = pController;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new worker instance.
|
|
||||||
* @return New instance of {@link XmlRpcWorker}.
|
|
||||||
*/
|
|
||||||
protected abstract XmlRpcWorker newWorker();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the factory controller.
|
|
||||||
* @return The controller
|
|
||||||
*/
|
|
||||||
public XmlRpcController getController() {
|
|
||||||
return controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns a worker for synchronous processing.
|
|
||||||
* @return An instance of {@link XmlRpcWorker}, which is ready
|
|
||||||
* for use.
|
|
||||||
* @throws XmlRpcLoadException The clients maximum number of concurrent
|
|
||||||
* threads is exceeded.
|
|
||||||
*/
|
|
||||||
public synchronized XmlRpcWorker getWorker() throws XmlRpcLoadException {
|
|
||||||
int max = controller.getMaxThreads();
|
|
||||||
if (max > 0 && numThreads == max) {
|
|
||||||
throw new XmlRpcLoadException("Maximum number of concurrent requests exceeded: " + max);
|
|
||||||
}
|
|
||||||
if (max == 0) {
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
++numThreads;
|
|
||||||
if (pool.size() == 0) {
|
|
||||||
return newWorker();
|
|
||||||
} else {
|
|
||||||
return pool.remove(pool.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called, when the worker did its job. Frees resources and
|
|
||||||
* decrements the number of concurrent requests.
|
|
||||||
* @param pWorker The worker being released.
|
|
||||||
*/
|
|
||||||
public synchronized void releaseWorker(XmlRpcWorker pWorker) {
|
|
||||||
--numThreads;
|
|
||||||
int max = controller.getMaxThreads();
|
|
||||||
if (pWorker != singleton) {
|
|
||||||
if (pool.size() < max) {
|
|
||||||
pool.add(pWorker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of currently running requests.
|
|
||||||
* @return Current number of concurrent requests.
|
|
||||||
*/
|
|
||||||
public synchronized int getCurrentRequests() {
|
|
||||||
return numThreads;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common.parser;
|
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract base implementation of {@link TypeParser}
|
|
||||||
* for parsing an atomic value.
|
|
||||||
*/
|
|
||||||
public abstract class AtomicParser extends TypeParserImpl {
|
|
||||||
private int level;
|
|
||||||
protected StringBuffer sb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance.
|
|
||||||
*/
|
|
||||||
protected AtomicParser() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void setResult(String pResult) throws SAXException;
|
|
||||||
|
|
||||||
public void startDocument() throws SAXException {
|
|
||||||
level = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void characters(char[] pChars, int pStart, int pLength) throws SAXException {
|
|
||||||
if (sb == null) {
|
|
||||||
if (!isEmpty(pChars, pStart, pLength)) {
|
|
||||||
throw new SAXParseException("Unexpected non-whitespace characters",
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sb.append(pChars, pStart, pLength);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
|
|
||||||
if (--level == 0) {
|
|
||||||
setResult(sb.toString());
|
|
||||||
} else {
|
|
||||||
throw new SAXParseException("Unexpected end tag in atomic element: "
|
|
||||||
+ new QName(pURI, pLocalName),
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
|
|
||||||
if (level++ == 0) {
|
|
||||||
sb = new StringBuffer();
|
|
||||||
} else {
|
|
||||||
throw new SAXParseException("Unexpected start tag in atomic element: "
|
|
||||||
+ new QName(pURI, pLocalName),
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common.parser;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parser for BigDecimal values.
|
|
||||||
*/
|
|
||||||
public class BigDecimalParser extends AtomicParser {
|
|
||||||
protected void setResult(String pResult) throws SAXException {
|
|
||||||
try {
|
|
||||||
super.setResult(new BigDecimal(pResult));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new SAXParseException("Failed to parse BigDecimal value: " + pResult,
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common.parser;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parser for BigInteger values.
|
|
||||||
*/
|
|
||||||
public class BigIntegerParser extends AtomicParser {
|
|
||||||
protected void setResult(String pResult) throws SAXException {
|
|
||||||
try {
|
|
||||||
super.setResult(new BigInteger(pResult));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new SAXParseException("Failed to parse BigInteger value: " + pResult,
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common.parser;
|
|
||||||
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parser for boolean values.
|
|
||||||
*/
|
|
||||||
public class BooleanParser extends AtomicParser {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setResult(String pResult) throws SAXException {
|
|
||||||
String s = pResult.trim();
|
|
||||||
if ("1".equals(s)) {
|
|
||||||
super.setResult(Boolean.TRUE);
|
|
||||||
} else if ("0".equals(s)) {
|
|
||||||
super.setResult(Boolean.FALSE);
|
|
||||||
} else {
|
|
||||||
throw new SAXParseException("Failed to parse boolean value: " + pResult,
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common.parser;
|
|
||||||
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A parser for base64 elements.
|
|
||||||
*/
|
|
||||||
public class ByteArrayParser extends TypeParserImpl {
|
|
||||||
private int level;
|
|
||||||
private StringBuilder sb;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startDocument() throws SAXException {
|
|
||||||
level = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void characters(char[] pChars, int pStart, int pLength) throws SAXException {
|
|
||||||
sb.append(new String(pChars, pStart, pLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
|
|
||||||
if (--level == 0) {
|
|
||||||
setResult(Base64.getDecoder().decode(sb.toString()));
|
|
||||||
} else {
|
|
||||||
throw new SAXParseException("Unexpected end tag in atomic element: "
|
|
||||||
+ new QName(pURI, pLocalName),
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
|
|
||||||
if (level++ == 0) {
|
|
||||||
sb = new StringBuilder();
|
|
||||||
} else {
|
|
||||||
throw new SAXParseException("Unexpected start tag in atomic element: "
|
|
||||||
+ new QName(pURI, pLocalName),
|
|
||||||
getDocumentLocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
package org.xbib.netty.http.xmlrpc.common.parser;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
|
|
||||||
import org.xbib.netty.http.xmlrpc.common.util.XsDateTimeFormat;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parser for integer values.
|
|
||||||
*/
|
|
||||||
public class CalendarParser extends AtomicParser {
|
|
||||||
|
|
||||||
private static final XsDateTimeFormat format = new XsDateTimeFormat();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setResult(String pResult) throws SAXException {
|
|
||||||
try {
|
|
||||||
super.setResult(format.parseObject(pResult.trim()));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
int offset = e.getErrorOffset();
|
|
||||||
final String msg;
|
|
||||||
if (offset == -1) {
|
|
||||||
msg = "Failed to parse dateTime value: " + pResult;
|
|
||||||
} else {
|
|
||||||
msg = "Failed to parse dateTime value " + pResult
|
|
||||||
+ " at position " + e.getErrorOffset();
|
|
||||||
}
|
|
||||||
throw new SAXParseException(msg, getDocumentLocator(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue