terça-feira, 30 de outubro de 2018

JSP hot-deploy in Jboss / Wildfly


To enable hot-deploy of JSPs in Wildfly, i.e. to automatically publish any changes to JSPs in ${WILDFLY_ROOT}/standalone/tmp/vfs/temp/tempxxxxxxx/content-xxxxxxx without requiring redeployment of war, set the development attribute of jsp-config within undertow subsystem to true as below:
<subsystem xmlns=”urn:jboss:domain:undertow:3.0″>
<servlet-container name=”default” default-encoding=”UTF-8″>
        <jsp-config development=”true” tag-pooling=”false”/>        <websockets/>
</servlet-container>

Ref: https://ohioedge.com/2018/01/31/jsp-hot-deploy-in-wildfly/

sexta-feira, 26 de outubro de 2018

Recursively display all 'csv' files in a list of directories


private static final String CONST_SUFFIX = "csv";
....
//method
for (String directoryPath : folders) {
if (Paths.get(directoryPath).toFile().isDirectory()) {
Files.list(Paths.get(directoryPath)).filter(Files::isRegularFile).forEach(path -> {
if(path.endsWith(CONST_SUFFIX) || path.toString().toLowerCase().endsWith(CONST_SUFFIX)){
System.out.println(path.getFileName());
}
});
}
}

segunda-feira, 22 de outubro de 2018

How to call the same methods from difference classes

public class Teste1 {

public String valor1;

public String getValor1() {
return valor1;
}

public void setValor1(String valor1) {
this.valor1 = valor1;
}
}
#########################################################################
public class Teste2 {

public String valor1;

public String getValor1() {
return valor1;
}

public void setValor1(String valor1) {
this.valor1 = valor1;
}

}

#########################################################################


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class GenericTest {

public static void main(String[] args) {

Teste1 t1 = new Teste1();
t1.setValor1("valor1");

Teste2 t2 = new Teste2();
t2.setValor1("valor2");

System.out.println(testeMetodo(t1, Teste1.class));
System.out.println(testeMetodo(t2, Teste2.class));
}
public static String testeMetodo(Object objecInstance, Class<?> clazz) {
String retorno = "";
try {
Method metodo = clazz.getMethod("getValor1");
retorno = (String) metodo.invoke(objecInstance, null);

} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return retorno;
}

}

sábado, 20 de outubro de 2018

how to check if attribute has '@notNull' annotation dynamic

This solution was used in a java project with String jdbcTemplate following the idea of @NotNull JPA Annotation to check ScreenMapper from Controller and @All attributes need to have the same name column in Database.


public Boolean validationRequiredFieldsInMapper(Class<?> clazz, final Map<String, Object> screenFieldMap) {
Boolean isError = false;

Object objValue = null;
Field field = null;
String strValue = "";
for (String column : screenFieldMap.keySet()) {
field = clazz.getDeclaredField(column);
if (field != null) {
if (field.isAnnotationPresent(NotNull.class)) {
objValue = screenFieldMap.get(column);
strValue = (String) objValue;
if (StringUtils.isBlank(strValue)) {
isError = true;
break;
}
}
}
}
}

Class:

@NotNull
private Integer sap;
@NotNull
private String address;
@NotNull
private Date dateRegister;

Map: 

@RequestMapping(value="examplecontroller", method=RequestMethod.POST)
public @ResponseBody ReturnObject setData(
@RequestParam(value="sap",required= true ) String sap,
@RequestParam(value="address", required= true) String address,
@RequestParam(value="dateRegister", required= true) String dateRegister,

Map<String,Object> screenFieldMap = new HashMap<String,Object>();
screenFieldMap.put("sap",sap);
screenFieldMap.put("address",address);
screenFieldMap.put("dateRegister",dateRegister);