ocpsoft rewrite one variable twice use - jsf

I want to rewrite my urls like this:
/admin/ -> /admin/admin.xhtml
I wrote this code:
return ConfigurationBuilder.begin()
.addRule(TrailingSlash.append())
.when(Path.matches("/{page}"))
.perform(Forward.to("/{page}/{page}.xhtml"))
but with this configuration I got this exception:
org.ocpsoft.rewrite.exception.ParameterizationException:
Must supply [2] values to build output string.
How can i use one variable from "when", twice in "perform"?

This bug has been documented in the Rewrite issue tracker, has now been resolved, and will be included in the 2.0.11.Final release of Rewrite in the next few days. Until then you can use the latest 2.0.11-SNAPSHOT when it deploys to the Sonatype Snapshots repository tonight, or build from sources if you need it sooner (https://github.com/ocpsoft/rewrite):
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>2.0.11-SNAPSHOT</version>
</dependency>
<!-- To use snapshots, you must also use the Sonatype Snapshots respository -->
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

Related

PIT-Cucumber plugin not finding scenarios in feature files

Try to institue PIT Mutation testing in a enterprise project. Got it to do existing JUNit tests, but we also have a lot of Cucumber tests that need to be part of the metric. Added pit-cucumber plugin to the maven project, but the output is no scenarios found. Not sure if there is some secret in the config of the plugin that I can't see.
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.4.7</version>
<configuration>
<testPlugin>Cucumber</testPlugin>
<targetClasses>
<param>org.tiaa.srk.eligibility.*</param>
</targetClasses>
<targetTests>
<param>org.tiaa.srk.eligibility.EligibilityTestRunnerIT</param>
</targetTests>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>com.github.alexvictoor</groupId>
<artifactId>pitest-cucumber-plugin</artifactId>
<version>0.8</version>
</dependency>
</dependencies>
</plugin>
I get this output:
INFO : Sending 0 test classes to minion
Make sure you're using Cucumber version 4.20 jars with pitest-cucumber-plugin 0.8
Everything else looks good. You may not need to specify targetClasses and targetTests.

log4j2 confguration file location when using jetty maven plugin

My application uses log4j2 and we have two of them one for production and another for development environment. I am using maven to run the application using mvn clean jetty:run. My plugin configuration in pom.xml looks like this:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.8.v20171121</version>
<configuration>
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>${log4j-dev.location}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
But my app still uses the log4j2.xml present in the WEB-INF/classes directory instead of the one in the log4j-dev.location path. Any ideas?
I found the solution for this problem. In the webdefault.xml file, I had to add the following code:
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2-custom.xml</param-value>
</context-param>
Hope it helps somebody who spent a whole day looking everywhere like me :)

Jhipster generated code after the error, Mapper could not be found

2016-10-20 18:03:51.253 WARN 17216 --- [ restartedMain] .s.c.a.CommonAnnotationBeanPostProcessor : Invocation of destroy method failed on bean with name 'cacheConfiguration': java.lang.NullPointerException
2016-10-20 18:03:51.274 WARN 17216 --- [ restartedMain] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined)
2016-10-20 18:03:51.749 ERROR 17216 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Field countryMapper in com.bosheng.java.service.impl.CountryServiceImpl required a bean of type 'com.bosheng.java.service.mapper.CountryMapper' that could not be found.
Action:
Consider defining a bean of type 'com.bosheng.java.service.mapper.CountryMapper' in your configuration.
If you are using IDEA and Maven, you need to activate the IDE profile in IntelliJ. This is used for applying IDE-specific tweaks which currently only includes applying the MapStruct annotation processor.
Open the “Maven Projects” tool window (View -> Tool Windows), check the IDE maven profile to activate it
I had a similar problem, but using Maven and Eclipse. At the end I realized that I hadn't read well the bottom of the "Configuring your IDE" page from jHipster docs, which says about MapStruct, but I also had to add the target/generated-sources folder to my build path (as instructed on http://g00glen00b.be/mapstruct/ ).
I have tried all the above solutions and followed the jHipster IDE configuration and my problem still not fixed.
That's what solved my problem:
mvnw clean
mvnw compile
For Gradle:
gradlew clean
gradlew compileJava
then refresh the project in the IDE and run it.
I had this issue and it was only an issue with my pom.xml. I needed to add mapstruct to the maven compiler plugin like so:
...
<properties>
<mapstruct.version>1.1.0.Final</mapstruct.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
</properties>
...
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
Please, next time, add the command line you use to build / launch your app and use code format, in order to have a good format for your question. ;o)
So, according to this log, I suggest you to use IDE and dev maven profil.
I am quite sure you don't use it, so mapstruct have the interface for bean but not generated the implementation classes.

Jhipster executable jar with undertow does not work - 404

