1 16 17 18 package org.apache.xmlrpc; 19 20 import java.io.ByteArrayOutputStream ; 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 33 public class XmlRpcClientRequestProcessor 34 { 35 38 public XmlRpcClientRequestProcessor() 39 { 40 } 41 42 50 public void encodeRequest(XmlRpcClientRequest request, String encoding, 51 OutputStream out) 52 throws XmlRpcClientException, IOException 53 { 54 XmlWriter writer; 55 56 writer = new XmlWriter(out, encoding); 57 58 writer.startElement("methodCall"); 59 writer.startElement("methodName"); 60 writer.write(request.getMethodName()); 61 writer.endElement("methodName"); 62 writer.startElement("params"); 63 64 int l = request.getParameterCount(); 65 for (int i = 0; i < l; i++) 66 { 67 writer.startElement("param"); 68 try 69 { 70 writer.writeObject(request.getParameter(i)); 71 } 72 catch (XmlRpcException e) 73 { 74 throw new XmlRpcClientException("Failure writing request", e); 75 } 76 writer.endElement("param"); 77 } 78 writer.endElement("params"); 79 writer.endElement("methodCall"); 80 writer.flush(); 81 } 82 83 92 public byte [] encodeRequestBytes(XmlRpcClientRequest request, String encoding) 93 throws XmlRpcClientException 94 { 95 ByteArrayOutputStream buffer; 96 97 try 98 { 99 buffer = new ByteArrayOutputStream (); 100 encodeRequest(request, encoding, buffer); 101 return buffer.toByteArray(); 102 } 103 catch (IOException ioe) 104 { 105 throw new XmlRpcClientException("Error occured encoding XML-RPC request", ioe); 106 } 107 } 108 109 116 protected boolean canReUse() 117 { 118 return true; 119 } 120 } 121 | Popular Tags |