SOAPUI java illegalstateexception方案'https'未注册 [英] SOAPUI java illegalstateexception scheme 'https' not registered

查看:100
本文介绍了SOAPUI java illegalstateexception方案'https'未注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用soap UI测试与webservice的连接。通过将WSDL导入soapUI来创建项目,并在SSL seetings下设置密钥库和密钥库密码。

I am trying to test connection to webservice using the soap UI. Created the project by importing the WSDL into soapUI and also set the keystore and keystore password under SSL seetings.

然而,当我提交请求时,我得到以下错误。不知道如何注册https。能帮忙吗?

However when I submit the request I get below error. Not sure how to register "https". Can you please help?

java.lang.IllegalStateException: Scheme 'https' not registered


推荐答案

您可以尝试使用下面的代码在testCase中创建一个groovy testStep,此代码创建SSLContext和注册表https方案...但是我不确定这可以在您的环境中工作,因为有时候 java.lang.IllegalStateException:Scheme'https'未注册是网络中的问题(可能是你在代理等等)。希望这会有所帮助。

You can try to create a groovy testStep in your testCase with the code below, this code creates the SSLContext and registry the https scheme... however I'm not sure that this can works in your environment because some times the java.lang.IllegalStateException: Scheme 'https' not registered is an issue in the network (could be you are behind a proxy etc.). Hope this helps.

import java.io.IOException;
import java.io.FileInputStream;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.ClientParamsStack;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.DefaultedHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.entity.InputStreamEntity;
import java.security.SecureRandom;
import java.security.KeyStore;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;


HttpClient httpclient = new DefaultHttpClient();

// init SSL

// load your keystore
KeyStore keyStore = KeyStore.getInstance("jks"); 
keyStore.load(new FileInputStream("path_to_your_keystore"), "your_keystore_password".toCharArray());
// create keystore manager
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(keyStore, password.toCharArray());

// load your truststore
KeyStore trustStore = KeyStore.getInstance("jks");
trustStore.load(new FileInputStream("path_to_your_truststore"), "your_trustore_password".toCharArray());
// create truststore manager
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
trustManagerFactory.init(trustStore);

// create the ssl context
SSLContext context = SSLContext.getInstance("SSL");
context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
SSLSocketFactory ssf = new SSLSocketFactory(ctx);

//register https protocol in httpclient's scheme registry
ClientConnectionManager ccm = httpclient.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));

// create the request
HttpPost post = new HttpPost("https://your_service_endpoint_url")
def bais = new ByteArrayInputStream("<SOAP:Envelope>...your_xml</SOAP:Envelope>".getBytes("UTF-8"))
def reqEntity = new InputStreamEntity(bais, bais.available());
reqEntity.setContentType("application/xml");
post.setEntity(reqEntity);

// make the post and get the response
ResponseHandler responseHandler = new BasicResponseHandler();
def responseBody = httpclient.execute(post, responseHandler);
log.info responseBody;

或者你可以使用 SOAPUI 5.1.3 版本,似乎没有这个问题。

Alternatively you can use SOAPUI 5.1.3 version, which seems that doesn't have this problem.

这篇关于SOAPUI java illegalstateexception方案'https'未注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