prevent org.springframework.messaging.MessagingException print stack trace - java

i am currently writing a websocket project using spring boot. And i have a websocket authentication config as this:
#EnableWebSocketMessageBroker
#Order(Ordered.HIGHEST_PRECEDENCE + 99)
public class WebSocketAuthenticationConfig implements WebSocketMessageBrokerConfigurer {
#Override
public void configureClientInboundChannel(ChannelRegistration registration) {
registration.interceptors(new ChannelInterceptor() {
#Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (StompCommand.CONNECT.equals(accessor.getCommand())) {
List<String> authorization = accessor.getNativeHeader("X-Authorization");
if (authorization.size() > 0) {
if (authorization.get(0).equals("hack")) {
throw new MessagingException("Invalid token");
} else {
accessor.setUser(new StompPrincipal(authorization.get(0)));
}
}
}
return message;
}
});
}
}
as you can see, i throw a messagingException inside configureClientInboundChannel method.
The problem is this exception keep print stack trace in console like this:
org.springframework.messaging.MessagingException: Invalid token
at com.school.chatbox.config.WebSocketAuthenticationConfig$1.preSend(WebSocketAuthenticationConfig.java:36) ~[classes/:na]
at org.springframework.messaging.support.AbstractMessageChannel$ChannelInterceptorChain.applyPreSend(AbstractMessageChannel.java:178) ~[spring-messaging-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:132) ~[spring-messaging-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:122) ~[spring-messaging-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageFromClient(StompSubProtocolHandler.java:302) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:335) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.handler.WebSocketHandlerDecorator.handleMessage(WebSocketHandlerDecorator.java:75) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.handleMessage(LoggingWebSocketHandlerDecorator.java:56) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.handleMessage(ExceptionWebSocketHandlerDecorator.java:58) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateMessages(AbstractSockJsSession.java:384) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.handleMessage(WebSocketServerSockJsSession.java:195) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler.handleTextMessage(SockJsWebSocketHandler.java:93) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.handler.AbstractWebSocketHandler.handleMessage(AbstractWebSocketHandler.java:43) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.handleTextMessage(StandardWebSocketHandlerAdapter.java:114) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.access$000(StandardWebSocketHandlerAdapter.java:43) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:85) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:82) ~[spring-websocket-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:395) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
is there any solution for me to prevent the print stack trace. Thank you

Question is a bit old, but I faced the same problem and found a workaround.
After debugging, I noticed its the StompSubProtocolHandler who prints this stack trace on the console:
...
catch (Throwable ex) {
if (logger.isErrorEnabled()) {
logger.error("Failed to send client message to application via MessageChannel" +
" in session " + session.getId() + ". Sending STOMP ERROR to client.", ex);
}
handleError(session, ex, message);
}
...
So I just set the logging level of the class to OFF. Just put this on application.properties:
logging.level.org.springframework.web.socket.messaging.StompSubProtocolHandler=OFF
Note that this will hide ALL errors from StompSubProtocolHandler.
In my case this is not a problem because all of StompSubProtocolHandler's errors are connection problems caused by clients bad internet connection.

Related

BlindSSLFactory for secure LDAP Authentication bypass doesn't work on production

