Issue with querying data with NativeSearchQuery from Elasticsearch - spring-boot

I'm new to Spring Elasticsearch and trying to build native query, however, I get following error message ;
2023-01-23T21:54:56.127+03:00 ERROR 46803 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.IllegalArgumentException: unhandled Query implementation
org.springframework.data.elasticsearch.client.erhlc.NativeSearchQuery] with root cause
I created two "BoolQueryBuilder" objects like below, My goal is to retrieve records with value "winlog.event_data.Status" equal to 0x18 or 0xC000006A and value of "winlog.event_data.TargetUserName" is USER001.
BoolQueryBuilder errorQuery = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("winlog.event_data.Status","0x18"))
.should(QueryBuilders.matchQuery("winlog.event_data.Status","0xC000006A"));
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("winlog.event_data.TargetUserName","USER001"))
.must(errorQuery);
Finally, when I run the queries as follows, I get the error I mentioned at the beginning of the topic.
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).build();
System.out.println(searchQuery.getQuery());
List<SearchHit<Winlog>> articles = elasticsearchOperations
.search(searchQuery, Winlog.class, IndexCoordinates.of("winlog"))
.getSearchHits();
but if I print the query with the following output and use this query directly in the ElasticsearchRepository interface, it works without any problems.
System.out.println(searchQuery.getQuery());
so i couldn't understand the problem.
#Repository
public interface WinlogRepository extends ElasticsearchRepository<Winlog,String> {
#Query("{\n" +
" \"bool\" : {\n" +
" \"must\" : [\n" +
" {\n" +
" \"match\" : {\n" +
" \"winlog.event_data.TargetUserName\" : {\n" +
" \"query\" : \"?0\",\n" +
" \"operator\" : \"OR\",\n" +
" \"prefix_length\" : 0,\n" +
" \"max_expansions\" : 50,\n" +
" \"fuzzy_transpositions\" : true,\n" +
" \"lenient\" : false,\n" +
" \"zero_terms_query\" : \"NONE\",\n" +
" \"auto_generate_synonyms_phrase_query\" : true,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
" }\n" +
" },\n" +
" {\n" +
" \"bool\" : {\n" +
" \"should\" : [\n" +
" {\n" +
" \"match\" : {\n" +
" \"winlog.event_data.Status\" : {\n" +
" \"query\" : \"0x18\",\n" +
" \"operator\" : \"OR\",\n" +
" \"prefix_length\" : 0,\n" +
" \"max_expansions\" : 50,\n" +
" \"fuzzy_transpositions\" : true,\n" +
" \"lenient\" : false,\n" +
" \"zero_terms_query\" : \"NONE\",\n" +
" \"auto_generate_synonyms_phrase_query\" : true,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
" }\n" +
" },\n" +
" {\n" +
" \"match\" : {\n" +
" \"winlog.event_data.Status\" : {\n" +
" \"query\" : \"0xC000006A\",\n" +
" \"operator\" : \"OR\",\n" +
" \"prefix_length\" : 0,\n" +
" \"max_expansions\" : 50,\n" +
" \"fuzzy_transpositions\" : true,\n" +
" \"lenient\" : false,\n" +
" \"zero_terms_query\" : \"NONE\",\n" +
" \"auto_generate_synonyms_phrase_query\" : true,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"adjust_pure_negative\" : true,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"adjust_pure_negative\" : true,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}\n")
Page<Winlog> getAll(String name,Pageable pageable);
}
I couldn't understand why I'm getting error with "NativeSearchQuery".
stacktrace of error ;
2023-01-23T21:54:56.127+03:00 ERROR 46803 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.IllegalArgumentException: unhandled Query implementation org.springframework.data.elasticsearch.client.erhlc.NativeSearchQuery] with root cause
java.lang.IllegalArgumentException: unhandled Query implementation org.springframework.data.elasticsearch.client.erhlc.NativeSearchQuery
at org.springframework.data.elasticsearch.client.elc.RequestConverter.getQuery(RequestConverter.java:1488) ~[spring-data-elasticsearch-5.0.1.jar:5.0.1]
at org.springframework.data.elasticsearch.client.elc.RequestConverter.searchRequest(RequestConverter.java:1059) ~[spring-data-elasticsearch-5.0.1.jar:5.0.1]
at org.springframework.data.elasticsearch.client.elc.RequestConverter.searchRequest(RequestConverter.java:1041) ~[spring-data-elasticsearch-5.0.1.jar:5.0.1]
at org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate.search(ElasticsearchTemplate.java:322) ~[spring-data-elasticsearch-5.0.1.jar:5.0.1]
at com.test.lab.adldapels.controller.main.retrieve(main.java:51) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:207) ~[spring-web-6.0.4.jar:6.0.4]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:152) ~[spring-web-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:884) ~[spring-webmvc-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1080) ~[spring-webmvc-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:973) ~[spring-webmvc-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1011) ~[spring-webmvc-6.0.4.jar:6.0.4]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) ~[spring-webmvc-6.0.4.jar:6.0.4]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:705) ~[tomcat-embed-core-10.1.5.jar:6.0]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) ~[spring-webmvc-6.0.4.jar:6.0.4]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:814) ~[tomcat-embed-core-10.1.5.jar:6.0]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-10.1.5.jar:10.1.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.0.4.jar:6.0.4]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.4.jar:6.0.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.0.4.jar:6.0.4]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.4.jar:6.0.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.0.4.jar:6.0.4]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.4.jar:6.0.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-10.1.5.jar:10.1.5]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
pom.xml;
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test.lab.adldapels</groupId>
<artifactId>adldap-els</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>adldap-els</name>
<description>adldap-els</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.17.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

