如果您想了解AzureJavaSDK:ServiceException:ForbiddenError:的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析Android2.3.xjavax.net
如果您想了解Azure Java SDK:ServiceException:ForbiddenError:的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析Android 2.3.x javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚、android – Glide – javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorExcept、Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.、Bitbucket 管道上的 Symfony Panther:FacebookWebDriverExceptionUnknownErrorException:未知错误:net::ERR_CONNECTION_REFUSED的各个方面,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- Azure Java SDK:ServiceException:ForbiddenError:
- Android 2.3.x javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚
- android – Glide – javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorExcept
- Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.
- Bitbucket 管道上的 Symfony Panther:FacebookWebDriverExceptionUnknownErrorException:未知错误:net::ERR_CONNECTION_REFUSED
Azure Java SDK:ServiceException:ForbiddenError:
尝试了基本的位置检索器代码(如下所示)
String uri = "https://management.core.windows.net/"; String subscriptionId = "XXXXXXXX-5fad-XXXXXX-9dfa-XXXXXX"; String keyStoreLocation = "D:\\test.jks"; String keyStorePassword = "123456"; Configuration config = ManagementConfiguration.configure( new URI(uri), subscriptionId, keyStoreLocation, // the file path to the JKS keyStorePassword, // the password for the JKS KeyStoreType.jks // flags that I''m using a JKS keystore ); ManagementClient client = ManagementService.create(config); // get the list of regions LocationsListResponse response = client.getLocationsOperations().list(); ArrayList<Location> locations = response.getLocations(); // write them out for( int i=0; i<locations.size(); i++){ System.out.println(locations.get(i).getDisplayName()); }
而且效果很好。但是当我尝试创建ComputeManagementClient并尝试重新启动VM时
ComputeManagementClient computeManagementClient = ComputeManagementService.create(config); VirtualMachineOperations virtualMachinesOperations= computeManagementClient.getVirtualMachinesOperations();virtualMachinesOperations.restart("SQLVM", "sqlvm.cloudapp.net");
我收到证书错误。
Exception in thread "main" java.util.concurrent.ExecutionException: com.microsoft.windowsazure.exception.ServiceException: ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription. at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:188) at com.microsoft.azure.management.compute.VirtualMachineOperationsImpl.restart(VirtualMachineOperationsImpl.java:9973) at com.microsoft.azure.compute.RestartVMExample.main(RestartVMExample.java:84)
PS:我从Java Keystore创建了一个.cer,然后毫无问题地上传到Azure。
有什么线索吗?
答案1
小编典典此问题是由于使用了不正确的Azure Java SDK库引起的。当我在下面的文件pom.xml中使用Maven依赖项时,我重现了相同的异常。
<dependency> <groupId>com.microsoft.azure</groupId> <artifactId>azure-mgmt-compute</artifactId> <version>0.8.3</version></dependency>
提供VM重新启动功能的库需要两个参数:resource group name
和vm name
。但是库的API azure-mgmt-compute
用于Azure资源管理。
若要重新启动VM,azure-svc-mgmt-compute
如果使用了JKS证书,则需要使用库的API 进行Azure Service
Management。类VirtualMachineOperations
提供同名函数restart
需要三个参数:servicename
,deployment name
和vm name
。您可以从Azure门户上的Cloud
Service仪表板中找到这些名称。在您的问题代码中,vm name
应当为“ sqlvm”。
正确的maven pom.xml用于依赖关系,如下所示:
<dependency> <groupId>com.microsoft.azure</groupId> <artifactId>azure-svc-mgmt</artifactId> <version>0.8.3</version></dependency><dependency> <groupId>com.microsoft.azure</groupId> <artifactId>azure-svc-mgmt-compute</artifactId> <version>0.8.3</version></dependency>
和下面的代码
virtualMachinesOperations.restart("<service name: sqlvm>", "<deployment name: sqlvm>", "<vm name: sqlvm>");
通过在路径JAVA_HOME / bin中使用Java Keytool进行genkeypair的以下步骤:
keytool -genkeypair -alias keyfile -keyalg RSA -keystore <KeyStore.jks> -keysize 2048 -storepass "<password>"keytool -v -export -file <KeyStore.cer> -keystore KeyStore.jks -alias keyfile
我的代码:
String uri = "https://management.core.windows.net/";String subscriptionId = "<subscription_id>";String keyStoreLocation = "KeyStore.jks";String keyStorePassword = "<password>";Configuration config = ManagementConfiguration.configure( new URI(uri), subscriptionId, keyStoreLocation, // the file path to the JKS keyStorePassword, // the password for the JKS KeyStoreType.jks // flags that I''m using a JKS keystore ); ComputeManagementClient computeManagementClient = ComputeManagementService.create(config);VirtualMachineOperations virtualMachinesOperations = computeManagementClient.getVirtualMachinesOperations();virtualMachinesOperations.restart("petercore", "petercore", "petercore");
Android 2.3.x javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚
这是我的HTTPRequestController:
public class HttpRequestController { private final static String TAG = "HttpRequestController"; private static HttpRequestController instance; public enum Method { PUT,POST,DELETE,GET } private HttpRequestController() { } public static HttpRequestController getInstance() { if (instance == null) instance = new HttpRequestController(); return instance; } public String doRequest(String url,HashMap<Object,Object> data,Method method,String token) throws Exception { InputStream certificateInputStream = null; if (MyApplication.PRODUCTION) { certificateInputStream = MyApplication.context .getResources().openRawResource(R.raw.production_cert); LogUtils.log("using production SSL certificate"); } else { certificateInputStream = MyApplication.context .getResources().openRawResource(R.raw.staging_cert); LogUtils.log("using staging SSL certificate"); } KeyStore trustStore = KeyStore.getInstance("BKS"); try{ trustStore.load(certificateInputStream,"re3d6Exe5HBsdskad8efj8CxZwv".tochararray()); } finally { certificateInputStream.close(); } TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); tmf.init(trustStore); LogUtils.log("SSL: did init TrustManagerFactory with trust keyStore"); SSLContext context = SSLContext.getInstance("TLS"); context.init(null,tmf.getTrustManagers(),null); LogUtils.log("SSL: did init context with trust keyStore"); URL request = new URL(url); HttpsURLConnection urlConnection = (HttpsURLConnection) request .openConnection(); LogUtils.log("SSL: did open HttpsURLConnection"); urlConnection.setHostnameVerifier(new StrictHostnameVerifier()); urlConnection.setSSLSocketFactory(context.getSocketFactory()); urlConnection.setConnectTimeout(15000); LogUtils.log("SSL: did set Factory and Timeout."); if (method != Method.GET){ urlConnection.setDoOutput(true); } urlConnection.setDoInput(true); urlConnection.setRequestProperty("Content-Type","application/json"); urlConnection.setRequestProperty("Accept","application/json"); LogUtils.log("SSL: urlConnection did set request properties."); if (token != null) { urlConnection.setRequestProperty("Authorization","Token " + token); } urlConnection.setRequestMethod(method.toString()); urlConnection.connect(); LogUtils.log("SSL: urlConnection did connect."); if (method != Method.GET) { ObjectMapper mapper = new ObjectMapper(); String jsonValue = mapper.writeValueAsstring(data); OutputStream os = urlConnection.getoutputStream(); os.write(jsonValue.getBytes()); os.flush(); LogUtils.log(TAG,"Params: " + jsonValue); } LogUtils.log(TAG,method.toString() + ": " + url); InputStream in = null; if (urlConnection.getResponseCode() == 200) { in = urlConnection.getInputStream(); } else { in = urlConnection.getErrorStream(); } String response = convertStreamToString(in); LogUtils.log(TAG,"Got response : " + url); LogUtils.log(TAG,"Response : " + response); return response; } public String convertStreamToString(InputStream inputStream) { BufferedReader buffReader = new BufferedReader(new InputStreamReader( inputStream)); StringBuilder stringBuilder = new StringBuilder(); String line = null; try { while ((line = buffReader.readLine()) != null) { stringBuilder.append(line + "\n"); } } catch (IOException e) { e.printstacktrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printstacktrace(); } } return stringBuilder.toString(); } public HttpClient retrieveHttpClient() { return new MyHttpClient(MyApplication.context); }
}
当我运行命令时:
openssl s_client -debug -connect www.mysitedomain.com:443
我收到了回复:
-- some key stuff -- Certificate chain 0 s:/OU=Domain Control Validated/CN=www.mydomainname.com i:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Domain Validation CA - G2 1 s:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Domain Validation CA - G2 i:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA 2 s:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA i:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA --- Server certificate -----BEGIN CERTIFICATE----- some more certificate stuff -----END CERTIFICATE----- ubject=/OU=Domain Control Validated/CN=www.mydomainname.com issuer=/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Domain Validation CA - G2 --- No client certificate CA names sent --- SSL handshake has read 4091 bytes and written 328 bytes --- New,TLSv1/SSLv3,Cipher is DHE-RSA-AES256-SHA Server public key is 2048 bit Secure Renegotiation IS supported Compression: NONE Expansion: NONE SSL-Session: Protocol : TLSv1 Cipher : DHE-RSA-AES256-SHA Session-ID: 57C379C59483809A7FE1BF8E235C5BFA7789E62AAEBCA9BC14B5273F5D1304E7 Session-ID-ctx: Master-Key: 6FCD498D1294415A42B57420F0C05AB903EF8E56CB6F1530390F73AF5E4CBC22B359D5CDA09811E075A5C598002C380D Key-Arg : None Start Time: 1390473282 Timeout : 300 (sec) Verify return code: 0 (ok) ---
所以它返回没问题…但它仍然给我测试的2.3.x设备的这个错误.
在此之后我得到一个例外:
LogUtils.log("SSL: urlConnection did set request properties.");
这是例外:
01-23 10:20:28.459: W/System.err(1623): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 01-23 10:20:28.459: W/System.err(1623): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:477) 01-23 10:20:28.459: W/System.err(1623): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:328) 01-23 10:20:28.459: W/System.err(1623): at org.apache.harmony.luni.internal.net.www.protocol.http.httpconnection.setupSecureSocket(httpconnection.java:185) 01-23 10:20:28.459: W/System.err(1623): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:433) 01-23 10:20:28.459: W/System.err(1623): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl$HttpsEngine.makeConnection(HttpsURLConnectionImpl.java:378) 01-23 10:20:28.459: W/System.err(1623): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205) 01-23 10:20:28.459: W/System.err(1623): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:152)
我称之为的方式是:
String response = HttpRequestController .getInstance() .doRequest(ApiUrls.LOGIN,params,Method.POST,null);
它适用于运行2.3.x以上Android版本的任何其他设备(根据我的测试).
Android文档似乎没有关于2.3兼容性的主题.
解决方法
我建议你在Android文档上做:
// Load CAs from an InputStream // (Could be from a resource or ByteArrayInputStream or ...) CertificateFactory cf = CertificateFactory.getInstance("X.509"); // From https://www.washington.edu/itconnect/security/ca/load-der.crt InputStream caInput = new BufferedInputStream(new FileInputStream("load-der.crt")); Certificate ca; try { ca = cf.generateCertificate(caInput); System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN()); } finally { caInput.close(); } // Create a KeyStore containing our trusted CAs String keyStoreType = KeyStore.getDefaultType(); KeyStore keyStore = KeyStore.getInstance(keyStoreType); keyStore.load(null,null); keyStore.setCertificateEntry("ca",ca); // Create a TrustManager that trusts the CAs in our KeyStore String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm); tmf.init(keyStore); // Create an SSLContext that uses our TrustManager SSLContext context = SSLContext.getInstance("TLS"); context.init(null,null); // Tell the URLConnection to use a SocketFactory from our SSLContext URL url = new URL("https://certs.cac.washington.edu/CAtest/"); HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection(); urlConnection.setSSLSocketFactory(context.getSocketFactory()); InputStream in = urlConnection.getInputStream(); copyInputStreamToOutputStream(in,System.out);
我也在做同样的事情,它在每台设备上运行正常,使用Android 2.3及以下版本,我的网站证书是私有的.
试试吧,告诉我它现在是否正常工作.
希望它能帮到你!
android – Glide – javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorExcept
我将服务器从HTTP迁移到HTTPS我已经使用自签名证书来发送带有HttpUrlConnection的网络请求并且它工作但是对于图像加载它不起作用,因为我使用Glide进行图像加载.
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.while loading images from https URL through glide library
Glide.with(mContext).load(currentItem.getimage_path().replace(" ", "%20"))
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
genericViewHolder.imageView_1.setimageResource(R.drawable.image_thumbnail);
genericViewHolder.progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
genericViewHolder.progressBar.setVisibility(View.GONE);
return false;
}
}).into(genericViewHolder.imageView_1);
我尝试使用this链接并使用GlideModule但它似乎不起作用.请帮忙.
解决方法:
问题是关于证书请按照此链接-https://stackoverflow.com/a/39032433/4741746
这将绕过证书并允许您进入系统
看到这个链接也是-https://futurestud.io/tutorials/glide-module-example-accepting-self-signed-https-certificates
创建您的自定义GlideModule类,OkHttpUrlLoader类并附上Glide,如上所述
你必须把
<Meta-data
android:name="io.futurestud.tutorials.glide.glidemodule.CustomImageSizeGlideModule"
android:value="GlideModule" />
AndroidMainifiest文件https://github.com/fs-opensource/android-tutorials-glide/blob/master/app/src/main/AndroidManifest.xml的内部应用程序标记
Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.
FATAL EXCEPTION: AdWorker #1 java.lang.NoSuchMethodError: java.io.IOException.<init> at com.google.android.gms.internal.g.f(UnkNown Source) at com.google.android.gms.internal.g.b(UnkNown Source) at com.google.android.gms.internal.e.a(UnkNown Source) at com.google.android.gms.internal.e.a(UnkNown Source) at com.google.android.gms.internal.bq.ac(UnkNown Source) at com.google.android.gms.internal.cg$1.run(UnkNown Source) at com.google.android.gms.internal.ch$1.run(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) at java.lang.Thread.run(Thread.java:1096)
除了它与谷歌广告/云服务有关,我不知道它来自哪里.直到昨天我才重现它,我启动了一个10英寸的模拟器并立即看到了问题.删除部分代码后,我认为以下部分是问题所在.
public void onActivityCreated(Bundle savedInstanceState) { ............ AdView adView = (AdView)getActivity().findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice("CED2A4FD2C192C08557081CC37AA9E54") .build(); adView.loadAd(adRequest); }
奇怪的是它只发生在10英寸或更高的设备上.我测试了各种不同的设备/版本.该问题仅发生在10英寸设备或更大的设备上. Android版本并不重要. 2.2或4.4它不断崩溃.
根据我的理解,我没有针对特定设备尺寸的任何不同布局文件夹.
我的广告定义的xml如下所示:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/mainContainer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" android:orientation="vertical" > <LinearLayout android:id="@+id/titleContainer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > </LinearLayout> <com.viewpagerindicator.TabPageIndicator android:id="@+id/indicator"android:layout_width="fill_parent" android:layout_height="wrap_content" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /> <LinearLayout android:id="@+id/adViewContainer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" > <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto" android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adUnitId="@string/adid" ads:adSize="SMART_BANNER" android:gravity="bottom" /> </LinearLayout> </LinearLayout>
我尝试了不同的横幅尺寸.没有帮助.删除广告请求代码可以解决问题,但也会删除广告.
谁有线索?
解决方法
http://developer.android.com/google/play-services/setup.html
Note: Google Play services 4.0.30 (released November 2013) and newer
versions require Android 2.3 or higher. If your app supports Android
2.2,you can continue development with the Google Play services SDK,but must instead install Google Play services for Froyo from the SDK
Manager.
http:// android-developers.blogspot.no/2013/10/google-play-services-40.html
With over 97% of devices Now running Android 2.3 (Gingerbread) or
newer platform versions,we’re dropping support for Froyo from this
release of the Google Play services SDK in order to make it possible
to offer more powerful APIs in the future. That means you will not be
able to utilize these new APIs on devices running Android 2.2 (Froyo).
https://developer.android.com/google/play-services/setup.html#ensure
Important: Because it is hard to anticipate the state of each device,
you must always check for a compatible Google Play services APK before
you access Google Play services features. For many apps,the best time
to check is during the onResume() method of the main activity.
Alernative 1用于在使用AdView之前检查Google Play服务是否可用.
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext(); if(status == ConnectionResult.SUCCESS) { //Success! Do what you want }
Alernative 2是使用GoogleAdMobAdsSdk-6.4.1.jar
Bitbucket 管道上的 Symfony Panther:FacebookWebDriverExceptionUnknownErrorException:未知错误:net::ERR_CONNECTION_REFUSED
如何解决Bitbucket 管道上的 Symfony Panther:Facebook\WebDriver\Exception\UnknownErrorException:未知错误:net::ERR_CONNECTION_REFUSED?
我们有一个基于 Symfony Panther 的功能测试,我们希望在每次提交后在 Bitbucket 管道中自动运行它。该测试可以在本地运行而没有任何问题,但在 Bitbucket 管道中它会引发以下异常:
Facebook\WebDriver\Exception\UnkNownErrorException:未知错误:net::ERR_CONNECTION_REFUSED
PHP 致命错误:未捕获的 Facebook\WebDriver\Exception\WebDriverCurlException:为 http DELETE 抛出 Curl 错误到 /session/ad5457c2f917dacfcd36b8719c20aed0 无法连接到 127.0.0.1 端口 9515:连接在 /opt/atlassian/pipelines/agent/build/vendor/PHP-webdriver/webdriver/lib/Remote/HttpCommandExecutor.PHP:332 中被拒绝
API_URL : https://localhost
任何解决问题的想法将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
今天关于Azure Java SDK:ServiceException:ForbiddenError:的讲解已经结束,谢谢您的阅读,如果想了解更多关于Android 2.3.x javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚、android – Glide – javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorExcept、Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.、Bitbucket 管道上的 Symfony Panther:FacebookWebDriverExceptionUnknownErrorException:未知错误:net::ERR_CONNECTION_REFUSED的相关知识,请在本站搜索。
本文标签: