Spring SaajSoapMessageFactory - Exception in saving multipart - java

I am creating an application to upload a file from browser. The web service client was build using the spring SaajSoapMessageFactory. Using websphere.
pom.xml
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3.16</version>
<scope>provided</scope>
</dependency>
dispatcher-servlet.xml
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="messageFactory">
<bean class="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl" />
</property>
</bean>
The spring web service throws the following exception during the file upload.
Exception created : [org.springframework.ws.soap.saaj.SaajSoapMessageException: Could not write message to OutputStream: Error during saving a multipart message; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
at org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:251)
at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:45)

Related

Connecting to MongoDB with Spring Data

My XML file looks like this
<mongo:mongo host="${mongo.host}" port="${mongo.port}"/>
<mongo:db-factory dbname="SmartSearch" mongo-ref="mongo" username="${mongo.user}" password="${mongo.password}"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
<mongo:repositories base-package="be.omniatravel.service.repository"/>
I have the latest dependency for MongoDB in maven
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.0.RELEASE</version>
</dependency>
It connects properly on the startup of my Tomcat server, but when i try to interact with the db i get the following error
HTTP Status 500 - Request processing failed; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [MY_DATABASE], username = [MY_USERNAME], password = [MY_PASSWORD]
I made sure the db, user and password are correct.
The code in my question was correct.
The problem was that the server admin changed the database name from SmartSearch to SmartSearchDev.

Unable to understand: "Scope 'session' is not active for the current thread"

Our project has batch process which is scheduled to run at server start up and then every 24 hours subsequently. Below is configuration in the spring file.
<bean id="RenewalBatchSvc" class="com.rsaame.pas.renewals.scheduler.RenewalBatchService" >
<property name="renewalBatchSchedulerSvc" ref="RenewalBatchSchedulerSvc" />
</bean>
<bean id="RenewalBatchScheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<!-- wait 20 seconds before starting repeated execution -->
<property name="delay" value="20000" />
<!-- run every 24 hrs 86400000-->
<property name="period" value="86400000" />
<property name="timerTask" ref="RenewalBatchSvc" />
</bean>
<bean id="RenewalBatchTimerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref bean="RenewalBatchScheduledTask" />
</list>
</property>
</bean>
What this batch process does is, it takes all the policies which are to be renewed, from the batch table, and renew them.
Each policy is taken, then renewal process is called. In the renewal process, we use a bean called "location" which is scoped as session. below is the definition.
<bean id="location" class="com.mindtree.ruc.cmn.utils.LoginLocation" scope="session">
<aop:scoped-proxy/>
</bean>
We don't use dispatcherservlet, but we use context listener as defined in below (in web.xml) :
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
Error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.location': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:341)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget(Cglib2AopProxy.java:653)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:604)
at com.mindtree.ruc.cmn.utils.LoginLocation$$EnhancerByCGLIB$$db19ad5f.getLocation(<generated>)
at com.mindtree.ruc.cmn.utils.LocationHandler.getLocation(LocationHandler.java:17)
at com.mindtree.ruc.cmn.utils.Utils.getSingleValueAppConfig(Utils.java:707)
Question:
The above exception will not occur when batch process runs at server start up. But it occurs only when batch is invoked after 24 hours. Why is it so ?
If the exception is coming, then it should come even when batch is running at (IBM websphere) server startup. How come session is available at server startup even before application is totally up and nobody is using it?
In the places where we are defining beans as session/request scope, but we are using those beans during server start up (no session or request is made yet), how come, spring will not throw exception?
Does your POM has :
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.1</version>
</dependency>
There are multiple things, see below post if you are doing it all:
Scope 'session' is not active for the current thread; IllegalStateException: No thread-bound request found

CXF JAXWS Client Creation error - No Such Method

I am trying to create a simple cxf client using the flowing snippet in my spring context:
<jaxws:client id="cxf_client" serviceClass="com.my.service" address="http://my.service.com/">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
</jaxws:outInterceptors>
</jaxws:client>
However when my server starts I am getting the following exception:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cxf_client': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.apache.cxf.common.util.ReflectionUtil.getDeclaredMethod(Ljava/lang/Class;Ljava/lang/String; [Ljava/lang/Class;)Ljava/lang/reflect/Method;
Does anyone have any idea what is causing my issue, I am using spring 4.0.5 and CXF 3.0.2.
Cheers

Spring Security Config Https issue

I am new with Spring. I have an issue regarding configuration to allow https redirection after login. I am using Vmware vfabric tc server as a web server.
In app-security-context.xml I have a warning in http block.
This warning is:
Referenced bean 'org.springframework.security.web.access.channel.
ChannelDecisionManagerImpl' not found
[config set: PresentationLayer/ web-context]
So when I try to login an error message appears in my browser "The page is not available"
I'm not sure if your problem comes from that warning (it's just a warning). When you deploy the app, don't you see any error trace?
Anyway, you can remove that warning by adding a few lines in your security context. For example:
<bean class="org.springframework.security.web.access.channel.ChannelDecisionManagerImpl">
<property name="channelProcessors">
<list>
<bean class="org.springframework.security.web.access.channel.SecureChannelProcessor" />
<bean class="org.springframework.security.web.access.channel.InsecureChannelProcessor" />
</list>
</property>
</bean>

Unable to locate provider for protocol: smtp

New to spring. I'm getting the following exception being caught:
2012-06-14 16:20:57,719 [http-8080-6] ERROR com.nimchip.lmu.data.service.impl.CoworkerServiceImpl - Error sending mail:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp. Failed messages: javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:400) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at com.nimchip.lmu.data.service.impl.CoworkerServiceImpl.genUpdateNomination(CoworkerServiceImpl.java:224) ~[lmu-dataaccess-1.0.0.jar:na]
at com.nimchip.lmu.controller.coworkerNom.CoworkerController.genUpdateNomination(CoworkerController.java:312)
I have a mail-config.xml which is registered in my web.xml. Here it is:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="10.30.137.190"/>
<property name="port" value="25"/>
</bean>
</beans>
I should be able to log anonymously to the mail server specified, so no user or password needed.
What am I missing?
Do you have the mail.jar and activation.jarin your classpath?
These classes should provide the smtp-provider.
If you are using maven, simply add this to your pom:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.0.2</version>
</dependency>
I had the same problem. I was using mailapi as artifact id and that was causing the issue.
I replaced
<artifactId>mailapi</artifactId> with
<artifactId>mail</artifactId> and it worked fine

Categories

Resources