WAR Contacts
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
1 #!/bin/sh
2 rm ../warcontacts.tgz
3 tar cvzf ../warcontacts.tgz ../warcontacts
4 cp ../warcontacts.tgz ../target/
5 docker exec -it jboss5_container /bin/sh -c 'cd /app;rm -rf warcontacts; tar xvzf warcontacts.tgz'
6 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;'
7 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
1 <project xmlns="http://maven.apache.org/POM/4.0.0"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>org.allowed.bitarus</groupId>
6 <artifactId>warcontacts</artifactId>
7 <version>0.0.1</version>
8 <packaging>war</packaging>
9 <dependencies>
10 <dependency>
11 <groupId>javaee</groupId>
12 <artifactId>javaee-api</artifactId>
13 <version>5</version>
14 <scope>provided</scope>
15 </dependency>
16 <dependency>
17 <groupId>org.allowed.bitarus</groupId>
18 <artifactId>ejbcontacts</artifactId>
19 <version>0.0.1</version>
20 <scope>provided</scope>
21 </dependency>
22 </dependencies>
23 <build>
24 <plugins>
25 <plugin>
26 <artifactId>maven-compiler-plugin</artifactId>
27 <configuration>
28 <source>1.5</source>
29 <target>1.5</target>
30 </configuration>
31 </plugin>
32 </plugins>
33 </build>
34 </project>
src/main/java/org/allowed/bitarus/Handler.java
1 package org.allowed.bitarus;
2
3 import java.util.logging.Logger;
4 import java.util.logging.Level;
5 import javax.servlet.ServletRequest;
6 import javax.servlet.ServletResponse;
7 import javax.servlet.jsp.JspWriter;
8 import javax.servlet.jsp.PageContext;
9 import javax.naming.InitialContext;
10 import java.io.IOException;
11 import java.util.List;
12 import javax.naming.NamingEnumeration;
13 import javax.naming.NameClassPair;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16 import java.util.Map;
17
18 public class Handler {
19 private static final String CONTACTS_WS_LOCAL = "ContactsWS/local";
20 private ServletRequest request;
21 private ServletResponse response;
22 private JspWriter out;
23
24 public Handler(ServletRequest request, ServletResponse response, JspWriter out) {
25 this.request = request;
26 this.response = response;
27 this.out = out;
28 }
29
30 public Handler(PageContext pageContext) {
31 this.request = pageContext.getRequest();
32 this.response = pageContext.getResponse();
33 this.out = (JspWriter) pageContext.getAttribute(PageContext.OUT);
34
35 HttpServletRequest hsr = (HttpServletRequest) this.request;
36 System.out.println(String.format("Current method %s", hsr.getMethod()));
37 System.out.println(String.format("Path %s", hsr.getServletPath()));
38
39 if ("POST".equals(hsr.getMethod())) {
40 Map<String, String> params = hsr.getParameterMap();
41 for (String key : params.keySet()) {
42 System.out.println(String.format("%s:%s", key, hsr.getParameter(key)));
43 }
44
45 handleAddPost(hsr);
46 handleDeletePost(hsr);
47 handleUpdatePost(hsr);
48 }
49 }
50
51 private void handleUpdatePost(HttpServletRequest hsr) {
52 if ("/update.jsp".equals(hsr.getServletPath())) {
53 try {
54 InitialContext context = new InitialContext();
55 ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL);
56 long id = Integer.parseInt(hsr.getParameter("cid"));
57 String firstName = hsr.getParameter("firstname");
58 String lastName = hsr.getParameter("lastname");
59 String address = hsr.getParameter("address");
60 String phoneNumber = hsr.getParameter("phonenumber");
61 contacts.edit(id, firstName, lastName, address, phoneNumber);
62 redirectToIndex(hsr);
63 } catch (Exception ex) {
64 }
65 }
66 }
67
68 private void handleDeletePost(HttpServletRequest hsr) {
69 if ("/delete.jsp".equals(hsr.getServletPath())) {
70 try {
71 InitialContext context = new InitialContext();
72 ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL);
73 contacts.remove(Integer.parseInt(hsr.getParameter("id")));
74 redirectToIndex(hsr);
75 } catch (Exception ex) {
76 }
77 }
78 }
79
80 private void handleAddPost(HttpServletRequest hsr) {
81 if ("/add.jsp".equals(hsr.getServletPath())) {
82 try {
83 InitialContext context = new InitialContext();
84 ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL);
85 contacts.add(hsr.getParameter("firstname"), hsr.getParameter("lastname"), hsr.getParameter("address"),
86 hsr.getParameter("phonenumber"));
87 redirectToIndex(hsr);
88 } catch (Exception ex) {
89 }
90 }
91 }
92
93 private void redirectToIndex(HttpServletRequest hsr) throws IOException {
94 ((HttpServletResponse) this.response).sendRedirect(hsr.getContextPath() + "/index.jsp");
95 }
96
97 public void writeHandler() {
98 try {
99 this.out.println(String.format("<p>Handler up %s</p>", this.request.getParameter("user")));
100 } catch (Exception ex) {
101 }
102 }
103
104 public void writeIP() {
105 try {
106 this.out.print("!!! Your IP address is " + this.request.getRemoteAddr());
107 } catch (Exception ex) {
108 }
109 }
110
111 public List<ContactEntity> getAllContacts() {
112 List<ContactEntity> ret = null;
113 try {
114 InitialContext context = new InitialContext();
115
116 ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL);
117 ret = contacts.getAll();
118 } catch (Exception ex) {
119 }
120 return ret;
121 }
122
123 public ContactEntity getContact(long id) {
124
125 ContactEntity ret = null;
126 try {
127 InitialContext context = new InitialContext();
128
129 ContactsLocal contacts = (ContactsLocal) context.lookup(CONTACTS_WS_LOCAL);
130 ret = contacts.get(id);
131 } catch (Exception ex) {
132 }
133
134 return ret;
135 }
136 }
src/main/webapp/add.jsp
1 <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %>
2 <% Handler h = new Handler(pageContext); %>
3 <html>
4 <head>
5 <jsp:include page="head.jsp" />
6 </head>
7 <body>
8 <jsp:include page="nav.jsp" />
9 <div class="container topspace">
10 <div class="row">
11 <div class="col-sm-2"></div>
12 <div class="col-sm-8">
13 <form action="add.jsp" method="post" >
14 <label for="firstname">First name:</label><br/>
15 <input type="text" id="firstname" name="firstname" class="form-control"><br/>
16 <label for="lastname">Last name:</label><br/>
17 <input type="text" id="lastname" name="lastname" class="form-control"><br/>
18 <label for="address">Address::</label><br/>
19 <input type="text" id="Address:" name="address" class="form-control"><br/>
20 <label for="phonenumber">Phone number:</label><br/>
21 <input type="text" id="phonenumber" name="phonenumber" class="form-control"><br/>
22 <input type="submit" value="Add" class="form-control btn btn-primary button"/>
23 </form>
24 </div>
25 <div class="col-sm-2"></div>
26 </div>
27 </div>
28 </body>
29 </html>
src/main/webapp/css/warcontacts.css
src/main/webapp/delete.jsp
<%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %> <% Handler h = new Handler(pageContext); %> <html> <head> <jsp:include page="head.jsp" /> </head> <body> <% ContactEntity ci = h.getContact( Integer.parseInt( request.getParameter("id") ) ); %> <jsp:include page="nav.jsp" /> <div class="container topspace"> <div class="row"> <div class="col-sm-2"></div> <div class="col-sm-8"> <% if(ci!=null) { %> <p><strong>Id:</strong> <%= ci.getId() %></p> <p><strong>First name:</strong> <%= ci.getFirstName() %></p> <p><strong>Last name:</strong> <%= ci.getLastName() %></p> <p><strong>Creation date:</strong> <%= ci.getCreationDate() %></p> <p><strong>Address:</strong> <%= ci.getAddress() %></p> <p><strong>Phone:</strong> <%= ci.getPhoneNumber() %></p> <form action="delete.jsp" method="post"> <input type="hidden" id="id" name="id" value="<%=ci.getId()%>" /> <input type="submit" class="form-control btn btn-primary button" value="Delete"> </form> <% } %> </div> <div class="col-sm-2"></div> </div> </div> </body> </html>
src/main/webapp/head.jsp
src/main/webapp/index.jsp
1 <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %>
2 <% Handler h = new Handler(pageContext); %>
3 <html>
4 <head>
5 <jsp:include page="head.jsp" />
6 </head>
7 <body>
8 <jsp:include page="nav.jsp" />
9 <div class="container topspace">
10 <div class="row">
11 <div class="col-sm-2"></div>
12 <div class="col-sm-8">
13 <% List<ContactEntity> contacts = h.getAllContacts(); %>
14 <a href="add.jsp" class="btn btn-primary button">Add</a>
15 <table class="table table-stripped" >
16 <tr>
17 <th>FirstName</th>
18 <th>LastName</th>
19 <th>Actions</th>
20 </tr>
21 <% for(int i=0; i<contacts.size() ;i++){ %>
22 <tr>
23 <% ContactEntity contact = ((ContactEntity)contacts.get(i)); %>
24 <td><%= contact.getFirstName() %></td>
25 <td><%= contact.getLastName() %></td>
26 <td>
27 <a href="view.jsp?id=<%=contact.getId()%>" class="btn btn-primary button">View</a>
28 <a href="update.jsp?id=<%=contact.getId()%>" class="btn btn-primary button">Update</a>
29 <a href="delete.jsp?id=<%=contact.getId()%>" class="btn btn-primary button">Delete</a>
30 </td>
31 </tr>
32 <%}%>
33 </table>
34 </div>
35 <div class="col-sm-2"></div>
36 </div>
37 </div>
38 </body>
39 </html>
src/main/webapp/nav.jsp
1 <nav class="navbar navbar-dark bg-dark navbar-fixed-top">
2 <div class="container">
3 <div class="navbar-header">
4 <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
5 <span class="sr-only">Toggle navigation</span>
6 <span class="icon-bar"></span>
7 <span class="icon-bar"></span>
8 <span class="icon-bar"></span>
9 </button>
10 <a class="navbar-brand" href="index.jsp">Contacts</a>
11 </div>
12 <div id="navbar" class="collapse navbar-collapse">
13 <ul class="nav navbar-nav">
14 <li class="active"><a href="index.jsp">List</a></li>
15 </ul>
16 </div>
17 </div>
18 </nav>
src/main/webapp/update.jsp
<%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %> <% Handler h = new Handler(pageContext); %> <html> <head> <jsp:include page="head.jsp" /> </head> <body> <jsp:include page="nav.jsp" /> <div class="container topspace"> <div class="row"> <div class="col-sm-2"></div> <div class="col-sm-8"> <% if( request.getParameter("id") != null ) { %> <% ContactEntity ci = h.getContact( Integer.parseInt( request.getParameter("id") ) ); %> <form action="update.jsp" method="post" > <label for="firstname">First name:</label><br/> <input class="form-control" type="text" id="firstname" name="firstname" value="<%= ci.getFirstName() %>"/><br/> <label for="lastname">Last name:</label><br/> <input class="form-control" type="text" id="lastname" name="lastname" value="<%= ci.getLastName() %>" /><br/> <label for="address">Address::</label><br/> <input class="form-control" type="text" id="Address:" name="address" value="<%= ci.getAddress() %>"/><br/> <label for="phonenumber">Phone number:</label><br/> <input class="form-control" type="text" id="phonenumber" name="phonenumber" value="<%= ci.getPhoneNumber() %>"/><br/> <input class="form-control" type="hidden" id="cid" name="cid" value="<%=ci.getId()%>"/> <input type="submit" value="Update" class="form-control btn btn-primary button" > </form> <% } %> </div> <div class="col-sm-2"></div> </div> </div> </body> </html>
src/main/webapp/view.jsp
1 <%@page import="org.allowed.bitarus.Handler, java.util.List, org.allowed.bitarus.ContactEntity" %>
2 <% Handler h = new Handler(pageContext); %>
3 <html>
4 <head>
5 <jsp:include page="head.jsp" />
6 </head>
7 <body>
8 <jsp:include page="nav.jsp" />
9 <div class="container topspace">
10 <div class="row">
11 <div class="col-sm-2"></div>
12 <div class="col-sm-8">
13 <% ContactEntity ci = h.getContact( Integer.parseInt( request.getParameter("id") ) ); %>
14 <p><strong>Id:</strong> <%= ci.getId() %></p>
15 <p><strong>First name:</strong> <%= ci.getFirstName() %></p>
16 <p><strong>Last name:</strong> <%= ci.getLastName() %></p>
17 <p><strong>Creation date:</strong> <%= ci.getCreationDate() %></p>
18 <p><strong>Address:</strong> <%= ci.getAddress() %></p>
19 <p><strong>Phone:</strong> <%= ci.getPhoneNumber() %></p>
20 </div>
21 <div class="col-sm-2"></div>
22 </div>
23 </div>
24 </body>
25 </html>
src/main/webapp/WEB-INF/web.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
1 <project xmlns="http://maven.apache.org/POM/4.0.0"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>org.allowed.bitarus</groupId>
6 <artifactId>warjee5</artifactId>
7 <version>0.0.1</version>
8 <packaging>war</packaging>
9 <dependencies>
10 <dependency>
11 <groupId>javaee</groupId>
12 <artifactId>javaee-api</artifactId>
13 <version>5</version>
14 <scope>provided</scope>
15 </dependency>
16 <dependency>
17 <groupId>org.allowed.bitarus</groupId>
18 <artifactId>ejbjee5</artifactId>
19 <version>0.0.1</version>
20 <scope>provided</scope>
21 </dependency>
22 </dependencies>
23 <build>
24 <sourceDirectory>src</sourceDirectory>
25 <plugins>
26 <plugin>
27 <artifactId>maven-compiler-plugin</artifactId>
28 <configuration>
29 <source>1.5</source>
30 <target>1.5</target>
31 </configuration>
32 </plugin>
33 </plugins>
34 </build>
35 </project>
src/main/java/org/allowed/bitarus/Handler.java
1 package org.allowed.bitarus;
2
3 import java.util.logging.Logger;
4 import java.util.logging.Level;
5 import javax.servlet.ServletRequest;
6 import javax.servlet.ServletResponse;
7 import javax.servlet.jsp.JspWriter;
8 import javax.servlet.jsp.PageContext;
9 import javax.naming.InitialContext;
10 import java.util.List;
11 import javax.naming.NamingEnumeration;
12 import javax.naming.NameClassPair;
13
14 public class Handler{
15 private ServletRequest request;
16 private ServletResponse response;
17 private JspWriter out;
18
19 public Handler(ServletRequest request, ServletResponse response,JspWriter out){
20 this.request = request;
21 this.response = response;
22 this.out = out;
23 }
24
25 public Handler(PageContext pageContext){
26 this.request = pageContext.getRequest();
27 this.response = pageContext.getResponse();
28 this.out = (JspWriter) pageContext.getAttribute(pageContext.OUT) ;
29 }
30
31 public void writeHandler(){
32 try{
33 this.out.println(String.format("<p>Handler up %s</p>" , this.request.getParameter("user") ));
34 }
35 catch(Exception ex){
36 }
37 }
38
39 public void writeIP(){
40 try{
41 this.out.print("!!! Your IP address is " + this.request.getRemoteAddr());
42 }
43 catch(Exception ex){
44 }
45 }
46
47 public void writeAddResults(){
48 try{
49 InitialContext context = new InitialContext();
50 NamingEnumeration<NameClassPair> namingList = context.list("");
51 while (namingList.hasMore()) {
52 out.println(namingList.next().getName() + "<br/>" );
53 }
54
55 AddLocal addLocal = (AddLocal) context.lookup("AddWS/local");
56 List<AddEntity> list = addLocal.getAll();
57 for(int idx=0; idx<list.size(); idx++){
58 this.out.println( list.get(idx).getCreationDate().toString() + "<br/>" );
59 }
60 }
61 catch(Exception ex){
62 }
63 }
64 }
src/main/java/org/allowed/bitarus/TestBean.java
1 package org.allowed.bitarus;
2 import java.util.logging.Logger;
3 import java.util.logging.Level;
4
5 public class TestBean{
6 private String name;
7 private Logger logger;
8
9 public TestBean(){
10 this.logger = Logger.getLogger(this.getClass().getName() );
11 this.logger.log(Level.INFO,"Created test bean");
12 this.name="Ioooo";
13 }
14
15 public String getName(){
16 this.logger.info("getName called");
17 return this.name;
18 }
19
20 public void setName(String name){
21 this.name=name;
22 }
23 }
src/main/webapp/WEB-INF/web.xml
1 <?xml version="1.0"?>
2 <web-app version="2.5"
3 xmlns="http://java.sun.com/xml/ns/javaee"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
6 <servlet>
7 <servlet-name>index</servlet-name>
8 <jsp-file>/index.jsp</jsp-file>
9 </servlet>
10 <servlet-mapping>
11 <servlet-name>index</servlet-name>
12 <url-pattern>/index**</url-pattern>
13 </servlet-mapping>
14 <servlet>
15 <servlet-name>otherindex</servlet-name>
16 <jsp-file>/otherindex.jsp</jsp-file>
17 </servlet>
18 <servlet-mapping>
19 <servlet-name>otherindex</servlet-name>
20 <url-pattern>/otherindex**</url-pattern>
21 </servlet-mapping>
22 </web-app>
src/main/webapp/index.jsp
1 <%@page import="org.allowed.bitarus.Handler" %>
2 <jsp:useBean id="test" class="org.allowed.bitarus.TestBean" />
3 <% //Handler h = new Handler(request,response,out); %>
4 <% Handler h = new Handler(pageContext); %>
5 <html>
6 <body>
7 <p>Hello</p>
8 <p>World <jsp:getProperty name="test" property="name" /> </p>
9 <% h.writeHandler(); %>
10 <h2><% out.print("Your IP address is " + request.getRemoteAddr()); %></h2>
11 <h3><% h.writeIP(); %></h3>
12 <h3><% h.writeAddResults(); %></h3>
13 </body>
14 </html>
src/main/webapp/otherindex.jsp
1 <%@page import="org.allowed.bitarus.Handler" %>
2 <jsp:useBean id="test" class="org.allowed.bitarus.TestBean" />
3 <% //Handler h = new Handler(request,response,out); %>
4 <% Handler h = new Handler(pageContext); %>
5 <html>
6 <body>
7 <p>Other Hello</p>
8 <p>World <jsp:getProperty name="test" property="name" /> </p>
9 <% h.writeHandler(); %>
10 <h2><% out.print("Your IP address is " + request.getRemoteAddr()); %></h2>
11 <h3><% h.writeIP(); %></h3>
12 </body>
13 </html>
Example WAR for JBoss5 in docker container
src/main/java/org/allowed/bitarus/TestBean.java
1 package org.allowed.bitarus;
2 import java.util.logging.Logger;
3 import java.util.logging.Level;
4
5 public class TestBean{
6 private String name;
7 private Logger logger;
8
9 public TestBean(){
10 this.logger = Logger.getLogger(this.getClass().getName() );
11 this.logger.log(Level.INFO,"Created test bean");
12 this.name="Ioooo";
13 }
14
15 public String getName(){
16 this.logger.info("getName called");
17 return this.name;
18 }
19
20 public void setName(String name){
21 this.name=name;
22 }
23 }
src/main/java/org/allowed/bitarus/Handler.java
1 package org.allowed.bitarus;
2
3 import java.util.logging.Logger;
4 import java.util.logging.Level;
5 import javax.servlet.ServletRequest;
6 import javax.servlet.ServletResponse;
7 import javax.servlet.jsp.JspWriter;
8 import javax.servlet.jsp.PageContext;
9
10 public class Handler{
11 private ServletRequest request;
12 private ServletResponse response;
13 private JspWriter out;
14
15 public Handler(ServletRequest request, ServletResponse response,JspWriter out){
16 this.request = request;
17 this.response = response;
18 this.out = out;
19 }
20
21 public Handler(PageContext pageContext){
22 this.request = pageContext.getRequest();
23 this.response = pageContext.getResponse();
24 this.out = (JspWriter) pageContext.getAttribute(pageContext.OUT) ;
25 }
26
27 public void writeHandler(){
28 try{
29 this.out.println(String.format("<p>Handler up %s</p>" , this.request.getParameter("user") ));
30 }
31 catch(Exception ex){
32 }
33 }
34
35 public void writeIP(){
36 try{
37 this.out.print("!!! Your IP address is " + this.request.getRemoteAddr());
38 }
39 catch(Exception ex){
40 }
41 }
42
43 }
src/main/webapp/otherindex.jsp
1 <%@page import="org.allowed.bitarus.Handler" %>
2 <jsp:useBean id="test" class="org.allowed.bitarus.TestBean" />
3 <% //Handler h = new Handler(request,response,out); %>
4 <% Handler h = new Handler(pageContext); %>
5 <html>
6 <body>
7 <p>Other Hello</p>
8 <p>World <jsp:getProperty name="test" property="name" /> </p>
9 <% h.writeHandler(); %>
10 <h2><% out.print("Your IP address is " + request.getRemoteAddr()); %></h2>
11 <h3><% h.writeIP(); %></h3>
12 </body>
13 </html>
src/main/webapp/index.jsp
1 <%@page import="org.allowed.bitarus.Handler" %>
2 <jsp:useBean id="test" class="org.allowed.bitarus.TestBean" />
3 <% //Handler h = new Handler(request,response,out); %>
4 <% Handler h = new Handler(pageContext); %>
5 <html>
6 <body>
7 <p>Hello</p>
8 <p>World <jsp:getProperty name="test" property="name" /> </p>
9 <% h.writeHandler(); %>
10 <h2><% out.print("Your IP address is " + request.getRemoteAddr()); %></h2>
11 <h3><% h.writeIP(); %></h3>
12 </body>
13 </html>
src/main/webapp/WEB-INF/web.xml
1 <?xml version="1.0"?>
2 <web-app version="2.5"
3 xmlns="http://java.sun.com/xml/ns/javaee"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
6 <servlet>
7 <servlet-name>index</servlet-name>
8 <jsp-file>/index.jsp</jsp-file>
9 </servlet>
10 <servlet-mapping>
11 <servlet-name>index</servlet-name>
12 <url-pattern>/index**</url-pattern>
13 </servlet-mapping>
14
15 <servlet>
16 <servlet-name>otherindex</servlet-name>
17 <jsp-file>/otherindex.jsp</jsp-file>
18 </servlet>
19 <servlet-mapping>
20 <servlet-name>otherindex</servlet-name>
21 <url-pattern>/otherindex**</url-pattern>
22 </servlet-mapping>
23
24 </web-app>
pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>org.allowed.bitarus</groupId>
6 <artifactId>warjee5</artifactId>
7 <version>0.0.1</version>
8 <packaging>war</packaging>
9 <dependencies>
10 <dependency>
11 <groupId>javaee</groupId>
12 <artifactId>javaee-api</artifactId>
13 <version>5</version>
14 <scope>provided</scope>
15 </dependency>
16 </dependencies>
17 <build>
18 <sourceDirectory>src</sourceDirectory>
19 <plugins>
20 <plugin>
21 <artifactId>maven-compiler-plugin</artifactId>
22 <configuration>
23 <source>1.5</source>
24 <target>1.5</target>
25 </configuration>
26 </plugin>
27 </plugins>
28 </build>
29 </project>
links servlets
pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>org.allowed.bitarus</groupId>
6 <artifactId>links-servlets</artifactId>
7 <version>0.0.1</version>
8 <packaging>war</packaging>
9 <dependencies>
10 <dependency>
11 <groupId>javaee</groupId>
12 <artifactId>javaee-api</artifactId>
13 <version>5</version>
14 <scope>provided</scope>
15 </dependency>
16 </dependencies>
17 <build>
18 <plugins>
19 <plugin>
20 <artifactId>maven-compiler-plugin</artifactId>
21 <configuration>
22 <source>1.5</source>
23 <target>1.5</target>
24 </configuration>
25 </plugin>
26 </plugins>
27 </build>
28 </project>
src/main/java/org/allowed/bitarus/AppleAppSiteAssociationServlet.java
1 package org.allowed.bitarus;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7 import javax.servlet.http.HttpServlet;
8
9 public class AppleAppSiteAssociationServlet extends HttpServlet {
10 private static final long serialVersionUID = 1L;
11
12 /*
13 * http://127.0.0.1:8080/links-servlets-0.0.1/apple-app-site-association
14 */
15 public void service(HttpServletRequest req, HttpServletResponse res) throws IOException {
16 res.setContentType("application/json");
17 PrintWriter out = res.getWriter();
18 String text = " {\n" +
19 " \"applinks\": {\n" +
20 " \"apps\": [],\n" +
21 " \"details\": [{\n" +
22 " \"appID\": \"D3KQX62K1A.com.example.photoapp\",\n" +
23 " \"paths\": [\"/albums\"]\n" +
24 " },\n" +
25 " {\n" +
26 " \"appID\": \"D3KQX62K1A.com.example.videoapp\",\n" +
27 " \"paths\": [\"/videos\"]\n" +
28 " }]\n" +
29 " }\n" +
30 "}";
31 out.println(String.format("%s", text));
32 }
33 }
src/main/java/org/allowed/bitarus/AssetLinksServlet.java
1 package org.allowed.bitarus;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7 import javax.servlet.http.HttpServlet;
8
9 public class AssetLinksServlet extends HttpServlet {
10 private static final long serialVersionUID = 1L;
11 /*
12 * http://127.0.0.1:8080/links-servlets-0.0.1/.well-known/assetlinks.json
13 */
14 public void service(HttpServletRequest req, HttpServletResponse res) throws IOException {
15 res.setContentType("application/json");
16 PrintWriter out = res.getWriter();
17 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\"] } }]";
18 out.println(String.format("%s", text));
19 }
20
21 }
src/main/webapp/WEB-INF/web.xml
1 <?xml version="1.0"?>
2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
5 <servlet>
6 <servlet-name>AssetLinksServlet</servlet-name>
7 <servlet-class>org.allowed.bitarus.AssetLinksServlet</servlet-class>
8 </servlet>
9 <servlet-mapping>
10 <servlet-name>AssetLinksServlet</servlet-name>
11 <url-pattern>/.well-known/assetlinks.json</url-pattern>
12 </servlet-mapping>
13
14 <servlet>
15 <servlet-name>AppleAppSiteAssociationServlet</servlet-name>
16 <servlet-class>org.allowed.bitarus.AppleAppSiteAssociationServlet</servlet-class>
17 </servlet>
18 <servlet-mapping>
19 <servlet-name>AppleAppSiteAssociationServlet</servlet-name>
20 <url-pattern>/apple-app-site-association</url-pattern>
21 </servlet-mapping>
22
23 </web-app>