I've a strange problem I can't get over since days, so I gave up and decided to consult to knowledgeable stackoverflow members.
Which java version I use?
Amazon coretto 1.8.0_275
What I want to achieve?
In my application, user has to authenticate himself using secure ldap connection. After authentication from LDAP directory, user will be redirected to the his homepage. However, I want that the certification check should be bypassed during the connection to the ldap server over secure port.
What I did so far and what works?
From other posts, I found that I need to use BlindSSLFactory class to bypass the certification check and inject this class to properties during ldap query, I added this to my project and If I run the project from eclipse, everything works absolutely fine and certification check is bypassed and user logs in. Note that: In my java truststore i have no signed certification whatsoever.
What doesn't work?
If I compile the project, with an installer I created, and run it as an application(not from eclipse, rather from its own installer), I get the following error.
Note: I debug the following line and it prints true, as I set it before the project runs:
-Dcom.sun.jndi.ldap.object.disableEndpointIdentification:
javax.naming.CommunicationException: simple bind failed: 10.148.129.11:636
at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:219) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2897) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:347) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxFromUrl(LdapCtxFactory.java:225) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:189) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:243) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84) ~[na:1.8.0_275]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) ~[na:1.8.0_275]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313) ~[na:1.8.0_275]
at javax.naming.InitialContext.init(InitialContext.java:244) ~[na:1.8.0_275]
at javax.naming.InitialContext.<init>(InitialContext.java:216) ~[na:1.8.0_275]
at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:101) ~[na:1.8.0_275]
at com.ricoh.sdced.festo.pab.web.login.LdapAuthentication.createLoginSession(LdapAuthentication.java:78) [classes!/:na]
at com.ricoh.sdced.festo.pab.web.login.LdapAuthentication.startLoginSession(LdapAuthentication.java:43) [classes!/:na]
at com.ricoh.sdced.festo.pab.web.views.LoginView.performLogin(LoginView.java:54) [classes!/:na]
at com.ricoh.sdced.festo.pab.web.views.LoginView.lambda$createLoginLayout$565279a2$1(LoginView.java:47) [classes!/:na]
at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.component.ComponentEventBus.handleDomEvent(ComponentEventBus.java:373) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.component.ComponentEventBus.lambda$addDomTrigger$dd1b7957$1(ComponentEventBus.java:264) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.internal.nodefeature.ElementListenerMap.lambda$fireEvent$2(ElementListenerMap.java:441) ~[flow-server-2.1.5.jar!/:2.1.5]
at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_275]
at com.vaadin.flow.internal.nodefeature.ElementListenerMap.fireEvent(ElementListenerMap.java:441) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.communication.rpc.EventRpcHandler.handleNode(EventRpcHandler.java:59) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:64) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:402) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$1(ServerRpcHandler.java:383) ~[flow-server-2.1.5.jar!/:2.1.5]
at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_275]
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:383) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:318) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:89) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1540) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:247) ~[flow-server-2.1.5.jar!/:2.1.5]
at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:95) ~[vaadin-spring-12.1.2.jar!/:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.37.jar!/:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:352) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.springframework.web.servlet.mvc.ServletForwardingController.handleRequestInternal(ServletForwardingController.java:141) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:177) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) ~[tomcat-embed-core-9.0.37.jar!/:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.37.jar!/:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93) ~[spring-boot-actuator-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_275]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_275]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.37.jar!/:9.0.37]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_275]
Caused by: java.net.SocketException: Connection or outbound has closed
at sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:967) ~[na:1.8.0_275]
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[na:1.8.0_275]
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) ~[na:1.8.0_275]
at com.sun.jndi.ldap.Connection.writeRequest(Connection.java:448) ~[na:1.8.0_275]
at com.sun.jndi.ldap.Connection.writeRequest(Connection.java:421) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapClient.ldapBind(LdapClient.java:359) ~[na:1.8.0_275]
at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:214) ~[na:1.8.0_275]
... 88 common frames omitted
How is my logic in the code?
public class BlindSSLSocketFactory extends SocketFactory {
private static SocketFactory blindFactory = null;
/**
* Builds an ALL trusting "blind" ssl socket factory.
*/
static {
// create a trust manager that will purposefully fall down on the
// job
TrustManager[] blindTrustMan = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] c, String a) {
}
public void checkServerTrusted(X509Certificate[] c, String a) {
}
} };
// create our "blind" ssl socket factory with our lazy trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, blindTrustMan, new java.security.SecureRandom());
blindFactory = sc.getSocketFactory();
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
}
/**
* #see javax.net.SocketFactory#getDefault()
*/
public static SocketFactory getDefault() {
return new BlindSSLSocketFactory();
}
/**
* #see javax.net.SocketFactory#createSocket(java.lang.String, int)
*/
public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException {
return blindFactory.createSocket(arg0, arg1);
}
/**
* #see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
*/
public Socket createSocket(InetAddress arg0, int arg1) throws IOException {
return blindFactory.createSocket(arg0, arg1);
}
/**
* #see javax.net.SocketFactory#createSocket(java.lang.String, int,
* java.net.InetAddress, int)
*/
public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3)
throws IOException, UnknownHostException {
return blindFactory.createSocket(arg0, arg1, arg2, arg3);
}
/**
* #see javax.net.SocketFactory#createSocket(java.net.InetAddress, int,
* java.net.InetAddress, int)
*/
public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException {
return blindFactory.createSocket(arg0, arg1, arg2, arg3);
}
}
And my LDAP login class where I inject this blindSSLFactory Class
#Component
public class LdapAuthentication {
private final Logger logger = LoggerFactory.getLogger(getClass());
private String username;
private String password;
private boolean isLoggedIn;
public LdapAuthentication() {
}
public void startLoginSession(String username, String password)
throws NamingException {
logger.info("preparing user login details...");
this.username = username;
this.password = password;
logger.info("user login will be attempted for user: " + this.username);
this.isLoggedIn = createLoginSession(this.username, this.password);
logger.info("login attempt success result: " + this.isLoggedIn);
}
private boolean createLoginSession(String username, String password)
throws NamingException {
logger.info("creating a LDAP Authentication session...");
logger.info("System property value for -Dcom.sun.jndi.ldap.object.disableEndpointIdentification:"
+ System.getProperty("com.sun.jndi.ldap.object.disableEndpointIdentification"));
String ldapServerUrl = buildLdapPrefix()
+ SettingsResolver.getInstance().getSetting(
"ldap.server.address")
+ ":"
+ SettingsResolver.getInstance().getSetting(
"ldap.server.port.number");
logger.info("LDAP authentication URL: " + ldapServerUrl);
Properties props = new Properties();
//use this line if you wanna discard ssl certificate validation
props.put("java.naming.ldap.factory.socket",
BlindSSLSocketFactory.class.getName());
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, ldapServerUrl);
props.put(Context.SECURITY_PRINCIPAL, username);
props.put(Context.SECURITY_CREDENTIALS, password);
InitialDirContext context = null;
try {
context = new InitialDirContext(props);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> results = context.search(
toDC(SettingsResolver.getInstance().getSetting(
"ldap.server.domain.name")), String.format(
"(& (userPrincipalName=%s)(objectClass=user))",
this.username), controls);
return results.hasMore();
} catch (NamingException namingException) {
logger.error(
"Exception occurred while authenticating to LDAP Server: ",
namingException);
throw namingException;
} finally {
try {
if (context != null)
context.close();
} catch (Exception ex) {
}
}
}
private static String toDC(String username) {
String result = "";
String[] parts = username.split("\\.");
for (int index = 0; index < parts.length - 1; index++)
result = result.concat("DC=").concat(parts[index]).concat(",");
return result.concat("DC=").concat(parts[parts.length - 1]);
}
public boolean isUserLoggedIn() {
return this.isLoggedIn;
}
private String buildLdapPrefix() {
String securePortEnabled = SettingsResolver.getInstance().getSetting(
"ldap.server.secure.port.enabled");
if (securePortEnabled.contains("true")) {
return "ldaps://";
} else {
return "ldap://";
}
}
}
Perhaps your BlindSSLFactory is not actually being utilized in the production environment. My money is on java.naming.ldap.factory.socket being overridden elsewhere in the code, as it seems to be the means of letting your app know it should utilize this factory via an SPI like interface
A good starting point would be to remote-debug the JVM and see what the property value is set to during runtime.
Your code looks fine and all the configuration provided seems to be correct.
After digging into the problem - please, see the different comments on the main question - by applying different configurations and debugging strategies, as you indicated, the problem seems to be related with the way the setup, standalone program, is created, and not with the LDAP server integration code presented in the question.

