Solved

XML RPC question

Posted on 2007-11-15
26
416 Views
Last Modified: 2011-04-14
Hi All,

I have been asked to complete the following :

______________________________________________________________________________

Can you write a XML-RPC Handler to handle the following request..

You can supply your own system username and system password. The response
should contain these fields.

The remote-ip should be the IP address of the machine that we will run this
test on, so you will need to read this in from the Environment.

The token can be the system time in milliseconds.


# RPC Request
<?xml version="1.0"?>
<methodCall>
    <methodName>XMLPRCServer.RetrieveUserToken</methodName>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>username</name>
                        <value>
                            <string>system username </string>
                        </value>
                    </member>
                    <member>
                        <name>password</name>
                        <value>
                            <string>system-password </string>
                        </value>
                    </member>
                    <member>
                        <name>remote-ip</name>
                        <value>
                            <string>calling-system-ip-address </string>
                        </value>
                    </member>
                </struct>
            </value>
        </param>
        <param>
            <value>
                <struct>
                    <member>
                        <name>token</name>
                        <value>
                            <string>363795792015</string>
                        </value>
                    </member>
                    <member>
                        <name>username</name>
                        <value> system username </value>
                    </member>
                </struct>
            </value>
        </param>
    </params>
</methodCall>


So your handler class should build the response to look like this. You can
supply a hardcoded msisdn in the 'DefaultMSISDN' field, or use the one
provided below.


The response should be of the following format...

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>
                            Username
                        </name>
                        <value>
                            <string>
                            Supplied username
                            </string>
                        </value>
                    </member>
                    <member>
                        <name>
                            Password
                        </name>
                        <value>
                            <string>
                                supplied
password
                            </string>
                        </value>
                    </member>
                    <member>
                        <name>
                            DefaultMSISDN
                        </name>
                        <value>
                        <string>
                            447967828974
                        </string>
                        </value>
                    </member>
                </struct>
            </value>
        </param>
    </params>
</methodResponse>


You will also need to provide a test class to build the request and send it
to the Handler. This should be in the format of a JUnit test.


So to help, the API's to use / research are:

http://ws.apache.org/xmlrpc/

All you need to provide to us is the Handler class to process this request
and a JUnit test class to send the request to the Handler.

This test class should then validate the fields in the response.

___________________________________________________________________________

This is not homework, I am in full time employment but XML RPC is relatively new to me and I need a solution quickly. I should be ok to handle the JUnit part myself but any help/code on the XML RPC part is greatly appreciated.

Thanks
0
Comment
Question by:iAwin
  • 13
  • 12
26 Comments
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
i have just completed a project using the XML-RPC class.

Here is a nice example that i used to get my head around it:  http://www.wordtracker.com/docs/api/ch03s02.html

If your really in trouble i will help you code something but at least give it a try yourself...
0
 

Author Comment

by:iAwin
Comment Utility

Sorry but im pretty lost, I would like to get the above working with code and then understand what the workings are. Is the above a complex program to complete ?

Thanks again
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
no open netbean or eclispe and create a new project - in your main class past the example code from the site and run it.  

when you run it, a XML-RPC request is made which returns a XML reponse.  

you can download the JAR file from http://ws.apache.org/xmlrpc/ that handles all this for you.  

once you have it downloaded add the JAR to your classpath and you will see the response output if you do something like:

System.out.println(response.toString());

These XML files you have pasted above - where did you get these?
0
 

Author Comment

by:iAwin
Comment Utility

Manager gave them to me, just gave me the above spec and wants it done by tomorrow.

Why you ask?
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
>>You will also need to provide a test class to build the request and send it
to the Handler. This should be in the format of a JUnit test.

This sound so much like homework or university work....

However you will need to send the request to the server.  My project send requests to my homepage:  http://xmlrpc.seandelaney.co.uk that mapped to a PHP funciton and returned information from a database back to my Java application.

if your application has to be all Java based - e.g your server then look at these examples of how to code a XMLRPC Server:

http://ws.apache.org/xmlrpc/server.html

0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
>>Why you ask?

As you need more information to complete the task other than 2 example XML file outputs...
0
 

Author Comment

by:iAwin
Comment Utility

>>This sound so much like homework or university work....

Really this is not homework, can't see how I can convince you from sitting at my pc !

What extra information do I need ?

Cheers
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
you need to find out about the XMLRPC Server - what type it is?

Are you expected to create a Java based server or can you use a web based server like my XML-RPC server or the http://test.xmlrpc.wordtracker.com/ example....

if it is java based then create your XML file like you have above and implement the XMLRCP Server examples above to execute it and return the response.  im not too sure how you can going to get your response back into XML again as the XMLRPCClient handles everything for you... also see: http://ws.apache.org/xmlrpc/apidocs/org/apache/xmlrpc/server/XmlRpcServer.html

if it is web-based then just use the exmaples in http://www.wordtracker.com/docs/api/ch03s02.html.  but you will need an webserver that supports XML-RPC requests.  the server-side scripting langauge can be whatever you like (ASP or PHP) that maps to a function "XMLPRCServer.RetrieveUserToken" and returns the username, password, token and password....
0
 

Author Comment

by:iAwin
Comment Utility

I can use a web based server.

