How can I invoke multiple web services using JAXB in Spring? - spring

I'm building an application with Spring MVC (3.2). This application need to invoke to 2 web services. It's ok when I invoke each service separately. However, it's not work when I call both. My application config file:
<bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_11" />
</property>
</bean>
<!-- The first service-->
<bean id="local" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="com.ws" />
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="marshaller" ref="local" />
<property name="unmarshaller" ref="local" />
<property name="defaultUri"
value="http://localhost:9999/ws/ProcessService" />
</bean>
<!-- The second service-->
<bean id="preconvert" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="com.ws.preprocess" />
<bean id="wstemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="soapMessageFactory" />
<property name="marshaller" ref="preconvert" />
<property name="unmarshaller" ref="preconvert" />
<property name="defaultUri"
value="http://localhost:9999/jod/PreProcessService" />
</bean>
Help me please! Thanks.

Hi chicky I solved the problem
Beans XML
<bean id="webServiceTemplate1" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="soapMessageFactory"/>
<property name="marshaller" ref="marshaller1"/>
<property name="unmarshaller" ref="marshaller1"/>
<property name="defaultUri" value="http://www.webservicex.net/CurrencyConvertor.asmx?WSDL"/>
</bean>
<bean id="webServiceTemplate2" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="soapMessageFactory"/>
<property name="marshaller" ref="marshaller2"/>
<property name="unmarshaller" ref="marshaller2"/>
<property name="defaultUri" value="http://www.w3schools.com/webservices/tempconvert.asmx?WSDL"/>
</bean>
webServiceTemplate1 service
#Autowired
private WebServiceTemplate webServiceTemplate1;
#Override
public double obtenerCambio(String from, String to) {
ConversionRate conversionRate = new ObjectFactory().createConversionRate();
conversionRate.setFromCurrency(Currency.fromValue(from));
conversionRate.setToCurrency(Currency.fromValue(to));
ConversionRateResponse conversionRateResponse = (ConversionRateResponse) webServiceTemplate1.marshalSendAndReceive(conversionRate);
return conversionRateResponse.getConversionRateResult();
}
And webServiceTemplate2
#Autowired
private WebServiceTemplate webServiceTemplate2;
#Override
public String obtenerConversion(String celcius) {
CelsiusToFahrenheit celsiusToFahrenheit = new ObjectFactory().createCelsiusToFahrenheit();
celsiusToFahrenheit.setCelsius(celcius);
CelsiusToFahrenheitResponse response = (CelsiusToFahrenheitResponse) webServiceTemplate2.marshalSendAndReceive(celsiusToFahrenheit);
return response.getCelsiusToFahrenheitResult();
}

Related

Spring boot Keep getting "required a single bean, but 10 were found" although I declared only one service

