-
Notifications
You must be signed in to change notification settings - Fork 4
Random Services Notes
Jinlian(Sunny) Wang edited this page Dec 27, 2018
·
13 revisions
- Spring Boot Profiles - Application Configuration made easy
- Quick Intro to Spring Cloud Configuration
- Testing in Production — Building Observable Distributed System
- HTTP Status Codes: full list of http status code and what it means for each of them.
mvn clean install
to build and mvn package -P devint-test cargo:run
to run from within the “web” module; to debug mvnDebug package -P devint-test cargo:run
, and then set up Remote Java Application to connect to the listening port - 8000. See this stackoverflow for arguments - MAVEN_DEBUG_OPT=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
Use -DskipTests
to skip tests.
Simple, get your sources and JavaDocs:
mvn dependency:resolve -Dclassifier=javadoc -Dclassifier=sources
To download sources for your dependencies: mvn eclipse:eclipse -DdownloadSources=true
To attach sources to an installation: mvn source:jar install
From this stackoverflow
@Component
public class SessionValidationInterceptorAdapter extends HandlerInterceptorAdapter {
private static final Logger logger = LoggerFactory.getLogger(SessionValidationInterceptorAdapter.class);
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
HandlerMethod method = (HandlerMethod) handler;
SessionValidationToken methodAnnotation =
method.getMethodAnnotation(SessionValidationToken.class);
GroupSessionValidationToken classAnnotation =
method.getMethod().getDeclaringClass().getAnnotation(GroupSessionValidationToken.class);
if (methodAnnotation != null || classAnnotation != null) {
// Decipher and validate the session token.
try {
UserToken userToken = new UserToken();
token = request.getHeader("Authorization").trim();
//decrypt the token and check its validity
if (this.isValid(userToken)) {
return true;
}
} finally {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return false;
}
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
}
}
- Spring AOP + @AspectJ Annotation Example with @Aspect, @Pointcut, @Before, @After, @Around, @AfterReturning, @AfterThrowing Advice
- Aspect Oriented Programming with Spring
- Define Aspect Config
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages="com.concretepage")
public class AspectConfig {
}
- Define annotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Auditable {
AuditCode value();
}
- Define advice with point cut expression
@Before("com.xyz.lib.Pointcuts.anyPublicMethod() && @annotation(auditable)")
public void audit(Auditable auditable) {
AuditCode code = auditable.value();
// ...
}
- Note that point cut can be defined separately from Advice -
@Pointcut("com.xyz.lib.Pointcuts.anyPublicMethod() && @annotation(auditable)")
public void pointcutDemo() {}
@Before("pointcutDemo())")
public void audit(Auditable auditable) {
AuditCode code = auditable.value();
// ...
}