Differences

This shows you the differences between two versions of the page.

Link to this comparison view

java:new-app-v2 [30/06/2017 17:20]
Anthony Arents [POM :]
java:new-app-v2 [14/12/2017 12:33] (current)
Anthony Arents [Tracking versions]
Line 1: Line 1:
 ====== New Java Web Applications ====== ====== New Java Web Applications ======
 +
 +End of life January 2019.
  
 If you are making a company project : If you are making a company project :
Line 7: Line 9:
   * Netbeans project   * Netbeans project
   * Maven   * Maven
-  * Spring (latest -> 4.3.9.RELEASE)+  * Spring (latest -> 4.3.12.RELEASE)
   * Spring Security (latest -> 4.2.3.RELEASE)   * Spring Security (latest -> 4.2.3.RELEASE)
-  * Hibernate (latest -> 5.2.10.Final)+  * Hibernate (latest -> 5.2.12.Final)
   * Javamelody (latest, developer tool, used for statistics)   * Javamelody (latest, developer tool, used for statistics)
   * ExtJS 6   * ExtJS 6
Line 21: Line 23:
 A website which allows you to keep a list of dependencies to watch :\\  A website which allows you to keep a list of dependencies to watch :\\ 
 https://www.artifact-listener.org/\\  https://www.artifact-listener.org/\\ 
 +\\
 +My list (on the right of the screenshot)\\ 
 +{{:java:screenshot-www.artifact-listener.org_2017-07-06_11-41-02.png?nolink&600|}}
 +
 \\  \\ 
 Spring Blog Spring Blog
Line 142: Line 148:
         <javax.servletjspapi>2.2.1</javax.servletjspapi>         <javax.servletjspapi>2.2.1</javax.servletjspapi>
                  
-        <spring.version>4.3.9.RELEASE</spring.version>+        <spring.version>4.3.10.RELEASE</spring.version>
         <springsecurity.version>4.2.3.RELEASE</springsecurity.version>         <springsecurity.version>4.2.3.RELEASE</springsecurity.version>
-        <mysql.version>5.1.42</mysql.version>+        <mysql.version>5.1.44</mysql.version>
         <dbcp.version>2.1.1</dbcp.version>         <dbcp.version>2.1.1</dbcp.version>
         <hibernate.version>5.2.10.Final</hibernate.version>         <hibernate.version>5.2.10.Final</hibernate.version>
-        <jackson.version>2.8.9</jackson.version>+        <jackson.version>2.8.10</jackson.version>
         <apache.taglibs.version>1.2.5</apache.taglibs.version>         <apache.taglibs.version>1.2.5</apache.taglibs.version>
-        <log4j.version>2.8.2</log4j.version>+        <log4j.version>2.9.0</log4j.version>
         <commons.lang.version>3.6</commons.lang.version>         <commons.lang.version>3.6</commons.lang.version>
         <commons.io.version>2.5</commons.io.version>         <commons.io.version>2.5</commons.io.version>
         <commons.beanutils.version>1.9.3</commons.beanutils.version>         <commons.beanutils.version>1.9.3</commons.beanutils.version>
-        <javax.mail.version>1.5.6</javax.mail.version>+        <javax.mail.version>1.6.0</javax.mail.version>
         <apache.poi.version>3.16</apache.poi.version>         <apache.poi.version>3.16</apache.poi.version>
-        <javamelody.version>1.67.0</javamelody.version>+        <javamelody.version>1.69.0</javamelody.version>
         <findbugs.helper.version>3.0.2</findbugs.helper.version>         <findbugs.helper.version>3.0.2</findbugs.helper.version>
                  
Line 168: Line 174:
         <report.plugin.maven.pmd>3.7</report.plugin.maven.pmd>         <report.plugin.maven.pmd>3.7</report.plugin.maven.pmd>
         <report.plugin.maven.surefire>2.20</report.plugin.maven.surefire>         <report.plugin.maven.surefire>2.20</report.plugin.maven.surefire>
-        <report.plugin.codehaus.findbugs>3.0.4</report.plugin.codehaus.findbugs>+        <report.plugin.codehaus.findbugs>3.0.5</report.plugin.codehaus.findbugs>
         <report.plugin.codehaus.taglist>2.4</report.plugin.codehaus.taglist>         <report.plugin.codehaus.taglist>2.4</report.plugin.codehaus.taglist>
         <report.plugin.codehaus.versions>2.3</report.plugin.codehaus.versions>         <report.plugin.codehaus.versions>2.3</report.plugin.codehaus.versions>
                  
         <build.plugin.maven.site>3.6</build.plugin.maven.site>         <build.plugin.maven.site>3.6</build.plugin.maven.site>