SymmetricDS client throws AuthenticationException

INFO [client-001-job-3] o.j.s.s.impl.DataLoaderService - Using registration URL of http://localhost:8080/sync/server/registration?nodeGroupId=client&externalId=001&syncURL=http%3A%2F%2Flocalhost%3A8081%2Fsync%2Fclient-001&schemaVersion=%3F&databaseType=H2&databaseVersion=1.4&symmetricVersion=3.11.9&deploymentType=client&hostName=XXXXXXX&ipAddress=XX3
ERROR [client-001-job-3] o.j.s.s.impl.RegistrationService - Unexpected error during registration: org.jumpmind.symmetric.transport.AuthenticationException
org.jumpmind.symmetric.transport.AuthenticationException: null
at org.jumpmind.symmetric.transport.http.HttpIncomingTransport.openStream(HttpIncomingTransport.java:139)
at org.jumpmind.symmetric.transport.http.HttpIncomingTransport.openReader(HttpIncomingTransport.java:156)
at org.jumpmind.symmetric.service.impl.DataLoaderService.loadDataFromTransport(DataLoaderService.java:592)
at org.jumpmind.symmetric.service.impl.DataLoaderService.loadDataFromPull(DataLoaderService.java:302)
at org.jumpmind.symmetric.service.impl.DataLoaderService.loadDataFromPull(DataLoaderService.java:258)
at org.jumpmind.symmetric.service.impl.RegistrationService.attemptToRegisterWithServer(RegistrationService.java:505)
at org.jumpmind.symmetric.service.impl.RegistrationService.registerWithServer(RegistrationService.java:481)
at org.jumpmind.symmetric.service.impl.PullService.pullData(PullService.java:89)
at org.jumpmind.symmetric.job.PullJob.doJob(PullJob.java:48)
at org.jumpmind.symmetric.job.AbstractJob.invoke(AbstractJob.java:227)
at org.jumpmind.symmetric.job.AbstractJob.run(AbstractJob.java:298)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:835)
I do not know why this symetricDS error occures.
I needed to register the clients /sync URL as well.
#Bean
public ServletRegistrationBean<SymmetricServlet> symServlet() {
ServletRegistrationBean<SymmetricServlet> bean = new ServletRegistrationBean<>(new SymmetricServlet(), "/sync/*");
bean.setLoadOnStartup(1);
return bean;
}

