Connecting the RISC Client to non-javascriptinterfaces

Similar documents
INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

LAB 1 PREPARED BY : DR. AJUNE WANIS ISMAIL FACULTY OF COMPUTING UNIVERSITI TEKNOLOGI MALAYSIA

Seminar reports and projects: Report options: option 1: general report

Advanced Internet Technology Lab # 4 Servlets

Servlets by Example. Joe Howse 7 June 2011

Session 8. Introduction to Servlets. Semester Project

JAVA SERVLET. Server-side Programming INTRODUCTION

AJP. CHAPTER 5: SERVLET -20 marks

Servlets and JSP (Java Server Pages)

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

Introduction to Servlets. After which you will doget it

This tutorial will teach you how to use Java Servlets to develop your web based applications in simple and easy steps.

CSC309: Introduction to Web Programming. Lecture 10

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans

Session 11. Calling Servlets from Ajax. Lecture Objectives. Understand servlet response formats

Implementing Asynchronous Web Application using Grizzly's Comet. Jeanfrancois Arcand Staff Engineer Java WebTier

CSC309: Introduction to Web Programming. Lecture 11

Lab session Google Application Engine - GAE. Navid Nikaein

Cloud Computing Platform as a Service

Session 9. Introduction to Servlets. Lecture Objectives

Web Programming. Lecture 11. University of Toronto

Database Applications Recitation 6. Project 3: CMUQFlix CMUQ s Movies Recommendation System

Université Antonine - Baabda

This page discusses topic all around using FOP in a servlet environment. 2. Example Servlets in the FOP distribution

Generating the Server Response: HTTP Status Codes

SSC - Web applications and development Introduction and Java Servlet (I)

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres

CS 112 Introduction to Programming

Web based Applications, Tomcat and Servlets - Lab 3 -

An implementation of Tree Panel component in EXT JS 4.0

Developing a Mobile Web-based Application with Oracle9i Lite Web-to-Go

Implementation Architecture

********************************************************************

Introduction. This course Software Architecture with Java will discuss the following topics:

Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013

why? Give an app access to a resource managed by someone else, without giving the app your password. A valet key for the web Allen I.

Servlet Basics. Agenda

Discovery data feed for Eid 2.0

ServletConfig Interface

Session 11. Ajax. Reading & Reference

Enterprise Java Unit 1- Chapter 4 Prof. Sujata Rizal Servlet API and Lifecycle

Servlets. How to use Apache FOP in a Servlet $Revision: $ Table of contents

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

Introduction to Java Servlets. SWE 432 Design and Implementation of Software for the Web

Three hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 21 st May Time:

Setting up a Maven Project

Flexible EAI-Lösungen mit Glassfish

Servlets. How to use Apache FOP in a Servlet $Revision: $ Table of contents

JSR 311: JAX-RS: The Java API for RESTful Web Services

CaptainCasa Enterprise Client. CaptainCasa Enterprise Client. CaptainCasa & Java Server Faces

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

AJAX Programming Chris Seddon

3. The pool should be added now. You can start Weblogic server and see if there s any error message.

Implementation Architecture

The Servlet Life Cycle

Make My Day Just Run A Web Scanner

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Bugs in software. Using Static Analysis to Find Bugs. David Hovemeyer

Lab 10. Google App Engine. Tomas Lampo. November 11, 2010

HTTP status codes. Setting status of an HTTPServletResponse

Generating the Server Response:

HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests

Servlets. An extension of a web server runs inside a servlet container


Applet. 1. init (): called once by the applet containers when an applet is loaded for execution.

The Road to Reactive with RxJava. Or: How to use non blocking I/O without wanting to kill yourself

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?

Servlet and JSP Review

Oracle 1Z Java EE 6 Web Component Developer(R) Certified Expert.

Servlet 5.1 JDBC 5.2 JDBC

Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios

CS506 Web Design & Development Final Term Solved MCQs with Reference

IDWedgeKB Serial Port and NodeJS

