I believe I have followed the guidelines correctly from this website https://vandeneyndefilip.nu/spring-boot/spring-boot-sending-email/, but I get an exception reading response.
I tried to find a solution to the problem on the internet and all I could get was to change the port from 465 to 587. unfortunately, I did use port 587 from the start
this is my application.properties
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=myemail#gmail.com
spring.mail.password=mypassword
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
this is my implementation
String jsonData = user.toJson();
System.out.println(jsonData);
byte[] arrayBlob = blobTemplate.getBytes(1, (int) blobTemplate.length());
String data = new String(arrayBlob);
String newData = MustacheProcessor.mustacheProcess(data, jsonData);
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(user.getEmail());
message.setSubject(template.getSubject());
message.setText(newData);
emailSender.send(message);
} catch (MailException e) {
e.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
I tried to see the data transfer on this line, and everything was fine
message.setTo(user.getEmail());
message.setSubject(template.getSubject());
message.setText(newData);
I have read the trace and there seems to be a problem when sending email
emailSender.send(message);
this is a half of the trace
nested exception is:
java.net.SocketException: Connection reset. Failed messages: javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset; message exception details (1) are:
Failed message 1:
javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2460)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2187)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
at javax.mail.Service.connect(Service.java:366)
at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:517)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:436)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:322)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:311)
at com.sender.tugaskp2.tugaskp2.service.impl.EmailServiceImp.sendSinglePayslip(EmailServiceImp.java:55)
at com.sender.tugaskp2.tugaskp2.controller.EmailController.sendSinglePayslip(EmailController.java:21)
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.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
I have solved this problem by replacing the network that I use and activating less secure app access for my email. I'm not sure this is the most appropriate answer to this problem.
I got the answer from this link
https://www.mkyong.com/spring-boot/spring-boot-how-to-send-email-via-smtp/
have a nice day
Related
I have to work with Amazon MQ. Amazon MQ is based on ActiveMQ. I found some code, and it should put a blob message (PDF size 230kB) on a queue. But if I run the program it errors out in the error stack below.
This is my code:
private final static String WIRE_LEVEL_ENDPOINT = "ssl://<examplednsname>-1.amazonaws.com:61617";
private final static String ACTIVE_MQ_USERNAME = "test123";
private final static String ACTIVE_MQ_PASSWORD = "test123";
public static void sendFileViaQueue(String uri, String queueName) throws JMSException {
File file = new File("test.pdf");
ConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
BlobMessage blobMsg = null;
MessageProducer producer = null;
try {
connectionFactory = new ActiveMQConnectionFactory(ACTIVE_MQ_USERNAME, ACTIVE_MQ_PASSWORD, WIRE_LEVEL_ENDPOINT);
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(session.createQueue(queueName));
blobMsg = ((ActiveMQSession) session).createBlobMessage(file);
blobMsg.setStringProperty("FILE.NAME", file.getName());
blobMsg.setLongProperty("FILE.SIZE", file.length());
producer.send(blobMsg);
session.commit();
} finally {
closeQuietly(producer);
closeQuietly(session);
closeQuietly(connection);
}
}
It seems like it want something to upload to 8080 but I didn't configure anything locally. It only should upload a PDF to a queue thats it.
Has anybody an idea to fix this?
It shouldn't be that complicated just upload a blob to a queue.
This is the stack-trace I am getting:
javax.jms.JMSException: PUT failed to: http://localhost:8080/uploads/ID:bpSligro-PC-50920-1584558692848-1:1:1:1:1
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:72)
at org.apache.activemq.command.ActiveMQBlobMessage.onSend(ActiveMQBlobMessage.java:177)
at org.apache.activemq.ActiveMQSession.send(ActiveMQSession.java:1952)
at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:288)
at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:223)
at org.apache.activemq.ActiveMQMessageProducerSupport.send(ActiveMQMessageProducerSupport.java:241)
at nl.bpittens.mq.AmazonMQExample.sendFileViaQueue(AmazonMQExample.java:81)
at nl.bpittens.mq.AmazonMQExample.main(AmazonMQExample.java:52)
Caused by: java.io.IOException: PUT failed to: http://localhost:8080/uploads/ID:bpSligro-PC-50920-1584558692848-1:1:1:1:1
at org.apache.activemq.blob.DefaultBlobUploadStrategy.uploadStream(DefaultBlobUploadStrategy.java:67)
at org.apache.activemq.blob.DefaultBlobUploadStrategy.uploadFile(DefaultBlobUploadStrategy.java:44)
at org.apache.activemq.blob.BlobUploader.upload(BlobUploader.java:53)
at org.apache.activemq.command.ActiveMQBlobMessage.onSend(ActiveMQBlobMessage.java:174)
... 6 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:357)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
at org.apache.activemq.blob.DefaultBlobUploadStrategy.uploadStream(DefaultBlobUploadStrategy.java:60)
... 9 more
Sending a normal JMS TextMessage works without a problem.
As noted in the documentation, a "blob" message:
allows massive BLOBs (Binary Large OBjects) to be sent around in some out-of-band transport mechanism. Possible out-of-band mechanisms could be HTTP or FTP or SCP or some other point-to-point protocol.
Notice that the actual binary data must be sent "in some out-of-band transport mechanism." In other words, the blob doesn't actually go to the queue. The blob is uploaded somewhere else and the message that goes to the queue simply points to that location.
You need to configure the transfer policy using the jms.blobTransferPolicy.uploadUrl parameter on the client URL. The default upload URL of the default transfer policy is http://localhost:8080/uploads/ which is what your client is trying to use to upload the binary data.
If you want to send an arbitrarily large message directly to a queue rather than using some out of band mechanism consider moving to ActiveMQ Artemis which supports that functionality.
If you're stuck using Amazon MQ then I don't think you have any other solution other than some kind of manual solution where you break the file into smaller chunks that you can put into individual messages and then re-assemble those chunks later in the consuming application.
I'm requesting some data from a remote database, using the c3p0 pool of connections approach. I can nicely retrieve all the data I need, but for some reason, that apparently seems to be related with network socket, I'm getting the java.net.SocketException according to this stack trace:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3697)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3586)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4131)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2597)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2758)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2820)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2769)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1569)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:327)
at MemsqlRequester.run(MemsqlRequester.java:28)
Caused by: java.net.SocketException: Connection timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:112)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:159)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:187)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3140)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3597)
... 9 more
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at java.util.Vector.get(Vector.java:748)
at GraphTransformer$$anonfun$getTxInformationList$1.apply$mcVI$sp(GraphTransformer.scala:38)
at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:141)
at GraphTransformer.getTxInformationList(GraphTransformer.scala:37)
at GraphTransformer.getFeaturesTx(GraphTransformer.scala:62)
at GraphTransformer.getFeatures(GraphTransformer.scala:327)
at GraphDatasetBuilder.lambda$publishGraphFeaturesFromMemsql$13(GraphDatasetBuilder.java:62)
at java.util.Vector.forEach(Vector.java:1249)
at GraphDatasetBuilder.publishGraphFeaturesFromMemsql(GraphDatasetBuilder.java:59)
at GraphDatasetBuilder.main(GraphDatasetBuilder.java:124)
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:497)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:674)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Basically the code snippet where I do the statement calls to retrieve my data from the remote dataset are below:
try {
...
Statement stmt = connection.createStatement();
rs = stmt.executeQuery(this.queryList.get(queryIndex)); // According to the stack trace, here is where I'm getting the SocketException
...
} catch (SQLException ex) {
ex.printStackTrace();
}
The problem is that I can add any catch clause surrounding this code because it tells me no SocketException is being thrown. Basically my question is what's going wrong here, considering that apparently I can't handle a SocketException in my code as stated in the stack trace.
The stacktrace that you have posted is not complete, we cannot see what exception has been thrown.
If you cannot catch the SocketException, I presume that the exception that you are receiving is a different one.
The SocketException is caught by the driver and re-thrown as a different exception. The SocketException that you can see in the stack trace is only the "caused by", that is the original exception that has been caught.
Update
You cannot catch The SocketException because it is not the exception that you receive. Please paste the full stack trace.
It seems that the ArrayIndexOutOfBoundsException is a new exception. I can be wrong, but I do not think that the driver would throw an ArrayIndexOutOfBoundsException. This exception seems thrown by spark.
I am not absolutely sure, but it seems to me that:
1) There is a network problem and you cannot access the database and open the connection;
2) A SocketException is thrown in the driver;
3) This Exception is caught and re-thrown as a different exception (the stack trace is incomplete and the exception thrown is not visible yet, but I guess that is a CommunicationsException);
4) As a consequence, the spark's code that is trying to read a graph fails and throws the ArrayIndexOutOfBoundsException;
I'm the new to redis, I start the server about this tutorial. And it work. Then I use write the code using java to connect redis, then it's ok, like this:
Jedis jedis = new Jedis("localhost");
System.out.println("Connection to server sucessfully");
//store data in redis list
jedis.lpush("tutorial-list", "Redis");
jedis.lpush("tutorial-list", "Mongodb");
jedis.lpush("tutorial-list", "Mysql");
But, when I use multithread to push the redis, it will throw the exception "read time out":
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException:
java.net.SocketTimeoutException: Read timed out at
redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:201)
at
redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
at redis.clients.jedis.Protocol.process(Protocol.java:141) at
redis.clients.jedis.Protocol.read(Protocol.java:205) at
redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
at
redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:233)
at redis.clients.jedis.Jedis.keys(Jedis.java:185) at
org.v11.redis_mongo_task.UpdateApp.jobDetail(UpdateApp.java:23) at
org.v11.redis_mongo_task.UpdateApp.main(UpdateApp.java:42) ... 5 more
Caused by: java.net.SocketTimeoutException: Read timed out at
java.net.SocketInputStream.socketRead0(Native Method) at
java.net.SocketInputStream.read(SocketInputStream.java:150) at
java.net.SocketInputStream.read(SocketInputStream.java:121) at
java.net.SocketInputStream.read(SocketInputStream.java:107) at
redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:195)
... 13 more
What happened for redis? why it can work in single thread?
According to this answer, a single Jedis instance is not threadsafe. You will have to use JedisPool for multithreading. You can read here on how use it and here to set the max connections and what will happen if those connections are all occupied.
I'm posting links since two of them are SO answers an they should get the credit and one is from github official repo, so if anything gets updated it should be reflected here too.
I've been struggling to solve this issue here, and i can't find what i am doing wrong.
I am trying to make a simple JSON Post, using Spring RestTemplate, and sending all information as String to be simple all the way around as follows:
RestTemplate restTemplate = new RestTemplate();
JSONObject issue = getJSONIssue(redmine);
try {
String response = restTemplate.postForObject(redmineProperties.getUrl()+"/issues.json?key="+redmineProperties.getKey(), issue.toJSONString(), String.class);
}catch(RestClientException e){
e.printStackTrace();
}
My JSONObject looks like:
{"issue":
{"priority_id":4,
"description":"asdasdasdasd",
"subject":"adasdad",
"project_id":4
}
}
This is the data i am trying to sendo via Post, and the server keep sending me the error:
[http-bio-8080-exec-7] WARN org.springframework.web.client.RestTemplate - POST request for "http://xxx.com.br/issues.json?key=b8143da980578fee4db0b33bd3cd3eec511797d6" resulted in 422 (Unprocessable Entity); invoking error handler
org.springframework.web.client.HttpClientErrorException: 422 Unprocessable Entity
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:589)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:547)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:503)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:331)
at br.com.cubbes.docmidia.controller.redmine.RedmineController.saveUser(RedmineController.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
when i send the same data via a client like insomnia by Google Chrome, the servers resolves without a problem.
Do anyone know what i could be doing wrong here?
For anyone coming here for 422 Unprocessable Entity, as suggested in one of the comments, setting the content-type:application/json fixed the error for me.
RequestEntity<ValidationRequest> requestEntity = RequestEntity.post(validatorUri)
.contentType(MediaType.APPLICATION_JSON)
.body(validationRequest);
JsonNode validationResponse = restTemplate.exchange(requestEntity, JsonNode.class).getBody();
I ended up using a specific library to manipulate this REST calls:
http://www.redmine.org/projects/redmine/wiki/Rest_api_with_java
Thanks guys
I can't seem to get this working. I'm just look at it for basic instruction for a lab, but I've no experience with RMI at all. I can't seem to get why I'm getting the error.
Server
public static void runServer() {
// Install security manager, if none is present
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
Registry registry = LocateRegistry.getRegistry();
System.out.println("Reg: " + registry.toString());
String name = "Server";
Server server = new Server();
I_Server stub = (I_Server) UnicastRemoteObject.exportObject(server, 0);
registry.rebind(name, stub);
System.out.println("All is well :-)\n");
} catch (RemoteException re) {
System.err.println("Remote Exception in DisplayGetEngine.main()\n");
re.printStackTrace();
}
}
}
I have the following run commands and arguments in NetBeans
Arguments: -cp C:\rmi\Server\src;C:\rmi\Server\dist\Server.jar -Djava.rmi.server.codebase=file:/C:/rmi/Server/dist/Server.jar
Working Directory: C:\rmi\Server
My stacktrace is, at the rebind method.
Reg: RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:[10.50.18.205:1099](remote),objID:[0:0:0, 0]]]]
Remote Exception in DisplayGetEngine.main()
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: server.I_Server
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at server.Server.runServer(Server.java:50)
at server.Server.main(Server.java:31)
If I don't run rmiregistry, this is my stacktrace
Remote Exception in DisplayGetEngine.main()
java.rmi.ConnectException: Connection refused to host: 10.50.18.205; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at server.Server.runServer(Server.java:50)
at server.Server.main(Server.java:31)
Try calling createRegistry() first to make sure that you have a running registry. Also, port 0 should be a reserved port so you won't be able to make your server listen on that particular port. Try the default one 1099.
There is no problem in running rmiregistry. If you look into the stacktrace closely,the problem seems to be ClassNotFoundException while the arguments are being unmarshalled in the rmi registry. You will have to check the code base of the RMI server whether server.I_Server class is present in the Server.jar while running it in the classpath.
From RMI FAQs
A.4 Why am I getting a ClassNotFoundException?
Most likely the java.rmi.server.codebase property has not been set (or has not been set correctly) on a VM that is exporting your remote object(s). Please take a look at our tutorial, Dynamic code downloading using Java RMI (Using the java.rmi.server.codebase Property).
The issue was in the build file. I needed to insert this statement.
<target name="startRMI" depends="init">
<exec executable="C:\Program\Files\Java\jdk1.7.0_51\jre\bin\rmiregistry"
dir="${build.classes.dir}"></exec>
</target>