Skip to content

Instantly share code, notes, and snippets.

View jamestrandung's full-sized avatar

James Tran jamestrandung

View GitHub Profile
@jamestrandung
jamestrandung / pom.xml
Last active November 1, 2019 03:10
POM for creating WAR with React
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>monolithic</artifactId>
<packaging>war</packaging>
<parent>
@jamestrandung
jamestrandung / YamlPropertySourceFactory.java
Last active March 31, 2023 12:37
Upgraded YamlPropertySourceFactory which can load profile-based YAML configurations
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;
@jamestrandung
jamestrandung / YamlPropertySourceFactory.java
Created May 9, 2019 09:28
Simple implementation of YamlPropertySourceFactory
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;
@jamestrandung
jamestrandung / Application.java
Last active April 9, 2019 02:57
Update javax.xml.bind.JAXBContextFactory to make use of packaged JAXB library
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// Updating javax.xml.bind.JAXBContextFactory to make use of com.sun.xml.bind.v2.ContextFactory from our packaged WAR
System.setProperty("javax.xml.bind.JAXBContextFactory", "com.sun.xml.bind.v2.ContextFactory");
@jamestrandung
jamestrandung / DatabaseConfiguration.java
Last active April 3, 2020 03:32
Set up LocalContainerEntityManagerFactoryBean
@Primary
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
emfBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
emfBean.setDataSource(dataSource);
// Other configurations
}
@jamestrandung
jamestrandung / Application.java
Last active April 8, 2019 07:36
Starting SpringBoot app in stand-alone servlet container
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
@jamestrandung
jamestrandung / MrBean.java
Last active December 15, 2015 17:59
The order of Action and Listener in JSF
package my.beanBag;
@ManagedBean(name = "mrBean")
@RequestScoped
public class MrBean implements ActionListener {
private String type;
public void triggerActionListener() {
System.out.println("MrBean is called by buttons' actionListener.");
}
@jamestrandung
jamestrandung / Filter redirecting.java
Last active December 15, 2015 15:39
Redirect after login
String requestURI = request.getRequestURI();
String queryString = request.getQueryString();
String encodedURL = URLEncoder.encode(requestURI + "?" + queryString, "UTF-8");
response.sendRedirect(request.getContextPath() + "/login.xhtml?originalURL=" + encodedURL);
@jamestrandung
jamestrandung / Managed bean.java
Last active October 8, 2017 16:40
Social authentication
@Named(value = "userSession")
@SessionScoped
public class UserSessionBean implements Serializable {
private SocialAuthManager manager;
private String originalURL;
private String providerID;
private Profile profile;
public UserSessionBean() { ... }
-Djavax.net.ssl.keyStorePassword=newpass
-Djavax.net.ssl.trustStorePassword=newpass