Get the cookies from the service request: Cookie[] HttpServletRequest.getCookies() Add a cookie to the service response:

ICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.

Java Card 3 Platform. Peter Allenbach Sun Microsystems, Inc.

Non-atomic check and use aka TOCTOU (Time of Check, Time of Use) or race conditions. Erik Poll Digital Security group Radboud University Nijmegen

EAI War Stories. ! Alexander Martin Praxisbeispiele zu EAI-Pattern und Lessons Learned

Unit-4: Servlet Sessions:

Algorithmic Verification of Procedural Programs in the Presence of Code Variability

Copyright 2014 Blue Net Corporation. All rights reserved

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

Handling the Client Request: HTTP Request Headers

Welcome to Ruby. Yehuda Katz. Engine Yard

Java Threads. Introduction to Java Threads

Advanced Internet Technology Lab # 6

Generating the Server Response: HTTP Response Headers

Stateless -Session Bean

JAVA SERVLET. Server-side Programming ADVANCED FEATURES

Module7: AJAX. Click, wait, and refresh user interaction. Synchronous request/response communication model. Page-driven: Workflow is based on pages

Using TCnative with Comet/Asynch. Jean-Frederic Clere, Red Hat November 9th

CaptainCasa Enterprise Client. Developers' Guide Beta Parts

CS 498RK FALL RESTFUL APIs

Introduction. This course Software Architecture with Java will discuss the following topics:

Handout 31 Web Design & Development

Module 4: SERVLET and JSP

JAVA Training Overview (For Demo Classes Call Us )

Achieving Continuous Delivery - Micro Services. - Vikram Gadang

Transcription:

Connecting the RISC Client to non-javascriptinterfaces Motivation In industry scenarios there is the necessity to connect the RISC client to client side subdevices or interfaces. Examples: serial / USB based scanner (which should not emulate a keyboard) Legic Reader for swipe cards direct access to client side files UDP messaging connection to an other program running on the client special label printers JavaScript does not provide functions to communicate to such interfaces directly. Architecture What we do not want to do: we do not want to enhance the browser by adding some plugins or extensions, that provide a possibility to connect to the native level from JavaScript. Such architecture comes with a high probability of failing in the real world of multiple browser with multiple version on multiple operating systems. So what's our approach? The solution is quite simple (and we are not the only ones doing this): the only possibility which allows the browser to talk to others is to use an http-connection. So we provide an invisible component in the RISC component library, that is able to 1

communicate to another program via http. The component's name is CLIENTHTTPSENDER. At the receiving side of the http interface there is any program that has the task to connect to the subdevices and to transfer messages between the subdevices and http: Interface Program http to interface CLIENTHTTPSENDER RISC Components http to server The direction of the http connection clearly is driven by the RISC client this is the one to request data from the client side interface program. Of course you may use long polling in order to let the http request wait until some event is available within the interface program. By default a browser client can only open up some communication to the server it was loaded from. With up to date browser installation supporting CORS (cross origin resource sharing) the browser may also talk to other web servers including the interface program, which typically directly runs on the client. 2

