I am a newbie to couchbase. I am using spring in my application through which I am trying to connect to couchbase in my local. I am trying to create a couchbase template(similar to what is done in mongo template) in configurations as below:
Spring configuration
Repository using couchbase template
But when I start application, I get autowiring errors and I am unable to fetch back anything. Can some please help with above issue?
Or if someone can share sample code to extract data from couchbase using sprin-data & spring configuration? Please help!
So you are using Spring Data Couchbase 1.4? The framework offers a dedicated namespace for the Spring xml configuration that you should use instead of attempting to call constructors:
xml configuration
<?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:couchbase="http://www.springframework.org/schema/data/couchbase"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/data/couchbase http://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<couchbase:couchbase host="127.0.0.1,192.168.1.101" bucket="default" password=""/>
<couchbase:template/> <!-- will use default client above, no additional tuning-->
</beans>
First notice the xmlns:couchbase and the couchbase-specific xsi:schemaLocation in the root.
Secondly, not providing ids will wire up beans with the default IDs (and same for references, eg. the default template will reference the default client if no "client-ref" attribute is specified).
Thirdly, notice the format for the "host" parameter is just a String, hostnames or ips separated by commas (in case you want to bootstrap from a cluster).
At this point the template should be available for autowiring.
repository
For CRUD operations, Spring Data Couchbase already comes with a CRUDRepository abstraction. You only need to:
declare an interface UsersRepository extending CRUDRepository<Users, String> (string being the type of the Users field identifying it). Let's say it's in package com.test.repo.
enable building of repositories by the framework in the xml config: <repositories base-package="com.test.repo" /> (click for relevant section of the doc)
autowire your repository: #Autowired public UsersRepository repo;
The documentation has many more details about concepts like the repositories, pre-requisites for a CRUD repository to work in couchbase (short story: you need to create a view to back it up), how to model and annotate entities, etc...
Please have a look at it, at http://docs.spring.io/spring-data/couchbase/docs/1.4.0.RELEASE/reference/html/
Related
Some tables were dropped at development environment during a spring-data-jpa project test and the developer responsible for it said it only used spring.jpa.hibernate.ddl-auto=update. Checking here, I suspected he had it set as create-drop, but since he said he didn't use, I went for this piece of information:
Spring Boot chooses a default value for you based on whether it thinks your database is embedded.
It defaults to create-drop if no schema manager has been detected
Since his application actually managed to connect to our development environment PostgreSQL database (since it dropped some tables), I start to think he maybe could have forgotten to set hbm2ddl.auto and automatically it went as create-drop.
Is it possible to connect to PostgreSQL and don't have a valid schema manager defined? Which are the most common schema managers?
PS: at this application #DataSource is set this way:
#Bean
public DataSource dataSource() {
Class.forName("org.postgresql.Driver");
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUrl(someUrlConnectionStringFromApplicationDotPropertiesFile);
return dataSource;
}
like String someUrlConnectionStringFromApplicationDotPropertiesFile = "jdbc:postgresql://ipAddress:port/dbName?user=user&password=pass". I know spring-data-jpa sets everything with spring jpa properties automatically without this method, this is currently an unchangeable legacy code :(
Spring Boot said they are Higher-level Database Migration Tool (Flyway or Liquibase).
ref: https://docs.spring.io/spring-boot/docs/2.7.x/reference/html/howto.html#howto.data-access.jpa-properties, https://docs.spring.io/spring-boot/docs/2.7.x/reference/html/howto.html#howto.data-access.jpa-properties
You can also configure them through Spring Boot documentation or their own docs. ref: https://docs.spring.io/spring-boot/docs/2.7.x/reference/html/howto.html#howto.data-initialization.migration-tool
For example, configure Flyway community version through maven (https://flywaydb.org/download/community):
<build>
...
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>9.12.0</version>
</plugin>
...
</build>
I develop a webApp which is connecting to many similar database.
The target databases are set by the final user in an administration GUI.
They work with differents database engine.
I use JPA and Eclipselink 2.6.4 to query theses databases.
Actually I've no other choice than writing a persistence.xml file on the fly and to use it to create an EntityManagerFactory.
pros.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, persistenceFilesPath + "/" + persistenceFileName);
Persistence.createEntityManagerFactory(envCode, pros);
I would like to bypass this step to get directly an EntityManagerFactory without writing an persitence.xml file.
I've read some things on PersistenceUnitInfo and createContainerEntityManagerFactory but nothing really concrete.
I'm looking for ideas to reach my goal. I hope you will have somes.
Thanks
I am reading data from DB2 table and dumping it into a file.
I execute my simple select query in the chunk listener's beforeChunk() and use the step context to get it in itemreader.
In the chunk i set the checkpoint policy as item and itemcount as 5.
The output is the first 5 records being read and written over and over again.
In this sample java batch code from IBM's site they have start and end parameters in the query.
Is it necessary to have start and end parameters in your query? Is there no other way to make sure that when the query is run again it reads the next chunk of data and not the same chunk again and again?
I am using IBM's implementation of JSR 352 on WebSphere Liberty
Try configuring the datasource to use unshareable connections.
If you are following this sample, you'll see it uses the older deployment descriptor XML files. You can edit batch-bonuspayout-application/src/main/webapp/WEB-INF/web.xml to add the line:
<res-sharing-scope>Unshareable</res-sharing-scope>
So in full you'd have:
<web-app id="BonusPayout" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>BonusPayout</display-name>
<description>This is the BonusPayout sample.</description>
<resource-ref>
<description>Bonus Payout DS</description>
<res-ref-name>jdbc/BonusPayoutDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
</web-app>
This can also be done with the newer #Resource annotation, but if you've already switched to that then you'll know how to apply this point there too.
With this change, the existing JNDI lookup at location: java:comp/env/jdbc/BonusPayoutDS will now use unshared connections, and the ResultSet will not be closed at the end of each chunk transaction.
This behavior is indirectly documented here in the WebSphere Application Server traditional documentation. (I don't see it in the Liberty documentation, there are some cases like these where the behavior is basically identical in Liberty and the topic is not documented separately in Liberty.) It's a bit indirect for the batch user. Also it's hard to describe completely since as the doc says the exact behavior varies by DB and JDBC provider. But this should work for DB2.
UPDATE: In newer (since 17.0.0.1) version of Liberty the unshareable connection can be obtained without needing to use a resource reference by configuring the connectionManager using the enableSharingForDirectLookups attribute, e.g.:
<connectionManager ... enableSharingForDirectLookups="false"/>
Following the spring.io example here: http://spring.io/guides/gs/accessing-data-rest/ for exposing a repository as a rest web service works just fine, but I cannot see how to change the URL of the exposed service. The API documentation is a little vague as to what the annotation parameters mean, perhaps some prior knowledge is assumed.
What I want - A HATEOAS service accessed at http://localhost:8080/api/people for a People repository. I want to achieve this URL using annotations only, not messing with the context root or similar. I tried the following repository annotations:
#RepositoryRestResource(collectionResourceRel = "api/people", path = "people")
#RepositoryRestResource(collectionResourceRel = "people", path = "api/people")
#RepositoryRestResource(collectionResourceRel = "api/people", path = "api/people")
None of these work.
I know I have probably missed the obvious, much appreciate anyone who can point it out.
As of Spring Boot 1.2 you are able to set this property:
spring.data.rest.baseUri=api
Alternatively:
spring.data.rest.base-uri=api
(Spring Boot uses a relaxed binding system)
NOTE: I have found that if you have extended RepositoryRestMvcConfiguration with custom configuration, the property does not take effect. For more information see:
https://github.com/spring-projects/spring-boot/issues/2392
Once the next version of Spring Boot is released (after 1.2.1), the solution will be to extend RepositoryRestMvcBootConfiguration instead.
As of Spring Boot 1.4.3 the code should be :
spring.data.rest.base-path:api
(I think baseUri is deprecated since 1.2.3)
Although I couldn't change the base path of the REST services using the annotation #RepositoryRestResource combined with a CrudRepository, I managed to do it using a JpaRepository and a custom controller with the annotation #RequestMapping.
The repository could be something like:
#Repository
interface PersonRepository : JpaRepository<Person, Long>
And the controller:
#RestController
#RequestMapping("/api/people")
class PersonRestController(private val personRepository: PersonRepository) {
...
On the other hand, you can change the base path of all your REST services modifying it in the application.properties file of your project. Add the lines:
# DATA REST (RepositoryRestConfiguration)
spring.data.rest.base-path = api
Change api with the path you wish you use in your URLs. The first line is a comment and, as so, it's not mandatory, but is useful to mark the nature of the configuration value for future references.
You can find all the common application properties of Spring Boot 2.0.1 in the Appendix A of the documentation.
Im currently evaluating different ESB Products (in fact im focuding on mule right now). The Use Case is to proxy a simple HTTP Service, an OpenGIS Web Mapping Service WMS.
Here is an example of an freely published WMS Service:
it responds with XML Metadata about the Service for a "GetCapablities" Request (http://www.wms.nrw.de/wms/uebersicht_nrw2?REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS)
it responds with Image data containing a map for a "GetMap" Request (http://www.wms.nrw.de/wms/uebersicht_nrw2?REQUEST=GetMap&VERSION=1.1.1&SERVICE=WMS&LAYERS=Uebersicht&SRS=EPSG:31466&FORMAT=image/png&BBOX=2538900,5656400,2619500,5777000&WIDTH=200&HEIGHT=200&STYLES=&)
Both returns its data as a byte array, which could possibly be the problem i am dealing with.
After I can proxy it through Mule ESB, I want to add security features as follows:
HTTP Basic and Digest Authentication
Authentication via TLS Client certificates
Implementing a XACML Policy Enforcement Point
provide some usage statistics over auditing services and implement some QoS and Throttling on it.
But basically the proxy itself isn't working as i want it to. Here is what I got so far. First I tried to proxy it with a flow to add a security provider on the inbound-adress. but the request doesn't seem to get through to the outbound-adress, and the response is empty.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:pattern="http://www.mulesoft.org/schema/mule/pattern" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security" xmlns:ss="http://www.springframework.org/schema/security" version="CE-3.2.1" xsi:schemaLocation="...cut..."
<mule-ss:security-manager>
<mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager"/>
</mule-ss:security-manager>
<spring:beans>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:user-service id="userService">
<ss:user name="ross" password="ross" authorities="ROLE_ADMIN"/>
<ss:user name="anon" password="anon" authorities="ROLE_ANON"/>
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
</spring:beans>
<http:connector name="NoSessionConnector">
<service-overrides sessionHandler="org.mule.session.NullSessionHandler" />
</http:connector>
<flow name="wfsFlow1" doc:name="wfsFlow1" processingStrategy="synchronous">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="wms" responseTimeout="10000000" doc:name="Geoserver OWS">
<mule-ss:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://www.wms.nrw.de/wms#[header:INBOUND:http.request]" encoding="UTF-8" disableTransportTransformer="true" responseTimeout="1000000" doc:name="Geoserver OWS"/>
</flow>
</mule>
I think the problem is the response from the WMS Service as byte array. I tried different repsonse transformers to transform from byte array to string or html response, but it didn't work.
I also tried the bridge pattern, but it wasn't providing the parameters with the GET Operation as i expected but by POST, which is not accepted by the underlying WMS Service.
I think my Use Case is pretty simple, but im trying to implement it since four weeks now. I did every sample Tutorial these vendors provided, but i wasn't able to set up a simple HTTP Parameter service with any kind of authentication.
Does anybody have any experiences with these products or would beso nice to answer me some specific questions on how to set up a HTTP Proxy with authentication on any of these products.
Many thanks!
David, your requirement is lengthy. Let me clarify some points on the WSO2 ESB so you can get started.
WSO2 ESB supports a variety of transports and content types not just SOAP. You may be most interested in the REST and probably JSON support. Links at here and here may help.
All WSO2 servers can be plugged into an external Directory service. Click here for instructions.
All your requirements can be covered. You can go through the comprehensive samples at this location to get a feel for what the ESB can do. Let me also point you to the articles at here, here, here, here and here that would help you with your requirements.
Hope this helps.
Mule relies on Spring Security when it comes to authenticate and authorize people.
Configuring Security is the documentation entry point for dealing with security in Mule. You'll find there information on configuring Spring Security, securing components (like your HTTP bridge) and LDAP authentication.
By default Mule serializes its session into an HTTP header when performing outbound requests. This not only can be a security issue if the remote site is not trusted, but it can also lead to Bad Request issues because the serialized session yields a too large HTTP header.
Knowing that when a security context is present, the Mule Session becomes pretty big, this can cause problem. And indeed, using your config, I was receiving bad request errors from my remote test site! So I added the following to ensure Mule doesn't send its requests over HTTP:
<http:connector name="NoSessionConnector">
<service-overrides sessionHandler="org.mule.session.NullSessionHandler" />
</http:connector>
Also I removed disableTransportTransformer="true" from your config because this can cause issues too.