I want to run transactions on my Spring webapp which uses Apache Jackrabbit repository. JackRabbit then uses relational database (MySQL/PgSQL) for text data. Binary data are stored to FileSystem.
So far I have this functional configuration of Jackrabbit beans:
<bean id="sessionFactory" class="com.example.MyJcrSessionFactory">
<constructor-arg index="0" ref="repository"/>
<constructor-arg index="1" ref="jcrCredentials"/>
</bean>
<bean id="repository" class="org.apache.jackrabbit.core.RepositoryImpl">
<constructor-arg index="0" ref="config" />
</bean>
<bean id="config" class="org.apache.jackrabbit.core.config.RepositoryConfig" factory-method="create">
<constructor-arg index="0" type="java.io.InputStream" value="classpath:jackrabbit/repository.xml"/>
<constructor-arg index="1" type="java.lang.String" value="/tmp/repository" />
</bean>
<bean id="jcrCredentials" class="javax.jcr.SimpleCredentials">
<constructor-arg index="0" type="java.lang.String" value="..." />
<constructor-arg index="1" type="char[]" value="..." />
</bean>
And rest of Jackrabbit configuration in repository.xml file.
What do I have to do to successfully run transactions on JackRabbit repository? Which technology am I supposed to use?
I'm running Spring 3.1, Jackrabbit 2.3.3 on Tomcat/Glassfish. And I don't want to use obsolete spring modules.
We're using a similar setup (Jackrabbit, Spring, Tomcat) with Jencks as a JCA provider.
Here's an example config:
<bean id="txManagerJencks" class="org.jencks.factory.TransactionManagerFactoryBean" />
<bean id="pooledConnectionManagerJcr" class="org.jencks.factory.ConnectionManagerFactoryBean">
<property name="transactionManager">
<ref local="txManagerJencks" />
</property>
<property name="transaction" value="xa" />
<property name="poolMinSize" value="1"/>
<property name="poolMaxSize" value="5"/>
<property name="connectionMaxIdleMinutes" value="5" />
</bean>
<bean id="repositoryManagedConnectionFactory" class="org.apache.jackrabbit.jca.JCAManagedConnectionFactory" destroy-method="finalize">
<property name="homeDir" value="${jackrabbit.homeDir}/jackrabbit" />
<property name="configFile" value="classpath:repository.xml" />
</bean>
<bean id="repository"
class="org.springframework.jca.support.LocalConnectionFactoryBean" >
<property name="managedConnectionFactory">
<ref local="repositoryManagedConnectionFactory" />
</property>
<property name="connectionManager">
<ref local="pooledConnectionManagerJcr" />
</property>
</bean>
Related
I'm trying to setup a Spring project and want to use Spring Boot Actuator 2.1.6. I've found list to pure POJO configurations but my app is using a XML config and wanted to keep using XML.
I've tried using the configuration listed below but it doesn't work as it's based on an earlier version of Actuator than I'm using.
<bean name="endpointHandlerAdapter" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter" />
<bean name="endpointHandlerMapping" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping" />
<bean class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$InfoPropertiesConfiguration" />
<bean name="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />
<beans>
<context:annotation-config />
<bean name="endpointAutoConfiguration" class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration"/>
</beans>
Using the config I get a number of class not found errors as the mvc package doesn't appear to exist in the newer version of Spring boot.
EDIT: Reading a bit more it seems that all of the available configurations are for the older Spring Boot Actuator 1 not the newer stuff. It looks like the amount of config that is needed has multiplied. Still interested in the answer but not holding out hope.
This is what we did for our spring + jersey project. As we are using an older version of spring (4.x), used spring boot actuator v1.5.22.RELEASE. Excluded autoconfigure dependency.
pom.xml snippet:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.5.22.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
</exclusions>
</dependency>
XML config snippet:
<!-- Health -->
<bean id="orderedHealthAggregator" class="org.springframework.boot.actuate.health.OrderedHealthAggregator" />
<bean id="applicationHealthIndicator" class="org.springframework.boot.actuate.health.ApplicationHealthIndicator" />
<bean id="dataSourceHealthIndicator" class="org.springframework.boot.actuate.health.DataSourceHealthIndicator">
<constructor-arg index="0" ref="optimaxDataSource" />
</bean>
<bean id="jmsHealthIndicator" class="org.springframework.boot.actuate.health.JmsHealthIndicator">
<constructor-arg index="0" ref="connectionFactory" />
</bean>
<bean id="mailHealthIndicator" class="org.springframework.boot.actuate.health.MailHealthIndicator">
<constructor-arg index="0" ref="mailSender" />
</bean>
<!-- TODO: Set threshold value for disk space -->
<bean id="diskSpaceHealthIndicatorProperties" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicatorProperties" />
<bean id="diskSpaceHealthIndicator" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicator">
<constructor-arg index="0" ref="diskSpaceHealthIndicatorProperties" />
</bean>
<bean id="healthEndpoint" class="org.springframework.boot.actuate.endpoint.HealthEndpoint">
<constructor-arg index="0" ref="orderedHealthAggregator" />
<constructor-arg index="1" type="java.util.Map">
<map>
<entry key="application" value-ref="applicationHealthIndicator" />
<entry key="db" value-ref="dataSourceHealthIndicator" />
<entry key="jms" value-ref="jmsHealthIndicator" />
<entry key="mail" value-ref="mailHealthIndicator" />
<entry key="disk" value-ref="diskSpaceHealthIndicator" />
</map>
</constructor-arg>
</bean>
<!-- Git & Build Info -->
<bean id="gitClasspathProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="singleton" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:git.properties</value>
</list>
</property>
</bean>
<bean id="gitProperties" class="org.springframework.boot.info.GitProperties">
<constructor-arg index="0" ref="gitClasspathProperties" />
</bean>
<bean id="gitInfoContributor" class="org.springframework.boot.actuate.info.GitInfoContributor">
<constructor-arg index="0" ref="gitProperties" />
<constructor-arg index="1">
<value type="org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode">FULL</value>
</constructor-arg>
</bean>
<bean id="buildClasspathProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="singleton" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:build-info.properties</value>
</list>
</property>
</bean>
<bean id="buildProperties" class="org.springframework.boot.info.BuildProperties">
<constructor-arg index="0" ref="buildClasspathProperties" />
</bean>
<bean id="buildInfoContributor" class="org.springframework.boot.actuate.info.BuildInfoContributor">
<constructor-arg index="0" ref="buildProperties" />
</bean>
<bean id="infoEndpoint" class="org.springframework.boot.actuate.endpoint.InfoEndpoint">
<constructor-arg index="0" type="java.util.List">
<list>
<ref bean="gitInfoContributor" />
<ref bean="buildInfoContributor" />
</list>
</constructor-arg>
</bean>
<!-- Metrics -->
<bean id="systemPublicMetrics" class="org.springframework.boot.actuate.endpoint.SystemPublicMetrics" />
<bean id="metricsEndpoint" class="org.springframework.boot.actuate.endpoint.MetricsEndpoint">
<constructor-arg index="0" ref="systemPublicMetrics" />
</bean>
<!-- Beans -->
<bean id="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />
<!-- Env -->
<bean id="environmentEndpoint" class="org.springframework.boot.actuate.endpoint.EnvironmentEndpoint" />
<!-- Thread Dump -->
<bean id="threadDumpEndpoint" class="org.springframework.boot.actuate.endpoint.DumpEndpoint" />
Exposed the monitoring functionality via a Jersey resource.
#Path("/actuator")
public class ActuatorResource {
private static final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
#Autowired
private HealthEndpoint healthEndpoint;
#GET
#Produces({ MediaType.APPLICATION_JSON })
#Path("/health")
#Transactional(readOnly = true)
public Response getHealth() throws JsonProcessingException {
return invoke(healthEndpoint);
}
private Response invoke(Endpoint<?> endpoint) {
try {
return Response.ok().entity(mapper.writeValueAsString(endpoint.invoke())).build();
} catch (Throwable t) {
logger.error("Error invoking endpoint : {}", endpoint.getClass().getName(), t);
return Response.serverError().entity("Request processing failed").build();
}
}
}
```
I want to initialize MongoDB cluster connection pool with replica set name so that in case my primary fails and other machine in cluster becomes primary then it should work, something like below :
MongoClientOptions options = MongoClientOptions.builder()
.requiredReplicaSetName("ReplicaSetName").
build();
ServerAddress serverAddress1 = new ServerAddress("192.168.5.5");
ServerAddress serverAddress2 = new ServerAddress("192.168.5.6"); List<ServerAddress> seeds = new ArrayList<>();
seeds.add(serverAddress1);seeds.add(serverAddress2);
MongoClient mongoClient = new MongoClient(seeds,options);
Above code works perfectly but I want to do the same in Spring context.xml.
Currently my application context look like this :
<bean id="mongoServerAddr1" class="com.mongodb.ServerAddress">
<constructor-arg name="host" value="${MONGO_CLUSTER1_HOST1}" />
<constructor-arg name="port" value="${MONGO_CLUSTER1_PORT1}" />
</bean>
<bean id="mongoServerAddr2" class="com.mongodb.ServerAddress">
<constructor-arg name="host" value="${MONGO_CLUSTER1_HOST2}" />
<constructor-arg name="port" value="${MONGO_CLUSTER1_PORT2}" />
</bean>
<util:list id="mongoHostList" value-type="com.mongodb.ServerAddress">
<ref bean="mongoServerAddr1" />
<ref bean="mongoServerAddr2" />
</util:list>
<bean id="mongoCredentialIDCluster1" class="com.mongodb.MongoCredential" factory-method="createScramSha1Credential">
<constructor-arg type="java.lang.String" name="userName" value="${MONGO_CLUSTER1_USER1}" />
<constructor-arg type="java.lang.String" name="source" value="${MONGO_CLUSTER1_SOURCE1}" />
<constructor-arg type="char[]" name="password" value="${MONGO_CLUSTER1_PASS1}" />
</bean>
<bean id="mongoCredentialIDCluster2" class="com.mongodb.MongoCredential" factory-method="createScramSha1Credential">
<constructor-arg type="java.lang.String" name="userName" value="${MONGO_CLUSTER1_USER2}" />
<constructor-arg type="java.lang.String" name="source" value="${MONGO_CLUSTER1_SOURCE2}" />
<constructor-arg type="char[]" name="password" value="${MONGO_CLUSTER1_PASS2}" />
</bean>
<util:list id="mongoCredentialList" value-type="com.mongodb.MongoCredential">
<ref bean="mongoCredentialIDCluster1" />
<ref bean="mongoCredentialIDCluster2" />
</util:list>
<bean id="mongoClient" class="com.mongodb.MongoClient">
<constructor-arg name="seeds" ref="mongoHostList" />
<constructor-arg name="credentialsList" ref="mongoCredentialList" />
</bean>
<bean id="mongoDao" class="com.dao.MongoDaoImpl">
<constructor-arg ref="mongoClient" />
</bean>
How can I achieve this ?
I have solve this problem with MongoClientURI class.
Config details:
MONGO_URI=mongodb://user:password#192.168.50.167:27017,192.168.50.169:27017/?authSource=admin&replicaSet=ReplicaSetName
This is my application context configuration:
<bean id="mongoURI" class="com.mongodb.MongoClientURI">
<constructor-arg name="uri" value="${MONGO_URI}" />
</bean>
<bean id="mongoCLIENT" class="com.mongodb.MongoClient">
<constructor-arg ref="mongoURI" />
</bean>
<bean id="mongoDao" class="com.dao.MongoDaoImpl">
<constructor-arg ref="mongoCLIENT" />
</bean>
A possible solution can be found here:
The example in the Spring Docs is:
Code
<beans>
<mongo:mongo-client host="localhost" port="27017">
<mongo:client-options connections-per-host="8"
threads-allowed-to-block-for-connection-multiplier="4"
connect-timeout="1000"
max-wait-time="1500}"
auto-connect-retry="true"
socket-keep-alive="true"
socket-timeout="1500"
slave-ok="true"
write-number="1"
write-timeout="0"
write-fsync="true"/>
</mongo:mongo-client>
</beans>
Replica Set XML Example
<mongo:mongo-client id="replicaSetMongo" replica-set="127.0.0.1:27017,localhost:27018"/>
Hope this helps.
I want to add basic authentication (http authentication) to SOAP web service from spring integration. I am following the approach below to authenticate:
<bean id="httpComponentsMessageSender"
class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
<property name="credentials">
<bean class="org.apache.commons.httpclient.UsernamePasswordCredentials">
<constructor-arg value="userName" />
<constructor-arg value="*******" />
</bean>
</property>
</bean>
<int-ws:outbound-gateway id="uniqueId"
request-channel="requestServiceChannel" reply-channel="replyChannel"
uri="end point url" message-sender="httpComponentsMessageSender"
marshaller="ServiceMarshaller" unmarshaller="ServiceMarshaller">
</int-ws:outbound-gateway>
But I am getting this error: org.springframework.ws.soap.client.SoapFaultClientException: Internal Error
Is there any way to authenticate soap web service by adding basic authentication to it?
i found the solution finally, here is the solution
<bean id="apacheHttpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams">
<property name="authenticationPreemptive" value="true" />
<property name="connectionManagerClass"
value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" />
</bean>
<bean id="apacheHttpClient" class="org.apache.commons.httpclient.HttpClient">
<constructor-arg ref="apacheHttpClientParams" />
</bean>
<bean id="credentials"
class="org.apache.commons.httpclient.UsernamePasswordCredentials">
<constructor-arg value="userName" />
<constructor-arg value="password" />
</bean>
<bean id="authentication"
class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
<constructor-arg ref="apacheHttpClient"></constructor-arg>
<property name="credentials" ref="credentials" />
</bean>
I have an application which uses embedded activeMQ 5.11. At the start of the application it creates activemq-data\producerBroker\KahaDB folder at the class path location. I do want to change the location but spring.xml doesn't take a location.
Spring.xml as given,
<bean id="producerBroker" class="org.apache.activemq.broker.SslBrokerService">
<property name="brokerName" value="producerBroker" />
<property name="persistent" value="true" />
<property name="persistenceAdapter" ref="persistenceAdapter"/>
<property name="transportConnectors">
<list>
<bean class="org.apache.activemq.broker.TransportConnector">
<property name="name" value="xxx"></property>
<property name="uri" value="${transportConnectorURIs}"></property>
</bean>
</list>
</property>
<property name="jmsBridgeConnectors">
<list>
<bean class="org.apache.activemq.network.jms.JmsQueueConnector">
<property name="outboundQueueConnectionFactory">
<bean class="org.apache.activemq.ActiveMQSslConnectionFactory">
<property name="brokerURL" value="${brokerURL}" />
<property name="userName" value="${username}" />
<property name="password" value="${password}" />
<property name="trustStore" value="${trust.store.path}" />
<property name="trustStorePassword" value="${trust.store.password}" />
<!-- <property name="keyStore" value="${key.store.path}"/> -->
<!-- <property name="keyStorePassword" value="${key.store.password}"/> -->
</bean>
</property>
<property name="outboundQueueBridges">
<list>
<bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
<constructor-arg value="${screenshotQueueName}" />
</bean>
<bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
<constructor-arg value="${resultXmlQueueName}" />
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
<bean id="persistenceAdapter" class="org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter">
<property name="directory" value="E:\test"/>
Current issue is it throws an error as "exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.activemq.store.kahadaptor.KahaPersistenceA
apter] for bean with name 'kahaPersistenceAdapter' defined in class path resource [spring/resultupload/resultupload.xml]; nested exception is java.la
g.ClassNotFoundException: org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter"
Anyone has experience in the directory change in activeMQ 5.11 in java spring?
The destination of the persistence location must be defined at the broker level.
The kahaPersistenceAdapter (which was file based) was removed with version 5.9. You should use the kahaDB.
kahaDB - uses KahaDB an embedded lightweight non-relational database
<broker brokerName="broker" persistent="true" useShutdownHook="false">
<transportConnectors>
<transportConnector uri="tcp://localhost:61616"/>
</transportConnectors>
<persistenceAdapter>
<kahaDB directory="e:/temp" ... />
</persistenceAdapter>
</broker>
all valid attributes: http://activemq.apache.org/schema/core/activemq-core-5.11.0-schema.html#kahaDB
Currently we are using jasig CAS server for SSO solution. We have two web application that is using same CAS server. We are using spring security for configuring CAS client. Sample code is like :
<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
<sec:filter-chain-map path-type="ant" >
<sec:filter-chain pattern="/j_spring_security_logout(.jsp)*" filters="appLogoutFilter,exceptionTranslationFilter,filterSecurityInterceptor"/>
<sec:filter-chain pattern="/**"
filters="securityContextPersistenceFilter,requestSingleLogoutFilter,appLogoutFilter,casAuthenticationFilter,requestCacheFilter,contextAwareFilter,exceptionTranslationFilter,filterSecurityInterceptor" />
</sec:filter-chain-map>
</bean>
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref="casAuthenticationProvider" />
</sec:authentication-manager>
<bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
<property name="authenticationUserDetailsService" ref="userDetailsServiceWrapper"/>
<property name="serviceProperties" ref="serviceProperties" />
<property name="ticketValidator" ref="ticketValidator"/>
<property name="key" value="an_id_for_this_auth_provider_only"/>
</bean>
<bean id="userDetailsServiceWrapper" class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
<property name="userDetailsService" ref="lormsSecurityUserDetailsService"/>
</bean>
<bean id="exceptionTranslationFilter" class="org.springframework.security.web.access.ExceptionTranslationFilter">
<constructor-arg ref="casEntryPoint"/>
<property name="accessDeniedHandler" ref="accessDeniedHandler"/>
</bean>
<bean id="appLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
<constructor-arg value="/j_spring_cas_security_logout"/>
<constructor-arg>
<list>
<ref bean="lormsLogOutHandler"/>
</list>
</constructor-arg>
<property name="logoutRequestMatcher">
<bean class="org.springframework.security.web.util.matcher.RegexRequestMatcher">
<constructor-arg name="pattern" value="/j_spring_security_logout(.jsp)*" />
<constructor-arg name="httpMethod">
<null/>
</constructor-arg>
</bean>
</property>
</bean>
<!-- This filter redirects to the CAS Server to signal Single Logout should be performed ?service=${singleSignOn.cas.app.url}/LORMS -->
<bean id="requestSingleLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
<constructor-arg value="${singleSignOn.cas.server.url}/logout?service=${singleSignOn.cas.app.url}/LORMS"/>
<constructor-arg>
<bean class= "org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/>
</constructor-arg>
<property name="logoutRequestMatcher">
<bean class="org.springframework.security.web.util.matcher.RegexRequestMatcher">
<constructor-arg name="pattern" value="/j_spring_cas_security_logout(.jsp)*" />
<constructor-arg name="httpMethod">
<null/>
</constructor-arg>
</bean>
</property>
</bean>
<bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator" id="ticketValidator">
<constructor-arg index="0" value="${singleSignOn.cas.server.url}" />
</bean>
<bean id="proxyGrantingTicketStorage" class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl" />
<bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationSuccessHandler" ref="authenticationSuccessHandler"/>
</bean>
<bean id="casEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
<property name="loginUrl" value="${singleSignOn.cas.server.url}/login"/>
<property name="serviceProperties" ref="serviceProperties"/>
</bean>
<bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
<property name="service" value="${singleSignOn.cas.app.url}/LORMS/j_spring_cas_security_check"/>
<property name="sendRenew" value="false"/>
</bean>
Now I have existing form based login UI. I want to use same instead of using jasig web login screen. I found this link "Using CAS from external link or custom external form" using which I can use my login UI. Can anybody help me to integrate same with spring security in my application ?
After you integrate your application.you can change and edit casviewpage.jsp.You can change all UI.You use default casview.jsp and edit it.Why dont want to edit casview.jsp?