Hi there,
I am trying to send xml request to a system that accepts it in a particular
format. If I do it using normal urlconnection and bufferdinputstream then it
works correctly. However If I use XMLRPC, the other does not interpret the
request correctly. How do I simulate the same thing in xmlrpc that is
passing my xml as a string parameter so that the other system reads it
correctly.
The main code used by me under both scenarios is pasted below. I am passing
my xml request as a string "xml". This is generated by the same class in
both cases.
Using normal Java classes:
====================
public String send() {
String response = "";
try {
remoteURL = new URL(host + "/" + url);
connection = remoteURL.openConnection();
System.out.println(connection.toString());
} catch (MalformedURLException mue) {
return Utils.Error(400, "Error in hostname: "+host+"/"+url+":
"+mue.getMessage());
} catch (InterruptedIOException iioe) {
// thread died while talking - do a retry
return Utils.Error(400, "Died while connecting to payandshop: "
+ iioe.getMessage());
} catch (IOException ioe) {
// other exception - probably config error - stop
return Utils.Error(400, "Cannot connect to "+host+"/"+url+":
"+ioe.getMessage());
}
connection.setRequestProperty("USER_AGENT", "payandshop.com Connect
V1.0 [Java 1.3.0]");
// if you need to authenticate with the proxy, uncomment the
next
// two lines and insert the correct usernae and password.
//String authString = "Basic " +
Base64Encode("username:password");
//connection.setRequestProperty("Proxy-Authorization",
authString);
try {
connection.setDoOutput(true);
printwriter = new PrintWriter(connection.getOutputStream());
printwriter.println(get("xml"));
printwriter.close();
} catch (IOException ioe) {
// can anything here be recoverable? - stop
return Utils.Error(400, "Error writing xml to payandshop:
"+ioe.getMessage());
}
try {
bufferedreader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
while ((inputLine = bufferedreader.readLine()) != null) {
response += inputLine;
}
bufferedreader.close();
} catch (IOException ioe) {
// ????
return Utils.Error(400, "Error reading xml from payandshop: "+
ioe.getMessage());
}
return response;
}
XMLRPC client method:
=================
public String send() throws Exception {
String response = "";
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
config.setServerURL(new
URL("https://epage.payandshop.com/epage.cgi"));
}
catch (MalformedURLException mue) {
return Utils.Error(400, "Error in hostname: "+mue.getMessage());
}
config.setEnabledForExtensions(true);
config.setConnectionTimeout(60 * 1000);
config.setReplyTimeout(60 * 1000);
config.setUserAgent("payandshop.com Connect V1.0 [Java 1.3.0]");
XmlRpcClient client = new XmlRpcClient();
// use Commons HttpClient as transport
client.setTransportFactory(
new XmlRpcCommonsTransportFactory(client));
// set configuration
client.setConfig(config);
System.out.println("Client configured");
Object[] params = new Object[]{ get("xml") };
System.out.println("calling server");
response = (String) client.execute("auth",params);
System.out.println(response.toString());
System.out.println("Done");
return response;
}
Please help me :(
Thanks in advance.
Latika
--
View this message in context:
http://www.nabble.com/XMLRPC-giving-issues-while-sending-the-entire-xml-as-string-parameter-tp22325716p22325716.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.