Whenever I run my spring boot application I keeb getting the following message:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field patchService in org.hisp.dhis.dxf2.metadata.objectbundle.DefaultObjectBundleService required a single bean, but 10 were found:
- org.hisp.dhis.patch.DefaultPatchService#0: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#1: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#2: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#3: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#4: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#5: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#6: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#7: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#8: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
- org.hisp.dhis.patch.DefaultPatchService#9: defined in URL [file:/D:/001Learning/JavaEE/Projects_FromNet/eagleboard2/eagleboard-services/eagleboard-service-core/target/classes/META-INF/dhis/beans.xml]
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
Process finished with exit code 1
Although Only one Service is declared in the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<bean id="org.eagleboard.preheat.PreheatService" class="org.eagleboard.preheat.DefaultPreheatService" scope="prototype">
<aop:scoped-proxy proxy-target-class="false" />
</bean>
<bean id="org.eagleboard.calendar.CalendarService" class="org.eagleboard.calendar.DefaultCalendarService" />
<bean class="org.eagleboard.calendar.impl.Iso8601Calendar" />
<bean class="org.eagleboard.calendar.impl.CopticCalendar" />
<bean class="org.eagleboard.calendar.impl.EthiopianCalendar" />
<bean class="org.eagleboard.calendar.impl.GregorianCalendar" />
<bean class="org.eagleboard.calendar.impl.IslamicCalendar" />
<bean class="org.eagleboard.calendar.impl.NepaliCalendar" />
<bean class="org.eagleboard.calendar.impl.ThaiCalendar" />
<bean class="org.eagleboard.calendar.impl.PersianCalendar" />
<bean id="org.eagleboard.query.planner.QueryPlanner" class="org.eagleboard.query.planner.DefaultQueryPlanner" />
<bean id="org.eagleboard.query.QueryParser" class="org.eagleboard.query.DefaultQueryParser" />
<bean id="org.eagleboard.query.CriteriaQueryEngine" class="org.eagleboard.query.CriteriaQueryEngine" />
<bean id="org.eagleboard.query.InMemoryQueryEngine" class="org.eagleboard.query.InMemoryQueryEngine" />
<bean id="org.eagleboard.query.QueryService" class="org.eagleboard.query.DefaultQueryService" />
<bean class="org.eagleboard.patch.DefaultPatchService" />
<bean id="org.eagleboard.render.RenderService" class="org.eagleboard.render.DefaultRenderService" />
<bean class="org.eagleboard.amqp.RabbitMQAmqpService" />
<bean id="org.eagleboard.interpretation.InterpretationStore" class="org.eagleboard.interpretation.hibernate.HibernateInterpretationStore">
<property name="clazz" value="org.eagleboard.interpretation.Interpretation" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!--Eagle Board part-->
<!-- Eagle Board Data Stores -->
<bean id="com.eagleboard.datafield.DataFieldStore" class="org.eagleboard.eagleboard.datafield.hibernate.HibernateDataFieldStore">
<property name="clazz" value="org.eagleboard.eagleboard.datafield.DataField" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.fieldset.FieldSetStore" class="org.eagleboard.eagleboard.fieldset.hibernate.HibernateFieldSetStore">
<property name="clazz" value="org.eagleboard.eagleboard.fieldset.FieldSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.todotask.TodoTaskStore" class="org.eagleboard.eagleboard.todotask.hibernate.HibernateTodoTaskStore">
<property name="clazz" value="org.eagleboard.eagleboard.todotask.TodoTask" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.activity.ActivityStore" class="org.eagleboard.eagleboard.activity.hibernate.HibernateActivityStore">
<property name="clazz" value="org.eagleboard.eagleboard.activity.Activity" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<bean id="com.eagleboard.project.ProjectStore" class="org.eagleboard.eagleboard.project.hibernate.HibernateProjectStore">
<property name="clazz" value="org.eagleboard.eagleboard.project.Project" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="cacheable" value="true" />
</bean>
<!-- Eagle Board Services -->
<bean id="org.eagleboard.eagleboard.datafield.DataFieldService" class="org.eagleboard.eagleboard.datafield.DefaultDataFieldService">
<property name="dataFieldStore" ref="com.eagleboard.datafield.DataFieldStore" />
</bean>
<bean id="org.eagleboard.eagleboard.fieldset.DefaultFieldSetService" class="org.eagleboard.eagleboard.fieldset.DefaultFieldSetService">
<property name="fieldSetStore" ref="com.eagleboard.fieldset.FieldSetStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<bean id="org.eagleboard.eagleboard.todotask.DefaultTodoTaskService" class="org.eagleboard.eagleboard.todotask.DefaultTodoTaskService">
<property name="todoTaskStore" ref="com.eagleboard.todotask.TodoTaskStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<bean id="org.eagleboard.eagleboard.activity.DefaultActivityService" class="org.eagleboard.eagleboard.activity.DefaultActivityService">
<property name="activityStore" ref="com.eagleboard.activity.ActivityStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<bean id="org.eagleboard.eagleboard.project.DefaultProjectService" class="org.eagleboard.eagleboard.project.DefaultProjectService">
<property name="projectStore" ref="com.eagleboard.project.ProjectStore" />
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
</bean>
<!-- Eagle Board DeletionHandlers -->
<bean id="org.eagleboard.eagleboard.datafield.DataFieldDeletionHandler" class="org.eagleboard.eagleboard.datafield.DataFieldDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.fieldset.FieldSetDeletionHandler" class="org.eagleboard.eagleboard.fieldset.FieldSetDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.todotask.TodoTaskDeletionHandler" class="org.eagleboard.eagleboard.todotask.TodoTaskDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.activity.ActivityDeletionHandler" class="org.eagleboard.eagleboard.activity.ActivityDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.eagleboard.project.ProjectDeletionHandler" class="org.eagleboard.eagleboard.project.ProjectDeletionHandler">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorStore" class="org.eagleboard.indicator.hibernate.HibernateIndicatorStore">
<property name="clazz" value="org.eagleboard.indicator.Indicator" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorTypeStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.indicator.IndicatorType" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorGroupStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.indicator.IndicatorGroup" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorGroupSetStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.indicator.IndicatorGroupSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.period.PeriodStore" class="org.eagleboard.period.hibernate.HibernatePeriodStore">
<property name="clazz" value="org.eagleboard.period.Period" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
<property name="transientIdentifiableProperties" value="true" />
</bean>
<bean id="org.eagleboard.expression.ExpressionStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="clazz" value="org.eagleboard.expression.Expression" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserStore" class="org.eagleboard.user.hibernate.HibernateUserStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.user.User" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.CurrentUserStore" class="org.eagleboard.user.hibernate.HibernateCurrentUserStore" />
<bean id="org.eagleboard.user.UserSettingStore" class="org.eagleboard.user.hibernate.HibernateUserSettingStore">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.user.UserAuthorityGroupStore" class="org.eagleboard.user.hibernate.HibernateUserAuthorityGroupStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.user.UserAuthorityGroup" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserCredentialsStore" class="org.eagleboard.user.hibernate.HibernateUserCredentialsStore">
<property name="clazz" value="org.eagleboard.user.UserCredentials" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserGroupStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.user.UserGroup" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.user.UserGroupAccessStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="clazz" value="org.eagleboard.user.UserGroupAccess" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.user.UserAccessStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="clazz" value="org.eagleboard.user.UserAccess" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.user.PasswordValidationService" class="org.eagleboard.user.DefaultPasswordValidationService" />
<bean id="org.eagleboard.user.PasswordHistoryValidationRule" class="org.eagleboard.user.PasswordHistoryValidationRule" />
<bean id="org.eagleboard.user.PasswordLengthValidationRule" class="org.eagleboard.user.PasswordLengthValidationRule" />
<bean id="org.eagleboard.user.DigitPatternValidationRule" class="org.eagleboard.user.DigitPatternValidationRule" />
<bean id="org.eagleboard.user.UpperCasePatternValidationRule" class="org.eagleboard.user.UpperCasePatternValidationRule" />
<bean id="org.eagleboard.user.SpecialCharacterValidationRule" class="org.eagleboard.user.SpecialCharacterValidationRule" />
<bean id="org.eagleboard.user.PasswordDictionaryValidationRule" class="org.eagleboard.user.PasswordDictionaryValidationRule" />
<bean id="org.eagleboard.user.UserParameterValidationRule" class="org.eagleboard.user.UserParameterValidationRule" />
<bean id="org.eagleboard.message.MessageConversationStore" class="org.eagleboard.message.hibernate.HibernateMessageConversationStore">
<property name="clazz" value="org.eagleboard.message.MessageConversation" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="statementBuilder" ref="statementBuilder" />
</bean>
<bean id="org.eagleboard.configuration.ConfigurationStore" class="org.eagleboard.hibernate.HibernateGenericStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.configuration.Configuration" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.constant.ConstantStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.constant.Constant" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.scheduling.JobConfigurationStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.scheduling.JobConfiguration" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.deletedobject.DeletedObjectStore" class="org.eagleboard.deletedobject.hibernate.HibernateDeletedObjectStore" />
<bean id="org.eagleboard.version.VersionStore" class="org.eagleboard.version.hibernate.HibernateVersionStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.version.Version" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.metadata.version.MetadataVersionStore"
class="org.eagleboard.metadata.version.hibernate.HibernateMetadataVersionStore">
<property name="sessionFactory" ref="sessionFactory" />
<property name="clazz" value="org.eagleboard.metadata.version.MetadataVersion" />
</bean>
<bean id="org.eagleboard.option.OptionSetStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.option.OptionSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.option.OptionStore" class="org.eagleboard.option.hibernate.HibernateOptionStore">
<property name="clazz" value="org.eagleboard.option.Option" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.option.OptionGroupStore" class="org.eagleboard.option.hibernate.HibernateOptionGroupStore">
<property name="clazz" value="org.eagleboard.option.OptionGroup" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.option.OptionGroupSetStore" class="org.eagleboard.option.hibernate.HibernateOptionGroupSetStore">
<property name="clazz" value="org.eagleboard.option.OptionGroupSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.legend.LegendSetStore"
class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.legend.LegendSet" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
</bean>
<bean id="org.eagleboard.i18n.I18nLocaleStore" class="org.eagleboard.i18n.hibernate.HibernateI18nLocaleStore">
<property name="clazz" value="org.eagleboard.i18n.locale.I18nLocale" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.keyjsonvalue.KeyJsonValueStore" class="org.eagleboard.keyjsonvalue.hibernate.HibernateKeyJsonValueStore">
<property name="clazz" value="org.eagleboard.keyjsonvalue.KeyJsonValue" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.userkeyjsonvalue.UserKeyJsonValueStore"
class="org.eagleboard.userkeyjsonvalue.hibernate.HibernateUserKeyJsonValueStore">
<property name="clazz" value="org.eagleboard.userkeyjsonvalue.UserKeyJsonValue" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.fileresource.FileResourceStore" class="org.eagleboard.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.eagleboard.fileresource.FileResource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.fileresource.ExternalFileResourceStore"
class="org.eagleboard.fileresource.hibernate.HibernateExternalFileResourceStore">
<property name="clazz" value="org.eagleboard.fileresource.ExternalFileResource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="org.eagleboard.fileresource.FileResourceContentStore" class="org.eagleboard.fileresource.JCloudsFileResourceContentStore">
<property name="configurationProvider" ref="dhisConfigurationProvider" />
<property name="locationManager" ref="locationManager" />
</bean>
<!-- File resource jobs -->
<bean id="org.eagleboard.fileresource.FileResourceUploadCallback" class="org.eagleboard.fileresource.FileResourceUploadCallback" />
<!--<bean id="fileResourceCleanUpJob" class="org.eagleboard.fileresource.FileResourceCleanUpJob" />-->
<!-- Service definitions -->
<!--<bean id="org.eagleboard.dataelement.DataElementGroupService" class="org.eagleboard.dataelement.DefaultDataElementGroupService" />-->
<bean id="org.eagleboard.indicator.IndicatorGroupService" class="org.eagleboard.indicator.DefaultIndicatorGroupService">
<property name="indicatorGroupStore" ref="org.eagleboard.indicator.IndicatorGroupStore" />
</bean>
<!--<bean id="org.eagleboard.dimension.DimensionService" class="org.eagleboard.dimension.DefaultDimensionService" />-->
<bean id="org.eagleboard.fileresource.FileResourceService" class="org.eagleboard.fileresource.DefaultFileResourceService">
<property name="fileResourceStore" ref="org.eagleboard.fileresource.FileResourceStore" />
<property name="fileResourceContentStore" ref="org.eagleboard.fileresource.FileResourceContentStore" />
<property name="schedulingManager" ref="org.eagleboard.scheduling.SchedulingManager" />
<property name="uploadCallback" ref="org.eagleboard.fileresource.FileResourceUploadCallback" />
</bean>
<bean id="org.eagleboard.fileresource.ExternalFileResourceService" class="org.eagleboard.fileresource.DefaultExternalFileResourceService">
<property name="externalFileResourceStore" ref="org.eagleboard.fileresource.ExternalFileResourceStore" />
</bean>
<bean id="org.eagleboard.indicator.IndicatorService" class="org.eagleboard.indicator.DefaultIndicatorService">
<property name="indicatorStore" ref="org.eagleboard.indicator.IndicatorStore" />
<property name="indicatorTypeStore" ref="org.eagleboard.indicator.IndicatorTypeStore" />
<property name="indicatorGroupStore" ref="org.eagleboard.indicator.IndicatorGroupStore" />
<property name="indicatorGroupSetStore" ref="org.eagleboard.indicator.IndicatorGroupSetStore" />
</bean>
<bean id="org.eagleboard.period.PeriodService" class="org.eagleboard.period.DefaultPeriodService">
<property name="periodStore" ref="org.eagleboard.period.PeriodStore" />
</bean>
<bean id="org.eagleboard.expression.ExpressionService" class="org.eagleboard.expression.DefaultExpressionService">
<property name="expressionStore" ref="org.eagleboard.expression.ExpressionStore" />
<property name="dataFieldService" ref="org.eagleboard.eagleboard.datafield.DataFieldService" />
<property name="constantService" ref="org.eagleboard.constant.ConstantService" />
<property name="idObjectManager" ref="org.eagleboard.common.IdentifiableObjectManager" />
</bean>
<bean id="org.eagleboard.user.UserSettingService" class="org.eagleboard.user.DefaultUserSettingService">
<property name="currentUserService" ref="org.eagleboard.user.CurrentUserService" />
<property name="userSettingStore" ref="org.eagleboard.user.UserSettingStore" />
<property name="userService" ref="org.eagleboard.user.UserService" />
<property name="systemSettingManager" ref="org.eagleboard.setting.SystemSettingManager" />
</bean>
PatchService interface:
public interface PatchService
{
Patch diff( PatchParams params );
void apply( Patch patch, Object target );
}
DefaultPatchService.java implementing that interface
public class DefaultPatchService implements PatchService
{
private static final Log log = LogFactory.getLog( DefaultPatchService.class );
private final SchemaService schemaService;
private final QueryService queryService;
private final AmqpService amqpService;
private final MetadataAuditService metadataAuditService;
private final CurrentUserService currentUserService;
private final RenderService renderService;
private final SystemService systemService;
public DefaultPatchService( SchemaService schemaService, QueryService queryService, AmqpService amqpService,
MetadataAuditService metadataAuditService, CurrentUserService currentUserService, RenderService renderService, SystemService systemService )
{
this.schemaService = schemaService;
this.queryService = queryService;
this.amqpService = amqpService;
this.metadataAuditService = metadataAuditService;
this.currentUserService = currentUserService;
this.renderService = renderService;
this.systemService = systemService;
}
...
DefaultObjectBundleService.java in which the DefaultPatchService is Autowired using the interface it implements PatchService which implemented only by it, no other service implementing this interface.
#Service
#Transactional
public class DefaultObjectBundleService implements ObjectBundleService
{
private static final LoggingManager.Logger log = LoggingManager
.createLogger( DefaultObjectBundleService.class );
#Autowired
private CurrentUserService currentUserService;
#Autowired
private PreheatService preheatService;
#Autowired
private SchemaService schemaService;
#Autowired
private SessionFactory sessionFactory;
#Autowired
private IdentifiableObjectManager manager;
#Autowired
private DbmsManager dbmsManager;
#Autowired
private HibernateCacheManager cacheManager;
#Autowired
private Notifier notifier;
#Autowired
private MergeService mergeService;
#Autowired
private DeletedObjectService deletedObjectService;
#Autowired
private PatchService patchService;
#Autowired
private MetadataAuditService metadataAuditService;
#Autowired
private RenderService renderService;
#Autowired
private SystemService systemService;
#Autowired
private AmqpService amqpService;
#Autowired( required = false )
private List<ObjectBundleHook> objectBundleHooks = new ArrayList<>();
#Override
public ObjectBundle create( ObjectBundleParams params )
{
PreheatParams preheatParams = params.getPreheatParams();
if ( params.getUser() == null )
{
params.setUser( currentUserService.getCurrentUser() );
}
preheatParams.setUser( params.getUser() );
preheatParams.setObjects( params.getObjects() );
ObjectBundle bundle = new ObjectBundle( params, preheatService.preheat( preheatParams ), params.getObjects() );
bundle.setObjectBundleStatus( ObjectBundleStatus.CREATED );
bundle.setObjectReferences( preheatService.collectObjectReferences( params.getObjects() ) );
return bundle;
}
...
...
could someone help me, please, also the project have multiple modules, Does dependency between modules have something to do with the problem
I changed the service xml definition from this:
<bean class="org.eagleboard.patch.DefaultPatchService" />
to this:
<bean id="org.eagleboard.patch.PatchService" class="org.eagleboard.patch.DefaultPatchService" />
and the error stopped showing up.
many thanks for all.

Message driven POJO with spring. Can't receive the message

my application deployed on Tomcat am I am trying to send and receive message from remote queue.
I already have succeeded to send few messages to remote queue. Now I am trying to build message listener container, however my onMessage(method is never called), don't understand what I am missing.
This is my configuration
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationResolver" ref="destinationResolver" />
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="targetConnectionFactory"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
</bean>
<bean id="targetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="MY_TEST_QUEUE" />
<property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
</bean>
<bean id="destinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="cache" value="true" />
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://host:port</prop>
</props>
</property>
</bean>
<bean id="messageListener" class="com.package.MyCustomMDB" />
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="destinationName" value="MY_TEST_QUEUE"/>
<property name="destinationResolver" ref="destinationResolver" />
<property name="messageListener" ref="messageListener" />
</bean>
And implementation of mdb
public class MyCustomMDB implements MessageListener {
#Override
public void onMessage(Message message) {
System.out.println(message.toString());
}}
Could you please advise me where I am doing something wrong?
You are using MY_TEST_QUEUE for the both the jndiName of targetConnectionFactory and destinationName of jmsContainer. The the jndiName of targetConnectionFactory should refer to the name of a connection factory rather than a queue.

Call SOAP service asynchronously using Spring

I've to call a SOAP web service asynchronously. Currently, I'm calling it in a synchronous way using Spring webservicetemplate.
Current config is like:
<bean id="interceptedHttpClientBuilder" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="httpClientBuilder" />
<property name="targetMethod" value="addInterceptorFirst"> </property>
<property name="arguments">
<list>
<bean class="org.springframework.ws.transport.http.HttpComponentsMessageSender.RemoveSoapHeadersInterceptor"/>
</list>
</property>
</bean>
<bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig" factory-method="custom">
<property name="socketTimeout" value="120000" />
</bean>
<bean id="requestConfig" factory-bean="requestConfigBuilder" factory-method="build" />
<bean id="httpClient" factory-bean="httpClientBuilder" factory-method="build" />
<bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder" factory-method="create">
<property name="defaultRequestConfig" ref="requestConfig" />
</bean>
<bean id="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
<constructor-arg ref="httpClient"></constructor-arg>
</bean>
<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="packagesToScan">
<list><value>...</value></list>
</property>
</bean>
<bean id="wsClientSecurityInterceptor"
class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
<property name="securementActions" value="UsernameToken" />
<property name="securementUsername"><value>${username}</value></property>
<property name="securementPassword"><value>${password}</value></property>
<property name="securementPasswordType" value="PasswordText" />
</bean>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="marshaller" ref="jaxb2Marshaller"></property>
<property name="unmarshaller" ref="jaxb2Marshaller"></property>
<property name="defaultUri"><value>${ws.url}</value></property>
<property name="interceptors">
<list>
<ref local="wsClientSecurityInterceptor"/>
</list>
</property>
<property name="messageSender" ref="messageSender"></property>
</bean>
Java call looks like:
MyResponse response = (MyResponse) webServiceTemplate.marshalSendAndReceive(req, new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) {
((SoapMessage) message).setSoapAction("test");
}
});
May I know how can I change it to call the service asynchronously? Or Do I need to use something else in spring to achieve this?
Not sure why you use spring-integration tag in your question, but if we are here, please, definitely take a look into the #MessagingGateway with the Future<> as a return type: https://docs.spring.io/spring-integration/docs/5.0.1.RELEASE/reference/html/messaging-endpoints-chapter.html#async-gateway
The SOAP WebService can be called via Spring Integration <int-ws:outbound-gateway>: https://docs.spring.io/spring-integration/docs/5.0.1.RELEASE/reference/html/ws.html
The samples are here: https://github.com/spring-projects/spring-integration-samples
To be more clear the code might looks like this:
<int:gateway id="mathService"
service-interface="org.springframework.integration.samples.async.gateway.MathServiceGateway"
default-request-channel="requestChannel"
async-executor="executor"/>
Where that MathServiceGateway is like this:
public interface MathServiceGateway {
Future<Integer> multiplyByTwo(int i);
}
The WS call is simple as well:
<int-ws:outbound-gateway request-channel="requestChannel" uri="http://www.w3schools.com/xml/tempconvert.asmx"/>