java.lang.IllegalArgumentException: unhandled Query implementation org.springframework.data.elasticsearch.client.erhlc.NativeSearchQuery
at org.springframework.data.elasticsearch.client.elc.RequestConverter.getQuery(RequestConverter.java:1488) ~[spring-data-elasticsearch-5.0.1.jar:5.0.1]
You are using Spring Boot 3 and so Spring Data Elasticsearch 5 which uses the new Elasticsearch client. You have to use the org.springframework.data.elasticsearch.client.elc.NativeQuery class for this.
The NativeSearchQuery class was from the old implementation that was based on the old deprecated RestHighLevelClient from Elasticsearch.
See the documentation:
When working with the NativeSearchQuery class, you’ll need to switch to the NativeQuery class, which can take a Query instance coming from the new Elasticsearch client libraries.

Related

Exception seen in Jersey Init, Spring Boot 3.0.1, Spring Boot Jersey Starter, GraalVM 22.3, Java 17 & 19

Attempting to get sample application on Spring Boot 3.0.1, Spring Boot Jersey Starter, GraalVM 22.3, Java 17 & 19. Maven Native Image creation is successful, executable starts, but on the first request to sample end point, there seems to be an error. So trying to figure out what could be missed to get this setup on Native Executable working.
Error Seen
➜ target ./nativedemo-bin
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.1)
2023-01-26T20:53:34.975+05:30 INFO 25349 --- [ main] c.e.nativedemo.NativedemoApplication : Starting AOT-processed NativedemoApplication using Java 19.0.1 with PID 25349 (/Volumes/data/experiments/nativedemo/target/nativedemo-bin started by demouser in /Volumes/data/experiments/nativedemo/target)
2023-01-26T20:53:34.975+05:30 INFO 25349 --- [ main] c.e.nativedemo.NativedemoApplication : No active profile set, falling back to 1 default profile: "default"
2023-01-26T20:53:34.987+05:30 INFO 25349 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-01-26T20:53:34.987+05:30 INFO 25349 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-01-26T20:53:34.987+05:30 INFO 25349 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.4]
2023-01-26T20:53:34.994+05:30 INFO 25349 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-01-26T20:53:34.994+05:30 INFO 25349 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 19 ms
2023-01-26T20:53:35.011+05:30 INFO 25349 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-01-26T20:53:35.011+05:30 INFO 25349 --- [ main] c.e.nativedemo.NativedemoApplication : Started NativedemoApplication in 0.052 seconds (process running for 0.13)
2023-01-26T20:53:43.807+05:30 ERROR 25349 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Servlet.init() for servlet [com.example.nativedemo.config.ApplicationConfig] threw exception
java.lang.ExceptionInInitializerError: null
at org.glassfish.jersey.server.internal.inject.FormParamValueParamProvider.<init>(FormParamValueParamProvider.java:82) ~[na:na]
at org.glassfish.jersey.server.internal.inject.ValueParamProviderConfigurator.init(ValueParamProviderConfigurator.java:90) ~[na:na]
at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$0(ApplicationHandler.java:307) ~[na:na]
at java.base#19.0.1/java.util.Arrays$ArrayList.forEach(Arrays.java:4204) ~[na:na]
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:307) ~[na:na]
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:274) ~[na:na]
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311) ~[na:na]
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154) ~[nativedemo-bin:na]
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:338) ~[nativedemo-bin:na]
at jakarta.servlet.GenericServlet.init(GenericServlet.java:158) ~[nativedemo-bin:6.0]
at jakarta.servlet.http.HttpServlet.init(HttpServlet.java:140) ~[nativedemo-bin:6.0]
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:992) ~[na:na]
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:695) ~[na:na]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:118) ~[na:na]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[na:na]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) ~[nativedemo-bin:10.1.4]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119) ~[na:na]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[nativedemo-bin:10.1.4]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[na:na]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[na:na]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400) ~[na:na]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[nativedemo-bin:10.1.4]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859) ~[na:na]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734) ~[na:na]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[nativedemo-bin:10.1.4]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[na:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[na:na]
at java.base#19.0.1/java.lang.Thread.run(Thread.java:1589) ~[nativedemo-bin:na]
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775) ~[nativedemo-bin:na]
at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203) ~[na:na]
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.glassfish.jersey.server.internal.inject.FormParamValueParamProvider$MultipartFormParamValueProvider.<clinit>(FormParamValueParamProvider.java:239) ~[na:na]
... 31 common frames omitted
2023-01-26T20:53:43.818+05:30 ERROR 25349 --- [nio-8080-exec-2] a.c.c.C.[.[.[.[.e.n.c.ApplicationConfig] : Allocate exception for servlet [com.example.nativedemo.config.ApplicationConfig]
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.glassfish.jersey.server.internal.inject.FormParamValueParamProvider$MultipartFormParamValueProvider.<clinit>(FormParamValueParamProvider.java:239) ~[na:na]
at org.glassfish.jersey.server.internal.inject.FormParamValueParamProvider.<init>(FormParamValueParamProvider.java:82) ~[na:na]
at org.glassfish.jersey.server.internal.inject.ValueParamProviderConfigurator.init(ValueParamProviderConfigurator.java:90) ~[na:na]
at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$0(ApplicationHandler.java:307) ~[na:na]
at java.base#19.0.1/java.util.Arrays$ArrayList.forEach(Arrays.java:4204) ~[na:na]
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:307) ~[na:na]
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:274) ~[na:na]
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311) ~[na:na]
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154) ~[nativedemo-bin:na]
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:338) ~[nativedemo-bin:na]
at jakarta.servlet.GenericServlet.init(GenericServlet.java:158) ~[nativedemo-bin:6.0]
at jakarta.servlet.http.HttpServlet.init(HttpServlet.java:140) ~[nativedemo-bin:6.0]
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:992) ~[na:na]
POM -
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>nativedemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>native-demo</name>
<packaging>jar</packaging>
<description>native-demo</description>
<properties>
<java.version>19</java.version>
<maven.test.skip>true</maven.test.skip>
<main.class>com.example.nativedemo.NativedemoApplication</main.class>
</properties>
<dependencyManagement>
<dependencies>
<dependency><!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>graalvm-reachability-metadata</artifactId>
<version>0.9.19</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>22.3.0</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<fallback>false</fallback>
<imageName>${project.artifactId}-bin</imageName>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
<requiredVersion>22.3</requiredVersion>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Jersey Config
package com.example.nativedemo.config;
import com.example.nativedemo.rest.Endpoints;
import jakarta.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;
#Component
#ApplicationPath("/demo")
public class ApplicationConfig extends ResourceConfig {
public ApplicationConfig(){
register(Endpoints.class);
}
}
Endpoint Class
package com.example.nativedemo.rest;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import org.springframework.stereotype.Component;
#Component
#Path("/api/v1")
public class Endpoints {
#GET
#Path("/health")
public String getHealth(){
return "Ok";
}
}
Spring Boot Main Class
package com.example.nativedemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class NativedemoApplication {
public static void main(String[] args) {
SpringApplication.run(NativedemoApplication.class, args);
}
}
I have tried options to pack the jar via maven plugins with respect to a normal jar, i.e without the BOOT-INF structure using the WAR layout and tried to build the native image out of it. Still with the same error.
Its quite a path to get the simple application on Spring Boot with GraalVM, yet with errors.
So my ask is, any settings is missed out to get the native image working, should there be any hints to graalvm inspite of using libraries which support the native image generation.
Found the issue, the solution was to run the spring boot jar with the following options
$JAVA_HOME/bin/java -agentlib:native-image-agent=config-output-dir=[output_location] -jar [app_name].jar
This generates reflect-config.json, resource-config.json and proxy-config.json.
Once generated these needs to be configured in the maven plugin.
<buildArg>-H:ResourceConfigurationFiles=target/classes/resource-config.json, -H:ReflectionConfigurationFiles=target/classes/reflect-config.json,-H:DynamicProxyConfigurationFiles=target/classes/proxy-config.json</buildArg>