I built a jhipster application. Added an entity. Built it with
mvn -Pprod package
Application runs fine with tomcat when I use
java -jar xyz.war
But, since we need Undertow for high load scenarios and fast startup time, I simply change the maven dependency from Tomcat to Undertow in all the places (all the profiles) wherever tomcat starter dependency was mentioned as per the Spring documentation : Using Undertow in Place of Tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
This runs fine when run from Eclipse and I can see the requests are now served by Undertow and not Tomcat as logs print XNIO as the thread-id.
But., when I again build it and try to run it with java -jar xyz.war,
Application boots up fine but when I hit the URLs
http://127.0.0.1:8081
or http://127.0.0.1/xyz
it says not found.
What else do I need to do to put jHipster application with Undertow embedded to work?
Any quick help appreciated as a critical POC to push jHipster in our organization hinges on this step.
We used to support Undertow, but removed it recently. So you shouldn't have much trouble setting it up back (and what you do looks good, then you don't post your whole configuration so it's hard to tell).
Anyway, concerning your specific use-case, you need to know why we removed Undertow:
Start-up time is indeed lower, by something like 300-500ms. We were mostly using this in our "dev" profile, as start-up time is important. But now that we have the Spring Dev Tools hot restart, this isn't useful at all anymore.
For "prod" usage, I haven't seen any performance difference between Tomcat and Undertow. Compared to just one database access (costing several ms), I guess you can't see this kind of improvements.
Besides, we have removed Undertow because it lacks a number of important features for us. Most importantly:
GZip compression support -> as you will lose this, your performance will in fact be much worse with Undertow than with Tomcat
Websocket support
Last but not least, it's easy to scale up your JHipster application by adding new nodes (and it will be even easier in JHipster 3.0), so handling a large number of users shouldn't be an issue.
I didn't manage to have your error. Undertow seems to work fine for me.
1) I generated a new JHipster project (from master), all default options
2) I replace tomcat by undertow only in this part of pom.xml :
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- log configuration -->
<logback.loglevel>DEBUG</logback.loglevel>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
<profile>
<id>prod</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
3) Build :
mvn package -Pprod
4) Start database :
docker-compose -f src/main/docker/prod.yml up -d
5) Start app
java -jar target/*.war --spring.profiles.active=prod
:: JHipster 🤓 :: Running Spring Boot 1.3.2.RELEASE ::
:: http://jhipster.github.io ::
2016-02-22 00:18:40.051 INFO 6118 --- [ main] com.mycompany.myapp.JhundertowApp : Starting JhundertowApp on pgrXps with PID 6118 (started by pgrimaud in /home/pgrimaud/workspace/tests2/32-undertow)
2016-02-22 00:18:40.054 INFO 6118 --- [ main] com.mycompany.myapp.JhundertowApp : The following profiles are active: prod
2016-02-22 00:18:44.024 WARN 6118 --- [ main] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2016-02-22 00:18:44.126 WARN 6118 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2016-02-22 00:18:44.742 INFO 6118 --- [ main] c.mycompany.myapp.config.WebConfigurer : Web application configuration, using profiles: [prod]
6) I change log in app to confirm it runs with undertow
----------------------------------------------------------
Application 'jhundertow' is running! Access URLs:
Local: http://127.0.0.1:8080
External: http://127.0.1.1:8080
----------------------------------------------------------
2016-02-22 00:20:20.585 TRACE 6118 --- [ XNIO-2 task-31] c.m.m.c.l.AngularCookieLocaleResolver : Parsed cookie value [%22en%22] into locale 'en'
2016-02-22 00:20:25.741 TRACE 6118 --- [ XNIO-2 task-32] c.m.m.c.l.AngularCookieLocaleResolver : Parsed cookie value [%22en%22] into locale 'en'
Fortunately for me, when I move the same war file to a RHEL system, it works just fine. :-) I am accepting #pgrimaud 's answer. Thanks #deepu and #Julien. You guys are awesome.
I will investigate what's going wrong on my Win7 machine-will post back here if I am able to figure out. (npm clear cache dint help. Will re-install node.js and npm as I had updated them for my other node.js work - I will see if that helps). I will also try to debug spring-boot-starter-undertow.
Finally, a solution for the nemesis is in place. Here is an update from me - Today, I started to debug spring boot and undertow code and realized that spring boot is looking for resources in the below locations :
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" };
After that, I created a folder called resources inside the META-INF directory and copied all the resources inside it using 7zip. And lo & behold., it works! :-).
Although spring boot is supposed to also load resources from
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
for some reason, it is not doing so. (which is where jHipster is putting all of the resource files)
I thought this to be a bug with spring boot version that jHipster uses and I upgraded my app spring boot version to 1.3.3.RELEASE , but that does not help either.

Using log4j with JBoss 7.1

How can I use log4j with JBoss 7.1?
I have a log4j-1.2.16.jar in my WebContent/WEB-INF/lib folder. When I output the result of Logger.getRootLogger().getClass().toString() I get class org.jboss.logmanager.log4j.BridgeLogger which is wrong.
If I add Dependencies: org.apache.commons.logging to my MANIFEST.MF file I get the same result.
This results into the problem that my log4j.properties file (which I created unter WEB-INF/classes) is ignored.
There will soon be a way that will just work for you, but currently you have to exclude the log4j dependency from your deployment. You will also have to manually invoke the PropertyConfigurator.configure() to load the properties file.
The following file (jboss-deployment-structure.xml) needs to contain the following:
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Then adding including your own version of log4j in the WEB-INF/lib directory should work as you expect it to.

Resources