1

次のコードがあります。

// Tell the URLConnection to use a SocketFactory from our SSLContext
                HttpsTransportSE transport = new HttpsTransportSE("nnn.nnn.nnn.nnnn", xxxx, "", 500000);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.setOutputSoapObject(IFXRq);
                transport.debug = true;
                envelope.setAddAdornments(false);
                envelope.implicitTypes = true;

                try {
                    AssetManager assetManager = getAssets();
                    InputStream caInput = assetManager.open("rootcert.der");
                    Certificate ca;
                    try {
                        CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
                        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.getInstance(keyStoreType);
                    keyStore.load(null, null);
                    keyStore.setCertificateEntry("ca", ca);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

                // 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("SSL");
                context.init(null, tmf.getTrustManagers(), null);
                SSLSocketFactory ctx = context.getSocketFactory();

                try {
                    ((HttpsServiceConnectionSE) transport.getConnection()).setSSLSocketFactory(ctx);
                }/* catch (KeyManagementException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (KeyStoreException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (NoSuchAlgorithmException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }*/ catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                transport.call(SOAP_ACTION, envelope);

DER でエンコードされた証明書「rootcert.der」があります。私が直面している問題は、次のコード行が実行されるときです。

((HttpsServiceConnectionSE) transport.getConnection()).setSSLSocketFactory(ctx);

次の例外が発生します。

java.lang.NullPointerException: Attempt to invoke virtual method 'void org.ksoap2.transport.HttpsServiceConnectionSE.setSSLSocketFactory(javax.net.ssl.SSLSocketFactory)' on a null object reference

誰かが上記の解決策を提案するのを手伝ってもらえますか?

4

0 に答える 0