Skip to content

Instantly share code, notes, and snippets.

Avatar
🕸️
👨🏼‍💻

Sachin Chavan sachinsmc

🕸️
👨🏼‍💻
View GitHub Profile
View gist:8f0f46ca2fc448b256e01b9a7c9524e2
CREATE TABLE `book` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`tags` json DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
View pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.smc</groupId>
<artifactId>JWTRestSecurity</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JWTRestSecurity Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
View web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>RestJWT API</display-name>
<servlet>
<servlet-name>RestJWT</servlet-name>
<servlet-class>
View index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>RestJWT</title>
</head>
<h2>
<b>Rest API oooooooooooOOOOOOOOOOOO</b>
View hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"//Hibernate/Hibernate Configuration DTD 4.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-4.0.dtd">
<hibernate-configuration xmlns="http://www.hibernate.org/xsd/orm/cfg"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-factory>
View accountWebService.java
package com.smc.webservice;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
View AccountDao.java
package com.smc.dao;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import com.smc.model.UserModel;
import com.smc.utils.Constants;
import com.smc.utils.HibernateUtil;
View UserModel.java
package com.smc.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonProperty;
View Constants.java
package com.smc.utils;
public class Constants {
public static final String SUCCESS = "SUCCESS";
public static final String FAILURE = "FAILURE";
public static final String USER_ID = "USER_ID";
public static final String USER_NAME = "USER_NAME";
public static final String USER_MESSAGE = "USER_MESSAGE";
}
View HibernateUtil.java
package com.smc.utils;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import com.smc.model.UserModel;
public class HibernateUtil {