Jetty fails to start with ClassNotFoundException: org.eclipse.jetty.client.HttpClient - websocket

I'm trying to create a war file containing single WebSocket servlet. For some reason jetty wants HttpClient, even though I'd like to have only server side logic. HttpClient is there in the "jetty-client-9.4.0.v20161208.jar" file under Jetty. But that's not listed in the status dump (jetty.server.dumpAfterStart=true).
web.xml
<web-app>
<display-name>WebSocketApp</display-name>
<servlet>
<servlet-name>wsservlet</servlet-name>
<servlet-class>com.example.test.MyJettyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>wsservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Socket:
#ServerEndpoint("/control")
public class ControlSocket {
#OnOpen
public void onOpen(Session session) {
System.out.println("WebSocket opened: " + session.getId());
}
#OnMessage
public void onMessage(String txt, Session session) throws IOException {
System.out.println("Message received: " + txt);
session.getBasicRemote().sendText(txt.toUpperCase());
}
#OnClose
public void onClose(CloseReason reason, Session session) {
System.out.println("Closing a WebSocket due to " + reason.getReasonPhrase());
}
}
Gradle build file:
dependencies {
compile 'org.projectlombok:lombok:1.16.2'
compile group: 'javax.websocket', name: 'javax.websocket-api', version: '1.1'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.16'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
testCompile 'junit:junit:4.11'
}
I'd assume something wrong with dependencies. But what exactly? Should I include websocket implementation jars? If yes, then why?

If you using jetty-distribution, add the client module.
$ cd /path/to/mybase
$ java -jar /path/to/jetty-dist/start.jar --add-to-start=client
This is being improved in Jetty 9.4.1 btw.

Related

ribbon.eureka.enabled=true not working in Zuul Gateway

