Spring Websocket: Error during WebSocket handshake: Unexpected response code: 404 - spring-websocket

I implemented my own Websocket application based on Spring framework and used the same configuration: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html
Server side code:
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
#Configuration
#EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
#Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
#Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").withSockJS();
}
}
client side code: *.jsp file
/*
*connect to websocket
*/
function connect() {
var socket = new SockJS("<c:url value='/ws'/>");
stompClient = Stomp.over(socket);
stompClient.connect();
}
function disconnect() {
stompClient.disconnect();
setConnected(false);
console.log("Disconnected");
}
pom.xml dependencies:
<!-- Spring websocket and messaging -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>${org.springframework.version}</version>
</dependency>
The application can run on Spring Tools Suite's Pivotal tc Server Developer Edition v3.0 (blinding with Tomcat8.0.15) or Tomcat7.0.53. However, when I deploy this application to server, the websocket is not working. The console shows:
stomp.min.js:8 Opening Web Socket...
sockjs.min.js:27 WebSocket connection to 'ws://serverip/ws/331/xsooi48g/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404
sockjs.min.js:27 POST http://serverip/ws/331/1mg08452/xhr_streaming 500 (Internal Server Error)
sockjs.min.js:27 POST http://serverip/ws/331/mmodvswk/xhr 500 (Internal Server Error)
stomp.min.js:8 Whoops! Lost connection to undefined
Did I miss something else?
UPDATE:
Tomcat version 7.0.52.0
Server side log:
WARN : org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService - Failed to create a default WebSocketTransportHandler
java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found
at org.springframework.web.socket.server.support.DefaultHandshakeHandler.initRequestUpgradeStrategy(DefaultHandshakeHandler.java:127)
at org.springframework.web.socket.server.support.DefaultHandshakeHandler.<init>(DefaultHandshakeHandler.java:96)
at org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService.getDefaultTransportHandlers(DefaultSockJsService.java:88)
at org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService.<init>(DefaultSockJsService.java:74)
at org.springframework.web.socket.config.annotation.SockJsServiceRegistration.createSockJsService(SockJsServiceRegistration.java:286)
at org.springframework.web.socket.config.annotation.SockJsServiceRegistration.getSockJsService(SockJsServiceRegistration.java:244)
at org.springframework.web.socket.config.annotation.WebMvcStompWebSocketEndpointRegistration$StompSockJsServiceRegistration.getSockJsService(WebMvcStompWebSocketEndpointRegistration.java:161)
at org.springframework.web.socket.config.annotation.WebMvcStompWebSocketEndpointRegistration.getMappings(WebMvcStompWebSocketEndpointRegistration.java:127)
at org.springframework.web.socket.config.annotation.WebMvcStompEndpointRegistry.getHandlerMapping(WebMvcStompEndpointRegistry.java:142)
at org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport.stompWebSocketHandlerMapping(WebSocketMessageBrokerConfigurationSupport.java:59)
at org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration$$EnhancerBySpringCGLIB$$4b464c58.CGLIB$stompWebSocketHandlerMapping$9(<generated>)
at org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration$$EnhancerBySpringCGLIB$$4b464c58$$FastClassBySpringCGLIB$$59d52b8d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration$$EnhancerBySpringCGLIB$$4b464c58.stompWebSocketHandlerMapping(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1229)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/ws/**] onto handler of type [class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]
INFO : org.springframework.context.support.DefaultLifecycleProcessor - Starting beans in phase 2147483647

After a week trying to solve the same error with no solution on the net, I manage to solve it.
Firstly, change this:
registry.addEndpoint("/ws").withSockJS();
to this :
registry.addEndpoint("/ws")
.setHandshakeHandler(new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy()))
.withSockJS();
This makes Tomcat accept websocket protocols as it could upgrade the HTTP protocol.
Maybe you are using Apache as I do, so you need to enable proxy and wstunnel modules, so you should run this commands on terminal:
$ sudo a2enmod proxy
$ sudo service apache2 restart
$ sudo a2enmod proxy_wstunnel
$ sudo service apache2 restart
You should upgrade your tomcat too

Related

Quarkus gRPC client injection

I'm trying to inject my grpc service via #GrpcClient as it is written in the documentation and have runtime NullPointerException when I call an endpoint on my client microservice because "Unsatisfied dependency: no bean matches the injection point". If I instantiate mutiny stub and channel manually it works as expected. With mvn compile and quarkus.generate-code.grpc.scan-for-imports=all I have done, so generated classes and interfaces exist in target.generated-sources.grpc.<package-name> path.
Data client
class PlatformDataClientImpl {
// #Inject with this does not work as well
#GrpcClient("baz")
GrpcPlatform baz;
public Uni<List<Platform>> getAllPlatforms() {
return baz
.getAllPlatforms(PlatformProto.GetAllRequest.newBuilder().build())
.onItem()
.transform(platformResponse -> platformResponse
.getPlatformList()
.stream()
.map(this::transformPlatform)
.collect(Collectors.toList())
);
}
}
Traceback
2022-07-09 14:03:25,390 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (vert.x-eventloop-thread-1) Request failed: java.lang.NullPointerException: Cannot invoke "com.kahnwald.command.GrpcPlatform.getAllPlatforms(com.kahnwald.command.PlatformProto$GetAllRequest)" because "this.baz" is null
at com.kahnwald.command.data.clients.PlatformDataClientImpl.getAllPlatforms(PlatformDataClientImpl.java:21)
at com.kahnwald.command.ExampleResource.gTest(ExampleResource.java:28)
at com.kahnwald.command.ExampleResource_Subclass.gTest$$superforward1(Unknown Source)
at com.kahnwald.command.ExampleResource_Subclass$$function$$1.apply(Unknown Source)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
at com.kahnwald.command.ExampleResource_Subclass.gTest(Unknown Source)
at com.kahnwald.command.ExampleResource$quarkusrestinvoker$gTest_3bdd2c95d9fa1dda6e9fab2c52cbe4fe8e995401.invoke(Unknown Source)
at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108)
at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:49)
at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:17)
at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:7)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1212)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:163)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)
at io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:83)
at io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:67)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1212)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:126)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)
at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:274)
at io.vertx.core.impl.future.FutureImpl$3.onSuccess(FutureImpl.java:141)
at io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:54)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:503)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Could anybody describe what I missed or do wrong? Do I need to implement services on client side or something?
Quarkus version: 2.9.2.Final

Spring Boot - java.lang.ClassNotFoundException: javax.servlet.ServletContext and Unable to start EmbeddedWebApplicationContext

I have a Spring Boot application (Grails 3.1.8), but when I run the application in IntelliJ IDEA I get the following error:
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:292)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:510)
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152)
... 29 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 common frames omitted
I tried adding javax-servlet-api dependency as suggested in an answer to Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext
But then I started getting:
ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
at grails.boot.GrailsApp.run(GrailsApp.groovy:374)
at grails.boot.GrailsApp.run(GrailsApp.groovy:363)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at closemytab.Application.main(Application.groovy:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
... 18 common frames omitted
This post then suggests to remove the javax-servlet-api: Spring boot -- Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
But then I face the original issue.
Any thoughts?
The issue was with the build.gradle file:
provided "org.springframework.boot:spring-boot-starter-tomcat"
IntelliJ IDEA wasn't happy with the provided.
As soon as I switched to
compile "org.springframework.boot:spring-boot-starter-tomcat"
the application worked.
Run with a Maven Spring Boot goal:
spring-boot:run
Steps to set up Maven configuration in IntelliJ IDEA:
Menu Debug/Run Configuration → Click on the + button visible at the top left → Select Maven → Set command line to spring-boot:run.
If you are using IntelliJ IDEA, you need to enable ' Include dependencies with "Provider" scope in menu Run → Edit Configurations → Application → 'your main class' (by default it's disabled)
Adding the dependency below fixed my issue:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Remember to have a parent dependency as well!
For me, it's because of the Tomcat version. I changed Tomcat version from 7.5 to 8.5, and the problem's solved.
Exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext only means you are not providing the Tomcat dependency to your application. In case you are using IntelliJ IDEA, it’s really simple to do that as shown below.
Select your project → open the Maven panel (it mostly resides on the top right side of the panel) → select embedded.

Grails 3.0.9 and Spring Security

I add Spring Security to Grails 3.0.9 and use Spring Security.
compile 'org.grails.plugins:spring-security-core:3.0.0.M1'
compile 'org.springframework.security:spring-security-core:3.2.9.RELEASE'
compile 'org.springframework.security:spring-security-web:3.2.9.RELEASE'
And I run application and I have this errors:
ERROR org.springframework.boot.context.embedded.tomcat.TomcatStarter - Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
ERROR grails.boot.GrailsApp - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
at grails.boot.GrailsApp.run(GrailsApp.groovy:52) [grails-core-3.0.9.jar:3.0.9]
at grails.boot.GrailsApp.run(GrailsApp.groovy:330) [grails-core-3.0.9.jar:3.0.9]
at grails.boot.GrailsApp.run(GrailsApp.groovy:319) [grails-core-3.0.9.jar:3.0.9]
at grails.boot.GrailsApp$run.call(Unknown Source) [grails-core-3.0.9.jar:3.0.9]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-2.4.5.jar:2.4.5]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-2.4.5.jar:2.4.5]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) [groovy-2.4.5.jar:2.4.5]
at up2you2.Application.main(Application.groovy:8) [main/:na]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:98) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:75) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
(...)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
When I deactive Spring Security this is project run.
Please help me.
Adibak

spring-boot does not honour #EntityScan in multimodule gradle build using GORM

I have a multimodule gradle build, using spring-boot and standalone GORM.
The domain entities are located in a separate submodule, so that these domain objects and gorm can be used across several spring-boot (and non-spring-boot) applications.
Structure
build.gradle
- module1-with-springboot-jersey (depending on module 3)
-- src/main/groovy/geit/api/Application.groovy
- module2-with-springboot-groovytemplate (depending on module 3)
- module3-standalone-gorm-with-entities
-- src/main/groovy/geit/domain/../Animal.groovy
- module4-apache-camel-app (depending on module 3)
When running gradle bootRun in module1, the jersey app, it starts the application, however when trying to access a rest resource returning an Animal, it fails with a stacktrace:
2014-11-03 13:16:03.679 ERROR 44316 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/api].[jerseyServlet] : Servlet.service() for servlet [jerseyServlet] in context with path [/api] threw exception [java.lang.IllegalStateException: Method on class [geit.domain.entity.experimental.reku.Animal] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.] with root cause
java.lang.IllegalStateException: Method on class [geit.domain.entity.experimental.reku.Animal] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
at geit.domain.entity.experimental.reku.Animal.currentGormStaticApi(Animal.groovy)
at geit.domain.entity.experimental.reku.Animal.$static_methodMissing(Animal.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1493)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1481)
at groovy.lang.ExpandoMetaClass.invokeStaticMethod(ExpandoMetaClass.java:1123)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at geit.api.experimental.reku.AnimalsResource.greet(AnimalsResource.groovy:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
un.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:195)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:406)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:350)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:320)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
at org.glassfish.jersey.servlet.WebComponent.servComponent.java:373)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:219)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:280)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:98)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
g.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration$MetricsFilter.doFilterInternal(MetricFilterAutoConfiguration.java:90)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:744)
So I read up on the documentation, and find this
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-separate-entity-definitions-from-spring-configuration
Hmm.. #EntityScan looks promising
So I annotate my Application class, like this
#ComponentScan
#EnableAutoConfiguration(exclude = GroovyTemplateAutoConfiguration.class)
#EntityScan(basePackageClasses=Animal)
class ApiApplication {
static void main(String[] args) {
SpringApplication.run ApiApplication, args
}
}
But now, the gradle bootRun fails at startup
2014-11-03 13:20:43.790 INFO 44376 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug)
2014-11-03 13:20:43.797 ERROR 44376 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.IllegalStateException: Unable to configure LocalContainerEntityManagerFactoryBean from #EntityScan, ensure an appropriate bean is registered.
at org.springframework.util.Assert.state(Assert.java:385)
at org.springframework.boot.orm.jpa.EntityScanRegistrar$EntityScanBeanPostProcessor.onApplicationEvent(EntityScanRegistrar.java:124)
at org.springframework.boot.orm.jpa.EntityScanRegistrar$EntityScanBeanPostProcessor.onApplicationEvent(EntityScanRegistrar.java:94)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:692)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:962)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:951)
at org.springframework.boot.SpringApplication$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
g.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at geit.api.ApiApplication.main(ApiApplication.groovy:31)
2014-11-03 13:20:43.798 INFO 44376 --- [ main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4c85ba73: startup date [Mon Nov 03 13:20:35 CET 2014]; root of context hierarchy
2014-11-03 13:20:43.801 INFO 44376 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2014-11-03 13:20:43.806 INFO 44376 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Unregistering JMX-exposed beans on shutdown
2014-11-03 13:20:43.806 INFO 44376 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Unregistering JMX-exposed beans
2014-11-03 13:20:43.807 INFO 44376 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Exception in thread "main" java.lang.IllegalStateException: Unable to configure LocalContainerEntityManagerFactoryBean from #EntityScan, ensure an appropriate bean is registered.
at org.springframework.util.Assert.state(Assert.java:385)
at org.springframework.boot.orm.jpa.EntityScanRegistrar$EntityScanBeanPostProcessor.onApplicationEvent(EntityScanRegistrar.java:124)
at org.springframework.boot.orm.jpa.EntityScanRegistrar$EntityScanBeanPostProcessor.onApplicationEvent(EntityScanRegistrar.java:94)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:692)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:962)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:951)
at org.springframework.boot.SpringApplication$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at geit.api.ApiApplication.main(ApiApplication.groovy:31)
:api:bootRun FAILED
FAILURE: Build failed with an exception.
I've also tried with
#EntityScan(basePackages = "geit.domain") to trigger scanning from a package higher in the hierarchy, but this gives the same error
But, if I move the domain/entity classes into the (jersey) application module, then it works. This however, prevents me from using gorm in more than one application.
Which is something we need to achieve, so that module 1,2 and 4 above can use the standalone gorm module
Is this a missing feature or bug?
:)
PS.
When moving the Application class to the top-level package, then it works ok!
That is, from package /geit/api/Application.groovy to /geit/Application.groovy
All submodules have the same toplevel package name, so maybe that is why it works?
It still puzzles my though
The question left unanswered. Our solution is to convert from GORM to spring-data/jpa.
I found a sort of hack way to do this.
Even if we're doing standalone GORM + Spring boot, GORM still gets an instance of a GrailsApplication.
So hook a bean post processor to the application. When it's turn to process sessionFactory, fetch the underlying grailsApplication and register your Groovy domain classes as domain class artifacts.
Here
#Component
class GrailsApplicationPostProcessor implements BeanPostProcessor {
public static final String DEFAULT_SESSION_FACTORY_BEAN_NAME = "sessionFactory"
public static final Class [] domainClasses = [
Client.class, Feature.class, User.class
]
#Override
Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (DEFAULT_SESSION_FACTORY_BEAN_NAME.compareTo(beanName) == 0) {
if (bean instanceof ConfigurableLocalSessionFactoryBean) {
ConfigurableLocalSessionFactoryBean sf = (ConfigurableLocalSessionFactoryBean) bean
GrailsApplication ga = sf.grailsApplication
String domainClassType = DomainClassArtefactHandler.TYPE
for (Class c in domainClasses) {
ga.addArtefact(domainClassType, c)
}
}
}
bean
}
#Override
Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
bean
}
}
Another solution would be to try and package the domains classes as a Grails binary plugin, and load the plugin (and therefore its bundled resources) in this post processing method. Hope this helps.

Error performing resource injection on glassfish

This is my problem:
I'm learning Java EE development and I wanted to build up a WebApplication using Ejb. First of all I tried developing on the same machine, creating a EJB module on a glassfish domain and accessing it through a web application running on the same machine but on different domain: all worked fine. I was able, using glassfish 3.1, to access to the EJBmodule from the webapp thanks to the definition of glassfish-web.xml in my WEB-ING folder:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
<ejb-ref>
<ejb-ref-name>ejb/FirstBeanRemote</ejb-ref-name>
<jndi-name>corbaname:iiop:127.0.0.1:3700#java:global/EJBModule/FirstBean!ejb.FirstBeanRemote</jndi-name>
</ejb-ref>
</glassfish-web-app>
After this, I wanted to change experiment, using different machines for the ejb module and the webapp. First of all I installed on a debian machine glassfish 3.1 and deployed my module including the required interfaces. No errors returned in the deploying so I proceeded starting the domain and again all seems to work fine. In server.log I copied the portable jndi names for my EJB FirstBean:
Portable JNDI names for EJB FirstBean: [java:global/EJBModule/FirstBean, java:global/EJBModule/FirstBean!ejb.FirstBeanRemote]
So now on another machine using Netbeans ( under windows 7 ) I created the same webapp as the previous one just changing the glassfish-web.xml in this way:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
<ejb-ref>
<ejb-ref-name>ejb/FirstBeanRemote</ejb-ref-name>
<jndi-name>corbaname:iiop:192.168.1.110:3700#java:global/EJBModule/FirstBean!ejb.FirstBeanRemote</jndi-name>
</ejb-ref>
</glassfish-web-app>
I'm sure about Ip(static in my lan) and port (I create a default domain on glassfish).
The problem comes now. When I start the webapplication I get the error:
com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean prova
at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:211)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:103)
at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Eccezione durante il tentativo di inserire Remote ejb-ref name=ejb/FirstBeanRemote,Remote 3.x interface =ejb.FirstBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=corbaname:iiop:192.168.1.110:3700#java:global/EJBModule123/FirstBean!ejb.FirstBeanRemote,refType=Session in class ciao.Prova: Lookup failed for 'java:comp/env/ejb/FirstBeanRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:194)
at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:205)
... 51 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Eccezione durante il tentativo di inserire Remote ejb-ref name=ejb/FirstBeanRemote,Remote 3.x interface =ejb.FirstBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=corbaname:iiop:192.168.1.110:3700#java:global/EJBModule123/FirstBean!ejb.FirstBeanRemote,refType=Session in class ciao.Prova: Lookup failed for 'java:comp/env/ejb/FirstBeanRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:703)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:184)
... 52 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/ejb/FirstBeanRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=ejb/FirstBeanRemote,Remote 3.x interface =ejb.FirstBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=corbaname:iiop:192.168.1.110:3700#java:global/EJBModule123/FirstBean!ejb.FirstBeanRemote,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'corbaname:iiop:192.168.1.110:3700#java:global/EJBModule123/FirstBean__3_x_Internal_RemoteBusinessHome__' [Root exception is org.omg.CORBA.BAD_PARAM: Buono: IOP00100009: string_to_object conversion failed due to bad schema specific part in name java:global/EJBModule123/FirstBean__3_x_Internal_RemoteBusinessHome__ vmcid: SUN minor code: 9 completed: No]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
... 55 more
Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=ejb/FirstBeanRemote,Remote 3.x interface =ejb.FirstBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=corbaname:iiop:192.168.1.110:3700#java:global/EJBModule123/FirstBean!ejb.FirstBeanRemote,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'corbaname:iiop:192.168.1.110:3700#java:global/EJBModule123/FirstBean__3_x_Internal_RemoteBusinessHome__' [Root exception is org.omg.CORBA.BAD_PARAM: Buono: IOP00100009: string_to_object conversion failed due to bad schema specific part in name java:global/EJBModule123/FirstBean__3_x_Internal_RemoteBusinessHome__ vmcid: SUN minor code: 9 completed: No]
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:191)
at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1109)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:169)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
... 59 more
Caused by: org.omg.CORBA.BAD_PARAM: Buono: IOP00100009: string_to_object conversion failed due to bad schema specific part in name java:global/EJBModule123/FirstBean__3_x_Internal_RemoteBusinessHome__ vmcid: SUN minor code: 9 completed: No
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)
at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99)
at $Proxy151.soBadSchemaSpecific(Unknown Source)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.resolveCorbaname(INSURLOperationImpl.java:227)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.resolveINSURL(INSURLOperationImpl.java:154)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.operate(INSURLOperationImpl.java:145)
at com.sun.corba.ee.impl.orb.ORBImpl.string_to_object(ORBImpl.java:976)
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:184)
... 64 more
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
at org.omg.CosNaming._NamingContextExtStub.resolve_str(_NamingContextExtStub.java:165)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.resolveCorbaname(INSURLOperationImpl.java:222)
... 68 more
It seems to me a jndi problem, infact in the exception list I can read "Lookup failed for 'java:comp/env/ejb/FirstBeanRemote', so the webapp is not even able to access to the EJBModule. But I'm wondering why, since I'm using the portable jndi provided me by the glassfish server itself!
I hope I was clear and someone can help me.
Max

Resources