Skip to content

Instantly share code, notes, and snippets.

View jpukg's full-sized avatar
🧭
Full Stack Developer (Java, Angular)

Jayaprakash (JP) jpukg

🧭
Full Stack Developer (Java, Angular)
View GitHub Profile
@jpukg
jpukg / UploadController.java
Created October 10, 2016 18:45 — forked from wangyangcx/UploadController.java
extjs file upload & spring mvc
@RequestMapping(value = "/upload", method = RequestMethod.POST, produces = MediaType.TEXT_HTML_VALUE)
@ResponseBody
public String upload(@RequestParam("file") MultipartFile file, String name, String message) throws Exception
{
Map<String, Object> resp = Maps.newHashMap();
FileCopyUtils.copy(file.getBytes(), new File('filename'));
resp.put("success", true);
resp.put("msg", "upload success.");
@jpukg
jpukg / findImageApi.java
Created October 10, 2016 18:47 — forked from marcoberri/findImageApi.java
Serve Spring MVC image on response
@RequestMapping(value = "/image/{id}", method = RequestMethod.GET)
public void findImage(@PathVariable("id") String id, HttpServletResponse resp){
final Foto anafoto = <find object>
resp.reset();
resp.setContentType(MediaType.IMAGE_JPEG_VALUE);
resp.setContentLength(anafoto.getImage().length);
final BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(anafoto.getImageInBytes()));
@jpukg
jpukg / SpringMVC_MultipleFileUpload.java
Created October 10, 2016 18:48 — forked from loictalbot/SpringMVC_MultipleFileUpload.java
Multiple file upload using Jquery + Spring MVC
package org.springframework.samples.mvc.fileupload;
import java.io.IOException;
import org.springframework.mvc.extensions.ajax.AjaxUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@jpukg
jpukg / EmployeeController.java
Created October 10, 2016 18:50
Spring MVC jQuery Ajax in jsp
@Controller
@RequestMapping(value = "employees")
public class EmployeeController {
@Autowired
CountryService countryService;
@RequestMapping(value="/findActiveCitiesByCountry", method=RequestMethod.GET,
headers = {"Accept=text/xml, application/json"})
@ResponseBody
@jpukg
jpukg / FileWatcher.java
Created October 10, 2016 19:43
Watching file events using built-in NIO 2 WatchService in Java 7
import java.io.IOException;
import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*;
public class FileWatcher {
private WatchService watchService;
private void init() {
Path path = Paths.get("/tmp/TARGET/");
@jpukg
jpukg / PHR.java
Created October 10, 2016 19:44 — forked from debbabi/PHR.java
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.*;
import java.io.*;
public class PHR {
public static void main(String[] args) throws IOException {
// monitor a single file
@jpukg
jpukg / GuavaCacheMXBean.java
Created October 10, 2016 19:49 — forked from kofemann/GuavaCacheMXBean.java
Expose Google's guava Cache vie JMX
public interface GuavaCacheMXBean {
public long getRequestCount();
public long getHitCount();
public double getHitRate();
public long getMissCount();
@jpukg
jpukg / LdapSecurityConfig.java
Created October 10, 2016 20:10 — forked from Cameron-C-Chapman/LdapSecurityConfig.java
Spring Security LDAP Config
package package.name;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
@jpukg
jpukg / SecurityConfiguration.java
Created October 10, 2016 20:11 — forked from jimador/SecurityConfiguration.java
Spring Boot Security config
import com.asi.hrportal.security.*;
import com.asi.hrportal.web.filter.CsrfCookieGeneratorFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
@jpukg
jpukg / SessionRegistryController.java
Created October 10, 2016 20:19 — forked from xak2000/SessionRegistryController.java
Expire or remove spring session
package test;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;