Skip to content

Commit adadd18

Browse files
author
Reza Rahman
committed
Restore
0 parents  commit adadd18

40 files changed

+2532
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.class
2+
3+
# Package Files #
4+
*.jar
5+
*.war
6+
*.ear
7+
.classpath
8+
.project
9+
.settings
10+
**/target

LICENSE

Lines changed: 814 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
javaee-javascript
2+
=================
3+
4+
This project demonstrates how you can utilize today's most popular JavaScript frameworks like Angular, Backbone, Knockout and Ember to utilize the core strengths of Java EE using JAX-RS, JSR 356/WebSocket, JSON-P, CDI and Bean Validation. We will also include Oracle's own JavaScript solution named project Avatar.

javaee-javascript-main/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Java EE 7 server-side application with an AngularJS front-end consisting of a chat application (powered by
2+
WebSocket) and a to-do list application (powered by REST). The server-side is implemented using
3+
the Java API for WebSocket, JSON-P, JAX-RS 2, CDI, Bean Validation, EJB 3 and JPA.
4+
5+
The application is secured. Before running the application, you must setup the right GlassFish security
6+
realm using the asadmin commands in the same directory as this file. You can also set the username/passwords
7+
via the database scripts in the source code. The passwords are stored as SHA-256
8+
hashes. The current users are reza, nicole and zehra. The passwords are set to secret1. When using the
9+
application, the browser will warn you about the self-signed SSL certificate that GlassFish uses by default.
10+
Simply ignore the warning, it's harmless.
11+
12+
The project is in standard Maven format. You should be able to open it using any IDE that supports Maven and
13+
run it using any Java EE 7 container. However, we used NetBeans and GlassFish 4. Note that the project uses
14+
the default Derby database that comes with GlassFish. Here are the instructions to get up and running
15+
using NetBeans and GlassFish:
16+
17+
* Install JDK 7
18+
* Install GlassFish 4+
19+
* Install the NetBeans 7.4+ Java EE version
20+
* Setup GlassFish in NetBeans (make sure Derby is started with GlassFish)
21+
* Open and build the project
22+
* Execute the asadmin commands in the 'create-javascript-realm.bat' file. The second command is more
23+
important and the first one might fail, so don't execute the batch file directly
24+
* Run the project on GlassFish 4
25+
* Open up a browser and go to http://localhost:8080/javaee-javascript-main
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
asadmin delete-auth-realm javascript-realm
2+
asadmin create-auth-realm --classname com.sun.enterprise.security.ee.auth.realm.jdbc.JDBCRealm --property jaas-context=jdbcRealm:datasource-jndi=jdbc/__default:user-table=javascript_users:user-name-column=username:password-column=password:group-table=javascript_groups:group-name-column=group_name javascript-realm
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
xml version="1.0" encoding="UTF-8"?>
2+
43+
<project-shared-configuration>
44+
50+
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
51+
57+
<netbeans.hint.j2eeVersion>1.7-webnetbeans.hint.j2eeVersion>
58+
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ideorg-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
59+
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv3ee6org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
60+
properties>
61+
project-shared-configuration>

javaee-javascript-main/pom.xml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
xml version="1.0" encoding="UTF-8"?>
2+
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44+
<modelVersion>4.0.0modelVersion>
45+
46+
<groupId>org.glassfishgroupId>
47+
<artifactId>javaee-javascript-mainartifactId>
48+
<version>1.0-SNAPSHOTversion>
49+
<packaging>warpackaging>
50+
51+
<name>javaee-javascript-mainname>
52+
53+
<properties>
54+
<endorsed.dir>${project.build.directory}/endorsedendorsed.dir>
55+
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
56+
<netbeans.hint.deploy.server>gfv3ee6netbeans.hint.deploy.server>
57+
properties>
58+
59+
<dependencies>
60+
<dependency>
61+
<groupId>javaxgroupId>
62+
<artifactId>javaee-apiartifactId>
63+
<version>7.0version>
64+
<scope>providedscope>
65+
dependency>
66+
<dependency>
67+
<groupId>org.glassfish.jersey.mediagroupId>
68+
<artifactId>jersey-media-moxyartifactId>
69+
<version>2.2version>
70+
<type>jartype>
71+
<scope>providedscope>
72+
dependency>
73+
dependencies>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.pluginsgroupId>
79+
<artifactId>maven-compiler-pluginartifactId>
80+
<version>3.1version>
81+
<configuration>
82+
<source>1.7source>
83+
<target>1.7target>
84+
<compilerArguments>
85+
<endorseddirs>${endorsed.dir}endorseddirs>
86+
compilerArguments>
87+
configuration>
88+
plugin>
89+
<plugin>
90+
<groupId>org.apache.maven.pluginsgroupId>
91+
<artifactId>maven-war-pluginartifactId>
92+
<version>2.3version>
93+
<configuration>
94+
<failOnMissingWebXml>falsefailOnMissingWebXml>
95+
configuration>
96+
plugin>
97+
plugins>
98+
build>
99+
100+
project>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
* http://glassfish.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.glassfish.javaee.javascript.backend.chat;
41+
42+
import java.io.StringReader;
43+
import java.text.SimpleDateFormat;
44+
import java.util.Date;
45+
import javax.json.Json;
46+
import javax.json.JsonObject;
47+
import javax.json.JsonReader;
48+
import javax.validation.constraints.NotNull;
49+
import javax.validation.constraints.Size;
50+
import javax.websocket.Decoder;
51+
import javax.websocket.Encoder;
52+
import javax.websocket.EndpointConfig;
53+
54+
public class ChatMessage
55+
implements Decoder.Text<ChatMessage>, Encoder.Text<ChatMessage> {
56+
57+
@NotNull
58+
@Size(min = 1, max = 42,
59+
message = "User must be between 1 and 42 characters")
60+
private String user;
61+
@NotNull
62+
@Size(min = 1, max = 255,
63+
message = "Message must be between 1 and 255 characters")
64+
private String message;
65+
66+
@Override
67+
public void init(EndpointConfig config) {
68+
// Nothing to do.
69+
}
70+
71+
@Override
72+
public ChatMessage decode(String value) {
73+
try (JsonReader jsonReader = Json.createReader(
74+
new StringReader(value))) {
75+
JsonObject jsonObject = jsonReader.readObject();
76+
user = jsonObject.getString("user");
77+
message = jsonObject.getString("message");
78+
}
79+
80+
return this;
81+
}
82+
83+
@Override
84+
public boolean willDecode(String string) {
85+
return true; // Detect if it's a valid format.
86+
}
87+
88+
@Override
89+
public String encode(ChatMessage chatMessage) {
90+
JsonObject jsonObject = Json.createObjectBuilder()
91+
.add("user", chatMessage.user)
92+
.add("message", chatMessage.message)
93+
.add("timestamp",
94+
new SimpleDateFormat("MM/dd/yyyy h:mm:ss a z")
95+
.format(new Date()))
96+
.build();
97+
98+
return jsonObject.toString();
99+
}
100+
101+
@Override
102+
public void destroy() {
103+
// Nothing to do.
104+
}
105+
106+
@Override
107+
public String toString() {
108+
return "ChatMessage{" + "user=" + user + ", message=" + message + '}';
109+
}
110+
}

0 commit comments

Comments
 (0)