[Opensource] Swing client
Turgay Zengin
turgay_zengin at hotmail.com
Tue Jul 9 05:37:39 PDT 2002
Thanks to everyone who helped me in this standalone client connecting to
Expresso idea. I want to finalize what I had done, in hope that it can be
helpful for others too.
I now have a servlet called "ExpressoClientInterfaceServlet" which handles
all communications between the standalone client and Expresso. You can find
the servlet code below.
The only remaining part is what you will return to the client - because the
"ControllerResponse" class cannot be serialized - I guess this is because it
contains lots of stuff that some of them are not serializable. So, one
should construct what to send back to the client as a response and return
it.
(Tsanko, you said before that there was no session to store user's info, but
there is. With the help of re-sending the jsessionid each time to the
server, the state information is preserved. I would like to hear your ideas
on how to convert this to RMI, you said it would be a better way to go -
please let me know offlist if you are interested)
Here is the servlet:
import com.jcorporate.expresso.core.controller.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.Properties;
public class ExpressoClientInterfaceServlet extends HttpServlet {
//call the controller and return the ControllerResponse
public ControllerResponse runState(HttpServletRequest request, String
controller, String state)
{
try{
Controller myController =
com.jcorporate.expresso.core.misc.ConfigManager.getControllerFactory().getController(controller);
//we should send a ControllerRequest, so construct one
ControllerRequest cReq =
ServletControllerRequest.parseParams(request,null,myController);
//newState is where the work is done - including security check
return myController.newState(state,cReq);
} catch (Exception e) { System.out.println(e.toString()); return null;
}
}
//client request reaches here...
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
String controller = request.getParameter("controller");
String state = request.getParameter("state");
try {
ControllerResponse cRes = runState(request,controller,state);
//here you should construct your own object from the
ControllerResponse and send it to the client
ObjectOutputStream out = new
ObjectOutputStream(response.getOutputStream());
YourResponse yourResponse = new YourResponse(cRes);
out.writeObject(yourResponse);
out.close();
} catch(Exception e){
System.out.println(e.toString());
}
}
}
And here is a possible client method to call the servlet:
private void btnGetDataActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
URL servlet = null;
try{
//remember that we had recorded the jSessionId before - when we logged
on...
servlet = new
URL("http://hostname:port/servlet/ExpressoClientInterfaceServlet;jsessionid="
+ jSessionId);
com.oreilly.servlet.HttpMessage msg = new
com.oreilly.servlet.HttpMessage(servlet);
Properties props = new Properties();
//put all your request parameters and their values here
props.put("stateParameter",parameterValue);
....
....
//put in your controller's name and the state
props.put("controller","tr.com.atas.helpdesk.controller.EquipmentController");
props.put("state","showEq");
InputStream in = msg.sendPostMessage(props);
ObjectInputStream oin = new ObjectInputStream(in);
Object o = oin.readObject();
oin.close();
YourResponse serverResponse = (YourResponse) o;
//now update your interface according to the values in the response
object....
} catch(Exception e) {
System.out.println("Error:\n"+e.toString());
}
}
I hope it's all clear, if not please let me know.
Regards,
Turgay Zengin.
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
More information about the Opensource
mailing list