I am trying to add Ignite to an existing apache-tomcat application and I am running into an issue trying to retrieve data that I have previously inserted into an IgniteCache.
Below is a mockup of the code in question.
public static MyClass getInstance(){
Ignite ig = WSUtil.getIgnite();
IgniteCache<Integer,MyClass> myCache = ig.getOrCreateCache("MyClass");
MyClass instance = myCache.get( 0 );
if(instance == null) {
try{
instance = //IO opperations to create instance
myCache.put(0, instance);
}catch(Exception e) {
log.error("\tMessage: "+e.getMessage());
throw e;
}finally {
//close IO
}
}
return instance;
}
The first time this method is called an instance variable is successful created and stored but the second time it is called, the following errors occur when myCache.get( 0 ) is called :
javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: com.xxxx.services.MyClass
at com.xxxx.services.misc.impl.yyyy.getInstance(yyyy.java:84)
at com.xxxx.services.misc.impl.zzzz.getProductName(zzzz.java:324)
at com.xxxx.services.misc.impl.cccc.getProductName(cccc.java:92)
at com.xxxx.services.misc.impl.cccc.getProductInfo(cccc.java:752)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at com.xxxx.prime.aop.MethodCachingInterceptor.invoke(MethodCachingInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy52.getProductInfo(Unknown Source)
at com.xxxx.ws.ProductInfoWS.invoke(ProductInfoWS.java:60)
at com.xxxx.ws.ProductInfoWS.invoke(ProductInfoWS.java:25)
at com.sun.xml.ws.api.server.InstanceResolver$1.invokeProvider(InstanceResolver.java:256)
at com.sun.xml.ws.server.InvokerTube$2.invokeProvider(InvokerTube.java:156)
at com.sun.xml.ws.server.provider.SyncProviderInvokerTube.processRequest(SyncProviderInvokerTube.java:78)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doGet(WSServlet.java:82)
at java.lang.Thread.run(Thread.java:748)
Caused by: class org.apache.ignite.IgniteCheckedException: com.xxxx.services.MyClass
... 60 more
Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: com.xxxx.services.MyClass
... 1 more
Caused by: java.lang.ClassNotFoundException: com.xxxx.services.MyClass
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
... 29 more
I have tried to so something similar with a simple Person object running an Ignite server on my workstation without any problem.
public static void main (String[] args) throws IgniteException{
//preparing igniteconfig
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(true);
cfg.setPeerClassLoadingEnabled(true);
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
Ignite ignite = Ignition.start(cfg);
IgniteCache <Integer, Person> personCache = ignite.getOrCreateCache("personCache");
Person p = new Person("Billy","Jean");
personCache.put(0, p);
Person p2 = personCache.get(0);
System.out.println("p: " + p.toString());
System.out.println("p2: " + p2.toString());
System.out.println(">> task exectued, check output");
ignite.close();
}
It's quite possible that Ignite and your code are loaded from two different classloaders (as you have pointed out), such as, Apache Ignite may be loaded from the common libraries directory while the user code may be loaded from a specific web app directory. In this case, Apache Ignite may not see your libraries.
You can try setting IgniteConfiguration.classLoader property to e.g. getClass().getClassLoader() before starting Ignite node.
Related
I work on a small educational project - easy java app with database and gui. I work in NetBeans IDE.
For graphical interface I use JavaFX, and as I've testet this part work perfectly fine, but I have some problem with JDBC part (I use JDBC driver for sqlite database, created with DB browser for sqlite). My main application class looks like this:
public class BazaLyoko extends Application {
#Override
public void start(Stage stage) throws Exception {
Database baza = new Database();
String tytul = baza.getEpisodeName(1);
stage.setTitle(tytul);
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
And when I change those lines:
Database baza = new Database();
String tytul = baza.getEpisodeName(1);
To this (to replace value retrieved from database to a placeholder - I did this to ensure if the error is rather connected with JavaFX or JDBC part)
String tytul = "";
Program start without problem, but when I try to use my database application don't start. There isn't any compilation error or anything like that (or maybe I just don't see them, as I'm quite new to this IDE, though I think such things are usually blatantly visible) just no application window appear.
Here's the code for my database class(they both share the same package):
public class Database {
public static Connection conn;
public Database()
{
connect();
}
public static void connect()
{
String connectionString = "jdbc:sqlite:BazaLyoko.db";
try
{
conn = DriverManager.getConnection(connectionString);
if (conn != null)
{
DatabaseMetaData meta = conn.getMetaData();
//System.out.println("Nazwa sterownika to " + meta.getDriverName());
//System.out.println("Stworzono baze danych.");
}
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
}
private ResultSet doQuery(String query) throws SQLException
{
Statement stmt = null;
try
{
stmt = this.conn.createStatement();
ResultSet result = stmt.executeQuery(query);
return result;
}
catch (SQLException e )
{
throw new Error("Problem", e);
}
finally
{
if (stmt != null) { stmt.close(); }
}
}
public String getEpisodeName(int nr) throws SQLException
{
ResultSet result = doQuery("SELECT tytul FROM Odcinki WHERE numer="+String.valueOf(nr));
result.next();
return result.getString("tytul");
}
}
Database of that name is located inside my project directory (i also tried to copy it to package directory but nothing changed), the names of the table and column are correct to and exist a row with value 1 in column numer.
What I'm missing or doing wrong?
Edit:
I manage to get the following Stack Trace:
No suitable driver found for jdbc:sqlite:BazaLyoko.db
at com.sun.corba.se.impl.util.Utility.printStackTrace(Utility.java:933)
at bazalyoko.Database.connect(Database.java:46)
at bazalyoko.Database.<init>(Database.java:26)
at bazalyoko.BazaLyoko.start(BazaLyoko.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at bazalyoko.Database.doQuery(Database.java:57)
at bazalyoko.Database.getEpisodeName(Database.java:75)
at bazalyoko.BazaLyoko.start(BazaLyoko.java:24)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
... 1 more
Exception running application bazalyoko.BazaLyoko
Java Result: 1
I am reading events from kinesis in my flink app. the events are in protobuf format. if i use 'com.google.protobuf:protobuf-java:3.7.1' with in the flink app i've no issues. however if i change that to 'com.google.protobuf:protobuf-java:3.10.0' i get the above exception with stack trace
java.lang.IncompatibleClassChangeError: class com.google.protobuf.Descriptors$OneofDescriptor has interface com.google.protobuf.Descriptors$GenericDescriptor as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.privateGetPublicMethods(Class.java:2917)
at java.lang.Class.getMethods(Class.java:1615)
at org.apache.flink.api.java.typeutils.TypeExtractor.isValidPojoField(TypeExtractor.java:1786)
at org.apache.flink.api.java.typeutils.TypeExtractor.analyzePojo(TypeExtractor.java:1856)
at org.apache.flink.api.java.typeutils.TypeExtractor.privateGetForClass(TypeExtractor.java:1746)
at org.apache.flink.api.java.typeutils.TypeExtractor.privateGetForClass(TypeExtractor.java:1643)
at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfoWithTypeHierarchy(TypeExtractor.java:921)
at org.apache.flink.api.java.typeutils.TypeExtractor.privateCreateTypeInfo(TypeExtractor.java:781)
at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfo(TypeExtractor.java:735)
at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfo(TypeExtractor.java:731)
at org.apache.flink.api.common.typeinfo.TypeInformation.of(TypeInformation.java:211)
at org.apache.flink.api.java.typeutils.ListTypeInfo.<init>(ListTypeInfo.java:45)
at com.bagi.streaming.serialization.ProtoSchema.getProducedType(ProtoSchema.java:40)
at org.apache.flink.streaming.connectors.kinesis.serialization.KinesisDeserializationSchemaWrapper.getProducedType(KinesisDeserializationSchemaWrapper.java:57)
at org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer.getProducedType(FlinkKinesisConsumer.java:363)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1456)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1414)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1396)
at com.bagi.streaming.StreamProcessor.getKinesisTrackingStream(StreamProcessor.java:101)
at com.bagi.streaming.StreamProcessor.getKinesisTrackingStream(StreamProcessor.java:110)
at com.bagi.streaming.StreamProcessor.consumeKinesis(StreamProcessor.java:117)
at com.bagi.streaming.StreamProcessor.main(StreamProcessor.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)
at org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:423)
at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:813)
at org.apache.flink.client.cli.CliFrontend.runProgram(CliFrontend.java:287)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:213)
at org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1050)
at org.apache.flink.client.cli.CliFrontend.lambda$main$11(CliFrontend.java:1126)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1844)
at org.apache.flink.runtime.security.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41)
at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1126)
i am using flink#1.8.0 and 'com.twitter:chill-protobuf:0.9.3'. i am building flink app jar locally on my mac. i've tried using protoc at both 3.10.0 and 3.7.1 for protobuf-java at 3.10.0 in case that matters.
here is my deserializer
public class ProtoSchema implements DeserializationSchema<List<Event>> {
#Override
public List<Event> deserialize(byte[] message) throws IOException {
List<Event> events = new LinkedList<>();
InputStream inputStream = new ByteArrayInputStream(message);
while (true) {
Event event = Event.parseDelimitedFrom(inputStream);
if (event != null) {
events.add(event);
} else {
break;
}
}
return events;
}
#Override
public boolean isEndOfStream(List<Event> nextElement) {
return false;
}
#Override
public TypeInformation<List<Event>> getProducedType() {
return new ListTypeInfo<>(Event.class);
}
}
which i am plugging in by doing
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
Properties consumerConfig = new Properties();
consumerConfig.put(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER, "AUTO");
consumerConfig.put(AWSConfigConstants.AWS_REGION, region);
consumerConfig.put(ConsumerConfigConstants.SHARD_GETRECORDS_INTERVAL_MILLIS, "300");
consumerConfig.put(ConsumerConfigConstants.SHARD_GETRECORDS_RETRIES, "10");
consumerConfig.put(ConsumerConfigConstants.SHARD_GETRECORDS_MAX, "5000");
consumerConfig.put(ConsumerConfigConstants.STREAM_INITIAL_POSITION, "LATEST");
env.addSource(new FlinkKinesisConsumer<>(name, new ProtoSchema(), consumerConfig)).name("KinesisSource");
env.getConfig().registerTypeWithKryoSerializer(Event.class, ProtobufSerializer.class);
Event.class is compiled from protobuf schema using protoc#3.10.0 and protobuf-java#3.10.0
As you said in comment from protobuf-java:3.9.0 there is binary incompatible change to lower versions (3.8-).
to class class Descriptors.OneofDescriptor added super-class Descriptors.GenericDescriptor,
which
A static field from a super-interface of a client class may hide a field (with the same name) inherited from new super-class and cause IncompatibleClassChangeError exception. More
So if you have on your classpath protobuf-java:3.9.0+ and also some lower version (3.8-) call this class you will got this error. (In my case it went from hadoop which has 2.5 protobuf-java version and my fat jar with 3.10)
Solution:
You need to shade one of the incompatible dependencies protobuf-java more how to shade depedency with gradle
Or use version 3.8 and lower as temporary shortsighted solution.
I have a program, that downloads a Git repository, builds it and launches defined Main class. It works properly with ordinary projects, but when I want to launch a JavaFX project, I get strange errors like:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at Main.main(Main.java:31)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: app.UI_Main
at javafx.application.Application.launch(Application.java:260)
at app.UI_Main.main(UI_Main.java:31)
... 5 more
Caused by: java.lang.ClassNotFoundException: app.UI_Main
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at javafx.application.Application.launch(Application.java:248)
... 6 more
My Main class is:
public class Main {
private static final String GIT_ADDRESS = "https://github.com/lerryv/CheckCheckerDesktop";
private static final String MAIN_PATH = "app/";
private static final String MAIN_CLASS = "app.UI_Main";
public static void main(String[] args) throws GitAPIException, IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Git.cloneRepository().setURI(GIT_ADDRESS).setDirectory(Paths.get("./dir/").toFile()).call();
Collection<String> result = compile(Paths.get("./dir/src/").toFile());
String command = System.getProperty("java.home") + "/../bin/javac -d dirOut -cp \".:json-simple-1.1.jar\" " + result.join(" ");
Runtime.getRuntime().exec(command);
URLClassLoader urlClassLoader = URLClassLoader.newInstance(
new URL[]{
new File("dirOut/").toURI().toURL()
}
);
Class clazz = urlClassLoader.loadClass(MAIN_CLASS);
Method main = clazz.getDeclaredMethod("main", String[].class);
assert Modifier.isStatic(main.getModifiers());
main.invoke(null, (Object) args);
}
private static Collection<String> compile(File directory) {
assert directory.isDirectory();
Collection<String> result = new Collection<>();
boolean hasFiles = false;
for (File file: directory.listFiles()) {
if (file.isDirectory()) {
result.addAll(compile(file));
} else {
if (!hasFiles) {
String path = file.getAbsolutePath();
String extension = path.substring(path.lastIndexOf(".") + 1);
if (extension.equals("java")) hasFiles = true;
}
}
}
if (hasFiles) result.add(directory.getAbsolutePath() + "/*.java");
return result;
};
}
At first I thought it cannot find the class, but when I removed the method.invoke statement, errors disappeared. Why does it happen and are there any workarounds?
Runtime.getRuntime().exec(command)
This is starting another process, so after this line is executed compilation is not yet finished, you need to wait for this process to end, and probably you should also handle output/error stream of process to check if it succeed or not.
Process compileProc = Runtime.getRuntime().exec(command);
compileProc.waitFor();
Also I don't know what are you trying to do, but remember that not everyone might have compiler available and configured java.hame property, or configured it to different java version. (like older one and your code will not compile or newer one and you code will not run)
The program opens a new thread to start the project, but it executes the next line without monitoring its completion, so the thread can be removed if it is not necessary. If necessary, you need to write a monitoring thread to monitor and schedule all threads so that it can continue to execute after it has finished its work. Tasks of the main thread.
am working with spring boot and mongoDB. have written the repository for my model and have written my own logic to increment id by using mongo inc. while doing
gradle test
the tests are failing with the following exception.
org.springframework.data.mapping.model.MappingException: Cannot use a complex object as a key value.
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeMapInternal(MappingMongoConverter.java:669)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createMap(MappingMongoConverter.java:585)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:471)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:430)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:418)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:322)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:418)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:392)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:356)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:79)
at org.springframework.data.mongodb.core.MongoTemplate.toDbObject(MongoTemplate.java:853)
at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:1014)
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:963)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy94.save(Unknown Source)
at org.springframework.data.repository.CrudRepository$save.call(Unknown Source)
at com.auth.mongo.impl.ApplicationRepositoryImpl.save(ApplicationRepositoryImpl.groovy:26)
at com.auth.repository.ApplicationRepository$save$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
can any one suggest me what am doing wrong
EDIT:
FOR Example: Application Class is the domain
class Application implements Serializable {
String id
APIKey apiKey
Map actions = [:]
Application() {
}
Application(APIKey apiKey) {
this.apiKey = apiKey
List customerActionsList = [] // added some actions
actions.put(Role.User, customerActionsList)
}
APIKey:
String apiKey
String application
DateTime whenCreated
boolean active
APIKey() {
}
APIKey(String application, DateTime whenCreated, boolean active) {
this.apiKey = generateAPIKey(application)
this.application = application
this.whenCreated = whenCreated
this.active = active
}
repository class is as follows:
#Component
class ApplicationRepositoryImpl implements ApplicationRepository {
private final Logger logger = LoggerFactory.getLogger(ApplicationRepositoryImpl.class)
#Autowired
ApplicationRepositoryMongo applicationRepositoryMongo
#Autowired
SequenceRepository sequenceRepository
#Override
Serializable save(Application application) {
application.id = application.id?:sequenceRepository.getNextSequenceId(Application.simpleName).sequence
return applicationRepositoryMongo.save(application).id
}
#Override
Application find(String id) {
return applicationRepositoryMongo.findOne(id)
}
I am incrementing the id of Application class as follows
public SequenceId getNextSequenceId(String type) {
//get sequence type
Query query = new Query(Criteria.where("id").is(type))
//increase sequence id by
Update update = new Update()
update.inc('sequence', 1)
//return new increased i
FindAndModifyOptions options = new FindAndModifyOptions()
options.returnNew(true)
//this is the magic happened
SequenceId seqId = mongoOperation.findAndModify(query, update, options, SequenceId.class)
return seqId
}
While saving the domain object getting the above exception. I have done all mongo configuration. the configuration is working for other domains.
There's an open Improvement in Spring Don't require Converters for Complex classes that are used as Ids. Currently Spring decided to not support it.
decided not to support it at all
I have followed several tutorials on running an RMI application. However, I can't seem to make it work, as I keep getting stuck on the same exception.
I am, at this point only running a server, so no client communication is involved.
I have a simple RMI program that consists of:
A server class SortServer
An interface ISortFactory<T>
An implementation QuickSortFactory<T>
An RMIUtils class
A policy file allpermissions.policy
Policy file contents
grant {
permission java.security.AllPermission;
};
RMIUtils
static {
// Set policy
setPolicy();
// Set Security manager if not present
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
setHost("127.0.0.1");
}
public static void addCodeBaseFor(Class<?> clazz) {
System.setProperty("java.rmi.server.codebase", clazz.getProtectionDomain().getCodeSource().getLocation().toString());
}
public static void setPolicy() {
System.setProperty("java.security.policy", PolicyFileLocator.getLocationOfPolicyFile());
}
public static void setHost(String hostAddress) {
System.setProperty("java.rmi.server.hostname", hostAddress);
}
public static String getHost() {
return System.getProperty("java.rmi.server.hostname");
}
SortServer
public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException {
RMIUtils.addCodeBaseFor(ISortFactory.class);
ISortFactory<String> strQSFactory = new QuickSortFactory<String>();
// Same error: Naming.bind("rmi://"+RMIUtils.getHost()+"/quicksortfactory", strQSFactory);
Registry registry = LocateRegistry.getRegistry();
registry.rebind("quicksortfactory-string", strQSFactory);
}
ISortFactory
public interface ISortFactory<T> extends Remote {
public ISorter<T> createSorter() throws RemoteException;
}
Implementing QuickSortFactory
public class QuickSortFactory<T> extends UnicastRemoteObject implements ISortFactory<T> {
private static final long serialVersionUID = -4856366323843718656L;
public QuickSortFactory() throws RemoteException {
super();
}
#Override
public ISorter<T> createSorter() throws RemoteException {
return new QuickSort<T>();
}
}
ISorter, QuickSorter and referenced objects
ISorter extends Remote and its methods throw RemoteExceptions.
QuickSort extends SortLogic and implements ISorter. Its methods throw RemoteExceptions.
SortLogic extends UnicastRemoteObject. Its methods throw RemoteExceptions.
Since I use JDK 1.5+, I shouldn't need to worry about stubs.
The rmiregistry is running fine, or I would have different errors.
Literal console output
2013-11-20 00:57:00 DEBUG RMIUtils:33 - Policy file path changed to 'C:\Users\Mark\AppData\Local\Temp\rmi-sorter5248481413010560777.policy'
2013-11-20 00:57:00 DEBUG RMIUtils:38 - RMI hostname set to 127.0.0.1
2013-11-20 00:57:00 DEBUG RMIUtils:27 - Codebase path added: file:/F:/Development/Git/Personal/parallel-sorter/bin/
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:400)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:248)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at nl.marktielemans.rmisorter.server.SortServer.main(SortServer.java:42)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:390)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:248)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:709)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:653)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:590)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:242)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1535)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1491)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1748)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1327)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
... 12 more
Without codebase parameter
I've tried without codebase parameter, but am not sure how to include the classes in the RMI classpath as I read I should.
I've tried starting the registry from the code in SortServer using RegistryLocator.getRegistry() as above, as well as starting it from a command line opened in my bin directory. Still, I would get the same error.
java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
...
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
The Registry doesn't have that class available in its CLASSPATH.
If you're using the java.rmi.server.codebase property you need to set it before exporting any remote objects, and the codebase needs to be something the Registry and the clients can use.
public static void addCodeBaseFor(Class<?> clazz) {
System.setProperty("java.rmi.server.codebase", clazz.getProtectionDomain().getCodeSource().getLocation().toString());
}
This isn't going to work. The location on the server of the containing JAR file can't be seen from the client. Generally it is an http: or ftp: URL.