Do you how I can map a function to a tomcat web server?`
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
what language are you using PHP?  if so then yes i do
0
 

Author Comment

by:iAwin
Comment Utility

It will be jsp ??
0
 

Author Comment

by:iAwin
Comment Utility
I'll be using jsp
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
Ouch!  I cant propram in JSP, but this might help you:

http://javaemerald.com/JavaMaster/xmlrpc.html

actually you think that example provides you will everything you need by the looks of it...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
sorry getting my words mixed up ....

"actually you think that example provides you will everything you need by the looks of it..."

should read

"actually i think that example provides you with everything you need by the looks of it..."
0
 

Author Comment

by:iAwin
Comment Utility

Thats seems pretty decent alright, what changes to I need to make to pass in my own xml file?

Thanks again
0
 

Author Comment

by:iAwin
Comment Utility

Thats seems pretty decent alright, what changes to I need to make to pass in my own xml file?

Thanks again
0
 

Author Comment

by:iAwin
Comment Utility

I think I see whats going on, the xml I posted initially posted is handled under the coper by xml-rpc. I just need to pass in the parameters according to the xml file, does this seem logical ?
0
 

Author Comment

by:iAwin
Comment Utility

>>I think I see whats going on, the xml I posted initially posted is handled under the coper by xml-rpc. I just need to pass in the parameters according to the xml file, does this seem logical ?


Should read:

I think I see whats going on. The xml I posted initially is handled under the cover by xml-rpc. I just need to pass in the parameters according to the xml file, does this seem logical ?
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
First of all you need to know how the XMLRCP API for Java works.  You dont pass an actual XML file to the server - you pass the function name "XMLPRCServer.RetrieveUserToken" you want to use.  the XMLRCP API sends the request as XML and receives the response in XML.

look at this article to get a better understanding:  http://www.ibm.com/developerworks/xml/library/j-xmlrpc.html

what you need to do is create yor XMLRPC client.  your request should be pointing to your Tomcat server.  your JSP page should then accept this request.  older versions of the XMLRPC API accepted GET requests, but now they only accept POST requests...  have you ever used wordpress or movtable type??  or even trackbacks?  these are usign the XMLRPC protocol with POST requests... anyways your JSP page should return you the username, password and IP etc values back to your Java app.  after that do what you want with them.... display them out to the screen...

you dont see any of the XML as the XMLRPC Client classes handles all this for you.  alot of people make this mistake and think they need to send a XML file...

i think your manager either doesnt fully understand how the API works themselfs or they are looking to see if you can figure it out on your own and they have just provided you with example request & response XML outputs...

hope this helps

ellandrd
0
 

Author Comment

by:iAwin
Comment Utility

It really helps. Wont get a chance to start code till this evening, ill post tomorrow though on how I get on.

Hopefully I havent wrecked your head too much.

Thanks for this
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
>>I think I see whats going on,

yes now you getting the hang of it and starting to understand how it works...  to be honest it is really really simple after you play about with the examples in http://www.wordtracker.com/docs/api/ch03s02.html.

when i first learnt about the XMLRPC protocol i was totally lost.  then i stripped an example of the XMLRPC for PHP apart one day and went through it line by line.... then i attacked the java version which is easier to understand than ther PHP version...
0
 

Author Comment

by:iAwin
Comment Utility

It works!


I can't believe how easy it really is, thing is though I dont really understand whats going on. I realise I can get my original question working fairly easily now by just changing a a few of the method names and return variables using :  http://javaemerald.com/JavaMaster/xmlrpc.html

Would you mind giving me a quick breakdown of what happens in the jsp and class file in
 :  http://javaemerald.com/JavaMaster/xmlrpc.html

Thanks a million
0
 
LVL 16

Expert Comment

by:ellandrd
Comment Utility
>>I can't believe how easy it really is,

i told you...

>>Would you mind giving me a quick breakdown of what happens in the jsp and class file in

JSP isnt a strong area for me, but if you read the comments for each function in the class file, it tells you what each function does.  for the JSP page, the same principle is applied:

the server is listening for requests from the client.  when it accepts a request, it validates it to make sure it is a POST request.  it then parses the XML data in the request using:

byte[] reqdata = readBytes(request.getInputStream());

but before that it creates a new XMLRPC object using "setXmlRpc()" which calls the MyRPCClass() class which displays the 2 numbers you passed to in your request using "showNums()" function.

it then executes the request using "xmlrpcServ.execute()".  notice the readBytes function is doing alot of parsing and processing of the XML data from the request.   basically the execute function triggers the showNums() function.

the server then sends back the response again in XML format to the client.

i dont know if i was clear enough for you to understand - i understand what im trying to say so i hope you do to??

im glad you got it working.  
0
 
LVL 16

Accepted Solution

by:
ellandrd earned 500 total points
Comment Utility
you still happy with my help?  is this question still open?
0
 

Expert Comment

by:ClasssifEye
Comment Utility
Something that doesn't seem to be answered in this thread is, when writing the server side,  how to return a Java class as teh return type of the XMLRPC call. The Apache XMLRPC library does not support the return of a user defined data structure (or class) eg
public class member{
    public String Username;
    public String Password;
    public String DefaultMSISDN;
}
How is this supposed to be accomplished?
0
 

Author Comment

by:iAwin
Comment Utility

Very sorry about delay, thanks again ;-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now