So lets begin... not a simple question at my point of view at least...
I have create an Rmi Server property works fine .
Inside to server i need to create a file if it rus for first time or overwrite it if it is already there. (1)
I have successfully created an rmi Client , i test the project works fine with the client class in the same project.
On my Rmi interface in some methods i need to pass Clients object as a parameter (2).
Here begins the problem . I need to run my Rmi Client multiple time but not using thread , I need to create another project that each one of them(client project), has the same code and run from there. When i run the Client from Servers project runs perfect, but When i run another distanced client it fails
giving me the common error for Security Mangager
run:
Exception in thread "main" java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at java.net.Socket.connect(Socket.java:584)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
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:342)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at Client.<init>(Client.java:69)
at Client.main(Client.java:142)
C:\Users\blue-icon\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)
So i googled and googled and saw that i need the security manager in order to give permission to a remote Client to download the Servers Code .So i add security Manager to server but because i use streams for my files(1) it gives me this error
Exception in thread "main" java.security.AccessControlException: access denied ("java.io.FilePermission" "Subscribe.txt" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.io.File.exists(File.java:814)
at RMIServer03.checkFile(RMIServer03.java:132)
at RMIServer03.<init>(RMIServer03.java:46)
at RMIServer03.main(RMIServer03.java:56)
(2) i cant compile my Server and interface on server project without an instance of clients Class because i need to pass it ass a parameter as i said
any help?
You misread. You need the security manager at the client, not the server.
Related
I am trying to run my load test on jmeter for REST api which is returning JSON.
I am passing the following header information in Header manager
Authorization: Bearer VHFAJ0dxNQfJlzPmr7miaH4QOFeNVmez6RXVHX59uovrFAL6z5zMv9krpBAvOcNTwqHRFa8REaidlpuJSUMF8Ol38t7n-sHP2WQn0KmrEnFrtdo6XDRdhspVP1D72oIlu9sP_-rdv1MdsnakVewqrzZ9PeDiWhVKqRBTjWVlnZFpLS-CZ86DFanQ9cw7VZ67a1yOWC7_os7vZYeIhaQ8dM_8n_ocYzFDcCHELSGqnz3NHc9DRrQQfjM6xB17aRjUKQ4ZNV52Ss_1BKG8-5H7bMpi1QiAdDS17K55WrNAZMzgHeaP6UwtQwJyo_gxiaW5PlNJZNQQn4rZvNkIRd_V9Q
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Few days ego I tried the same test on local internal server and it was working fine. Now I am running this on UAT env which is setup on AWS.
This is working fine with chrome Postman extension.
Also I have followed the below link but no success and getting the socket closed exception
Non HTTP response message: The target server failed to respond: Is my server failing to handle load
java.net.SocketException: Socket closed
at java.net.PlainSocketImpl.socketConnect(Native Method)
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.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
at org.apache.jmeter.protocol.http.sampler.MeasuringConnectionManager$MeasuredConnection.open(MeasuringConnectionManager.java:107)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:643)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:517)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:331)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
at java.lang.Thread.run(Thread.java:745)
Please let me know if more information is required
If your UAT deployment is behind Elastic Load Balancer or Elastic IP it may be the situation when JMeter resolves IP address of only one server and it becomes overloaded while others are idle.
Try adding DNS Cache Manager to your Test Plan to see if it helps. Check out The DNS Cache Manager: The Right Way To Test Load Balanced Apps guide for more information on the domain.
You should read this:
https://wiki.apache.org/jmeter/JMeterSocketClosed
Note Socket closed can be an issue with your server.
I recently updated to jre8. It seem that the present security settings are really nasty. I am unable to run javadb
I get the following error
Mon Mar 31 02:04:54 IST 2014 : Security manager installed using the Basic server security policy.
Mon Mar 31 02:04:54 IST 2014 : access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
what are the steps taken by me
changed the permission in java.policy file to listen to 1527 (also added resolve)-but to no avail
this is what http://www.oracle.com/technetwork/java/javase/8-known-issues-2157115.html gives out
Bug 8030961
Area: Java DB Synopsis An additional permission may be needed to
bring up the Java DB network server. In particular, the startup
scripts in may fail to boot the network server.
While attempting to boot, the network server may fail and raise the
following error:
access denied ("java.net.SocketPermission" "localhost:1527"
"listen,resolve") java.security.AccessControlException: access denied
("java.net.SocketPermission" "localhost:1527" "listen,resolve") To fix
this problem, you must bring up the network server with a security
policy that includes the missing permission. Instead of booting the
network server as:
java org.apache.derby.drda.NetworkServerControl start boot the network
server as follows:
java -Djava.security.manager -Djava.security.policy=${yourPolicyFile}
org.apache.derby.drda.NetworkServerControl start where
${yourPolicyFile} is a file containing a customized version of the
policy file described in the Java DB Admin Guide section titled Basic
Network Server security policy. You must customize that generic policy
file to fit your application. In addition, you must add the following
permission to the permissions block granted to the
${derby.install.url}derbynet.jar codebase:
permission java.net.SocketPermission "localhost:${port}", "listen";
where ${port} should be replaced by the port number where the network
server listens for incoming connection requests. By default, that is
port 1527.
now I exactly not sure what to do
*do I need to do any additional stuff
*found derbynet.jar ( as an executable jar file) how do I edit, what do I edit
Thanks,
Think you need to show
1) How your start the server (cmdline)
2) The stacktrace you get
3) Content of your policy file
Alternatively you could study the comments in the corresponding Derby Jira issue
After significant searching and trial and error, I still can not determine if a Security Manager is necessary and if so, how to make it work.
Code to start server:
Registry registry;
try {
System.setProperty("java.security.policyfile", "\\\\...\\security.policy");
if (System.getSecurityManager() == null) {
RMISecurityManager securityManager = new RMISecurityManager();
System.setSecurityManager(securityManager);
}
registry = LocateRegistry.createRegistry(port);
registry.bind(serviceName, remote);
System.out.println("RMI registry created.");
} catch (RemoteException e) {
//error means registry already exists
System.out.println("RMI registry already exists.");
}
System.setProperty("java.rmi.server.hostname", hostURL);
Naming.rebind(hostURL, remote);
Error Message on Server:
D:\>java -jar Server.jar
RMI server starting up
RMI registry created.
Exception in thread "main" ...Exception: Unable to start the Remote Server Server[UnicastServerRef [liveRef: [...]]
at ServiceProvider.start(ServiceProvider.java:64)
at Server.main(Server.java:76)
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.rmi.server.hostname" "write")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at ServiceProvider.start(ServiceProvider.java:61)
... 1 more
Policy file:
grant {
permission java.security.AllPermission;
};
Thank you to anyone who can help.
I'll admit I'm not even sure I need the Security Manager, but when I didn't use it, I got the below. At least here the server started and I was able to connect to it from the client (the IP address provided was not used to get the connection, this was figured out internally). However, I get the below error message when I try to use one of the methods from the server, even just "printTime", which is supposed to just display the time on the server side.
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: ...IP...; nested exception is:
java.net.ConnectException: Connection timed out: connect
Thanks again.
Edit:
OK, I have removed the security manager, because all classes needed are inside my interface which is included in both my client and my server projects.
#EJP, you are clearly extremely knowledgeable when it comes tom Java and RMI. I value your comments.
I continue to get the Connection timed out error. I realize this is common, but I have tried everything I can think of.
I added the property: java.rmi.server.codebase with all of the jar files in my lib folder.
A friend indicated to me that my problem is I have included POJOs (Plain Old Java Objects) which are too complicated for RMI to transmit. But all of my POJOs are serializable. Also, I was able to run the server on my localhost and access it using a client app without issue. This tells me that RMI can do the work I'm asking.
I don't get this Connection error until I run the server on a remote machine and then start my client. My client is able to connect, but then gets hung up at the printTime method.
Code to run client:
final Registry registry = LocateRegistry.getRegistry(hostURL, port);
final HXTTDBFInterface serverIX = (HXTTDBFInterface) registry.lookup(serviceName);
//Start with simple Server Connection Test
serverIX.printTime(); //CONNECTION TIMED OUT ERROR HERE
String time = serverIX.getTime();
System.out.println("Time From Server: " + time);
If anyone has any suggestions for things to try, I am all ears.
Thanks in advance.
Further Clarification:
I used the command netstat -a and it showed:
LocalAddress ForeignAddress State
0.0.0.0:1099 SERVERNAME:0 LISTENING
[::]:1099 SERVERNAME:0 LISTENING
XX.XX.XX.XX:53373 SERVERNAME:1099 ESTABLISHED
(Among many other lines)
Does this mean that it's actually listening?
You only need to install a security manager for RMI if the peer is using the codebase facility to supply classes to you dynamically. Otherwise it is strictly up to you whether you use one or not. I would avoid it unless you know it's required.
I am trying to execute this program,
http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/WebCrawler.java
The program compiles without any error after i referred this page,
http://www.velocityreviews.com/forums/t146972-web-crawler.html
But while executing using the command "appletviewer WebCrawler.html" i get this exception..
Exception in thread "Thread-4"
java.security.AccessControlException:access denied(java.net.SocketPermission java.sun.com:80 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at java.net.URL.openStream(URL.java:1010)
at WebCrawler.robotSafe(WebCrawler.java:139)
at WebCrawler.run(WebCrawler.java:235)
at java.lang.Thread.run(Thread.java:619)
How do i make it work.?
By default, an applet may only connect to the same server + port from which it is located. You could do one of the following:
Convert the app into an application, removng the security restriction
Use a trusted/signed applet
Also you could have a look at configuring the crossdomain for the applet, see:
http://weblogs.java.net/blog/2008/05/28/java-doodle-crossdomainxml-support
It's pretty straight forward to self-sign an applet (which you can do for free). If you don't sign the applet you'll only get bare minimum security access and won't give access to the sockets.
Simple 3 step guide is here:
http://www.narendranaidu.com/2007/11/3-easy-steps-to-self-sign-applet-jar.html
or a more in-depth explination:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html
When I am running RMI Server in netbeans I am getting java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
What to do?
You need to set the permissions within a policy file. An example can be found at the RMI tutorial site and also further information concering policy files.