jochen 2005/05/13 14:06:37
Modified: src/java/org/apache/xmlrpc/client Tag: b20050512_streaming XmlRpcStreamTransport.java XmlRpcHttpTransport.java src/java/org/apache/xmlrpc/serializer Tag: b20050512_streaming XmlRpcWriter.java I4Serializer.java I2Serializer.java I1Serializer.java I8Serializer.java src/test/org/apache/xmlrpc/test Tag: b20050512_streaming SerializerTest.java HttpTransportTest.java src/java/org/apache/xmlrpc/server Tag: b20050512_streaming XmlRpcStreamServer.java src/java/org/apache/xmlrpc/webserver Tag: b20050512_streaming WebServer.java src/java/org/apache/xmlrpc/common Tag: b20050512_streaming TypeFactoryImpl.java src/java/org/apache/xmlrpc/parser Tag: b20050512_streaming XmlRpcResponseParser.java Log: Webserver based unit tests are working. Revision Changes Path No revision No revision 1.1.2.3 +29 -3 ws-xmlrpc/src/java/org/apache/xmlrpc/client/Attic/XmlRpcStreamTransport.java Index: XmlRpcStreamTransport.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/client/Attic/XmlRpcStreamTransport.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- XmlRpcStreamTransport.java 13 May 2005 00:18:21 -0000 1.1.2.2 +++ XmlRpcStreamTransport.java 13 May 2005 21:06:37 -0000 1.1.2.3 @@ -15,6 +15,8 @@ */ package org.apache.xmlrpc.client; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -161,7 +163,7 @@ XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) pRequest.getConfig(); Object connection = newConnection(config); try { - initConnection(config, pRequest); + initConnection(config, connection); OutputStream ostream = getOutputStream(config, connection); try { writeRequest(config, ostream, pRequest); @@ -198,18 +200,42 @@ } protected Object readResponse(XmlRpcStreamRequestConfig pConfig, InputStream pStream) throws XmlRpcException { + if (true) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + byte[] buffer = new byte[1024]; + for (;;) { + int res = pStream.read(buffer); + if (res == -1) { + break; + } else if (res > 0) { + baos.write(buffer, 0, res); + } + } + } catch (IOException e) { + throw new XmlRpcClientException(e.getMessage(), e); + } + System.out.println("Input: " + new String(baos.toByteArray())); + pStream = new ByteArrayInputStream(baos.toByteArray()); + } + InputSource isource = new InputSource(pStream); XMLReader xr = newXMLReader(); + XmlRpcResponseParser xp; try { - XmlRpcResponseParser xp = new XmlRpcResponseParser(pConfig, getClient().getTypeFactory()); + xp = new XmlRpcResponseParser(pConfig, getClient().getTypeFactory()); xr.setContentHandler(xp); xr.parse(isource); - return xp.getResult(); } catch (SAXException e) { throw new XmlRpcClientException("Failed to parse servers response: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcClientException("Failed to read servers response: " + e.getMessage(), e); } + if (xp.isSuccess()) { + return xp.getResult(); + } else { + throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage()); + } } protected void writeRequest(XmlRpcStreamRequestConfig pConfig, OutputStream pStream, XmlRpcRequest pRequest) 1.1.2.2 +5 -0 ws-xmlrpc/src/java/org/apache/xmlrpc/client/Attic/XmlRpcHttpTransport.java Index: XmlRpcHttpTransport.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/client/Attic/XmlRpcHttpTransport.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- XmlRpcHttpTransport.java 12 May 2005 01:58:51 -0000 1.1.2.1 +++ XmlRpcHttpTransport.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -89,9 +89,14 @@ } } + protected void setContentType(XmlRpcHttpClientConfig pConfig, Object pConnection) throws XmlRpcClientException { + setRequestHeader(pConnection, "Content-Type", "text/html"); + } + protected void initConnection(XmlRpcStreamRequestConfig pConfig, Object pConnection) throws XmlRpcClientException { super.initConnection(pConfig, pConnection); XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pConfig; + setContentType(config, pConnection); setCredentials(config, pConnection); setCompressionHeaders(config, pConnection); } No revision No revision 1.1.2.3 +1 -1 ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/XmlRpcWriter.java Index: XmlRpcWriter.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/XmlRpcWriter.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- XmlRpcWriter.java 13 May 2005 00:18:21 -0000 1.1.2.2 +++ XmlRpcWriter.java 13 May 2005 21:06:37 -0000 1.1.2.3 @@ -122,7 +122,7 @@ handler.startElement("", "fault", "fault", ZERO_ATTRIBUTES); Map map = new HashMap(); map.put("faultCode", new Integer(pCode)); - map.put("faultString", pMessage); + map.put("faultString", pMessage == null ? "" : pMessage); writeValue(map); handler.endElement("", "fault", "fault"); handler.endElement("", "methodResponse", "methodResponse"); 1.1.2.2 +5 -1 ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I4Serializer.java Index: I4Serializer.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I4Serializer.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- I4Serializer.java 12 May 2005 01:58:52 -0000 1.1.2.1 +++ I4Serializer.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -21,9 +21,13 @@ /** A [EMAIL PROTECTED] TypeSerializer} for integers. */ public class I4Serializer extends TypeSerializerImpl { + /** Tag name of an int value. + */ + public static final String INT_TAG = "int"; + /** Tag name of an i4 value. */ - public static final String I4_TAG = "int"; + public static final String I4_TAG = "i4"; public void write(ContentHandler pHandler, Object pObject) throws SAXException { write(pHandler, I4_TAG, pObject.toString()); 1.1.2.2 +2 -2 ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I2Serializer.java Index: I2Serializer.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I2Serializer.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- I2Serializer.java 12 May 2005 01:58:52 -0000 1.1.2.1 +++ I2Serializer.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -23,11 +23,11 @@ public class I2Serializer extends TypeSerializerImpl { /** Tag name of an i2 value. */ - public static final String I2_TAG = "short"; + public static final String I2_TAG = "i2"; /** Fully qualified name of an i2 value. */ - public static final String EX_I2_TAG = "ex:short"; + public static final String EX_I2_TAG = "ex:i2"; public void write(ContentHandler pHandler, Object pObject) throws SAXException { write(pHandler, I2_TAG, EX_I2_TAG, pObject.toString()); 1.1.2.2 +2 -2 ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I1Serializer.java Index: I1Serializer.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I1Serializer.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- I1Serializer.java 12 May 2005 01:58:52 -0000 1.1.2.1 +++ I1Serializer.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -23,11 +23,11 @@ public class I1Serializer extends TypeSerializerImpl { /** Tag name of an i1 value. */ - public static final String I1_TAG = "byte"; + public static final String I1_TAG = "i1"; /** Fully qualified name of an i1 value. */ - public static final String EX_I1_TAG = "ex:byte"; + public static final String EX_I1_TAG = "ex:i1"; public void write(ContentHandler pHandler, Object pObject) throws SAXException { write(pHandler, I1_TAG, EX_I1_TAG, pObject.toString()); 1.1.2.2 +2 -2 ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I8Serializer.java Index: I8Serializer.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/I8Serializer.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- I8Serializer.java 12 May 2005 01:58:52 -0000 1.1.2.1 +++ I8Serializer.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -23,11 +23,11 @@ public class I8Serializer extends TypeSerializerImpl { /** Tag name of an i8 value. */ - public static final String I8_TAG = "long"; + public static final String I8_TAG = "i8"; /** Fully qualified name of an i8 value. */ - public static final String EX_I8_TAG = "ex:long"; + public static final String EX_I8_TAG = "ex:i8"; public void write(ContentHandler pHandler, Object pObject) throws SAXException { write(pHandler, I8_TAG, EX_I8_TAG, pObject.toString()); No revision No revision 1.1.2.2 +1 -1 ws-xmlrpc/src/test/org/apache/xmlrpc/test/Attic/SerializerTest.java Index: SerializerTest.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/test/org/apache/xmlrpc/test/Attic/SerializerTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- SerializerTest.java 13 May 2005 00:18:21 -0000 1.1.2.1 +++ SerializerTest.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -100,7 +100,7 @@ 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:byte>3</ex:byte></value></param></params></methodCall>"; + + "<methodName>byteParam</methodName><params><param><value><ex:i1>3</ex:i1></value></param></params></methodCall>"; assertEquals(expect, got); } 1.1.2.2 +7 -1 ws-xmlrpc/src/test/org/apache/xmlrpc/test/Attic/HttpTransportTest.java Index: HttpTransportTest.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/test/org/apache/xmlrpc/test/Attic/HttpTransportTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- HttpTransportTest.java 12 May 2005 01:58:52 -0000 1.1.2.1 +++ HttpTransportTest.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -21,6 +21,8 @@ import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; import org.apache.xmlrpc.client.XmlRpcHttpTransportFactory; import org.apache.xmlrpc.client.XmlRpcTransportFactory; +import org.apache.xmlrpc.server.XmlRpcServer; +import org.apache.xmlrpc.server.XmlRpcServerConfigImpl; import org.apache.xmlrpc.webserver.WebServer; @@ -28,11 +30,15 @@ * [EMAIL PROTECTED] org.apache.xmlrpc.client.XmlRpcHttpTransport}. */ public class HttpTransportTest extends BaseTestCase { - private WebServer webServer = new WebServer(0); + private final WebServer webServer = new WebServer(0); private boolean isActive; public void setUp() throws Exception { if (!isActive) { + XmlRpcServer server = webServer.getXmlRpcServer(); + server.setHandlerMapping(getHandlerMapping()); + XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig(); + serverConfig.setEnabledForExtensions(true); webServer.start(); isActive = true; } No revision No revision 1.1.2.3 +7 -2 ws-xmlrpc/src/java/org/apache/xmlrpc/server/Attic/XmlRpcStreamServer.java Index: XmlRpcStreamServer.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/server/Attic/XmlRpcStreamServer.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- XmlRpcStreamServer.java 13 May 2005 00:18:22 -0000 1.1.2.2 +++ XmlRpcStreamServer.java 13 May 2005 21:06:37 -0000 1.1.2.3 @@ -65,6 +65,10 @@ try { xr.parse(new InputSource(pStream)); } catch (SAXException e) { + Exception ex = e.getException(); + if (ex != null && ex instanceof XmlRpcException) { + throw (XmlRpcException) ex; + } throw new XmlRpcException("Failed to parse XML-RPC request: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcException("Failed to read XML-RPC request: " + e.getMessage(), e); @@ -107,6 +111,7 @@ } message = pError.getMessage(); try { + pError.printStackTrace(); getXmlRpcWriter(pConfig, pStream).write(pConfig, code, message); } catch (SAXException e) { throw new XmlRpcException("Failed to write XML-RPC response: " + e.getMessage(), e); @@ -152,11 +157,11 @@ Object pConnection) throws IOException, XmlRpcException { try { - InputStream istream = getInputStream(pConfig, pConnection); - XmlRpcRequest request = getRequest(pConfig, istream); Object result; Throwable error; try { + InputStream istream = getInputStream(pConfig, pConnection); + XmlRpcRequest request = getRequest(pConfig, istream); result = execute(request); error = null; } catch (Throwable t) { No revision No revision 1.1.2.2 +8 -6 ws-xmlrpc/src/java/org/apache/xmlrpc/webserver/Attic/WebServer.java Index: WebServer.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/webserver/Attic/WebServer.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- WebServer.java 12 May 2005 01:58:53 -0000 1.1.2.1 +++ WebServer.java 13 May 2005 21:06:37 -0000 1.1.2.2 @@ -276,12 +276,7 @@ try { if (allowConnection(socket)) { final Connection con = new Connection(this, server, socket); - ThreadPool.Task task = new ThreadPool.Task(){ - public void run() throws Throwable { - server.execute(con.getRequestConfig(), con); - } - }; - if (pool.startTask(task)) { + if (pool.startTask(con)) { socket = null; } else { log("Maximum load of " + pool.getMaxThreads() @@ -360,4 +355,11 @@ public synchronized void log(String pMessage) { System.err.println(df.format(new Date()) + ", " + Thread.currentThread().getName() + ": " + pMessage); } + + /** Returns the [EMAIL PROTECTED] org.apache.xmlrpc.server.XmlRpcServer}. + * @return The server object. + */ + public XmlRpcStreamServer getXmlRpcServer() { + return server; + } } No revision No revision 1.1.2.3 +1 -1 ws-xmlrpc/src/java/org/apache/xmlrpc/common/Attic/TypeFactoryImpl.java Index: TypeFactoryImpl.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/common/Attic/TypeFactoryImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- TypeFactoryImpl.java 13 May 2005 00:18:22 -0000 1.1.2.2 +++ TypeFactoryImpl.java 13 May 2005 21:06:37 -0000 1.1.2.3 @@ -155,7 +155,7 @@ return new FloatParser(); } } else if ("".equals(pURI)) { - if (I4Serializer.I4_TAG.equals(pLocalName)) { + if (I4Serializer.INT_TAG.equals(pLocalName) || I4Serializer.I4_TAG.equals(pLocalName)) { return new I4Parser(); } else if (BooleanSerializer.BOOLEAN_TAG.equals(pLocalName)) { return new BooleanParser(); No revision No revision 1.1.2.3 +48 -20 ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/XmlRpcResponseParser.java Index: XmlRpcResponseParser.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/XmlRpcResponseParser.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- XmlRpcResponseParser.java 13 May 2005 00:18:21 -0000 1.1.2.2 +++ XmlRpcResponseParser.java 13 May 2005 21:06:37 -0000 1.1.2.3 @@ -52,12 +52,12 @@ super.setResult(pResult); } else { Map map = (Map) pResult; - String faultCode = (String) map.get("faultCode"); + Integer faultCode = (Integer) map.get("faultCode"); if (faultCode == null) { throw new SAXParseException("Missing faultCode", getDocumentLocator()); } try { - errorCode = Integer.parseInt(faultCode); + errorCode = faultCode.intValue(); } catch (NumberFormatException e) { throw new SAXParseException("Invalid faultCode: " + faultCode, getDocumentLocator()); @@ -93,19 +93,33 @@ } break; case 2: - if (!"".equals(pURI) || !"param".equals(pLocalName)) { - throw new SAXParseException("Expected param element, got " - + new QName(pURI, pLocalName), - getDocumentLocator()); + if (isSuccess) { + if (!"".equals(pURI) || !"param".equals(pLocalName)) { + throw new SAXParseException("Expected param element, got " + + new QName(pURI, pLocalName), + getDocumentLocator()); + } + } else { + if ("".equals(pURI) && "value".equals(pLocalName)) { + startValueTag(); + } else { + throw new SAXParseException("Expected value element, got " + + new QName(pURI, pLocalName), + getDocumentLocator()); + } } break; case 3: - if ("".equals(pURI) && "value".equals(pLocalName)) { - startValueTag(); + if (isSuccess) { + if ("".equals(pURI) && "value".equals(pLocalName)) { + startValueTag(); + } else { + throw new SAXParseException("Expected value element, got " + + new QName(pURI, pLocalName), + getDocumentLocator()); + } } else { - throw new SAXParseException("Expected value element, got " - + new QName(pURI, pLocalName), - getDocumentLocator()); + super.startElement(pURI, pLocalName, pQName, pAttrs); } break; default: @@ -139,19 +153,33 @@ break; } case 2: - if (!"".equals(pURI) || !"param".equals(pLocalName)) { - throw new SAXParseException("Expected /param, got " - + new QName(pURI, pLocalName), - getDocumentLocator()); + if (isSuccess) { + if (!"".equals(pURI) || !"param".equals(pLocalName)) { + throw new SAXParseException("Expected /param, got " + + new QName(pURI, pLocalName), + getDocumentLocator()); + } + } else { + if ("".equals(pURI) && "value".equals(pLocalName)) { + endValueTag(); + } else { + throw new SAXParseException("Expected /value, got " + + new QName(pURI, pLocalName), + getDocumentLocator()); + } } break; case 3: - if ("".equals(pURI) && "value".equals(pLocalName)) { - endValueTag(); + if (isSuccess) { + if ("".equals(pURI) && "value".equals(pLocalName)) { + endValueTag(); + } else { + throw new SAXParseException("Expected /value, got " + + new QName(pURI, pLocalName), + getDocumentLocator()); + } } else { - throw new SAXParseException("Expected /value, got " - + new QName(pURI, pLocalName), - getDocumentLocator()); + super.endElement(pURI, pLocalName, pQName); } break; default: