== WAR Contacts == {{{#!highlight sh wget https://github.com/twbs/bootstrap/releases/download/v4.5.0/bootstrap-4.5.0-dist.zip wget https://code.jquery.com/jquery-3.5.1.min.js }}} External files: * src/main/webapp/js/bootstrap.min.js * src/main/webapp/js/jquery-3.5.1.min.js * src/main/webapp/css/bootstrap.min.css === deploy_to_target.sh === {{{#!highlight sh #!/bin/sh rm ../warcontacts.tgz tar cvzf ../warcontacts.tgz ../warcontacts cp ../warcontacts.tgz ../target/ docker exec -it jboss5_container /bin/sh -c 'cd /app;rm -rf warcontacts; tar xvzf warcontacts.tgz' docker exec -it jboss5_container /bin/sh -c 'cd /app/warcontacts; rm /app/jboss-5.1.0.GA/server/default/deploy/warcontacts-0.0.1.war; mvn clean install;' docker exec -it jboss5_container /bin/sh -c 'cp /app/warcontacts/target/warcontacts-0.0.1.war /app/jboss-5.1.0.GA/server/default/deploy' }}} === pom.xml === {{{#!highlight xml 4.0.0 org.allowed.bitarus warcontacts 0.0.1 war javaee javaee-api 5 provided org.allowed.bitarus ejbcontacts 0.0.1 provided maven-compiler-plugin 1.5 1.5 }}} === src/main/java/org/allowed/bitarus/Handler.java === {{{#!highlight java package org.allowed.bitarus; import java.util.logging.Logger; import java.util.logging.Level; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.naming.InitialContext; import java.io.IOException; import java.util.List; import javax.naming.NamingEnumeration; import javax.naming.NameClassPair; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Map; public class Handler { private static final String CONTACTS_WS_LOCAL = "ContactsWS/local"; private ServletRequest request; private ServletResponse response; private JspWriter out; public Handler(ServletRequest request, ServletResponse response, JspWriter out) { this.request = request; this.response = response; this.out = out; } public Handler(PageContext pageContext) { this.request = pageContext.getRequest(); this.response = pageContext.getResponse(); this.out = (JspWriter) pageContext.getAttribute(PageContext.OUT); HttpServletRequest hsr = (HttpServletRequest) this.request; System.out.println(String.format("Current method %s", hsr.getMethod())); System.out.println(String.format("Path %s", hsr.getServletPath())); if ("POST".equals(hsr.getMethod())) { Map params = hsr.getParameterMap(); for (String key : params.keySet()) { System.out.println(String.format("%s:%s", key, hsr.getParameter(key))); } handleAddPost(hsr); handleDeletePost(hsr); handleUpdatePost(hsr); } } private void handleUpdatePost(HttpServletRequest hsr) { if ("/update.jsp".equals(hsr.getServletPath())) { try { InitialContext context = new InitialContext(); ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL); long id = Integer.parseInt(hsr.getParameter("cid")); String firstName = hsr.getParameter("firstname"); String lastName = hsr.getParameter("lastname"); String address = hsr.getParameter("address"); String phoneNumber = hsr.getParameter("phonenumber"); contacts.edit(id, firstName, lastName, address, phoneNumber); redirectToIndex(hsr); } catch (Exception ex) { } } } private void handleDeletePost(HttpServletRequest hsr) { if ("/delete.jsp".equals(hsr.getServletPath())) { try { InitialContext context = new InitialContext(); ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL); contacts.remove(Integer.parseInt(hsr.getParameter("id"))); redirectToIndex(hsr); } catch (Exception ex) { } } } private void handleAddPost(HttpServletRequest hsr) { if ("/add.jsp".equals(hsr.getServletPath())) { try { InitialContext context = new InitialContext(); ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL); contacts.add(hsr.getParameter("firstname"), hsr.getParameter("lastname"), hsr.getParameter("address"), hsr.getParameter("phonenumber")); redirectToIndex(hsr); } catch (Exception ex) { } } } private void redirectToIndex(HttpServletRequest hsr) throws IOException { ((HttpServletResponse) this.response).sendRedirect(hsr.getContextPath() + "/index.jsp"); } public void writeHandler() { try { this.out.println(String.format("

Handler up %s

", this.request.getParameter("user"))); } catch (Exception ex) { } } public void writeIP() { try { this.out.print("!!! Your IP address is " + this.request.getRemoteAddr()); } catch (Exception ex) { } } public List getAllContacts() { List ret = null; try { InitialContext context = new InitialContext(); ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL); ret = contacts.getAll(); } catch (Exception ex) { } return ret; } public ContactEntity getContact(long id) { ContactEntity ret = null; try { InitialContext context = new InitialContext(); ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL); ret = contacts.get(id); } catch (Exception ex) { } return ret; } } }}} === src/main/webapp/add.jsp === {{{#!highlight xml <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %> <% Handler h = new Handler(pageContext); %>








}}} === src/main/webapp/css/warcontacts.css === {{{#!highlight css .button{margin-top:2px; margin-bottom:2px;} .topspace { padding-top: 10px; } }}} === src/main/webapp/delete.jsp === {{{ <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %> <% Handler h = new Handler(pageContext); %> <% ContactEntity ci = h.getContact( Integer.parseInt( request.getParameter("id") ) ); %>
<% if(ci!=null) { %>

Id: <%= ci.getId() %>

First name: <%= ci.getFirstName() %>

Last name: <%= ci.getLastName() %>

Creation date: <%= ci.getCreationDate() %>

Address: <%= ci.getAddress() %>

Phone: <%= ci.getPhoneNumber() %>

<% } %>
}}} === src/main/webapp/head.jsp === {{{#!highlight xml }}} === src/main/webapp/index.jsp === {{{#!highlight xml <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %> <% Handler h = new Handler(pageContext); %>
<% List contacts = h.getAllContacts(); %> Add <% for(int i=0; i <% ContactEntity contact = ((ContactEntity)contacts.get(i)); %> <%}%>
FirstName LastName Actions
<%= contact.getFirstName() %> <%= contact.getLastName() %> View Update Delete
}}} === src/main/webapp/nav.jsp === {{{#!highlight xml }}} === src/main/webapp/update.jsp === {{{ <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %> <% Handler h = new Handler(pageContext); %>
<% if( request.getParameter("id") != null ) { %> <% ContactEntity ci = h.getContact( Integer.parseInt( request.getParameter("id") ) ); %>








<% } %>
}}} === src/main/webapp/view.jsp === {{{#!highlight xml <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %> <% Handler h = new Handler(pageContext); %>
<% ContactEntity ci = h.getContact( Integer.parseInt( request.getParameter("id") ) ); %>

Id: <%= ci.getId() %>

First name: <%= ci.getFirstName() %>

Last name: <%= ci.getLastName() %>

Creation date: <%= ci.getCreationDate() %>

Address: <%= ci.getAddress() %>

Phone: <%= ci.getPhoneNumber() %>

}}} === src/main/webapp/WEB-INF/web.xml === {{{#!highlight xml }}} == WAR web app that invokes ejb using JNDI name == * mvn clean install * cp target/warjee5-0.0.1.war /app/jboss-5.1.0.GA/server/default/deploy/warjee5-0.0.1.war === pom.xml === {{{#!highlight xml 4.0.0 org.allowed.bitarus warjee5 0.0.1 war javaee javaee-api 5 provided org.allowed.bitarus ejbjee5 0.0.1 provided src maven-compiler-plugin 1.5 1.5 }}} === src/main/java/org/allowed/bitarus/Handler.java === {{{#!highlight java package org.allowed.bitarus; import java.util.logging.Logger; import java.util.logging.Level; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.naming.InitialContext; import java.util.List; import javax.naming.NamingEnumeration; import javax.naming.NameClassPair; public class Handler{ private ServletRequest request; private ServletResponse response; private JspWriter out; public Handler(ServletRequest request, ServletResponse response,JspWriter out){ this.request = request; this.response = response; this.out = out; } public Handler(PageContext pageContext){ this.request = pageContext.getRequest(); this.response = pageContext.getResponse(); this.out = (JspWriter) pageContext.getAttribute(pageContext.OUT) ; } public void writeHandler(){ try{ this.out.println(String.format("

Handler up %s

" , this.request.getParameter("user") )); } catch(Exception ex){ } } public void writeIP(){ try{ this.out.print("!!! Your IP address is " + this.request.getRemoteAddr()); } catch(Exception ex){ } } public void writeAddResults(){ try{ InitialContext context = new InitialContext(); NamingEnumeration namingList = context.list(""); while (namingList.hasMore()) { out.println(namingList.next().getName() + "
" ); } AddLocal addLocal = (AddLocal) context.lookup("AddWS/local"); List list = addLocal.getAll(); for(int idx=0; idx" ); } } catch(Exception ex){ } } } }}} === src/main/java/org/allowed/bitarus/TestBean.java === {{{#!highlight java package org.allowed.bitarus; import java.util.logging.Logger; import java.util.logging.Level; public class TestBean{ private String name; private Logger logger; public TestBean(){ this.logger = Logger.getLogger(this.getClass().getName() ); this.logger.log(Level.INFO,"Created test bean"); this.name="Ioooo"; } public String getName(){ this.logger.info("getName called"); return this.name; } public void setName(String name){ this.name=name; } } }}} === src/main/webapp/WEB-INF/web.xml === {{{#!highlight xml index /index.jsp index /index** otherindex /otherindex.jsp otherindex /otherindex** }}} === src/main/webapp/index.jsp === {{{#!highlight html <%@page import="org.allowed.bitarus.Handler" %> <% //Handler h = new Handler(request,response,out); %> <% Handler h = new Handler(pageContext); %>

Hello

World

<% h.writeHandler(); %>

<% out.print("Your IP address is " + request.getRemoteAddr()); %>

<% h.writeIP(); %>

<% h.writeAddResults(); %>

}}} === src/main/webapp/otherindex.jsp === {{{#!highlight html <%@page import="org.allowed.bitarus.Handler" %> <% //Handler h = new Handler(request,response,out); %> <% Handler h = new Handler(pageContext); %>

Other Hello

World

<% h.writeHandler(); %>

<% out.print("Your IP address is " + request.getRemoteAddr()); %>

<% h.writeIP(); %>

}}} == Example WAR for JBoss5 in docker container == {{attachment:warFile.png}} {{{#!highlight sh mvn clean install cp /app/warjee5/target/warjee5-0.0.1.war /app/jboss-5.1.0.GA/server/default/deploy # http://127.0.0.1:8080//warjee5-0.0.1/otherindex.jsp }}} === src/main/java/org/allowed/bitarus/TestBean.java === {{{#!highlight java package org.allowed.bitarus; import java.util.logging.Logger; import java.util.logging.Level; public class TestBean{ private String name; private Logger logger; public TestBean(){ this.logger = Logger.getLogger(this.getClass().getName() ); this.logger.log(Level.INFO,"Created test bean"); this.name="Ioooo"; } public String getName(){ this.logger.info("getName called"); return this.name; } public void setName(String name){ this.name=name; } } }}} === src/main/java/org/allowed/bitarus/Handler.java === {{{#!highlight java package org.allowed.bitarus; import java.util.logging.Logger; import java.util.logging.Level; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; public class Handler{ private ServletRequest request; private ServletResponse response; private JspWriter out; public Handler(ServletRequest request, ServletResponse response,JspWriter out){ this.request = request; this.response = response; this.out = out; } public Handler(PageContext pageContext){ this.request = pageContext.getRequest(); this.response = pageContext.getResponse(); this.out = (JspWriter) pageContext.getAttribute(pageContext.OUT) ; } public void writeHandler(){ try{ this.out.println(String.format("

Handler up %s

" , this.request.getParameter("user") )); } catch(Exception ex){ } } public void writeIP(){ try{ this.out.print("!!! Your IP address is " + this.request.getRemoteAddr()); } catch(Exception ex){ } } } }}} === src/main/webapp/otherindex.jsp === {{{#!highlight html <%@page import="org.allowed.bitarus.Handler" %> <% //Handler h = new Handler(request,response,out); %> <% Handler h = new Handler(pageContext); %>

Other Hello

World

<% h.writeHandler(); %>

<% out.print("Your IP address is " + request.getRemoteAddr()); %>

<% h.writeIP(); %>

}}} === src/main/webapp/index.jsp === {{{#!highlight html <%@page import="org.allowed.bitarus.Handler" %> <% //Handler h = new Handler(request,response,out); %> <% Handler h = new Handler(pageContext); %>

Hello

World

<% h.writeHandler(); %>

<% out.print("Your IP address is " + request.getRemoteAddr()); %>

<% h.writeIP(); %>

}}} === src/main/webapp/WEB-INF/web.xml === {{{#!highlight xml index /index.jsp index /index** otherindex /otherindex.jsp otherindex /otherindex** }}} === pom.xml === {{{#!highlight xml 4.0.0 org.allowed.bitarus warjee5 0.0.1 war javaee javaee-api 5 provided src maven-compiler-plugin 1.5 1.5 }}} == links servlets == === pom.xml === {{{#!highlight xml 4.0.0 org.allowed.bitarus links-servlets 0.0.1 war javaee javaee-api 5 provided maven-compiler-plugin 1.5 1.5 }}} === src/main/java/org/allowed/bitarus/AppleAppSiteAssociationServlet.java === {{{#!highlight java package org.allowed.bitarus; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; public class AppleAppSiteAssociationServlet extends HttpServlet { private static final long serialVersionUID = 1L; /* * http://127.0.0.1:8080/links-servlets-0.0.1/apple-app-site-association */ public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { res.setContentType("application/json"); PrintWriter out = res.getWriter(); String text = " {\n" + " \"applinks\": {\n" + " \"apps\": [],\n" + " \"details\": [{\n" + " \"appID\": \"D3KQX62K1A.com.example.photoapp\",\n" + " \"paths\": [\"/albums\"]\n" + " },\n" + " {\n" + " \"appID\": \"D3KQX62K1A.com.example.videoapp\",\n" + " \"paths\": [\"/videos\"]\n" + " }]\n" + " }\n" + "}"; out.println(String.format("%s", text)); } } }}} === src/main/java/org/allowed/bitarus/AssetLinksServlet.java === {{{#!highlight java package org.allowed.bitarus; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; public class AssetLinksServlet extends HttpServlet { private static final long serialVersionUID = 1L; /* * http://127.0.0.1:8080/links-servlets-0.0.1/.well-known/assetlinks.json */ public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { res.setContentType("application/json"); PrintWriter out = res.getWriter(); String text = "[{ \"relation\": [\"delegate_permission/common.handle_all_urls\"], \"target\": { \"namespace\": \"android_app\", \"package_name\": \"com.example\", \"sha256_cert_fingerprints\": [\"14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5\"] } }]"; out.println(String.format("%s", text)); } } }}} === src/main/webapp/WEB-INF/web.xml === {{{#!highlight xml AssetLinksServlet org.allowed.bitarus.AssetLinksServlet AssetLinksServlet /.well-known/assetlinks.json AppleAppSiteAssociationServlet org.allowed.bitarus.AppleAppSiteAssociationServlet AppleAppSiteAssociationServlet /apple-app-site-association }}}