No X509TrustManager implementation available htmlunit - java

For some reason my code with everything imported correctly, using Htmlunit causes an error.
package htmlunittesting;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class httpunittest {
public static void main(String[] args) throws Exception{
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("https://blockchain.info/address/17iyEdbcG3G6RrDHYsi2MzG6RY8vRYvjXm");
final HtmlDivision div = page.getHtmlElementById("final_balance");
// final HtmlAnchor anchor = page.getAnchorByName("anchor_name");
System.out.println(div);
webClient.closeAllWindows();
}
}
My error is:
Caused by: java.security.cert.CertificateException: No X509TrustManager implementation available
at sun.security.ssl.DummyX509TrustManager.checkServerTrusted(Unknown Source)
... 27 more
All I want to do is print out what the final balance is on this test wallet.
Entire StackTrace as requested:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No X509TrustManager implementation available
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:275)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:254)
at com.gargoylesoftware.htmlunit.HtmlUnitSSLConnectionSocketFactory.connectSocket(HtmlUnitSSLConnectionSocketFactory.java:155)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:117)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:178)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1313)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1230)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:338)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392)
at htmlunittet.httpunittest.main(httpunittest.java:12)
Caused by: java.security.cert.CertificateException: No X509TrustManager implementation available
at sun.security.ssl.DummyX509TrustManager.checkServerTrusted(Unknown Source)
... 27 more
And yes that is all my code, no other classes.

You should add these parameters to java virtual machine:
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "../path/yourtruststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "yourpasswordfortruststore");
If you need Mutual Authentication:
System.setProperty("javax.net.ssl.keyStore","../path../yourkeystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword","yourpasswordforkeystore");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");

Related

How to turn of the SSL certificate and get Login response using JSOUP/Rest Assured Api?

*When i tried turning off the ssl certificate validation in Postman,i got the response but iam not sure how to turn off the ssl certificate validation through code
I have used below code (JSOUP) and i am getting "javax.net.ssl.SSLHandshakeException:"
public String Login () throws Exception {
Connection.Response response = (Connection.Response) Jsoup.connect("url").ignoreContentType(true)
.method(Connection.Method.POST)
.data("login_submit","Log In", "password","Password1","username","batman","Content-Type","application/x-www-form-urlencoded")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Cache-Control", "no-cache")
.execute();
System.out.println(response.cookie("PHPSESSID"));
return response.cookie("PHPSESSID");
}
**Stacktrace:**
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
at lib.dataObject.dataCleanup.DeprecateOrganizations.Login(DeprecateOrganizations.java:24)
at lib.dataObject.dataCleanup.Login.login(Login.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 40 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 46 more*
Please tell me a way to get login response.
You can turn off the TLS certificate validation by adding the following to your connect statement:
.validateTLSCertificates(false)
like:
Jsoup.connect("url").validateTLSCertificates(false)
I finally found the answer used the below function before my Login function
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.security.cert.X509Certificate;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
public class DeprecateOrganizations {
#SuppressWarnings("unused")
public void disableSSLCertCheck() throws NoSuchAlgorithmException, KeyManagementException {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
#Override
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
throws CertificateException {
// TODO Auto-generated method stub
}
#Override
public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
throws CertificateException {
// TODO Auto-generated method stub
}
}
};

Connect to Athena using JDBC in a maven project

I'm trying to connect to the Amazon Athena, using jdbc in a maven project, but an exception is being raised. I think that the class is not being found. In Athena's guide it says:
Set the JDBC property, aws_credentials_provider_class, equal to the class name, and include itin your classpath. (1)
Since I'm using eclipse, I thought that the class would be already in the classpath, but apparently not. I tested the code in a simple java project (not maven) and it worked.
AmazonCredentialsProvider.java:
package athena;
import com.amazonaws.auth.AWSCredentials;
public class AmazonCredentials implements AWSCredentials {
#Override public String getAWSAccessKeyId() { return "..."; }
#Override public String getAWSSecretKey() { return "..."; }
}
AmazonCredentialsProvider.java:
package athena;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
public class AmazonCredentialsProvider implements AWSCredentialsProvider {
#Override public AWSCredentials getCredentials() { return new AmazonCredentials(); }
#Override public void refresh() {}
}
The code snippet of the connection :
Class.forName("com.amazonaws.athena.jdbc.AthenaDriver");
Properties properties = new Properties();
properties.setProperty("user", user);
properties.setProperty("password", password);
properties.setProperty("aws_credentials_provider_class", "athena.AmazonCredentialsProvider");
Connection connection = DriverManager.getConnection("jdbc:awsathena://athena." + region + ".amazonaws.com:443", properties);
The exception:
java.sql.SQLException: Failed to load AWS credentials provider class:
athena.AmazonCredentialsProvider at
com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.lambda$parseProperties$2(AthenaDriverPropertiesFactory.java:52)
at
com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.setClientConfigProperty(AthenaDriverPropertiesFactory.java:159)
at
com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.parseProperties(AthenaDriverPropertiesFactory.java:40)
at
com.amazonaws.athena.jdbc.AthenaDriver.connect(AthenaDriver.java:110)
at java.sql.DriverManager.getConnection(Unknown Source) at
java.sql.DriverManager.getConnection(Unknown Source) at
athena.Athena.(Athena.java:94) at
services.GraphService.verify(GraphService.java:194) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
at
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:183)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.lambda$apply$0(ResourceMethodInvoker.java:405)
at
org.glassfish.jersey.server.ServerRuntime$AsyncResponder$2$1.run(ServerRuntime.java:843)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272) at
org.glassfish.jersey.internal.Errors$1.call(Errors.java:268) at
org.glassfish.jersey.internal.Errors.process(Errors.java:316) at
org.glassfish.jersey.internal.Errors.process(Errors.java:298) at
org.glassfish.jersey.internal.Errors.process(Errors.java:268) at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
at
org.glassfish.jersey.server.ServerRuntime$AsyncResponder$2.run(ServerRuntime.java:838)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown
Source) at java.util.concurrent.FutureTask.run(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
java.lang.Thread.run(Unknown Source) Caused by:
java.lang.ClassNotFoundException: athena.AmazonCredentialsProvider at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Unknown Source) at
com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.lambda$parseProperties$2(AthenaDriverPropertiesFactory.java:44)
... 31 more
Does anyone know how to solve it?
Are you using the latest version of the JDBC driver?
If yes, try to follow these instructions:
https://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection-with-maven.html