The component CLIENTHTTPSENDER The component CLIENTHTTPSENDER is a quite simple one. You pass the following information by using certain attributes: URL: the URL to connect to ( http://localhost:8080/ ) URLPOSTDATA, optional: The POST-string ( param1=value1&param2=value2& ) that you want to send with the URL HTTPHEADERPARAMS, optional: some http header parameters URLCALLBACK, optional: definition if the response of sending the URL is transferred back to the server (calling the method defined in ACTIONLISTENER) or not. The default is false, this means you have to explicitly switch it on by setting the value true. TRIGGER: trigger for sending the URL When activating the TRIGGER attribute of the component, then the component will open up a connection (via XMLHttpRequest). The result of the request is received and if attribute URLCALLBACK is set to true - is transferred to the server side using the ACTIONLISTENER of the component (event BaseActionEventClientHttpSend ). Please check the example in the demo workplace: Developing a client-side Interface Program The CLIENTHTTPSENDER is a generic component it just transfers a message from the RISC client to an other program and delegates the response back into the server side processing. There is no predefined semantics of how data transferred should look like. You now only have to develop an interface program that opens up a little web server on client side, so that you can send http-requests using the CLIENTHTTPSENDER component. Using Java the default way of using such program is to write a servlet and to embed it into some small servlet engine like Tomcat or Jetty, that you then install on client side. CaptainCasa has written such interface program as show case, you may obtain the whole code on request. There are some issues to be pointed out - that are listed in the following chapters. 3

Implementing CORS so that RISC Client can talk to multiple servers The interface program needs to explicitly allow the page that is loaded within the browser (i.e. the RISC dialog ) to use the response that is sent by the interface program. This is done by setting the http-repsonse header parameter Access-Control-Allow-Origin and passing the original domain of the page. This sounds complex, but is not at all! Take a look onto the following image: The situation described in the image is: In the browser a RISC-dialog is loaded from http://www.captaincasademo.com/ccdemos/xyz.risc?ccstyle=defaultrisc - so the original domain is http://www.captaincasademo.com As consequence the domain http://www.captaincasademo.com has to be added to the repsonse header of all response messages that are returned by the interface prorgram, so that the local interface programm allows the browser to also use it together with the page domain. A hard coded way to do this within you servlet processing would be: public class LocalGatewayServlet extends HttpServlet @Override protected void dopost(httpservletrequest req, HttpServletResponse resp) throws ServletException, IOException try resp.setheader("access-control-allow-origin", http://www.captaincasademo.com ); You may implement CORS within your servlet in a quite generic way: public class LocalGatewayServlet extends HttpServlet @Override protected void doget(httpservletrequest req, HttpServletResponse resp) throws ServletException, IOException dopost(req, resp); } 4

@Override protected void dopost(httpservletrequest req, HttpServletResponse resp) throws ServletException, IOException try String pagedomain = req.getheader("origin"); if (pagedomain!= null) checksendingpagedomain(pagedomain); resp.setheader("access-control-allow-origin",pagedomain); } In the code the domain of the page is dynamically detected by using http-request header parameter origin. The domain is set as valid domain for the response. Of course you need to pay attention: by using this code you open up your local interface program to anyone! So you should at least have some additional code to check the origin! Sending Information <=> Waiting for Events When communicating from the browsers CLIENTHTTPSENDER component to the client side interface program there are two different scenarios: You want to pass certain information to the client side. Example: you have a certain printer connected via serial interface. So the client side interface program is triggered by the CLIENTHTTPSENDER, within the http message the information what to print is passed. serial http request Interface Program http response In this case it's quite simple: you send the message to the client side interface program by triggering the CLIENTHTTPSENDER component. The result of the processing is sent back to the server side. You want to wait for a certain event that occurs on client side. Example: you have a barcode scanner connected via serial interface. In this case you have to establish some type of long polling communication to your client side interface program: 5

serial http request Interface Program http response Implementing some kind of long polling means: The CLIENTHTTPSENDER gets triggered and calls the client side interface program. The client interface program does not immediately send the response but it waits for a certain event. The waiting can be implemented by some thready synchronization (Object.wait()). The event of scanning is received in the client side interface program and releases the thread that is currently waiting (Object.notify()/ Object.notifyAll()). The thread that now is released sends the response. As consequence the CLIENTHTTPSENDER component talks to the server side. The server side immediately triggers the CLIENTHTTPSENDER component again, so that a new connection is built up to wait for new events. Dependent on the quality of receiving events you need to think carefully about some issues: It can happen that the http request to the client side interface program is aborted or timed out. In this case the server gets notified but receives some error information: the server side event of type BaseActionEventClientHttpSend has a corresponding method getsuccess() which returns false if there was communication problem on client side. It may happen that there is an event triggered by the scanner just at this point of time when the http response was given and the response is transferred to the server side. When establishing a new connection from the browser to the client side interface program then it's already to late to catch the event. In this case you have to first write the event information in some queue and pick up the queue correspondingly so that no event information gets lost. 6