Upgrading mongo-java-driver to Version 3.9.1 - mongodb

I am in the midst of upgrading the Spring version of one of our projects. As a result of this, the MongoDB library also had to be upgraded.
I am not able to track what the previous version of the MongoDB library used was, but the current version is now 3.9.1.
I have the following piece of code that doesn't work because of the upgrade, how should I rewrite it?
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.ServerAddress;
public sampleMethod() {
MongoClient client = null;
if (...) {
List<ServerAddress> saList = new ArrayList<>();
for (...) {
saList.add(...);
}
client = new MongoClient(saList);
} else if (...) {
MongoClientURI mongoClientURI = new MongoClientURI("mongodb://...");
client = new MongoClient(mongoClientURI);
} else {
MongoClientURI mongoClientURI = new MongoClientURI("mongodb://..." + this.encryptedProperties.getProperty("mongo.username") + "....");
client = new MongoClient(mongoClientURI);
}
return new MongoTemplate(client, srcDbname);
}
The problem now is with the return statement, because post Version 2.1, MongoTemplate's signature is now public MongoTemplate(com.mongodb.client.MongoClient mongoClient, String databaseName). Pre Version 2.1, it was public MongoTemplate(com.mongodb.MongoClient mongoClient, String databaseName).
I was looking at the documentation for the MongoClient interface (com.mongodb.client.MongoClient package) & it states that "Instances of this class can be created via the MongoClients factory.". Looking at MongoClients, the methods can't accommodate the creation of MongoClient with parameters List<ServerAddress>, MongoClientURI like MongoClient (com.mongodb.MongoClient package) does.
Package
Old Version
Link
New Version
Link
mongo-java-driver / com.mongodb
not sure, couldn't locate but will update
-
3.9.1
https://www.javadoc.io/static/org.mongodb/mongo-java-driver/3.9.1/index.html
org.springframework.data:spring-data-mongodb
2.0.8.RELEASE
https://docs.spring.io/spring-data/mongodb/docs/2.0.8.RELEASE/api/
3.2.0
https://docs.spring.io/spring-data/mongodb/docs/3.2.0/api/
Please bear with me as I am a junior dev (6 months of work experience) & I'm not familiar with upgrading project versions, thank you for your understanding
I am not sure how to proceed, I am currently reading the docs & doing some Google searches to see what a possible solution would be
I don't have experience in MongoDB

It looks like you're upgrading to version 3.2 of Spring Data MongoDB. As per the reference documentation, that major version series (3.x) requires you to use the 4.x version of the MongoDB Java Driver.
7.1. Dependency Changes Instead of the single artifact uber-jar mongo-java-driver, imports are now split to include separate
artifacts:
org.mongodb:mongodb-driver-core (required)
org.mongodb:mongodb-driver-sync (optional)
org.mongodb:mongodb-driver-reactivestreams (optional)
Depending on the application one of the mongodb-driver-sync,
mongodb-driver-reactivestreams artifacts is is required next to the
mandatory mongodb-driver-core. It is possible to combine the sync and
reactive drivers in one application if needed.

Related

webClient issue - Between ReactorClientHttpConnector and httpClient

I am facing a problem with versions , first let me explain the problem.
I have the below code :
public WebClient createWebClient() throws SSLException {
SslContext sslContext = SslContextBuilder
.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(sslContext));
return WebClient.builder().baseUrl(endpointURL)
.clientConnector(new ReactorClientHttpConnector(httpClient))
.filter(errorHandlingFilter())
.build();
}
with spring-web version 5.2.3 and netty version 0.9.3 the part with the clientConnector is working fine.
Now the version I have is 5.0.11 (ONLY) and then this part of the code stops to work with the error :
incompatible types: reactor.netty.http.client.HttpClient cannot be converted to java.util.functi
on.Consumer<? super reactor.ipc.netty.http.client.HttpClientOptions.Builder>
Is there any alternative with the older version of spring-web?
Thanks in advance =)
I don't think this is possible. The HttpClientOptions has been removed from reactor-netty in its 0.8.x generation, and you're effectively trying to use a 2 years old Spring Framework generation with a 9 months old release.
The Spring team is trying hard to maintain compatibility, but in the case of reactor netty, this is still a project in its 0.x phase and API changes/repackaging are still expected.