java.security.cert.CertificateException: No subject alternative DNS name matching

I am writing a file reader through REST api, simple code as below:
import domain
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.ssl.HttpsURLConnection;
import java.net.MalformedURLException;
public class Verifier{
public static void main(String args[]) throws IOException
{
URL url = new URL("https://somehostname.xx.xxx.net/somecontent?somequery=number");
try{
HttpsURLConnection http=(HttpsURLConnection) url.openConnection();
int reponse = http.getResponseCode();
//some json processing
//...
}catch (MalformedURLException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
Then I got the error at line
int reponse = http.getResponseCode();
where the error message is:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching somehostname.xx.xxx.net found.
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at domain.main(Verifier.java:39)
Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching somehostname.xx.xxx.net found.
at sun.security.util.HostnameChecker.matchDNS(Unknown Source)
at sun.security.util.HostnameChecker.match(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 15 more
The content from the same site can be retrieved through the chrome browser, without any username or password (but it did show there is a problem with this website's security certificate in IE explorer, not in Chrome, you can continue to get the json content without typing anything).
I am thinking there might be some certificate problem in JAVA/eclipse, maybe? How can I solve it?
Thanks.
SSLContext sc = SSLContext.getInstance( "TLS");
TrustManager[] tmArr = {new X509TrustManager() {
#Override
public void checkClientTrusted(
X509Certificate[] paramArrayOfX509Certificate,
String paramString) throws CertificateException {
}
#Override
public void checkServerTrusted(
X509Certificate[] paramArrayOfX509Certificate,
String paramString) throws CertificateException {
}
#Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}};
sc.init(null, tmArr, new SecureRandom());
if (isDetail) {
if (!ValueWidget.isNullOrEmpty(tmArr)) {
System.out.println("first TrustManager:" + tmArr[0]);
}
}
huc = (HttpsURLConnection) url.openConnection();
//解决 javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching apis.map.qq.com found.
((HttpsURLConnection) huc).setHostnameVerifier(new HostnameVerifier() {
#Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});

basic: eccezione: java.lang.ExceptionInInitializerError java.lang.RuntimeException: java.lang.ExceptionInInitializerError

I am trying to write an applet that run in html page .
If I run the applet in eclipse with debug as JApplet it runs fine, but if i put it in an html it has an error.
Java console say :
basic: eccezione: java.lang.ExceptionInInitializerError
java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at org.restlet.resource.ClientResource.(ClientResource.java:405)
at com.gabrielepiscitelli.JAppletGui.RestClient.Client.listAllThreads(Client.java:39)
at com.gabrielepiscitelli.JAppletGui.Gui.GUIApplet.(GUIApplet.java:191)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.util.logging.config.file" "read")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at org.restlet.engine.Engine.configureLog(Engine.java:194)
at org.restlet.engine.Engine.register(Engine.java:380)
at org.restlet.engine.Engine.register(Engine.java:368)
at org.restlet.engine.Engine.getInstance(Engine.java:252)
at org.restlet.data.Method.(Method.java:334)
at org.restlet.data.Method.(Method.java:393)
at org.restlet.data.Method.(Method.java:358)
at org.restlet.data.Method.(Method.java:57)
... 28 more
the code at Client.java:39 is the line cr = new ClientResource(lURI); in this part of java file:
/**
*
*/
package com.gabrielepiscitelli.JAppletGui.RestClient;
import java.io.IOException;
import org.restlet.data.Status;
import org.restlet.resource.ClientResource;
import org.restlet.resource.ResourceException;
import com.gabrielepiscitelli.JAppletGui.DataGui.DataGuiPost;
import com.gabrielepiscitelli.JAppletGui.DataGui.DataGuiThread;
import com.gabrielepiscitelli.JAppletGui.DataGui.DataGuiUser;
import com.gabrielepiscitelli.SystemForum.Utils.ExceptionForum;
import com.google.gson.Gson;
/**
* #author Gabriele
*
*/
public class Client {
/**
*
* #return
* #throws ExceptionForum
*/
public static DataGuiThread[] listAllThreads() throws ExceptionForum{
DataGuiThread[] lRestDataGuiThreads = null;
ClientResource cr = null;
Gson gson = new Gson();
Status status = null;
String json = null;
String lURI = "http://localhost:8182/ListThreadsAll";
cr = new ClientResource(lURI);
try {
json = cr.get().getText();
status = cr.getStatus();
if (status.getCode() != 200) {
// System.out.println(status);
// System.exit(status.getCode());
Status lStatusJson = gson.fromJson(json, Status.class);
throw new ExceptionForum(ExceptionForum.ExType.CLIENT,
"Client error.",
lStatusJson.getDescription() + lStatusJson.getReasonPhrase());
} else {
lRestDataGuiThreads = gson.fromJson(json, DataGuiThread[].class);
}
} catch (ResourceException e) {
// e.printStackTrace();
throw new ExceptionForum(ExceptionForum.ExType.CLIENT,
"Client error.",
e.getMessage());
} catch (IOException e) {
// e.printStackTrace();
throw new ExceptionForum(ExceptionForum.ExType.CLIENT,
"Client error.",
e.getMessage());
}
return lRestDataGuiThreads;
}
Html file is simply :
<html><body>
<p>
<applet code="com.gabrielepiscitelli.JAppletGui.Gui.GUIApplet.class" archive="GUIApplet.jar,miglayout15-swing.jar,org.restlet.jar,gson-2.2.4.jar"
width="800" height="640"></applet>
</p>
Is there someone that can explain me the problem? thanks in advances!
Caused by: java.security.AccessControlException: access denied
("java.util.PropertyPermission" "java.util.logging.config.file" "read")
This applet needs to be trusted. Digitally sign the applet code.

ServerException is being thrown while binding RMI service

I'm trying to build simple echo server as RMI application (step by step as it's described in Sun tutorial).
All source code is shown below, it's very simple:
package test;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface EchoServer extends Remote {
public String sendString (String str) throws RemoteException;
}
package test;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class EchoServerImpl extends UnicastRemoteObject implements EchoServer {
public EchoServerImpl () throws RemoteException {
super ();
}
public String sendString (String str) throws RemoteException {
return str.toUpperCase();
}
}
package test;
import java.rmi.Naming;
public class RMIServer {
public RMIServer () {
try {
EchoServer eServer = new EchoServerImpl ();
Naming.rebind ("rmi://localhost:1099/EchoService", eServer); // <--exception
} catch (Exception e) {
e.printStackTrace ();
}
}
public static void main(String[] args) {
new RMIServer ();
}
}
I compile code with rmic and I see file EchoServerImpl_Stub.class. After that I run 'rmiregistry' and then I start RMIServer. And at that moment I see ServerException:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.EchoServerImpl_Stub
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
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 java.rmi.Naming.rebind(Naming.java:160)
at test.RMIServer.(RMIServer.java:10)
at test.RMIServer.main(RMIServer.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.EchoServerImpl_Stub
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: test.EchoServerImpl_Stub
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 12 more
I think it's a common problem and it's probably connected with wrong deploying. How to fix it?
I think it's your rmiregistry classpath. The test.EchoServer interface needs to be accessible to the rmiregistry itself. Set your CLASSPATH environment variable before you run up the rmiregistry e.g.
C:\>set CLASSPATH="MyBinFolder"
C:\>rmiregistry
Also, rmic is a hangover from before Java 5. It isn't necessary to run it anymore. Just run your server and client as normal and the proxies will be created dynamically.
Regards,
MK

Categories

Resources