Data passing from client to server

We have a native java code at client system. Client will run java code, as a result an encrypted string will generate.
How can we pass that encrypetd data to vaadin application.

Is there any such mechanism to get data from cleint system to our server.

Thank you.

You could use a Servlet. If the “receiver app” on the server is a Vaadin app you could use VaadinServlet and then process your HTTP request (Maybe POST for just sending data and GET when you also want to receive Data). The Client then just opens a TCP Socket, builds an Http Request and sends it to servlet.
This topic doesn’t really has much to do with Vaadin though.

Hi Marius.
How can we send request to inner static servlet(Deafault class is Servlet) of MyVaadinUI class?
Thanks.

To send a Http Request from client:
http://stackoverflow.com/questions/1359689/how-to-send-http-request-in-java

The VaadinServlet processes all Requests coming to yoururl:yourport/YourApp. It has a doPost and a doGet method you can overwrite to create your own handling to HTTP POST and GET requests. In these methods you have access to the request coming in and can look through it. This way you could include some identifier to the request on the client so that the servlet when parsing through the request can decide whether it will just do super.doGet (or super.doPost) or some custom handling for the data from your “native java” client.

Application Servlet can be defined as a separate class that extends VaadinServlet and overrides servletInitialized under which a custom request handler can be included.

For ex.
public class ApplicationServlet extends VaadinServlet {

private final RequestHandler requestHandler = new AppRequestHandler();
private class AppRequestHandler implements RequestHandler {

    @Override
    public boolean handleRequest(VaadinSession session,
            VaadinRequest request, VaadinResponse response)
            throws IOException {
        .............
    }
}

   @Override
   protected void servletInitialized() throws ServletException {
      super.servletInitialized();
      getService().addSessionInitListener(new SessionInitListener() {
         @Override
         public void sessionInit(SessionInitEvent event) throws ServiceException {
             event.getSession().addRequestHandler(requestHandler);
        }
      });
   }

}

Thanks for responce.

Here is my client code:

String toservlet = “http://localhost:8080/servlet/MyServlet”;

URL servleturl = new URL(toservlet);
URLConnection servletconnection = servleturl.openConnection();
servletconnection.setDoInput(true);
servletconnection.setDoOutput(true);
servletconnection.setUseCaches(false);
servletconnection.setDefaultUseCaches(false);

DataOutputStream out=new DataOutputStream(servletconnection.getOutputStream());
out.writeBytes( “param=Testing text” );
out.flush();
out.close();
in.close();

and i try to catch parameters at servlet through request object like this:

private final RequestHandler requestHandler = new AppRequestHandler();
private class AppRequestHandler implements RequestHandler {

    @Override
    public boolean handleRequest(VaadinSession session,
            VaadinRequest request, VaadinResponse response)
            throws IOException {
                 System.out.println(request.getParameter("param").toString());
    }
}

When i run the above code snippets, am getting null instead of required parameter.
And is it possible to add recieved value from client to VaadinSession at servlet?

The problem with your code snippet is that on the client you add param=… as the content of the request but in the servlet you’re looking for the parameter.
If you want to work with parameters it would be
String toservlet = “http://localhost:8080/servlet/MyServlet?param=…”;

You could add the value as an attribute using:
session.setAttribute(name, value);
as you have access to the session inside handleRequest.