application.properties :-
spring.application.name=zuulgateway
management.endpoints.web.exposure.include=*
zuul.routes.clientone.path=/clientone/**
zuul.routes.clientone.service-id=clientone
ribbon.eureka.enabled=true
#clientone.ribbon.listOfServers = http://localhost:8001
zuul.ignored-services=*
logging.level.org.springframework=DEBUG
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
server.port=8000
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
build.gradle :-
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-zuul', version: '2.2.7.RELEASE'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client', version: '3.0.2'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-config', version: '3.0.3'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-bootstrap', version: '3.0.2'
}
ext {
springCloudVersion = '2020.0.0'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
Main class :-
#EnableZuulProxy
#EnableDiscoveryClient
#SpringBootApplication
public class ZuulGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulGatewayApplication.class, args);
}
}
When I try to access endpoint present in clientone service I'm getting error like
Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: clientone
Error :-
021-04-04 20:19:30.811 DEBUG 24288 --- [nio-8000-exec-4] o.s.c.n.zuul.filters.SimpleRouteLocator : route matched=ZuulRoute{id='clientone', path='/clientone/**', serviceId='clientone', url='null', stripPrefix=true, retryable=null, sensitiveHeaders=[], customSensitiveHeaders=false, }
2021-04-04 20:19:30.816 WARN 24288 --- [nio-8000-exec-4] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering
com.netflix.zuul.exception.ZuulException: Forwarding error
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:198) ~[spring-cloud-netflix-zuul-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:173) ~[spring-cloud-netflix-zuul-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:119) ~[spring-cloud-netflix-zuul-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117) ~[zuul-core-1.3.1.jar:1.3.1]
When I uncomment clientone.ribbon.listOfServers in properties file getting success response. Then what is the use of this ribbon.eureka.enabled=true property if I provide list of servers.

spring boot 2.0.3 oauth2 authentication

I have the following configuration
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.0.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.0.3.RELEASE'
runtime('org.springframework.boot:spring-boot-devtools')
compile group: 'org.springframework.security', name: 'spring-security-config', version: '5.0.6.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-oauth2-client', version: '5.0.6.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-oauth2-jose', version: '5.0.6.RELEASE'
A simple sprint boot app
#SpringBootApplication
public class App{
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
And the client configs
spring.security.oauth2.client.registration.google.client-id=x
spring.security.oauth2.client.registration.google.client-secret=y
spring.security.oauth2.client.registration.facebook.client-id=x
spring.security.oauth2.client.registration.facebook.client-secret=y
After checking a few resources and the spring security oauth2 docs https://docs.spring.io/spring-security/site/docs/current/reference/html5/#jc-oauth2login I am expecting that all this code will configure the application as an #EnableWebFlux with #EnableWebFluxSecurity and will configure the default ClientRepository with the clients provided in properties file.
They say when you access your app you will get a list with the clients you added. Instead I receive a basic authentication mechanism. Any idea what is happening or am I doing something wrong?

SpringBoot EntityManagerFactory not found

So, trying to run first sprinboot application with JPA implementation and got the following error :
Description:
Field personneDAO in com.example.demo.controller.PersonneController required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
tried to add #Repositoy on my repo, and #EnableJpaRepositories to the main, but it doesn't helps...
the repository (nothing too fancy):
#Repository
public interface PersonneDAO extends JpaRepository<Personne, Integer>{
}
the main :
#SpringBootApplication
#EnableJpaRepositories(basePackages ="com.example.demo.repository")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
gradle dependencies :
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.apache.tomcat.embed:tomcat-embed-jasper')
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.16.Final'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.6.RELEASE'
testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.5.1.jre9-preview'
}
Any ideas guys? :/
PS : forgot the application.properties
spring.mvc.view.prefix = /WEB-INF/
spring.mvc.view.suffix = .jsp
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:sqlserver://localhost/DB_TEST
spring.datasource.username=sa
spring.datasource.password=Pa$$w0rd
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
JPA will not get auto-configured without spring-boot-starter-data-jpa as a dependency. With the dependency in place, you shouldn't even need #EnableJpaRepositories.
Also, you may remove spring-data-jpa as spring-boot-starter-data-jpa already depends on that.

Spring Boot tests fail for missing javax.servlet.http.HttpServletRequest

I have a springboot 1.5.9 using Spock for my integration tests. These tests all worked before with SpringBoot 1.3.5 but after upgrading Spring and Spock, I get the following when I run
gradle clean build test
Error on each integration test:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.http.HttpServletRequest' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
My dependencies:
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
dependencies {
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4:2.1.2.RELEASE')
compile('com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.0')
compile("org.hibernate:hibernate-core:4.3.4.Final")
compile("org.hibernate:hibernate-entitymanager:4.3.4.Final")
compile("org.hibernate:hibernate-validator")
compile("org.apache.velocity:velocity:1.7")
compile('javax.mail:mail:1.4.1')
compile("org.springframework:spring-context-support")
compile("mysql:mysql-connector-java:5.1.6")
compile("com.h2database:h2:1.3.172")
compile("joda-time:joda-time:2.3")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
compile('org.jadira.usertype:usertype.jodatime:2.0.1')
compile("org.liquibase:liquibase-core")
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
testCompile(group: 'org.spockframework', name: 'spock-core', version: '1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile(group: 'org.spockframework', name: 'spock-spring', version: '1.1-groovy-2.4') {
exclude group: 'org.spockframework', module: 'spock-core'
exclude group: 'org.spockframework', module: 'spring-beans'
exclude group: 'org.spockframework', module: 'spring-test'
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
testCompile("junit:junit")
}
And all my spock tests use this as their base:
#ContextConfiguration(classes = MainClass)
#WebAppConfiguration()
#SpringBootTest(webEnvironment=SpringBootTest.WebEnvironment.NONE)
public class BaseSpecification extends Specification {
}
And here is the main class:
#ComponentScan
#EnableAutoConfiguration
#EnableGlobalMethodSecurity(securedEnabled = true)
public class MainClass {
public static void main(String[] args) {
ApplicationContext mc = SpringApplication.run( MainClass.class, args );
}
}
For Spring based test, we need the SpringJUnit4ClassRunner so application context is created.
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = MainClass.class)
#WebAppConfiguration
#SpringBootTest(webEnvironment=SpringBootTest.WebEnvironment.NONE)
public class BaseSpecification extends Specification {
}
and also add
compile("org.springframework.boot:spring-boot-starter-tomcat")

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration

I am trying to write a standalone executable jar (fat jar) . I am using spring boot gradle plugin and writing a SpringBoot App to do this.
Here is my Application.java file
#Configuration
#EnableAutoConfiguration
#EnableRabbit
#EntityScan("persistence.domain")
#EnableJpaRepositories("persistence.repository")
#ComponentScan(basePackages = {"common","service"})
public class Application {
public static void main(final String[] args) {
final SpringApplicationBuilder appBuilder = new SpringApplicationBuilder(
Application.class);
appBuilder.profiles("common", "common_db").run(args);
}
#Bean
#Primary
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().build();
}
}
I have specified properties in yml files. For ex application-common etc . While running Application.java I am getting error :
[2015-09-24 14:40:22.304] boot - 32791 INFO [main] ---AnnotationConfigEmbeddedWebApplicationContext: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#51a282af: startup date [Thu Sep 24 14:40:22 IST 2015]; root of context hierarchy
[2015-09-24 14:40:23.194] boot - 32791 WARN [main] --- AnnotationConfigEmbeddedWebApplicationContext: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: ; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:392)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:305)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:611)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
at storm.Application.main(Application.java:28)
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:58)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:190)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:435)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:389)
... 12 more
Caused by: java.lang.NullPointerException
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.getMatchOutcome(OnPropertyCondition.java:61)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45)
... 16 more
Here is my build.gradle
def projects= [
":common",
":persistence",
":adapter"
]
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies { classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: springBootVersion }
}
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
apply from: "${rootDir}/deployTasks.gradle"
springBoot {
mainClass = "storm.Application"
}
dependencies {
compile project(':common')
compile project(':adapter')
compile project(':persistence')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.1.8.RELEASE'
compile group : 'org.springframework.boot',name: 'spring-boot-autoconfigure', version : '1.1.8.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.1.8.RELEASE'
}
Database specification as in application-common_db.yml
database:
host: localhost
port: 3306
schema: subscriptions
username: root
password: root
autoconnect:
maxReconnects: 3
initialTimeout: 2
timeout:
connectTimeout: 0
socketTimeout: 0
failover:
host: localhost
port: 3306
queriesBeforeRetryMaster: 50
secondsBeforeRetryMaster: 30
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://${database.host}:${database.port},${database.failover.host}:${database.failover.port}/${database.schema}?${database.properties}
username: ${database.username}
password: ${database.password}
continueOnError: true
initialize: false
initialSize: 0
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
removeAbandonedTimeout: 60
removeAbandoned: true
minIdle: 0
I am not sure how to resolve this error . Can nybody suggest what is going wrong here and why am i getting nullPointerException.
Help is appreciated .
Thanks
This is caused by non-matching Spring Boot dependencies. Check your classpath to find the offending resources. You have explicitly included version 1.1.8.RELEASE, but you have also included 3 other projects. Those likely contain different Spring Boot versions, leading to this error.
I know this is quite an old one, but I faced similar issue and resolved it in a different way. The actuator-autoconfigure pom somehow was invalid and so it was throwing IllegalStateException. I removed the actuator* dependencies from my maven repo and did a Maven update in eclipse, which then downloaded the correct/valid dependencies and resolved my issue.
In my case I had created a SB app from the SB Initializer and had included a fair number of deps in it to other things. I went in and commented out the refs to them in the build.gradle file and so was left with:
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.hsqldb:hsqldb'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
as deps. Then my bare-bones SB app was able to build and get running successfully. As I go to try to do things that may need those commented-out libs I will add them back and see what breaks.
This error is because of multiple projects having the offending resources.
Try out adding the dependencies projects another way around. (like in pom.xml or external dependencies)
I had the same its because of hibernate-core version issue when you remove the version so it resolve the problem you should try it.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
If it's a new project, make sure you remembered to add spring starter web dependency
I had the same its because of version incompatibility check for version or remove version if using spring boot

Resources