This is an old revision of the document!
Example demostrates use of Web services for ADUCID (aka WSA) and Web integration API for ADUCID. Example is based on Servlet 3.0 specification and tested on Tomcat 9.0 application server.
Image below shows Java web application project structure:
Let's describe project files:
OpenCheckServlet.java
- servlet running at /openCheck
and processing authentication resultOpenServlet.java
- servlet running at /open
and starting authentication operationProxyServlet.java
- servlet running at /proxy
and checking authentication statusrunning.gif
- picture representing running authenticationaducid-api.js
- see Client API for Web Integrationjquery.min.js
- required by aducid-api.js
web.xml
- web application configuration fileindex.jsp
- page starting authentication operationsecure.jsp
- page showing authentication resultbuild.bat
- batch file generating WS classes and building web applicationpom.xml
- maven configuration fileUse of Client API for Web Integration requires preparation of 3 servlets.
First one starts authentication process:
@WebServlet("/open") public class OpenServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { PrintWriter out = response.getWriter(); // initialize client URL url = new URL(getServletContext().getInitParameter("wsUrl")); QName qname = new QName("http://impl.ws.sdk.aducid.com/", "AducidApiServiceImplService"); Service service = Service.create(url, qname); AducidApiService client = service.getPort(AducidApiService.class); try { // generate unique browser tab identifier - necessary not to share session attributes String id = UUID.randomUUID().toString(); // start operation RequestOperationArguments arguments = new RequestOperationArguments(); arguments.setPeigReturnName(request.getRequestURL() + "Check?id=" + id); // required by iOS arguments.setGenerateQrCodePicture(true); arguments.setQrCodePictureWidth(300); arguments.setQrCodePictureHeight(300); RequestOperationResult result = client.startAuthenticationSession(arguments); result.setId(id); System.out.println("authId: " + result.getAuthId()); // save authId with id prefix to session request.getSession().setAttribute(id + "_authId", result.getAuthId()); // success - send JSON response to integration API out.print(client.toJson(result, null)); } catch (AducidClientException exception) { // error - send JSON response to integration API out.print(client.toErrorJson(exception.getFaultInfo().getResult(), "index.jsp")); } out.flush(); out.close(); } }
Some minor notes to source code:
wsUrl
is described in Web Application Configuration File chapterid
, we can start authentication in more than one browser tab, then authId
value in session would be overwritten by last tab authId
value and authentication in previous tabs would stop workingsetPeigReturnName
must be set to authentication result URL, here it is /openCheck
with id
query parameterThis servlet asks for authentication operation status:
@WebServlet("/proxy") public class ProxyServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { PrintWriter out = response.getWriter(); // initialize client URL url = new URL(getServletContext().getInitParameter("wsUrl")); QName qname = new QName("http://impl.ws.sdk.aducid.com/", "AducidApiServiceImplService"); Service service = Service.create(url, qname); AducidApiService client = service.getPort(AducidApiService.class); try { // read authId with id prefix from session String authId = (String) request.getSession().getAttribute(request.getParameter("id") + "_authId"); // ask for operation status String status = client.getStatus(authId); System.out.println("status: " + status); // success - send JSON response to integration API out.print(client.toJson(status, null)); } catch (AducidClientException exception) { // error - send JSON response to integration API out.print(client.toErrorJson(exception.getFaultInfo().getResult(), "index.jsp")); } out.flush(); out.close(); } }
Notes to source code:
wsUrl
is described in Web Application Configuration File chapterServlet evaluating authentication operation result:
@WebServlet("/openCheck") public class OpenCheckServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { PrintWriter out = response.getWriter(); // initialize client URL url = new URL(getServletContext().getInitParameter("wsUrl")); QName qname = new QName("http://impl.ws.sdk.aducid.com/", "AducidApiServiceImplService"); Service service = Service.create(url, qname); AducidApiService client = service.getPort(AducidApiService.class); try { // read authId with id prefix from session String authId = (String) request.getSession().getAttribute(request.getParameter("id") + "_authId"); // ask for operation result GetPSLAttributesResponse result = client.getResult(authId, request.getParameter("authKey")); System.out.println("status: " + result.getStatusAIM().name().toLowerCase()); System.out.println("authentication: " + result.getStatusAuth()); // save result to session request.getSession().setAttribute("result", result); // success - send JSON response to integration API out.print(client.toJson(null, "secure.jsp")); } catch (AducidClientException exception) { // error - send JSON response to integration API out.print(client.toErrorJson(exception.getFaultInfo().getResult(), "index.jsp")); } out.flush(); out.close(); } }
Some notes to source code:
wsUrl
is described in Web Application Configuration File chapterServlets described earlier are used in part of web integration. Self-explaining example is
This file is required by Servlet API. This file provides to application wsUrl
configuration value:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <display-name>Example WS</display-name> <context-param> <param-name>wsUrl</param-name> <param-value>${ws.url}/aducid-client-api-ws/wsa</param-value> </context-param> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Value ${ws.url}
is replaced at application building phase. See Building Application chapter.