XStream JavaBeanConverter Spring config to serialize using getter

I would like to register XStream JavaBeanConverter in Spring config. I see test examples where JavaBeanConverter is registered as below.
xstream.registerConverter(new JavaBeanConverter(xstream.getClassMapper(), "class"), -20);
But how do I set it up in my spring config.
Currently my spring config is setup as below
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" >
<property name="renderedAttributes" value="document" />
</bean>
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller">
<bean class="org.springframework.oxm.xstream.XStreamMarshaller" p:autodetectAnnotations="true">
<property name="encoding" value="UTF-8" />
</bean>
</property>
<property name="contentType" value="application/xml;charset=UTF-8" />
<property name="modelKey" value="person" />
</bean>
</list>
</property>
<property name="ignoreAcceptHeader" value="true" />
</bean>
I am using xstream annotation for Alias and Converter.
I tried extending my custom converter from JavaBeanConverter. It serializes normal properties fine but I want it to serialize getXXX method.
public class MyCustomConverter extends JavaBeanConverter {
public MyCustomConverter(Mapper mapper) {
super(mapper);
}
#Override... marshal.. unmarshal... canConvert methods...
}
Thanks a lot!
Add this to your marshaller bean definition:
<property name="converters">
<util:list>
<bean class="com.MyBeanConverter">
<constructor-arg value="com.MyBean" index="0" />
</bean>
</util:list>
</property>
And then, define the following class that will implement the conversion
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.javabean.JavaBeanConverter;
public class MyBeanConverter extends JavaBeanConverter {
public MyBeanConverter(Class<?> theClass) {
super(new XStream().getMapper(), theClass);
}
}