Authenticate javax.naming.NamingException: LDAP

I am trying authenticate with LDAP using SpringBoot, but I get error for NamingException, I am new with this, but I saw this post Authenticating using LDAP with spring LDAP API and without using spring security
Pom.xml
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency> -> 2.3.2
Then, I created my config to access
#Configuration
public class LdapConfig {
/** The ldap url. */
#Value("${ldap.url}")
private String ldapUrl; // ldap://MYCOMPANY.com:389
/** The ldap access password. */
#Value("${ldap.password}")
private String ldapAccessPassword; // Password to access LDAP
/** The ldap U base user. */
#Value("${ldap.base}")
private String ldapUBaseUser; // OU=USERS,OU=ACCOUNTS,DC=rg,DC=MYCOMPANY,DC=com
/**
* Context source.
*
* #return the ldap context source
*/
#Bean
public LdapContextSource contextSource() {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl(ldapUrl);
contextSource.setPassword(ldapAccessPassword);
contextSource.setBase(ldapUBaseUser);
return contextSource;
}
/**
* Ldap template.
*
* #return the ldap template
*/
#Bean
public LdapTemplate ldapTemplate() {
return new LdapTemplate(contextSource());
}
}
Ok, Here I have a big question... I create my connection with url (logic) with password(logic) ...... ¿¿ WHERE is my user ?? I put password but I never see in google put user, really ???
Finally my Impl:
#Autowired
private LdapTemplate ldapTemplate;
#Value("${ldap.base}")
private String base; // WHY DO I REPEAT THIS VALUE ??? In my #configuration I especified the base
public boolean existUser(String usr, String pwd) {
try {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("mailNickname", usr));
Boolean authenticate = ldapTemplate.authenticate(base, filter.encode(), pwd);
boolean result = authenticate.booleanValue();
if(!result) {
LOGGER.info("The: " + usr + " , is failed.");
}
return result;
} catch (Exception e) {
LOGGER.error("Error existUser() --> " +e);
e.printStackTrace();
return false;
}
}
Finally I call my method existUser() with user and password the front-End, I need know if this user/password exists in LDAP, but I get this error:
12-02-2020 09:03:27.821 [http-nio-80-exec-5] ERROR e.c.service.impl.LoginServiceImp.existUser -Error existUser() --> org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: e rror code 1 - 000004DC: LdapErr: DSID-0C0907C2, comment: In order to perform this operation a s uccessful bind must be completed on the connection., data 0, v2580]; remaining name 'OU=USERS,O U=ACCOUNTS,DC=rg,DC=MYCOMPANY,DC=com'
org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC:LdapErr: DSID-0C0907C2, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580]; remaining name 'OU=USERS,OU=ACCOUNTS,DC=rg,DC=rep sol,DC=com'
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:228)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:309)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:642)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:578)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1441)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1426)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1369)
at es.MYPROJECT.service.impl.LoginServiceImp.existUser(LoginServiceImp.java:29)
at es.MYPROJECT.controller.LoginController.login(LoginController.java:40)
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:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHand lerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(Invoc ableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod. invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.i nvokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.h andleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(Abstr actHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java: 967)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:9 01)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.jav a:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:317)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(Exceptio nTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionMan agementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilt er(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter. doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(Reque stCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutF ilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWr iterFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(S ecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFil ter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(Filter ChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy. java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177 )
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilter Proxy.java:347)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy. java:263)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextF ilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutForm ContentFilter.java:108)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMet hodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java :166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEnc odingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.ja va:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh ain.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:50 4)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:7 90)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0907C2 , comment: In order to perform this operation a successful bind must be completed on the connec tion., data 0, v2580]; remaining name 'OU=USERS,OU=ACCOUNTS,DC=rg,DC=MYCOMPANY,DC=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3194)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3100)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2891)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1846)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContex t.java:358)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:276)
at org.springframework.ldap.core.LdapTemplate$3.executeSearch(LdapTemplate.java:303)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363)
... 92 more
Thanks.
An authentication(bind) is required before performing the search operation. You need to add contextSource.setUserDn("userDn"); to the ldapcontextsource, or try:
/**
* this method is used to verify and authenticate the user.
*
* #param login user's login
* #param password user's password
*/
public void verifyCredentials(String login, String password)
{
LdapQuery query = LdapQueryBuilder.query().where("cn").is(login);
ldapTemplate.authenticate(query, password);
}

