Spring boot 404 and still works - spring-mvc

When i run my spring boot application as JAR file, all my controllers work fine(though i still get "Did not find handler method for ..." in logs but somehow appropriate controller and view is rendered just fine. When i run this in WAR mode, it's giving me 404 with same error in logs "Did not find handler method for ...".
Here is my application class:
#SpringBootApplication
public class RAApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//set register error pagefilter false
//setRegisterErrorPageFilter(false);
return application.sources(RAApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(RAApplication.class, args);
}
}
My main application class is under com.xyz.abc and all controllers under say com.xyz.abc.controllers and every other component is in child package of com.xyz.abc .
/mappings and /beans work just fine and /mappings do show something like this :
"{[/],methods=[GET]}":{"bean":"requestMappingHandlerMapping","method":"public java.lang.String com.xyz.abc.controllers.HomeController.renderIndexPage(org.springframework.ui.Model)"}
FYI, I checked there is only one mapping of [/] in case it's useful.
Any pointers to what might be going wrong? All usual searches points to controllers not being found but /mappings show all of them are mapped correctly but why does it give 404 in war mode and works with error in jar mode?
Thanks!
UPDATE : I've set
servlet.contextPath=/
in application.properties and rest other actuator endpoints are configured correctly too e.g.
15:21:09.253 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'metricsFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'webRequestLoggingFilter' to: [/*]
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Filter errorPageFilter was not registered (disabled)
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'applicationContextIdFilter' to: [/*]
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/]
15:21:09.289 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.OrderedRequestContextFilter - Initializing filter 'requestContextFilter'
15:21:09.291 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.OrderedRequestContextFilter - Filter 'requestContextFilter' configured successfully
15:21:09.291 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.ApplicationContextHeaderFilter - Initializing filter 'applicationContextIdFilter'
15:21:09.291 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.ApplicationContextHeaderFilter - Filter 'applicationContextIdFilter' configured successfully

If you deploy your WAR in a web container like Tomcat then you have a context path.
For example localhost:8080/ in JAR mode becomes localhost:8080/myapp/ in web container.

Related

Symfony 4 enable logging with Monolog's Redis handler

I have a working ELK stack connected to Redis.
I also have a working stateless Symfony 4 application and I want to send all the production logs to my Redis.
I know Monolog has a Redis handler, but I don't know how I'm supposed to tweak the config/prod/monolog.yaml file to accomplish this of if there’s another approach.
This is how it looks right now:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404]
nested:
type: stream
path: "php://stderr"
level: debug
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
deprecation:
type: stream
path: "php://stderr"
deprecation_filter:
type: filter
handler: deprecation
max_level: info
channels: ["php"]
The approach I took was, first installing the predis client:
composer require predis/predis
Then create a custom service class that extends the RedisHandler class that comes with the Monolog package:
namespace App\Service\Monolog\Handler;
use Monolog\Handler\RedisHandler;
use Monolog\Logger;
use Predis\Client as PredisClient;
class Redis extends RedisHandler
{
public function __construct( $host, $port = 6379, $level = Logger::DEBUG, $bubble = true, $capSize = false)
{
$predis = new PredisClient( "tcp://$host:$port" );
$key = 'logstash';
parent::__construct($predis, $key, $level, $bubble, $capSize);
}
}
Next, activate the service we just created on the services.yml config file:
services:
monolog.handler.redis:
class: App\Service\Monolog\Handler\Redis
arguments: [ '%redis.host%' ]
Be sure the parameter redis.host is set and points to your Redis server. In my case, my parameter value is the IP of my Redis server.
I added other parameters to the class like port and log level. You can set it at the moment of instantiating your service like with the host parameter.
Finally, configure your custom log handler service in your monolog.yaml config file. In my case, I need it only the production logs with the config as follow:
handlers:
custom:
type: service
id: monolog.handler.redis
level: debug
channels: ['!event']

using network-bootstrapper to generate node-info expects certificates with devMode=false

I am trying to use network-bootstrapper tool to generate node-infos(like certificates etc) by passing node.conf file as input with devMode=false, following is my node.conf file:
myLegalName="O=Bank,L=Paris,C=FR"
p2pAddress="localhost:10011"
devMode=false
rpcSettings {
address="localhost:10012"
adminAddress="localhost:10052"
}
security {
authService {
dataSource {
type=INMEMORY
users=[
{
password=test
permissions=[
ALL
]
user=user3
}
]
}
}
}
I am passing the path of node.conf file as an argument to the bootsrapper.jar, but it is exiting with error code 1, below is the screenshot of the error:
following is the log generated:
[INFO ] 2018-07-04T14:19:21,901Z [main] internal.Node.generateAndSaveNodeInfo - Generating nodeInfo ... {}
[ERROR] 2018-07-04T14:19:21,901Z [main] internal.Node.validateKeystore - IO exception while trying to validate keystore {}
java.nio.file.NoSuchFileException: C:\corda\work\keys- gen\Bank\certificates\sslkeystore.jks
......
......
And
[ERROR] 2018-07-04T14:19:21,917Z [main] internal.Node.run - Exception during node startup {}
java.lang.IllegalArgumentException: Identity certificate not found. Please either copy your existing identity key and certificate from another node, or if you don't have one yet, fill out the config file and run corda.jar --initial- registration. Read more at: https://docs.corda.net/permissioning.html
......
......
Can you please let me know how to generate certificates and place it already inside the folder {workspace}/{nodeName}/certificates which already does not exists and is being generated by the bootstrapper tool itself? can you help with certificate generation and usage of network-bootstrapper.jar tool with devMode turned off?
The bootstrapper tool can't be used outside of devMode. Outside of devMode, proper certificates and a network map server must be used.
This issue is being tracked here: https://r3-cev.atlassian.net/browse/CORDA-1735.

Having problems setting up AWS S3/Cloudfront with Symfony and LiipImagineBundle

I'm trying to set up AWS S3/Cloudfront to work with liipimaginebundle in Symfony, but I really have no idea what I'm doing.
So far I have tried the following documented here http://symfony.com/doc/current/bundles/LiipImagineBundle/cache-resolver/aws_s3.html:
Installed aws-sdk-php:
"require": {
"aws/aws-sdk-php": "^3.28",
}
Set up my parameters (with the correct values not this dummy data):
amazon.s3.key: "your-aws-key"
amazon.s3.secret: "your-aws-secret"
amazon.s3.bucket: "your-bucket.example.com"
amazon.s3.region: "your-bucket-region"
Set up a resolver (although I'm not sure what that even means).
"%amazon.s3.cache_bucket%" is in the documentation but the parameter doesn't exist so I used "%amazon.s3.bucket%" instead:
liip_imagine:
cache: profile_photos
resolvers:
profile_photos:
aws_s3:
client_config:
credentials:
key: "%amazon.s3.key%"
secret: "%amazon.s3.secret%"
region: "%amazon.s3.region%"
bucket: "%amazon.s3.bucket%"
get_options:
Scheme: https
put_options:
CacheControl: "max-age=86400"
Added these lines to create the services:
services:
acme.amazon_s3:
class: Aws\S3\S3Client
factory: Aws\S3\S3Client
arguments:
-
credentials: { key: "%amazon.s3.key%", secret: "%amazon.s3.secret%" }
region: "%amazon.s3.region%"
acme.imagine.cache.resolver.amazon_s3:
class: Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver
arguments:
- "#acme.amazon_s3"
- "%amazon.s3.bucket%"
tags:
- { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }
I'm currently getting this error when I run php bin/console server:run:
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedFunctionException: Attempted to call function "S3Client" from namespace "Aws\S3". in /var/www/swing-polls/var/cache/dev/appDevDebugProjectContainer.php:360
I've tried half a dozen other configs/tutorials to no avail. If someone can point me in the right direction I'd be incredibly grateful.
Using the code provided at Simple S3 Symfony Service with a few tweaks, I've been able to get my images to upload to my s3 bucket, but I just don't know how to get liipimaginebundle work with them.
In vendor/liip/imagine-bundle/DependencyInjection/Compiler/ResolversCompilerPass.php you can see the CompilerPass is getting the value from "resolver" attribute of the tag and is using it to create a Reference object. This means the resolver should contain the id of a service.
Try replacing
tags:
- { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }
with
tags:
- { name: "liip_imagine.cache.resolver", resolver: "acme.amazon_s3" }

Spring Profile values getting mixed

I'm using Spring Boot 1.4.3.RELEASE and gradle 2.13 for developing an api. On local environment, 'local' profile is working perfectly, but I'm getting issue while deploying code in Linux/Unix server.
Here is my application.yml with two profiles : dev and local
---
spring:
profiles:
active: dev
server:
context-path: /api/v1
port: 8080
build:
version: 1.0.0
cache:
storage:
path: '/home/user/content/storage/'
---
spring:
profiles:
active: local
server:
context-path: /content-delivery/api/v1
port: 8081
build:
version: 1.0.0
cache:
storage:
path: '/Yogen/api/code/cachedData'
The command I'm using to deploy my war file is:
jdk1.8.0_112/bin/java -jar _-Dspring.profiles.active=dev content-delivery.jar
When I run my war it was working fine with only one profile, but once i added another profile, I'm getting values get mixed up causing error as below:
01:56:16.557 INFO ContentDeliveryApplication - The following profiles are active: dev
............
02:00:48.182 INFO PropertyPlaceholderConfigurer - Loading properties file from file [/home/542596/content-api/resources/app-dev.properties]
02:00:51.939 INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [class org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$290c5e2d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
02:00:55.736 INFO AnnotationActionEndpointMapping - Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
02:01:25.559 INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$a08e9c2b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
02:01:56.522 INFO TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 8081 (http)
02:01:57.669 INFO StandardService - Starting service Tomcat
02:01:57.877 INFO StandardEngine - Starting Servlet Engine: Apache Tomcat/8.5.6
02:02:11.228 INFO [/content-delivery/api/v1] - Initializing Spring embedded WebApplicationContext
02:02:11.228 INFO ContextLoader - Root WebApplicationContext: initialization completed in 353263 ms
02:02:19.412 INFO ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/]
02:02:19.517 INFO ServletRegistrationBean - Mapping servlet: 'messageDispatcherServlet' to [/services/*]
02:02:19.829 INFO FilterRegistrationBean - Mapping filter: 'metricsFilter' to: [/*]
02:02:19.829 INFO FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
02:02:19.829 INFO FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
02:02:19.829 INFO FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
02:02:19.829 INFO FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
02:02:19.829 INFO FilterRegistrationBean - Mapping filter: 'webRequestLoggingFilter' to: [/*]
02:02:19.829 INFO FilterRegistrationBean - Mapping filter: 'applicationContextIdFilter' to: [/*]
02:02:46.283 ERROR EhcacheManager - Initialize failed.
02:02:46.284 WARN AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonObjectCacheManager': Invocation of init method failed; nested exception is org.ehcache.StateTransitionException: Directory couldn't be created: /Yogen/api/code/cachedData/cachedData
02:02:46.285 INFO StandardService - Stopping service Tomcat
02:02:47.528 INFO AutoConfigurationReportLoggingInitializer -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
02:02:48.103 ERROR SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonObjectCacheManager': Invocation of init method failed; nested exception is org.ehcache.StateTransitionException: Directory couldn't be created: /Yogen/api/code/cachedData/cachedData
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
The PropertyPlaceholderConfigurer has been configured as follows:
#Configuration
public class PropertyConfiguration {
#Bean
#Profile("dev")
public static PropertyPlaceholderConfigurer developmentPropertyPlaceholderConfigurer() {
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
configurer.setLocation(new FileSystemResource("/home/542596/content-api/resources/app-dev.properties"));
configurer.setIgnoreUnresolvablePlaceholders(true);
return configurer;
}
}
The console shows that properties file being read is correct also the profile is 'dev', but the port started and context-path and other values are being fetched from 'local' profile instead 'dev' profile.
What I'm missing?? Thanks.
Your profiles are getting overridden.
Better Boostrap your application using bootstrap.yml
and have two application.yml as follows :
application-dev.yml
application-local.yml
set profiles in bootstrap.yml to decide which property file to load:
spring:
profiles:
active : dev # choose which application properties to load dev/local
Like #Barath stated, you cannot separate profile properties within a single application.yml file. Create a yml file for each profile, name it as follows
application-{profile}.yml
I would not use bootstrap.yml to specify which profile to load as you'll want to externalize this if possible, so passing it to the VM via -Dspring.profiles.active=dev would be preferable.
We also have another option similar to #Maxwell answer instead of passing the profile through VM property :
you can have following files:
application.yml
application-dev.yml
application-local.yml
And define profile in application.yml :
spring:
profiles:
active : dev
This ensures loading of application.yml as well as application-dev.yml.

Symfony 2.8 disable security/request.INFO logging

Symfony is logging two INFO level statements for every request in my application, inflating an apache log file very rapidly. We're not using Monolog (using an alternate solution), and I've disabled it by removing the bundle in the AppKernel.
[2016-06-23 12:11:04] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2016-06-23 12:11:06] request.INFO: Matched route "contact". {"route_parameters":{"_controller": ...
How can I disable this logging?
This happens because Monolog (which symfony will use itself even if you disable it in your app) defaults to std:error:
public function addRecord($level, $message, array $context = array())
{
if (!$this->handlers) {
$this->pushHandler(new StreamHandler('php://stderr', static::DEBUG));
}
Adding any handler in app/config/config.yml will make addRecord reject the unwanted info notice instead.
monolog:
handlers:
syslog:
type: syslog
level: error

Resources