how to get transaction supporting proxy from spring application context?

i need to use bean from spring application context not in a spring managed bean, so i do next: annotate bean with #Service annotation, so instance of bean created during spring loading.
<bean id="customRevisionListener" class="ru.csbi.registry.services.impl.envers.CustomRevisionListener" />
This instance is ApplicationContextAware, so application context is injected in this bean instance and i save it to static variable:
#Service
public class CustomRevisionListener implements EntityTrackingRevisionListener, ApplicationContextAware {
private static ApplicationContext applicationContext;
private ModelInformationService modelInformationService;
#Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
CustomRevisionListener.applicationContext = applicationContext;
}
private ModelInformationService getModelInformationService() {
if (modelInformationService == null) {
modelInformationService = applicationContext.getBean(ModelInformationService.class);
}
// TransactionProxyFactoryBean
return modelInformationService;
}
After that another instance of CustomRevisionListener created in not spring context(hibernate envers context). Here i use static variable to receive spring applicationContext
after that i'm getting beans from application context:
private ModelInformationService getModelInformationService() {
if (modelInformationService == null) {
modelInformationService = applicationContext.getBean(ModelInformationService.class);
}
the problem is that this bean has all #Autowired properties injected correctly:
#Service
public class ModelInformationServiceImpl implements ModelInformationService {
#Autowired
private EntityChangeService entityChangeService; // injected correctly
#Autowired
private PropertyService propertyService; // injected correctly
#Autowired
private ru.csbi.registry.services.reflection.HibernateDomainService hibernateService; // injected correctly
, but they are simple instances of java classes not Proxies supporting #Transactional annotation, which they are for my regular spring code:
getModelInformationService().getClass().getName() is "ru.csbi.registry.services.impl.envers.ModelInformationServiceImpl"
and must be something like
$Proxy71
How to get transaction supporting proxies, which spring genereates for example when injecting beans in #Controller, in bean not managed by spring?
i'm using next spring config:
<bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<constructor-arg ref="lazyConnectionDataSourceProxy"/>
</bean>
<bean id="lazyConnectionDataSourceProxy" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource">
<ref local="dataSourceTarget" />
</property>
</bean>
<bean id="dataSourceTarget" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${ds.driver}" />
<property name="url" value="${ds.url}" />
<property name="username" value="${ds.user}" />
<property name="password" value="${ds.password}" />
<property name="initialSize" value="${ds.initialSize}" />
<property name="maxActive" value="${ds.maxActive}" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!--property name="entityInterceptor">
<bean class="ru.csbi.registry.utils.audit.AuditLogInterceptor">
<property name="sessionFactory" ref="auditSessionFactory" />
</bean>
</property-->
<property name="dataSource" ref="dataSource" />
<property name="lobHandler" ref="oracleLobHandler" />
<property name="packagesToScan" value="ru.csbi.registry.domain" />
<property name="hibernateProperties">
<bean id="hibernatePropertiesFactoryBean" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>file:${realtyregistry.settings.path}/hibernate-config.properties</value>
</list>
</property>
</bean>
</property>
<property name="eventListeners">
<map>
<entry key="post-insert" value-ref="auditEventListener" />
<entry key="post-update" value-ref="auditEventListener" />
<entry key="post-delete" value-ref="auditEventListener" />
<entry key="pre-collection-update" value-ref="auditEventListener" />
<entry key="pre-collection-remove" value-ref="auditEventListener" />
<entry key="post-collection-recreate" value-ref="auditEventListener" />
</map>
</property>
</bean>
<bean id="auditEventListener" class="org.hibernate.envers.event.AuditEventListener" />
<bean id="persistenceManagerHibernate" class="ru.csbi.registry.utils.PersistenceManagerHibernate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

Resources