You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by lplpp <la...@gmail.com> on 2009/03/04 09:34:14 UTC

XMLRPC giving issues while sending the entire xml as string parameter

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.

Re: XMLRPC giving issues while sending the entire xml as string parameter

Posted by lplpp <la...@gmail.com>.
Thanks Stano.

I will try using wireshark
-- 
View this message in context: http://www.nabble.com/XMLRPC-giving-issues-while-sending-the-entire-xml-as-string-parameter-tp22325716p22326718.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


Re: XMLRPC giving issues while sending the entire xml as string parameter

Posted by Stanislav Miklik <st...@gmail.com>.
Hi,

general remark: if you really want to see what is transmitted between
client and server, you can always use eg. wireshark to capture the TCP
stream.

But more concrete: your two solutions are totally different:
1) plain java.
you just copy your xml to the socket. And your XML is not valid XML
RPC request (see http://www.xmlrpc.com/spec ) for an example.

2) using xml rpc.
your xml now goes only as String (I guess that get("xml") returns
String)  parameter of the XML RPC call auth, ie. there is some XML RPC
stuff and inside is your XML as string parameter of XML RPC call (see
spec once again)

I hope I help little bit and I was not confusing ;-)

Regards
Stano

On Wed, Mar 4, 2009 at 09:49, lplpp <la...@gmail.com> wrote:
>
> Also the xml that IO ma sending as a string is as below:
>
> ========================================
> <Request timestamp="20010403123245" type="auth">
> <merchantid>aisling</merchantid>
> <account>internet</account>
> <orderid>ord-123</orderid>
> <amount currency="EUR">2000</amount>
> <card>
> <number>490303400005718902</number>
> <expdate>0403</expdate>
> <chname>John Doe</chname>
> <type>MC</type>
> <issueno></issueno>
> <cvn>
> <number>453</number>
> <presind>1</presind>
> </cvn>
> </card>
> <autosettle flag="1"/>
> <md5hash>2bf9800c5170836d9cc76d67079f24bd</md5hash>
> </Request>
> --
> View this message in context: http://www.nabble.com/XMLRPC-giving-issues-while-sending-the-entire-xml-as-string-parameter-tp22325716p22325928.html
> Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.
>
>

Re: XMLRPC giving issues while sending the entire xml as string parameter

Posted by lplpp <la...@gmail.com>.
Also the xml that IO ma sending as a string is as below:

========================================
<Request timestamp="20010403123245" type="auth">
<merchantid>aisling</merchantid>
<account>internet</account>
<orderid>ord-123</orderid>
<amount currency="EUR">2000</amount>
<card>
<number>490303400005718902</number>
<expdate>0403</expdate>
<chname>John Doe</chname>
<type>MC</type>
<issueno></issueno>
<cvn>
<number>453</number>
<presind>1</presind>
</cvn>
</card>
<autosettle flag="1"/>
<md5hash>2bf9800c5170836d9cc76d67079f24bd</md5hash>
</Request>
-- 
View this message in context: http://www.nabble.com/XMLRPC-giving-issues-while-sending-the-entire-xml-as-string-parameter-tp22325716p22325928.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.