Failed to execute CommandLineRunner - Spring security

Hi I am very new to Spring batch and I am getting the following exception which I am not able to resolve:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-01-23 18:55:43.965 ERROR 8576 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:771) ~[spring-boot-2.7.8.jar:2.7.8]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.8.jar:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-2.7.8.jar:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.8.jar:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.8.jar:2.7.8]
at com.akalanka.authsql.AuthSqlApplication.main(AuthSqlApplication.java:17) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.7.8.jar:2.7.8]
Caused by: java.lang.NullPointerException: Cannot invoke "com.akalanka.authsql.entity.User.getRoles()" because "user" is null
at com.akalanka.authsql.service.UserServiceImpl.addRoleToUser(UserServiceImpl.java:43) ~[classes/:na]
at com.akalanka.authsql.service.UserServiceImpl$$FastClassBySpringCGLIB$$8e8300.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.25.jar:5.3.25]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.25.jar:5.3.25]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.25.jar:5.3.25]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.25.jar:5.3.25]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.25.jar:5.3.25]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.25.jar:5.3.25]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.25.jar:5.3.25]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.25.jar:5.3.25]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.25.jar:5.3.25]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.25.jar:5.3.25]
at com.akalanka.authsql.service.UserServiceImpl$$EnhancerBySpringCGLIB$$301bb374.addRoleToUser(<generated>) ~[classes/:na]
at com.akalanka.authsql.AuthSqlApplication.lambda$run$0(AuthSqlApplication.java:33) ~[classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768) ~[spring-boot-2.7.8.jar:2.7.8]
... 10 common frames omitted
My code here, I have used CommandLineRunner to execute following code block.
#SpringBootApplication
public class AuthSqlApplication {
public static void main(String[] args) {
SpringApplication.run(AuthSqlApplication.class, args);
}
#Bean
CommandLineRunner run(UserService userService) {
return args -> {
userService.saveRole(new Role(null, "ROLE_USER"));
userService.saveRole(new Role(null, "ROLE_MANAGER"));
userService.saveRole(new Role(null, "ROLE_ADMIN"));
userService.saveRole(new Role(null, "ROLE_SUPER_ADMIN"));
userService.saveUser(new User(null, "John Travolta", "john", "1234", new ArrayList<>()));
userService.saveUser(new User(null, "Will Smith", "will", "1234", new ArrayList<>()));
userService.saveUser(new User(null, "Jim Carry", "jim", "1234", new ArrayList<>()));
userService.saveUser(new User(null, "Arnold Schwarzenegger", "arnold", "1234", new ArrayList<>()));
userService.addRoleToUser("john", "ROLE_USER");
userService.addRoleToUser("john", "ROLE_MANAGER");
userService.addRoleToUser("will", "ROLE_MANAGER");
userService.addRoleToUser("jim", "ROLE_ADMIN");
userService.addRoleToUser("arnold", "ROLE_SUPER_ADMIN");
userService.addRoleToUser("arnold", "ROLE_ADMIN");
userService.addRoleToUser("arnold", "ROLE_USER");
};
}
}
This is the xml file related to my scenario.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.akalanka</groupId>
<artifactId>auth-sql</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>auth-sql</name>
<description>Project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

