A design problem

I have a client/server application in which the client sends a request (in the form of xml) and the expects a response to come back from the server for that particular request.

Let's say the client sends a"login" request to the server, then it expects a"login" response. This part is very clear for the client side. I have used XML binding for each request, in the sense if lets say the XML login request is:

<login>

<user_name>sri</user_name>

<password>some_password</password>

</login>

Then I have a classes for generating this request:

publicclass LoginRequest{

// All the setters/getters and marshalling/unmarshalling code here

// for "LoginRequest"

}

When I want to generate alogin request (from client side), I just say:

loginRequest.setUser("sri");

loginRequest.setPassword("some_password");

loginRequest.marshal(writer);

// And send this generated XML to the server

And when it gets a response, it expects a"login" response to come in from the server.

LoginResponse loginResponse =new LoginResponse();

// Try and Unmarshal the response

try{

loginResponse.unmarshal("the_response_from_server");

// We have a login response, let's do the other steps...

}catch (Exception e){

// Do something when the response is incorrect.

}

It's very obvious from the client side on what to give and what to expect. But my problem is with the server side. The server can get any type of request, may be"login", may be"logout" or something like"delete a resource" or"fetch a resource".

But how do I unmarshal the XML request on the server side when I don't know what request it is... For example I can't say loginRequest.unmarshal() because it may not be a login request. And it seems like this is a very common issue which every server of this kind may face.

How do I design the server to unmarshal with the right kind of object, that is a"login" request with a LoginRequest object? I hope I have explained my problem clearly, if I have not made myself clear on anything please let me know. I will explain my problem more on that.

Thanks,

Srikanth

[2921 byte] By [sri1025a] at [2007-10-3 11:08:02]
# 1

Don't have a different schema for every message type. Define 1 schema that is flexible enough to handle all the different messages. This schema will likely have a "type" or "code" element which will be your "login", "logout" etc bit. By unmarshalling the message and reading this element you will know how to process the request. You also only want 1 schema that is flexible enough to handle the various responses (so 1 request schema and 1 response schema in total)

btw: If you are not already using something like castor or apache digester I suggest you look into them.

-

YoGeea at 2007-7-15 13:30:59 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Thanks YooGee,I am looking at Castor now. I will let you know once I succeed.Thanks again,Srikanth
sri1025a at 2007-7-15 13:31:00 > top of Java-index,Other Topics,Patterns & OO Design...