-        <build.plugin.maven.compiler>3.6.1</build.plugin.maven.compiler>+        <build.plugin.maven.compiler>3.6.2</build.plugin.maven.compiler>
         <build.plugin.maven.deploy>2.8.2</build.plugin.maven.deploy>         <build.plugin.maven.deploy>2.8.2</build.plugin.maven.deploy>
         <build.plugin.maven.clean>3.0.0</build.plugin.maven.clean>         <build.plugin.maven.clean>3.0.0</build.plugin.maven.clean>
Line 2775: Line 2781:
  
     public ApiDTO() {     public ApiDTO() {
 +    }
 +
 +    public static ApiDTO error() {
 +        final ApiDTO apiDto = new ApiDTO();
 +        apiDto.setSuccess(Boolean.FALSE);
 +        return apiDto;
     }     }
          
Line 2834: Line 2846:
 </code> </code>
  
 +===== Presentation (Ajax, MultiActionController) =====
 +
 +use requestmapping to map based on action parameter
 +
 +<code java>
 +package de.jcpis.analyse.presentation;
 +
 +import org.apache.logging.log4j.LogManager;
 +import org.apache.logging.log4j.Logger;
 +import org.springframework.beans.factory.annotation.Autowired;
 +import org.springframework.stereotype.Controller;
 +import org.springframework.web.bind.annotation.RequestMapping;
 +import org.springframework.web.context.request.WebRequest;
 +import org.springframework.web.servlet.ModelAndView;
 +import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
 +
 +/**
 + *
 + * @author anthonyarents
 + */
 +@Controller
 +@RequestMapping("/bankverbindung.json")
 +public class BankverbindungController {
 +
 +@RequestMapping(params = "action=validateBankverbindung")
 +    public ModelAndView validateBankverbindung(final WebRequest hsr) {
 +    }
 +    }
 +</code>
  
 ===== Presentation (Restcontroller) ===== ===== Presentation (Restcontroller) =====
Line 3126: Line 3167:
          
 } }
 +</code>
 +
 +===== Server-side validation =====
 +
 +At this time, I've only added a check to disallow "dangerous" html on fields which will display the html as is (instead of htmlEncoded like the rest of the output)
 +
 +extra requirements on the project :
 +  * el-api (v2.2 is used for tomcat6 & tomcat7, v3.0.0 is used with java8 & tomcat8)
 +  * hibernate-validator (v5.4.1.Final in case of tomcat6 & 7, use latest in case of java8 & tomcat8)
 +  * jsoup (use latest)
 +
 +==== DTO ====
 +=== imports ===
 +<code java>
 +import org.hibernate.validator.constraints.SafeHtml;
 +</code>
 +=== Getter ===
 +<code java>
 +@SafeHtml
 +    public String getDescription() {
 +        return description;
 +    }
 +</code>
 +==== Presentation ====
 +=== Imports ===
 +<code java>
 +import org.springframework.validation.BindingResult;
 +import org.springframework.validation.annotation.Validated;
 +</code>
 +
 +=== Changes to methods updateById & createNew ===
 +<code java>
 +@JsonView(View.Public.class)
 +    @PreAuthorize("hasRole('ROLE_ADMIN')")
 +    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
 +    @ResponseStatus(HttpStatus.OK)
 +    public ApiDTO updateById(@PathVariable final UUID id, @RequestBody @Validated final NotificationDTO dto, final BindingResult bindingResult) {
 +        if (bindingResult.hasErrors()) {
 +            return ApiDTO.error();
 +        }
 +        dto.setId(id);
 +        final Notification result = notificationService.save(dto);
 +        return new ApiDTO(result);
 +    }
 +
 +    @JsonView(View.Public.class)
 +    @PreAuthorize("hasRole('ROLE_ADMIN')")
 +    @RequestMapping(value = "", method = RequestMethod.POST)
 +    @ResponseStatus(HttpStatus.CREATED)
 +    public ApiDTO createNew(@RequestBody @Validated final NotificationDTO dto, final BindingResult bindingResult) {
 +        if (bindingResult.hasErrors()) {
 +            return ApiDTO.error();
 +        }
 +        final Notification result = notificationService.save(dto);
 +        return new ApiDTO(result);
 +    }
 </code> </code>
  
Line 4124: Line 4221:
  
 [[https://letsencrypt.org/]] free certificate provider (certificate is 90 days with auto renewal)\\ [[https://letsencrypt.org/]] free certificate provider (certificate is 90 days with auto renewal)\\
-[[https://certbot.eff.org/]] easy AUTOMATIC install +[[https://certbot.eff.org/]] easy AUTOMATIC install \\  
 +\\  
 +the certbot-auto script is usually placed in ''/usr/share/'' (as seen in crontab)\\ 
 + 
 +==== Quick way to add domains ==== 
 +you can simply boot the script :\\ 
 +''cd /usr/share/''\\ 
 +''sudo ./certbot-auto''\\
  
 +the interface will then present you with the options you can provide a certificate for, it's 1 certificate for all urls you select.
 ===== provide for normal domains ===== ===== provide for normal domains =====
 ''sudo ./certbot-auto --apache'' ''sudo ./certbot-auto --apache''