Getting AJAX HTTP 500 in SpringMVC response

I am trying to get the list of users from Mongodb with ajax it works without ajax. I did this with MySQL and it worked so I don't understand what is wrong with my code.
I can send the request and go to the method and return the List<User>.
But when I put it in map can't get that map as a response in the success function.
My Console Output:
free.js:31 Uncaught TypeError: Cannot read property 'action' of null
at window.onmessage (free.js:31)
window.onmessage # free.js:31
jquery.min.js:2 POST http://localhost:8080/UserManagementMongoDB/list 500
send # jquery.min.js:2
ajax # jquery.min.js:2
load # submitedform:342
onload # submitedform:25
submitedform:355 Uncaught ReferenceError: response is not defined
at Object.error (submitedform:355)
at u (jquery.min.js:2)
at Object.fireWith [as rejectWith] (jquery.min.js:2)
at k (jquery.min.js:2)
at XMLHttpRequest.<anonymous> (jquery.min.js:2)
Here is my Controller method
#RequestMapping(value="/list", method=RequestMethod.POST)
public #ResponseBody Map<String,Object> getAll(User user) {
Map<String,Object> map = new HashMap<String,Object>();
List<User> list = mainPageService.getAllUsers();
if (list != null){
map.put("status","200");
map.put("message","Data found");
map.put("data", list);
}else{
map.put("status","404");
map.put("message","Data not found");
}
return map;
}
And my ajax load function
data = "";
load = function(){
$.ajax({
url:'list',
type:'POST',
success: function(response){
alert("Hello");
data = response.data;
$('.tr').remove();
for(i=0; i<response.data.length; i++){
$("#table").append("<tr class='tr'> <td> "+response.data[i].userName+" </td> <td> "+response.data[i].userSurname+" </td> <td> <a href='#' onclick= edit("+i+");> Edit </a> </td> </td> <td> <a href='#' onclick='delete_("+response.data[i].userId+");'> Delete </a> </td> </tr>");
}
},
error: function () {
alert(response);
}
});
Here is my dependencies
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>UserManagementMongoDB</groupId>
<artifactId>UserManagementMongoDB</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>UserManagementMongoDB Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Servlet Library -->
<!-- http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- Spring dependencies -->
<!-- http://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${spring.data.commons.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring.data.mongodb.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.tanesha.recaptcha4j/recaptcha4j -->
<dependency>
<groupId>net.tanesha.recaptcha4j</groupId>
<artifactId>recaptcha4j</artifactId>
<version>0.0.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish/javax.json -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.10</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.framework.version}</version>
</dependency>
</dependencies>
<!-- Properties for the dependencies -->
<properties>
<java-version>1.7</java-version>
<!-- Spring properties -->
<spring.framework.version>5.0.9.RELEASE</spring.framework.version>
<spring.data.commons.version>1.12.1.RELEASE</spring.data.commons.version>
<spring.data.mongodb.version>1.10.6.RELEASE</spring.data.mongodb.version>
<!-- Other properties -->
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
<junit.version>4.12</junit.version>
<jstl.version>1.2</jstl.version>
</properties>
<build>
<finalName>ExampleWebApplication</finalName>
</build>
</project>
I am getting 500 right now I just can't get the response everything other than that works. I can send my parameters with ajax just can't receive the map resources
My model code:
public class User {
#Id
private String userId;
private String userName;
private String userSurname;
private String phoneNo;
public User(String userId,String userName,String userSurname,String phoneNo) {
setUserId(userId);
setUserName(userName);
setUserSurname(userSurname);
setPhoneNo(phoneNo);
}
public User() {
// TODO Auto-generated constructor stub
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserSurname() {
return userSurname;
}
public void setUserSurname(String userSurname) {
this.userSurname = userSurname;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
My Stacktrace:
ava.lang.Exception
at com.kaan.springmvc.controller.MainPageController.getAll(MainPageController.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Blockquote
Do you separate the front end and back end?
If yes, it might be different server or port number and violate CORS. Please help to update more information.
The second point, your method require User object, but i don't any thing relative to it from ajax request?

CXF : Elasticsearch Java API

When using Elasticsearh Java API inside Servlet in Tomcat, getting "org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available"
I am trying to create a simple REST API using cxf.
It will do following work -
will read some records from Elasticsearch cluster(using https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html).
Return the return the result as Json.
When I heat the url = "http://localhost:8080/aee-services/sequence/?txID=5f64f331-63c9-485d-9018-6872b1cf5f91"
I am getting this
/sequence : txId = 5f64f331-63c9-485d-9018-6872b1cf5f91
no modules loaded
loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
loaded plugin [org.elasticsearch.transport.Netty3Plugin]
loaded plugin [org.elasticsearch.transport.Netty4Plugin]
19:09:09.147 [http-nio-8080-exec-4] DEBUG o.a.cxf.phase.PhaseInterceptorChain - Invoking handleFault on interceptor org.apache.cxf.interceptor.ServiceInvokerInterceptor#1464d94b
19:09:09.147 [http-nio-8080-exec-4] DEBUG o.a.cxf.phase.PhaseInterceptorChain - Invoking handleFault on interceptor org.apache.cxf.interceptor.OneWayProcessorInterceptor#168896e2
19:09:09.148 [http-nio-8080-exec-4] DEBUG o.a.cxf.phase.PhaseInterceptorChain - Invoking handleFault on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor#2494bbf9
19:09:09.148 [http-nio-8080-exec-4] DEBUG o.a.cxf.phase.PhaseInterceptorChain - Invoking handleFault on interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor#4e848932
19:09:09.164 [http-nio-8080-exec-4] WARN o.a.cxf.phase.PhaseInterceptorChain - Application {http://services.aee.onap.amdocs.com/}RestServer has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: None of the configured nodes are available: [{#transport#-1}{tIRObbGrQ3KLmv0v4OL4ag}{10.247.83.8}{10.247.83.8:9300}]
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:163) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:129) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:200) ~[cxf-rt-frontend-jaxrs-3.0.3.jar:3.0.3]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99) ~[cxf-rt-frontend-jaxrs-3.0.3.jar:3.0.3]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:197) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:290) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:214) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [servlet-api.jar:na]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) [cxf-rt-transports-http-3.0.3.jar:3.0.3]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.0.M22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.0.M22]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.0.M22]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.0.M22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.0.M22]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:9.0.0.M22]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.0.M22]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475) [catalina.jar:9.0.0.M22]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:9.0.0.M22]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [catalina.jar:9.0.0.M22]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:625) [catalina.jar:9.0.0.M22]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:9.0.0.M22]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [catalina.jar:9.0.0.M22]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498) [tomcat-coyote.jar:9.0.0.M22]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:9.0.0.M22]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796) [tomcat-coyote.jar:9.0.0.M22]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1372) [tomcat-coyote.jar:9.0.0.M22]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.0.M22]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_121]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.0.M22]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_121]
Caused by: org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{tIRObbGrQ3KLmv0v4OL4ag}{10.247.83.8}{10.247.83.8:9300}]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:363) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54) ~[elasticsearch-5.5.2.jar:5.5.2]
at org.openecomp.sequence.elastic.data.ElasticDataSourceRetriveRecords.getLogRecords(ElasticDataSourceRetriveRecords.java:43) ~[classes/:na]
at com.amdocs.onap.aee.services.RestServer.getSequenceById(RestServer.java:35) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_121]
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:181) ~[cxf-core-3.0.3.jar:3.0.3]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:97) ~[cxf-core-3.0.3.jar:3.0.3]
... 37 common frames omitted
19:09:09.170 [http-nio-8080-exec-4] DEBUG o.a.cxf.phase.PhaseInterceptorChain - Adding interceptor org.apache.cxf.interceptor.MessageSenderInterceptor#54b8545c to phase prepare-send
19:09:09.170 [http-nio-8080-exec-4] DEBUG o.a.cxf.phase.PhaseInterceptorChain - Adding interceptor org.apache.cxf.jaxrs.interceptor.JAXRSDefaultFaultOutInterceptor#28d9d97 to phase marshal
19:09:09.170 [http-nio-8080-exec-4] DEBUG o.a.cxf.phase.PhaseInterceptorChain - Chain org.apache.cxf.phase.PhaseInterceptorChain#48c00d4 was created. Current flow:
prepare-send [MessageSenderInterceptor]
marshal [JAXRSDefaultFaultOutInterceptor]
My
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>onap-aee-services</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/aeeserver-beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
-beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<jaxrs:server id="sequence" address="/">
<jaxrs:serviceBeans>
<bean class="com.aee.services.RestServer" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
</jaxrs:providers>
</jaxrs:server>
</beans>
And REST request handler class
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.openecomp.sequence.SequenceGenerator;
import org.openecomp.sequence.elastic.data.ElasticDataSourceRetriveRecords;
import org.openecomp.sequence.elastic.data.LogRecord;
import org.openecomp.sequence.impl.SequenceGeneratorImpl;
import org.openecomp.sequence.json.SequenceResponse;
public class RestServer {
#GET
#Path("/sequence")
#Produces(MediaType.APPLICATION_JSON)
public SequenceResponse getSequenceById(#QueryParam("txID") final String txId) {
System.out.println("\n\n\n\n/sequence : txId = " + txId + "\n\n\n\n");
org.elasticsearch.common.settings.Settings settings = Settings.builder().put("client.transport.sniff", true)
.put("cluster.name", "onap-cluster").build();
TransportClient client = null;
try {
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("10.247.83.8"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("10.247.83.8"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
// on shutdown
String[] mdcs = { "PartnerName", "Component", "loglevel", "Timestamp", "Thread", "LogType", "BeginTimestamp",
"EndTimestamp" };
String[] mdcsexclude = { "message", "#timestamp", "#version", "beat" };
SearchResponse response1 = client.prepareSearch("onaplogs*").addSort("Timestamp", SortOrder.ASC).setFrom(0)
.setSize(100).setQuery(QueryBuilders.matchQuery("RequestId", txId))
.setFetchSource(mdcs, mdcsexclude).execute().actionGet();
SearchHits hits = response1.getHits();
List<LogRecord> logs = new ArrayList<LogRecord>();
System.out.println(
"totalHits" + response1.getHits().getTotalHits() + "hitlenght" + response1.getHits().getHits().length);
SequenceResponse sequenceResponse = null;
return sequenceResponse;
}
}
pom.xm
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amdocs.onap.aee.services</groupId>
<artifactId>onap-aee-services</artifactId>
<version>0.0.1-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<properties>
<jackson.version>1.8.6</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Please correct me where I am wrong
Can we use Elasticsearch Java API inside Servlen Container?
Note when I am testing using J4Unit test case it is working fine.
Plz ensure that the cluster name you have provided in the transport client (onap-cluster) matches with the actual cluster name.
Also any reason for adding the same ip (10.247.83.8) twice?

java.lang.NullPointerException exception in my controller file (using Spring Hibernate Maven)

The problem happens when I run this part (#RequestMapping("/SearchStaff")) in my controller file. I can display my search form successfullt (the request mapping below SearchStaff).
The problem doesn't seemed to have anything to do with Hibernate. As I've commented the Hibernate stuff but I'm still getting it.
If I comment out this line
message = staffDAO.searchForStaff(search);
in my controller file, it goes through ok. But I don't see anything wrong with searchForStaff function. It's a very simple function that just returns the string "test" and run system.out.println("test").
Can you please help? thanks
But this is the error that I'm getting:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.NullPointerException
org.flinders.staffdirectory.controllers.SearchController.showSearchResults(SearchController.java:25)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
My spring-servlet xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="org.flinders.staffdirectory.controllers" />
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<tx:annotation-driven />
<bean
id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/spring.properties" />
<bean
id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean
id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="${hibernate.config}"
p:packagesToScan="org.flinders.staffdirectory"/>
<bean
id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"
p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView" />
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
p:definitions="/WEB-INF/tiles.xml" />
<bean
id="staffDAO"
class="org.flinders.staffdirectory.dao.StaffDAO"
p:sessionFactory-ref="sessionFactory" />
<!-- <bean
id="staffService"
class="org.flinders.staffdirectory.services.StaffServiceImpl"
p:staffDAO-ref="staffDAO" />-->
</beans>
This is my controller file
package org.flinders.staffdirectory.controllers;
import java.util.List;
//import org.flinders.staffdirectory.models.database.SearchResult;
import org.flinders.staffdirectory.models.misc.Search;
import org.flinders.staffdirectory.dao.StaffDAO;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class SearchController {
//#Autowired
private StaffDAO staffDAO;
private String message;
#RequestMapping("/SearchStaff")
public ModelAndView showSearchResults(#ModelAttribute Search search) {
//List<SearchResult> searchResults =
message = staffDAO.searchForStaff(search);
//System.out.println(search.getSurname());
return new ModelAndView("search/SearchForm", "Search", new Search());
//return new ModelAndView("search/SearchResults", "searchResults", searchResults);
}
#RequestMapping("/SearchForm")
public ModelAndView showSearchForm() {
return new ModelAndView("search/SearchForm", "search", new Search());
}
}
my dao class
package org.flinders.staffdirectory.dao;
import java.util.List;
import org.hibernate.SessionFactory;
//import org.springframework.beans.factory.annotation.Autowired;
import org.flinders.staffdirectory.models.database.SearchResult;
import org.flinders.staffdirectory.models.misc.Search;
public class StaffDAO {
//#Autowired
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public String searchForStaff(Search search) {
/*String SQL = "select distinct telsumm_id as id, telsumm_parent_id as parentId, telsumm_name_title as title, (case when substr(telsumm_surname, length(telsumm_surname) - 1, 1) = ',' then substr(telsumm_surname, 1, length(telsumm_surname) - 1) else telsumm_surname end) as surname, telsumm_preferred_name as firstname, nvl(telsumm_tele_number, '-') as telephoneNumber, nvl(telsumm_role, '-') as role, telsumm_display_department as department, lower(telsumm_entity_type) as entityType from teldirt.teld_summary where (telsumm_search_surname is not null) and not (nvl(telsumm_tele_directory,'xxx') IN ('N','S','D')) and not (telsumm_tele_number IS NULL AND telsumm_alias IS NULL) and (telsumm_alias_list = 'Y' OR (telsumm_tele_directory IN ('A','B'))) and ((nvl(telsumm_system_id_end,sysdate+1) > SYSDATE and telsumm_entity_type = 'P') or (telsumm_entity_type = 'N')) and (telsumm_search_department NOT like 'SPONSOR%')";
if (search.getSurname().length() > 0) {
SQL += " and (telsumm_search_surname like '" + search.getSurname().toUpperCase() + "%')";
}
if (search.getSurnameLike().length() > 0) {
SQL += " and (telsumm_search_soundex like soundex(('%" + search.getSurnameLike().toUpperCase() + "%'))";
}
if (search.getFirstname().length() > 0) {
SQL += " and (telsumm_search_preferred_name like '" + search.getFirstname().toUpperCase() + "%' or telsumm_search_first_name like '" + search.getFirstname() + "%')";
}
if (search.getTelephoneNumber().length() > 0) {
SQL += " and (telsumm_tele_number like '" + search.getTelephoneNumber() + "%')";
}
if (search.getDepartment().length() > 0) {
SQL += " and (telsumm_search_department like '" + search.getDepartment().toUpperCase() + "%')";
}
if (search.getRole().length() > 0) {
SQL += " and (telsumm_search_role like '" + search.getRole().toUpperCase() + "%')";
}
SQL += " order by surname, firstname";
List<Object[]> list = (List<Object[]>) sessionFactory.getCurrentSession().createQuery(SQL).list();
for(int j=0;j<list.size();j++){
Object [] obj= (Object[])list.get(j);
for(int i=0;i<obj.length;i++)
System.out.println(obj[i]);
}*/
System.out.println("test");
return "test";
}
}
my pom.xml
<project
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.flinders.staffdirectory</groupId>
<artifactId>directory-maven</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>directory-maven Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<org.springframework.version>3.1.3.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<finalName>directory-maven</finalName>
</build>
</project>
StaffDAO is null . Any reason why you commented out its autowiring.
Also I see private SessionFactory sessionFactory; Autowired is also commented. Please try removing those comments.
//#Autowired

Resources