Skip to content

Commit

Permalink
DKaraoke Init
Browse files Browse the repository at this point in the history
  • Loading branch information
ddn488 committed Sep 9, 2015
1 parent 5536a65 commit 9c8d005
Show file tree
Hide file tree
Showing 67 changed files with 62,999 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
42 changes: 42 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dkaraoke</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
83 changes: 83 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<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">
<modelVersion>4.0.0</modelVersion>

<groupId>dennis</groupId>
<artifactId>dkaraoke</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>dkaraoke</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0-rc4</version>
</dependency>
</dependencies>
</project>
42 changes: 42 additions & 0 deletions src/main/java/dennis/dkaraoke/Router.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dennis.dkaraoke;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class Router implements javax.servlet.Filter {

private static final Pattern REWRITE_PATTERN = Pattern.compile("(^[1-9]\\d*)$");

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;

if("/".equals(request.getPathInfo())) {
RequestDispatcher dispatcher = request.getRequestDispatcher("index.htm");
dispatcher.forward(req, res);
}else {
fc.doFilter(req, res);
}
}

@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

@Override
public void destroy() {
// TODO Auto-generated method stub

}
}
52 changes: 52 additions & 0 deletions src/main/java/dennis/dkaraoke/WebSocketConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package dennis.dkaraoke;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
*
* WebSocketConfig is annotated with @Configuration to indicate that it is a
* Spring configuration class. It is also
* annotated @EnableWebSocketMessageBroker. As its name
* suggests, @EnableWebSocketMessageBroker enables WebSocket message handling,
* backed by a message broker.
*
* The configureMessageBroker() method overrides the default method in
* WebSocketMessageBrokerConfigurer to configure the message broker. It starts
* by calling enableSimpleBroker() to enable a simple memory-based message
* broker to carry the messages back to the client on destinations prefixed with
* "/topic".
*
* It also designates the "/app" prefix for messages that are bound
* for @MessageMapping-annotated methods.
*
* The registerStompEndpoints() method registers the "/song" endpoint, enabling
* SockJS fallback options so that alternative messaging options may be used if
* WebSocket is not available.
*
* This endpoint, when prefixed with "/app", is the endpoint that the
* MessageController.songTopic() method is mapped to handle.
*
*
*/

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/song").withSockJS();
}

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}



}
55 changes: 55 additions & 0 deletions src/main/java/dennis/dkaraoke/controller/MessageController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dennis.dkaraoke.controller;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import dennis.dkaraoke.model.SongAction;

/*
* Create a message-handling controller
*/
@Controller
public class MessageController {

private Set<String> songQueue = new LinkedHashSet<String>();// to keep the
// elements in
// the inserting
// order.

@MessageMapping("/song")
@SendTo("/topic/song")
public Object[] songActionHandle(SongAction songAction) throws InterruptedException {

if (songAction.getAction().equals(SongAction.ADD)) {
songQueue.add(songAction.getSongIndex());
} else if (songAction.getAction().equals(SongAction.REMOVE) &&
songQueue.contains(songAction.getSongIndex())) {
songQueue.remove(songAction.getSongIndex());
}

// list of string song indexes is sent to the topic queue where all subscribers will receive
return songQueue.toArray();
}

@RequestMapping(value = "/getHostAddress", method = RequestMethod.GET)
@ResponseBody
public String getHostAddress() throws UnknownHostException {
InetAddress ip = InetAddress.getLocalHost();

// return ip.getHostName();
return ip.getHostAddress();

}
}
45 changes: 45 additions & 0 deletions src/main/java/dennis/dkaraoke/model/Song.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dennis.dkaraoke.model;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Song {

private Long id;
private String fileName;
private String title;
private String artist;

@XmlAttribute
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

@XmlAttribute
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}

@XmlAttribute
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}

@XmlAttribute
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
}
33 changes: 33 additions & 0 deletions src/main/java/dennis/dkaraoke/model/SongAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dennis.dkaraoke.model;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class SongAction {

final public static String ADD = "add";
final public static String REMOVE = "remove";

private String songIndex;
private String action;

@XmlAttribute
public String getSongIndex() {
return songIndex;
}

public void setSongIndex(String songIndex) {
this.songIndex = songIndex;
}

@XmlAttribute
public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

}
Loading

0 comments on commit 9c8d005

Please sign in to comment.