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 "fahad.aizaz" <fa...@gmail.com> on 2008/03/12 10:56:22 UTC

embedding a string into structure XML RPC request

Hi guys! 

I recently used apache xml-rpc library to create a client that send XML data
to the server to get individual details. 

Now the server is created by a third party entity and they have provided us
the guidelines to create clients accordingly. 

The XML data that is needed to be sent to the server is as follows: 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
<?xmlversion="1.0"?> 
<methodCall><methodName>GetAccountDetailsRequest</methodName> 
<params> 

<value> 
<struct> 
<member><name>originNodeType</name><value><string>TEST</string></value></member> 
<member><name>originHostName</name><value><string>TEST</string></value></member> 
<member><name>originTransactionID</name><value><int>12345</int></value></member> 
<member><name>originTimeStamp</name><value><dateTime.iso8601>20080229T13:37:00+0000</dateTime.iso8601></value></member> 
<member><name>subscriberNumber</name><value><string>826953722</string></value></member> 
</struct> 
</value> 

</params> 
</methodCall> 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

Now i am unable create exact structure for this kind of XML data. The code
is below: 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
import java.net.*; 
import java.util.*; 
import org.apache.xmlrpc.XmlRpcException; 
import org.apache.xmlrpc.client.*; 

public class XMLClient { 
    
    public XMLClient() { 
    } 

    public static void main(String[] args) { 
        
        HashMap data = new HashMap(); 
        data.put("originNodeType", new String("TEST") ); 
        data.put("originHostName", new String("TEST") ); 
        data.put("originTransactionID", new Integer(12345)); 
        data.put("originTimeStamp", new Date()); 
        data.put("subscriberNumber", new String("826629828") ); 
        
        
        Vector params = new Vector(); 
        Object paramsR =  new Object(); 
        params.addElement(data); 
        
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); 
        try 
        { 
            config.setServerURL(new
URL("http://accountdetailsserver:8080/RPC2")); 
            XmlRpcClient client = new XmlRpcClient(); 
            client.setConfig(config); 
            client.execute("BalanceEnquiryTRequest", params); 
            paramsR = (Object)client.execute("GetAccountDetailsRequest",
params); 
  
        } catch (MalformedURLException e) 
        { 
            System.err.println(e); 
        } catch (XmlRpcException e) 
        { 
             System.err.println(e); 
        } 
        System.out.println( paramsR ); 
    } 
    
} 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
The output of this code is as below 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
<?xmlversion="1.0"?> 
<methodCall><methodName>GetAccountDetailsRequest</methodName> 
<params> 

<value> 
<struct> 
<member><name>originNodeType</name><value>TEST</value></member> 
<member><name>originHostName</name><value>TEST</string></member> 
<member><name>originTransactionID</name><value><int>12345</int></value></member> 
<member><name>originTimeStamp</name><value><dateTime.iso8601>20080229T13:37:00+0000</dateTime.iso8601></value></member> 
<member><name>subscriberNumber</name><value>826953722</value></member> 
</struct> 
</value> 

</params> 
</methodCall> 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
The tag <string></string> is missing from the output xml data above. 

<member><name>originNodeType</name><value><string>TEST</string></value></member> 
<member><name>originHostName</name><value><string>TEST</string></value></member> 
<member><name>subscriberNumber</name><value><string>826953722</string></value></member> 

and therefore the query responds with an error code from the server end.
Please help me solve this issue, i ve tried to search for the solution a lot
but all in vain. 

Regards, 

Fahad 
-- 
View this message in context: http://www.nabble.com/embedding-a-string-into-structure-XML-RPC-request-tp16001079p16001079.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org


Re: embedding a string into structure XML RPC request

Posted by tomek01 <to...@akcja.pl>.
HI Fahad,
could you show us your string TAG problem solution?

BR.
Tomek

fahad.aizaz wrote:
> 
> Hi Jochen,
> 
> I have solved that string TAG problem and now all my structures containing
> the the string values are represented by <string> TAG. I also have
> modified my client to use a different Date format.
> 
> The method you have posted on the below link under the custom data types:
> http://ws.apache.org/xmlrpc/advanced.html
> 
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> 
> 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);
>             }
>         }
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> 
> I am unable to understand what this method is used for. And the variable
> 'pFormat' what exactly is this.
> 
> I understand that 
> private DateFormat newFormat();
> created the custom format and 
> public TypeSerializer getSerializer();
> is the serializer for the newFormat()
> 
> Is there any documentation available that describes the fucntionality of
> these classes.
> 
> regards,
> 
> Fahad 
> 

