Friday, October 30, 2015

How to add images to output with AsciiDoctor Gradle plugin

To add images to output with AsciiDoctor Gradle plugin

add the following configuration to your `build.gradle` file:

asciidoctor {
    resources {
        from (sourceDir) {
            include "**/*.png"
        }
    }
}

Reference:
https://github.com/asciidoctor/asciidoctor-gradle-plugin

ERR_CONNECTION_ABORTED in Chrome when you deploy a WAR file to Tomcat via Manager App

You might get ERR_CONNECTION_ABORTED in Chrome when you deploy a WAR file to Tomcat via a Manager App.

If so, check your log file for the Manager App, `logs/manager.2015-10-30.log`.

It might look like this:

30-Oct-2015 15:49:08.586 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.ApplicationContext.log HTMLManager: FAIL - Deploy Upload Failed, Exception: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (59114627) exceeds the configured maximum (52428800)
 java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (59114627) exceeds the configured maximum (52428800)
        at org.apache.catalina.connector.Request.parseParts(Request.java:2804)
        at org.apache.catalina.connector.Request.parseParameters(Request.java:3073)
        at org.apache.catalina.connector.Request.getParameter(Request.java:1095)
        at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:380)
        at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:185)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (59114627) exceeds the configured maximum (52428800)
        at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:811)
        at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256)
        at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280)
        at org.apache.catalina.connector.Request.parseParts(Request.java:2734)
        ... 28 more

If you encounter the above error, you should change file size in `webapps/manager/WEB-INF/web.xml` appropriately:

    <multipart-config>
      <!-- 50MB max -->
      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>
      <file-size-threshold>0</file-size-threshold>
    </multipart-config>

Friday, October 23, 2015

Tuesday, October 6, 2015

Make sure a corresponding org.thymeleaf.doctype.resolution.IDocTypeResolutionEntry implementation is provided by you dialect

When you use Thymeleaf with Spring Boot and use the following DOCTYPE:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">

you will get the following errors:

2015-10-07 10:19:45.957 ERROR 3301 --- [io-18080-exec-1] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-18080-exec-1] Exception processing template "restaurants/add": Unsupported entity requested with PUBLICID "null" and SYSTEMID "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd". Make sure a corresponding org.thymeleaf.doctype.resolution.IDocTypeResolutionEntry implementation is provided by you dialect
2015-10-07 10:19:45.964 ERROR 3301 --- [io-18080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Unsupported entity requested with PUBLICID "null" and SYSTEMID "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd". Make sure a corresponding org.thymeleaf.doctype.resolution.IDocTypeResolutionEntry implementation is provided by you dialect] with root cause
org.thymeleaf.exceptions.TemplateProcessingException: Unsupported entity requested with PUBLICID "null" and SYSTEMID "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd". Make sure a corresponding org.thymeleaf.doctype.resolution.IDocTypeResolutionEntry implementation is provided by you dialect
at org.thymeleaf.templateparser.EntityResolver.resolveEntity(EntityResolver.java:75) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]
...

You should use the following DOCTYPE:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

Reference:
http://stackoverflow.com/questions/25132189/thymleaf-unsupported-entity-requested-with-publicid-null

Thursday, October 1, 2015

Kibana doesn't recognize changed `not_analyzed`

When you change index type to `not_analyzed`

and Kibana doesn't recognize `not_analyzed`,

do as follows:

Settings -> Reload field list

and try again.

Make a field as `not_analyzed` index in Elasticsearch

To make a field as `not_analyzed` index in Elasticsearch,

use `@Field` as follows:

  @Field(type = FieldType.String, index = FieldIndex.not_analyzed)
  private String name;

and check as follows:

curl -XGET 'http://localhost:9200/event/_mapping?pretty'

and then you will see as follows:

          "name" : {
            "type" : "string",
            "index" : "not_analyzed"
          },

Note that the following annotation doesn't work:

  @Field(index = FieldIndex.not_analyzed)

I'm not sure why type inference doesn't work.

Set a `java.util.Date` typed field as `date` type in Elasticsearch

To set a `java.util.Date` typed field as `date` type in Elasticsearch,

use `@Field` as follows:

  @Field(type = FieldType.Date)
  private Date timestamp;

and check as follows:

curl -XGET 'http://localhost:9200/event/_mapping?pretty'

and then you will see as follows:

          "timestamp" : {
            "type" : "date",
            "format" : "dateOptionalTime"
          }