Axon - The type DefaultMongoTemplate is deprecated

I am developing Spring Boot + AXON example from the link: https://blog.novatec-gmbh.de/event-sourcing-spring-boot-axon/ and just updated Spring Boot version 2.1.0.RELEASE.
Multiple markers at this line
- The type DefaultMongoTemplate is deprecated
- The constructor DefaultMongoTemplate(MongoClient) is
deprecated
Code
import com.mongodb.MongoClient;
import org.axonframework.eventsourcing.eventstore.EventStorageEngine;
import org.axonframework.mongo.eventsourcing.eventstore.DefaultMongoTemplate;
import org.axonframework.mongo.eventsourcing.eventstore.MongoEventStorageEngine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class AggregateConfig {
#Bean
public EventStorageEngine eventStore(MongoClient client) {
return new MongoEventStorageEngine(new DefaultMongoTemplate(client));
}
}
Looks like DefaultMongoTemplate code is deprecated, what's the replacement for it ?
As off Axon release 4.0, extension package, like Mongo, have been moved to a dedicated repository (which you can find here). Additionally, when upgraded from Axon 3.x to 4.0, we have replaced several constructors on the infrastructure components in favor of the Builder pattern.
One of these which has undergone that change, is the DefaultMongoTemplate.
A part from that story though, I just checked out Axon 3.x (as I assume you're not looking at 4.0 at the moment), and the org.axonframework.mongo.eventhandling.saga.repository.DefaultMongoTemplate is deprecated in favor of the org.axonframework.mongo.DefaultMongoTemplate. I pull this from the javadoc at the moment, so I had hoped that would be visible on your side.
Any how, I hope this helps you out!
And if you've got the change, I'd recommend to upgrade to Axon 4.x, as new features will get added in that version instead of version 3.x.

Why do I need to import collections in router file?

I'm building simple webs with meteor, just to get to know each other, and I'm playing with iron:router as router.
The "problem" I got is that in my meteorapp/lib/routes.js I need to import my collection file which is in meteorapp/imports/ui/reservations.js:
import { Reservations } from '../imports/api/reservations.js';
Otherwise I'm not able to reach it in the template, even though I imported it same line (different path) in the templage.js file like this:
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
//collection Reservations
import { Reservations } from '../api/reservations.js';
import './roomSchedule.html';
Template.roomSchedule.onCreated(function roomScheduleOnCreated() {
Meteor.subscribe('reservations');
});
Template.roomSchedule.helpers({
allHours() {
return Reservations.find();
},
});
I don't know if this would help, meteor list output:
user#laptop:~/Documents/meteorApps/mymeteorApp$ meteor list
blaze-html-templates 1.1.2 Compile HTML templates into reactive UI with Meteor Blaze
ecmascript 0.10.3* Compiler plugin that supports ES2015+ in all .js files
es5-shim 4.7.3 Shims and polyfills to improve ECMAScript 5 support
insecure 1.0.7 (For prototyping only) Allow all database writes from the client
iron:router 1.1.2 Routing specifically designed for Meteor
meteor-base 1.3.0 Packages that every Meteor app needs
mobile-experience 1.0.5 Packages for a great mobile user experience
mongo 1.4.3 Adaptor for using MongoDB and Minimongo over DDP
reactive-var 1.0.11 Reactive variable
shell-server 0.3.1 Server-side component of the `meteor shell` command.
standard-minifier-css 1.4.1 Standard css minifier used with Meteor apps by default.
standard-minifier-js 2.3.2 Standard javascript minifiers used with Meteor apps by default.
tracker 1.1.3 Dependency tracker to allow reactive callbacks
So it works... but don't know why... Thanks in advance to everyone.
Axel.

Restlet proxy generation fails with latest GWT 2.5.0-RC1

Upgraded to GWT 2.5.0-RC1 and the proxy generation for Restlet breaks - I have the latest release 2.1-RC6 in my project. This is the stack trace :
java.lang.NoSuchMethodException: com.google.gwt.user.rebind.rpc.SerializableTypeOracleBuilder.<init>(com.google.gwt.core.ext.TreeLogger, com.google.gwt.core.ext.PropertyOracle, com.google.gwt.core.ext.typeinfo.TypeOracle)
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.restlet.rebind.ClientProxyGenerator.getSerializableTypeOracleBuilder2_2(ClientProxyGenerator.java:767)
at org.restlet.rebind.ClientProxyGenerator.generateSerializers(ClientProxyGenerator.java:569)
at org.restlet.rebind.ClientProxyGenerator.generateProxy(ClientProxyGenerator.java:500)
at org.restlet.rebind.ClientProxyGenerator.generate(ClientProxyGenerator.java:242)
The actual exception gets thrown here :
private SerializableTypeOracleBuilder getSerializableTypeOracleBuilder2_2()
throws Exception {
SerializableTypeOracleBuilder result = null;
Constructor<SerializableTypeOracleBuilder> c = null;
c = SerializableTypeOracleBuilder.class.getDeclaredConstructor(
TreeLogger.class, PropertyOracle.class, TypeOracle.class);
result = c.newInstance(getLogger(), getContext().getPropertyOracle(),
getTypeOracle());
return result;
}
This following call seems problematic, though I do not see why :
c = SerializableTypeOracleBuilder.class.getDeclaredConstructor(
TreeLogger.class, PropertyOracle.class, TypeOracle.class);
Somebody got Restlet GWT working with the latest GWT 2.5.0-rc1 ??
UPDATE: issue opened #647
I just checked the POMs for the following GWT versions of Restlet:
http://maven.restlet.org/org/restlet/gwt/org.restlet/2.2-SNAPSHOT/
http://maven.restlet.org/org/restlet/gwt/org.restlet/2.1.1/
and they all have dependencies on version 2.2 of GWT.
That's the problem when using internal classes: SerializableTypeOracleBuilder's constructor no longer takes a TypeOracle argument, but a GeneratorContext.
http://code.google.com/p/google-web-toolkit/source/browse/releases/2.5/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java#782
That was already the case in GWT 2.4 though (with the experimental GeneratorContextExt instead): http://code.google.com/p/google-web-toolkit/source/browse/releases/2.4/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java#747
and even GWT 2.3: http://code.google.com/p/google-web-toolkit/source/browse/releases/2.3/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java#763
In other words, Restlet still depends on a 18 months old version, namely GWT 2.2: http://code.google.com/p/google-web-toolkit/source/browse/releases/2.2/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java#757
Thanks for reporting this issue. The 2.1 and master branches have been updated.

MEF - Migration from .NET 3.5 to .NET 4.0

I've got an easy sample from the internet that works fine in the .NET 3.5 framework using System.ComponentModel.Composition.dll version v2.0.50727
I've changed the project definition and changed the target to .NET 4.0 and it works perfect.
When I replace the v2.0.50727 version of the above .dll to the latest version which is v4.0.30319 I get an error that complains during the composition of the container. The code where it break is as follows:
private void LoadPlugins() {
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
container.ExportsChanging += new EventHandler(container_ExportsChanging);
var batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch); // throws Exception
}
And the exception is the following:
System.ComponentModel.Composition.ChangeRejectedException was unhandled
Message=The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) More than one export was found that matches the constraint '((exportDefinition.ContractName == "MefTutorial.IPlugin") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "MefTutorial.IPlugin".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.
Resulting in: Cannot set import 'MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin")' on part 'MefTutorial.PluginConsumer'.
Element: MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin") --> MefTutorial.PluginConsumer
What do I need to do to migrate to the .NET 4.0 concerning MEF?
Could it be that another project still references the .net 3.5 version? The error message says that there are two exports of type IPlugin, which I'm quite certain of means that finds both the 3.5 and 4.0 version of the dll.
Check that only the 4.0 version of MefTutorial is referenced and/or present.
OK, I found the problem. Apparently in the previous version the notation was as mentioned in my previous comment, but in the new .NET 4.0 version the syntax for import should be:
code>
[ImportMany(typeof(IPlugin))]
internal List _myPlugins { get; set; }
Notice the use of List and ImportMany instead of IList and Import.