-- 
View this message in context: http://www.nabble.com/embedding-a-string-into-structure-XML-RPC-request-tp16001079p17105606.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


Re: embedding a string into structure XML RPC request

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Thu, Mar 13, 2008 at 10:41 AM, fahad.aizaz <fa...@gmail.com> wrote:

>  public TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl

You don't need to create a custom parser. The serializer is sufficient
in your case. Btw, it would be nice if you could create an entry on
http://wiki.apache.org/ws/XML-RPC, which describes what you did,
because your problem is somewhat of an FAQ.

Thanks,

Jochen


-- 
Look, that's why there's rules, understand? So that you think before
you break 'em.

 -- (Terry Pratchett, Thief of Time)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org


Re: embedding a string into structure XML RPC request

Posted by "fahad.aizaz" <fa...@gmail.com>.
Hi Jochen,

I have solved that string TAG problem and now all my structures containing
the the string values are represented by <string> TAG. I also have modified
my client to use a different Date format.

The method you have posted on the below link under the custom data types:
http://ws.apache.org/xmlrpc/advanced.html

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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);
            }
        }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I am unable to understand what this method is used for. And the variable
'pFormat' what exactly is this.

I understand that 
private DateFormat newFormat();
created the custom format and 
public TypeSerializer getSerializer();
is the serializer for the newFormat()

Is there any documentation available that describes the fucntionality of
these classes.

regards,

Fahad 
-- 
View this message in context: http://www.nabble.com/embedding-a-string-into-structure-XML-RPC-request-tp16001079p16024127.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org


Re: embedding a string into structure XML RPC request

Posted by "fahad.aizaz" <fa...@gmail.com>.
Thanks Jochen, now i atleast know that its not the code that i wrote was
faulty;
I am now gonna start looking into "custom data type" its a big task for me
since i am not really gud at understanding by looking at the javadocs;



Jochen Wiedmann wrote:
> 
> On Wed, Mar 12, 2008 at 10:56 AM, fahad.aizaz <fa...@gmail.com>
> wrote:
> 
>> 
>> <member><name>originNodeType</name><value><string>TEST</string></value></member>
> 
> [...]
> 
>>  <member><name>originNodeType</name><value>TEST</value></member>
> 
> [...]
> 
>>  The tag <string></string> is missing from the output xml data above.
> 
> The XML-RPC spec specifies the absence of any type indicator as
> equivalent with the use of the "string" indicator. In other words, it
> is the servers fault that it doesn't accept your response.
> 
> However, to know that won't help you. Visit
> http://ws.apache.org/xmlrpc/advanced.html and find the section on
> "Custom data types". What you need is to have a custom type factory
> with a custom TypeSerializer for the String class. The default
> TypeSerializer for string is omitting the <string> tag, your's would
> add it.
> 
> 
> Jochen
> 
> 
> 
> -- 
> Look, that's why there's rules, understand? So that you think before
> you break 'em.
> 
>  -- (Terry Pratchett, Thief of Time)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/embedding-a-string-into-structure-XML-RPC-request-tp16001079p16004677.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org


Re: embedding a string into structure XML RPC request

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Wed, Mar 12, 2008 at 10:56 AM, fahad.aizaz <fa...@gmail.com> wrote:

>  <member><name>originNodeType</name><value><string>TEST</string></value></member>

[...]

>  <member><name>originNodeType</name><value>TEST</value></member>

[...]

>  The tag <string></string> is missing from the output xml data above.

The XML-RPC spec specifies the absence of any type indicator as
equivalent with the use of the "string" indicator. In other words, it
is the servers fault that it doesn't accept your response.

However, to know that won't help you. Visit
http://ws.apache.org/xmlrpc/advanced.html and find the section on
"Custom data types". What you need is to have a custom type factory
with a custom TypeSerializer for the String class. The default
TypeSerializer for string is omitting the <string> tag, your's would
add it.


Jochen



-- 
Look, that's why there's rules, understand? So that you think before
you break 'em.

 -- (Terry Pratchett, Thief of Time)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org