Sunday, 25 September 2016

Weblogic Virtual Path Directory config for Static images etc


Using the below configuration you can basically create a content repository for your application using the feature provided by weblogic to host static content .

for example below your application context is webApp

Hence static will be hosted at IP:Port/webApp/image.jpg

<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">
    <wls:weblogic-version>10.3.4</wls:weblogic-version>
    <wls:context-root>webApp</wls:context-root>
    <wls:container-descriptor>
                   <!-- virtual directory -->
         <wls:index-directory-enabled>true</wls:index-directory-enabled>
         <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
           
    </wls:container-descriptor>
  
     <!-- virtual directory -->
         <wls:virtual-directory-mapping>
           <wls:local-path>/deployment/static</wls:local-path>
               <wls:url-pattern>*</wls:url-pattern>
         </wls:virtual-directory-mapping>
 
</wls:weblogic-web-app>

Wednesday, 21 September 2016

Input Json Model Validation using Jackson and Gson

      

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.gson.JsonIOException;

public class JsonValidator {
 
 
 public static void main(String[] args) throws JsonIOException, IOException {
  
  ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
         Validator validator = factory.getValidator();
         ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
         List jsonObjString = new ArrayList();
         jsonObjString.add("postBox: Mumbai " );
        
         for(String attribute  : jsonObjString){
             System.out.println("Attribute :\n" + attribute);
             Address user = null;
             try {
                 user = objectMapper.readValue(attribute, Address.class);
             } catch (IOException e) {
               System.out.println("Exception caught:");
             }
             if (user != null) {
                 final Set> violations = validator.validate(user);
                 if (violations.size() > 0) {
                     System.out.println("Config contains errors:");
                     for (ConstraintViolation
u : violations){ System.out.println(" \"" + u.getPropertyPath().toString() + "\"" + " " + u.getMessage()); } } else { System.out.println("NO ERRORS " ); } } }; } } /// ADD a model class of Address to test the validation and the messages returned for the import org.hibernate.validator.constraints.NotEmpty; import com.fasterxml.jackson.annotation.JsonInclude; import com.sun.istack.internal.NotNull; /** * Author : Sanal Samuel * */ @JsonInclude(JsonInclude.Include.NON_NULL) public class Address { @NotNull @NotEmpty(message="Incorrect Data") private String postBox; @NotNull @NotEmpty(message="Incorrect Data") private String flatNumber; public String getPostBox() { return postBox; } public void setPostBox(String postBox) { this.postBox = postBox; } public String getFlatNumber() { return flatNumber; } public void setFlatNumber(String flatNumber) { this.flatNumber = flatNumber; } }

Sunday, 4 September 2016

Spring Scheduler Example

Requirement to perform some action at end of day - that would be used within the application , since this was better to map our application structure , we used spring scheduler to do this task.


 xmlns:task="http://www.springframework.org/schema/task"
 http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd" 
 Add the above schema definition to your parent bean. 
 Below annotation in to register you anotated class.
 
 task:annotation-driven (Please add <>)

 And Finally your method to execute with the cron parameter for execution trigger details
  
   //* "0 0 * * * *" = the top of every hour of every day.
   //* "*/10 * * * * *" = every ten seconds.
   //* "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
   //* "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
   //* "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
   //* "0 0 0 25 12 ?" = every Christmas Day at midnight
 
 
   +-------------------- second (0 - 59)
   |  +----------------- minute (0 - 59)
   |  |  +-------------- hour (0 - 23)
   |  |  |  +----------- day of month (1 - 31)
   |  |  |  |  +-------- month (1 - 12)
   |  |  |  |  |  +----- day of week (0 - 6) (Sunday=0 or 7)
   |  |  |  |  |  |  +-- year [optional]
   |  |  |  |  |  |  |
   *  *  *  *  *  *  * command to be executed 
 
   @Scheduled(cron = "*/10 * * * * *")
   public void demoServiceMethod()

       

AWS Certificate Manager - Import Certificate

How to import a certificate. Use Key Store Explorer to open the cert and export keypair in PEM format  This will save a file cert.pem. Make ...