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

