Skip to content
This repository was archived by the owner on Jan 30, 2019. It is now read-only.

Commit e577f2f

Browse files
author
Arun Gupta
committed
Adding a simple Bean Validation 1.1 sample, not working on b80
Former-commit-id: 134c7fc46e0a5e145986e2e844a777b842b6b532
1 parent 65483ef commit e577f2f

File tree

5 files changed

+289
-0
lines changed

5 files changed

+289
-0
lines changed

samples/validation/methods/pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.mycompany</groupId>
6+
<artifactId>methods</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>war</packaging>
9+
10+
<name>methods</name>
11+
12+
<properties>
13+
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>javax</groupId>
20+
<artifactId>javaee-web-api</artifactId>
21+
<version>6.0</version>
22+
<scope>provided</scope>
23+
</dependency>
24+
</dependencies>
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-compiler-plugin</artifactId>
31+
<version>2.3.2</version>
32+
<configuration>
33+
<source>1.7</source>
34+
<target>1.7</target>
35+
</configuration>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-war-plugin</artifactId>
40+
<version>2.1.1</version>
41+
<configuration>
42+
<failOnMissingWebXml>false</failOnMissingWebXml>
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
48+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.sample.validation;
41+
42+
import javax.validation.constraints.Size;
43+
44+
/**
45+
* @author Arun Gupta
46+
*/
47+
public class MyBean {
48+
public String sayHello(@Size(max = 3)String name) {
49+
return "Hello " + name;
50+
}
51+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.sample.validation;
41+
42+
import java.io.BufferedWriter;
43+
import java.io.IOException;
44+
import java.io.OutputStreamWriter;
45+
import java.io.PrintWriter;
46+
import java.net.HttpURLConnection;
47+
import java.net.URL;
48+
import java.util.logging.Level;
49+
import java.util.logging.Logger;
50+
import javax.inject.Inject;
51+
import javax.servlet.ServletException;
52+
import javax.servlet.annotation.WebServlet;
53+
import javax.servlet.http.HttpServlet;
54+
import javax.servlet.http.HttpServletRequest;
55+
import javax.servlet.http.HttpServletResponse;
56+
57+
/**
58+
* @author Arun Gupta
59+
*/
60+
@WebServlet(name = "TestClient", urlPatterns = {"/TestClient"})
61+
public class TestClient extends HttpServlet {
62+
63+
@Inject MyBean bean;
64+
65+
/**
66+
* Processes requests for both HTTP
67+
* <code>GET</code> and
68+
* <code>POST</code> methods.
69+
*
70+
* @param request servlet request
71+
* @param response servlet response
72+
* @throws ServletException if a servlet-specific error occurs
73+
* @throws IOException if an I/O error occurs
74+
*/
75+
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
76+
throws ServletException, IOException {
77+
response.setContentType("text/html;charset=UTF-8");
78+
try (PrintWriter out = response.getWriter()) {
79+
out.println("<html>");
80+
out.println("<head>");
81+
out.println("<title>Servlet TestClient</title>");
82+
out.println("</head>");
83+
out.println("<body>");
84+
out.println("<h1>Servlet TestClient at " + request.getContextPath() + "</h1>");
85+
out.println(bean.sayHello("Duke"));
86+
out.println("</body>");
87+
out.println("</html>");
88+
}
89+
}
90+
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
91+
/**
92+
* Handles the HTTP
93+
* <code>GET</code> method.
94+
*
95+
* @param request servlet request
96+
* @param response servlet response
97+
* @throws ServletException if a servlet-specific error occurs
98+
* @throws IOException if an I/O error occurs
99+
*/
100+
@Override
101+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
102+
throws ServletException, IOException {
103+
processRequest(request, response);
104+
}
105+
106+
/**
107+
* Handles the HTTP
108+
* <code>POST</code> method.
109+
*
110+
* @param request servlet request
111+
* @param response servlet response
112+
* @throws ServletException if a servlet-specific error occurs
113+
* @throws IOException if an I/O error occurs
114+
*/
115+
@Override
116+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
117+
throws ServletException, IOException {
118+
processRequest(request, response);
119+
}
120+
121+
/**
122+
* Returns a short description of the servlet.
123+
*
124+
* @return a String containing servlet description
125+
*/
126+
@Override
127+
public String getServletInfo() {
128+
return "Short description";
129+
}// </editor-fold>
130+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans 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/beans_1_0.xsd">
5+
</beans>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!--
2+
/*
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4+
*
5+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
6+
*
7+
* The contents of this file are subject to the terms of either the GNU
8+
* General Public License Version 2 only ("GPL") or the Common Development
9+
* and Distribution License("CDDL") (collectively, the "License"). You
10+
* may not use this file except in compliance with the License. You can
11+
* obtain a copy of the License at
12+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
13+
* or packager/legal/LICENSE.txt. See the License for the specific
14+
* language governing permissions and limitations under the License.
15+
*
16+
* When distributing the software, include this License Header Notice in each
17+
* file and include the License file at packager/legal/LICENSE.txt.
18+
*
19+
* GPL Classpath Exception:
20+
* Oracle designates this particular file as subject to the "Classpath"
21+
* exception as provided by Oracle in the GPL Version 2 section of the License
22+
* file that accompanied this code.
23+
*
24+
* Modifications:
25+
* If applicable, add the following below the License Header, with the fields
26+
* enclosed by brackets [] replaced by your own identifying information:
27+
* "Portions Copyright [year] [name of copyright owner]"
28+
*
29+
* Contributor(s):
30+
* If you wish your version of this file to be governed by only the CDDL or
31+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
32+
* elects to include this software in this distribution under the [CDDL or GPL
33+
* Version 2] license." If you don't indicate a single choice of license, a
34+
* recipient has the option to distribute your version of this file under
35+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
36+
* its licensees as provided above. However, if you add GPL Version 2 code
37+
* and therefore, elected the GPL Version 2 license, then the option applies
38+
* only if the new code is made subject to such option by the copyright
39+
* holder.
40+
*/
41+
-->
42+
<%@page contentType="text/html" pageEncoding="UTF-8"%>
43+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
44+
"http://www.w3.org/TR/html4/loose.dtd">
45+
46+
<html>
47+
<head>
48+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
49+
<title>Method Validation in BV 1.1</title>
50+
</head>
51+
<body>
52+
<h1>Method Validation in BV 1.1</h1>
53+
<a href="${pageContext.request.contextPath}/TestClient">Method parameter validation</a><br/>
54+
</body>
55+
</html>

0 commit comments

Comments
 (0)