HDiv redirecting to error page Error[HDIV_PARAMETER_DOES_NOT_EXIST] - struts-1

Running Struts 1.3.8
hdiv-config.xml
<hdiv:config excludedExtensions="css,png,js,gif,jpeg"
protectedExtensions=".*.do" maxPagesPerSession="20" confidentiality="true" avoidCookiesIntegrity="true">
<hdiv:startPages>/loginForm.do</hdiv:startPages>
<hdiv:startPages>/login.do</hdiv:startPages>
<hdiv:startPages>/logout.do</hdiv:startPages>
<hdiv:startPages>/home.do</hdiv:startPages>
<hdiv:startPages>/pages/BillDischarge/NewPrepaidBill.do</hdiv:startPages>
<hdiv:startParameters>org.apache.struts.action.TOKEN,org.apache.struts.taglib.html.TOKEN</hdiv:startParameters>
</hdiv:config>
<hdiv:editableValidations>
<hdiv:validationRule url=".*"/>
</hdiv:editableValidations>
`
Every page except the ones defined under startPages redirects me to the 'Unauthorized' Error Page.
Log:
2016-10-19 14:42:10 [#] INFO Logger: HDIV_PARAMETER_DOES_NOT_EXIST;/pages/Common/PatientSearch.do;_HDIV_STATE_;;;0:0:0:0:0:0:0:1;0:0:0:0:0:0:0:1;anonymous;
Help?

It seems your link and forms are not processed by Hdiv.
Check the configuration of the tag libraries. The application have to load Hdiv tld files instead of Struts's ones.
Have a look at this example application for a working web.xml file:
https://github.com/hdiv/hdiv-struts-examples/blob/master/src/main/webapp/WEB-INF/web.xml#L122

Related

Spring application war - Google App Engine - How to specify Log location, profile, environment variab;les

I have a spring boot application bundled as war file , and able to push to App Engine
But I am getting problems starting app (I suspect there could be an issue with DB too...but couldnt remember where I saw...a nightmare)
java.lang.RuntimeException: java.lang.IllegalStateException: Logback
configuration error detected: ERROR in
ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Failed to
create parent directories for
[/base/data/home/apps/e~pemy/20210716t001812.436581063072799646/logs/pynew.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] -
openFile(logs/pynew.log,true) call failed.
java.io.FileNotFoundException: logs/pynew.log (No such file or
directory)
I am using the below properties in my application props
> logging.file.path=logs
> logging.file.name=${logging.file.path}/pynew.log
I am finding it very hard to include google specific dependencies and properties , and making a mess of my project...created app.yaml, web-inf>> appengine-web xml, logging.properties (not sure why but added as told in a tutorial)
Question: How can I create parent directory or link to cloud storage folder etc?
I also want to specify a profile and I see I can do it in yaml file. Is this used only
env_variables:
JAVA_USER_OPTS: '-Dspring.profiles.active=prod'
But I would like to know how to connect to Cloud SQL
spring.datasource.url=jdbc:mysql:///mydb?cloudSqlInstance=myapp:europe-west2:dBinstancename&socketFactory=com.google.cloud.sql.mysql.SocketFactory
spring.datasource.username=${dbuser}
spring.datasource.password=ENC(${dbencpwd})
spring.cloud.gcp.sql.database-name=mydb
spring.cloud.gcp.sql.instance-connection-name=myapp:europe-west2:dBinstancename
It is so confusing that I keep forgetting which connection needs password and which wont. and keep breaking my local
Question
Assuming that I need to supply credentials, How can I supply - ${dbuser}
I used the default spring logger with logback-spring.xml for all my development, and this is not working on AppEngine
So I followed https://cloud.google.com/logging/docs/setup/java
and added logback.xml and the dependency
implementation 'com.google.cloud:google-cloud-logging-logback:0.121.3-alpha'

Thymeleaf, Spring Boot 2: invalid path to resources when handle error

I have a basic SpringBoot Thymeleaf app with default settings:
id 'org.springframework.boot' version '2.2.2.RELEASE'
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
Problem is in invalid path to resources in some cases when handle error and as a result app can't show resoures (css/js/image) on page.
Path to resoures: /src/main/resources/static/assets
For logging path I made RequestInterceptor. It logs the part of request's URL.
I describe 4 cases. Paths and logs in interceptor:
calling the correct path /home - all work fine
[09:02:48.759][INFO] /home
[09:02:48.759][INFO] /assets/img/java60.png
calling the incorrect path /first (expect 404 error) - all work fine
[09:02:48.759][INFO] /first
[09:02:48.777][INFO] /error
[09:02:49.589][INFO] /assets/css/simple.css
[09:02:49.590][INFO] /assets/img/notFound.png
[09:02:49.715][INFO] /favicon.ico
calling the incorrect path /first/second (expect 404 error) - unexpected behavior
[09:03:00.390][INFO] /first/second
[09:03:00.395][INFO] /error
[09:03:00.422][INFO] /first/assets/css/simple.css
[09:03:00.422][INFO] /first/assets/img/notFound.png
[09:03:00.426][INFO] /error
[09:03:00.426][INFO] /error
calling the incorrect path /first/second/third (expect 404 error) - unexpected behavior
[09:39:06.404][INFO] /first/second/third
[09:39:06.409][INFO] /error
[09:39:06.441][INFO] /first/second/assets/css/simple.css
[09:39:06.441][INFO] /first/second/assets/img/notFound.png
[09:39:06.446][INFO] /error
[09:39:06.446][INFO] /error
In third and fourth cases app redirects to error and set up path (request's URL + path to assets on page). Why spring make invalid path to resources in 3 and 4 cases?
The complete source code is available over on Github
You have to link resources using an absolute path. Currently, you are linking using relative paths like <link rel="stylesheet" th:href="#{assets/css/simple.css}">.
Try to update your resources to:
<link rel="stylesheet" th:href="#{/assets/css/simple.css}">
<img th:src="#{/assets/img/java60.png}" sizes="16x16" alt="love">

Error with Spring Boot Jsp sample application

I'm trying to configure a Spring Boot application with JSP template. I'm having some problems with it so I'm comparing my application with Spring Boot's sample jsp application: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp
To my surprise I've got the same problem with the sample. I'm going to try to describe the steps I've followed:
Download spring-boot: git clone https://github.com/spring-projects/spring-boot
Move to a stable version: git checkout v1.4.0.RELEASE
Move to the sample application: cd spring-boot/spring-boot-samples/spring-boot-sample-web-jsp/
Run the application: mvn spring-boot:run
In the application's logs I see the available request mappings: /, /foo and /error
I do this request curl -XGET localhost:8080/ and I get this answer:
{"timestamp":1471504557212,"status":404,"error":"Not Found","message":"No message available","path":"/"}
The result that I expected was the html of welcome.jsp. It seems that there is a problem when Spring Mvc tries to render welcome.jsp.
Any idea what I am doing wrong?

How do I load ${catalina.home}/conf/application.properties in a Spring / Tomcat webapp?

How do I load ${catalina.home}/conf/application.properties in a Spring / Tomcat webapp?
Looking around on StackOverflow and Google I see many discussions which claim it's possible. However, it's just not working for me. In line with the advice from my research my Spring applicationContext.xml file contains the following line:
<context:property-placeholder location="${catalina.home}/conf/application.properties"/>
But I get this in the logs:
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/Users/username/Servers/apache-tomcat-6.0.36/conf/application.properties]
From the log entry I can see that ${catalina.home} is expanding correctly. When I expand it by hand in the applicationContext.xml file it returns the same error. The following returns the contents of the application.properties file as expected:
cat /Users/username/Servers/apache-tomcat-6.0.36/conf/application.properties
So the path is clearly correct. Is this a webapp security or Tomcat server configuration issue?
The location of a context:property-placeholder is a Resource, which means that if you provide just a file path (as opposed to a full URL with a protocol) then the path will be resolved against the base directory of the webapp - it is trying to load /Users/username/Servers/apache-tomcat-6.0.36/webapps/<appname>/Users/username/Servers/apache-tomcat-6.0.36/conf/application.properties, which does not exist. If you prefix it with file: it'll work as you require:
<context:property-placeholder location="file:${catalina.home}/conf/application.properties"/>
For annotation based configuration you can use:
#PropertySource("file:${catalina.home}/conf/application.properties")

jboss/tomcat tld cache invalidation

I have a jboss application with some ears. There's war inside ear and there's file monitor.tld inside WEB-INF folder of war.
There's some tag definitions inside the monitor.tld. I added my custom tag definition in this file, and restarted jsboss. After that, when I use my tag in jsp I get error:
2011-04-23 16:38:31,829 INFO [STDOUT] 2011-04-23 16:38:31,761 [http-0.0.0.0-8080-4] ERROR [] org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/Monitor].[jsp] - Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /tiles/layout/wizardLayout.jsp(140,4) No tag "wizardNavEx" defined in tag library imported with prefix "mon"
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1213)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1449)
at org.apache.jasper.compiler.Parser.parse(Parser.java:133)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1078)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:295)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:271)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:332)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
...
So, my custom tag wizardNavEx doesn't work, but wizardNav defined in monitor.tld a couple of lines above works fine.
I think the problem is tomcat/jboss cached previous version of monitor.tld in someplace. How can I clear that caches? Any ideas?
Versions:
X-Powered-By='Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5'
The problem was that another monitor.tld existed inside one of jar files.

Resources