Error using hibernate transaction in Servlet

I don't know how the method getCurrentSession() working in javaBean which be used at servlet
I have configed hibernate sessionFactory at applicationContext.xml,and 'current_session_context_class' at hibernate.cfg.xml.
this is my service bean:
#Service()
public class serviceDao{
#Autowired
private sessionFactory sessionFactory;
public session getSession(){
return sessionFactory.getCurrentSession();
}
public void startTransaction(){
getSession().beginTransaction();
}
public void submitTransaction(){
getSession().getTransaction().commit();
}
public void doSomething(){
getSession.createQuery("...");
......
}
}
this is servlet
public class CommentAction extends HttpServlet {
private serviceDao serviceDao;
#Override
public void init() throws ServletException {
super.init();
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
serviceDao = (serviceDao) context.getBean("serviceDao");
}
public void doPost(){
serviceDao.startTransaction();
serviceDao.doSomething();
serviceDao.submitTransaction();
}
}
If the servlet processes 10 requests in a row, it will report an error.
09-Nov-2019 23:19:11.206 [http-nio-8080-exec-123] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [commentAction] in context with path [] threw exception
java.lang.IllegalStateException: Transaction already active
at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:74)
at org.hibernate.internal.AbstractSharedSessionContract.beginTransaction(AbstractSharedSessionContract.java:467)
at sun.reflect.GeneratedMethodAccessor251.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:350)
at com.sun.proxy.$Proxy358.beginTransaction(Unknown Source)
at com.qiang.dao.serviceDao.startTransaction(serviceDao.java:28)
at com.qiang.dao.serviceDao$$FastClassBySpringCGLIB$$19d44572.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671)
at com.qiang.dao.serviceDao$$EnhancerBySpringCGLIB$$71a65c7d.startTransaction(<generated>)
at com.qiang.servlet.CommentAction.doPost(CommentAction.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
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 com.qiang.servlet.LoginFilter.doFilter(LoginFilter.java:61)
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:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
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:678)
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:861)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Hello you can check the java documentations , explaining clearly what is the real problem
public class IllegalStateException
extends RuntimeException
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
Since:
JDK1.1
See Also:
Serialized Form
enter link description here

Spring boot apache CXF capture soap errors and return http error code

I am using spring boot with Apache CXF. The starter im using is the spring boot cxf-spring-boot-starter-jaxws. I followed the guides from apaches cxf own website. http://cxf.apache.org/docs/springboot.html.
I am also using Java11.
The problem I'm having is that soap requests into the application that error always return 200 headers regardless if there was an error or not.
The web service endpoint I'm hitting is a void method but I would still like to return a 500 code in the http header if it doesn't work.
The strategy I have in mind is to create an interceptor that will intercept soap requests that error and modify the final response with a http header code. So the body would be null for void methods but the header is 400 or 500.
My soap service configuration looks like this
#Configuration
#Slf4j
public class WebServiceConfiguration {
#Autowired
private Bus bus;
#Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, new SoapEventEndpoint());
endpoint.publish("/EventEndpoint");
endpoint.setWsdlLocation("ReceiveEvent.wsdl");
// this interceptor works
endpoint.getInInterceptors().add(soapInterceptor());
// these two fault interceptors do not work!
endpoint.getInFaultInterceptors().add(soapFaultInterceptor());
endpoint.getOutFaultInterceptors().add(soapFaultInterceptor());
return endpoint;
}
#Bean
public AbstractSoapInterceptor soapFaultInterceptor(){
return new SoapFaultInterceptor( Phase.PRE_STREAM);
}
#Bean
public AbstractSoapInterceptor soapInterceptor(){
return new SoapInterceptor( Phase.PRE_STREAM);
}
}
Interceptors
#Slf4j
public class SoapFaultInterceptor extends AbstractSoapInterceptor {
public SoapFaultInterceptor(String phase) {
super(phase);
}
#Override
public void handleMessage(SoapMessage message) throws Fault {
log.info("THIS NEVER GETS CALLED!! Execpting errors to invoke this method");
}
}
#Slf4j
public class SoapInterceptor extends AbstractSoapInterceptor {
public SoapInterceptor(String p){
super(p);
}
#Override
public void handleMessage(SoapMessage message) throws Fault {
log.info("THIS WORKS");
}
}
WSDL to Java Generated event endpoint
#WebService(targetNamespace = "xyz", name = "ReceiveEventEndpoint")
#XmlSeeAlso({ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface ReceiveEventEndpoint {
#WebMethod(operationName = "ReceiveEvent", action = "xyz")
#Oneway
public void receiveEvent(
#WebParam(partName = "in", name = "ReceiveEventRequest", targetNamespace = "xyz")
ReceiveEventRequest in
);
}
1) When I invalidate with the XML and send the request. Only the SoapInterceptor intercepts it? The SoapFaultInterceptor doesnt? Any suggestions?
Interceptor for {http://xyz/}SoapEventEndpointService#{http:/xyz}ReceiveEvent has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"http://xyz", local:"EventId1"). Expected elements are <{http://xyz}LocalAssessmentId>,<{http://xyz}LOTId>,<{http://xyz}EventId>,<{http://xyz}Benefit>
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:938) ~[cxf-rt-databinding-jaxb-3.3.1.jar:3.3.1]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:744) ~[cxf-rt-databinding-jaxb-3.3.1.jar:3.3.1]
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:172) ~[cxf-rt-databinding-jaxb-3.3.1.jar:3.3.1]
at org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:194) ~[cxf-rt-wsdl-3.3.1.jar:3.3.1]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[cxf-core-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[cxf-core-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276) ~[cxf-rt-transports-http-3.3.1.jar:3.3.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.16.jar:9.0.16]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: javax.xml.bind.UnmarshalException: null
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:483) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:417) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:394) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:887) ~[cxf-rt-databinding-jaxb-3.3.1.jar:3.3.1]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$200(JAXBEncoderDecoder.java:103) ~[cxf-rt-databinding-jaxb-3.3.1.jar:3.3.1]
at org.apache.cxf.jaxb.JAXBEncoderDecoder$3.run(JAXBEncoderDecoder.java:926) ~[cxf-rt-databinding-jaxb-3.3.1.jar:3.3.1]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:924) ~[cxf-rt-databinding-jaxb-3.3.1.jar:3.3.1]
... 51 common frames omitted
Caused by: com.sun.istack.SAXParseException2: unexpected element (uri:"xyz", local:"EventId1"). Expected elements are <{http://xyz}LocalAssessmentId>,<{http://xyz}LOTId>,<{http://xyz}EventId>,<{http://xyz}Benefit>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:744) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:262) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:257) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:124) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:105) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:268) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:574) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:556) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:246) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:180) ~[jaxb-runtime-2.3.1.jar:2.3.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:415) ~[jaxb-runtime-2.3.1.jar:2.3.1]
... 57 common frames omitted
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://uxyz", local:"EventId1"). Expected elements are <{http://xyz}LocalAssessmentId>,<{http://xyz}LOTId>,<{http://xyz}EventId>,<{http://uxyz}Benefit>
... 68 common frames omitted
2019-03-27 15:44:15.245 DEBUG 22552 --- [nio-8080-exec-4] o.a.c.t.http.AbstractHTTPDestination : Finished servicing http request on thread: Thread[http-nio-8080-exec-4,5,main]
2019-03-27 15:44:15.245 DEBUG 22552 --- [nio-8080-exec-4] o.a.c.t.servlet.ServletController : Finished servicing http request on thread: Thread[http-nio-8080-exec-4,5,main]
**2) How do I add an interceptor (or fault listener) or some other method to update the http header after errors are intercepted?
Did you try something like this:
#Override
public void handleFault(Message message) {
Map<String, List> headers = (Map<String, List>) message.get(Message.PROTOCOL_HEADERS);
try {
headers.put("Status", "500");
...
} catch (Exception ce) {
...
}
}
In the ReceiveEventEndpoint interface the method receiveEvent is annotated with the #OneWay annotation that means it has only an input message and no output (including Faults).
You can find more details here Understanding #Oneway annotation in JAX-WS, http://cxf.547215.n5.nabble.com/Detecting-unmarshalling-error-with-Oneway-operations-td5742536.html, and http://cxf.547215.n5.nabble.com/OneWay-interpretation-and-HTTP-binding-td5711719.html
For debugging reasons if you need to throw Faults in OneWay operations, you can add the Message.ROBUST_ONEWAY property to your endpoint:
#Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, new SoapEventEndpoint());
endpoint.publish("/EventEndpoint");
endpoint.setWsdlLocation("ReceiveEvent.wsdl");
// interceptors...
//To throw exceptions in OneWay messages
Map<String, Object> prop = new HashMap<>();
prop.put(Message.ROBUST_ONEWAY, true);
endpoint.setProperties(prop);
return endpoint;
}
For invalid requests, you will get an HTTP 500 with the following body without the necessity to add a custom interceptor:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element (uri:"http://xyz", local:"EventId1")...</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The following worked for me: in the class package-info.java in project, I changed:
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED

Categories