[英]IBM MQ throws java.lang.UnsupportedOperationException on SSL handshake
[英]IBM java POST API Throws an SSL HandShake Exception
我试图使用IBM Java(1.6)创建post API Rest Call,它是Out of Box of Websphere server 7(Application Server)。 建立连接时,它会抛出
线程“main”中的异常java.net.SocketException:java.lang.ClassNotFoundException:找不到指定的类com.ibm.websphere.ssl.protocol.SSLSocketFactory
通过这些链接中的这些步骤
修复该问题后,在发布请求时会抛出一个
线程“main”中的异常javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure
相同的代码适用于Oracle Java(1.6)
下面的代码是我尝试过的
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.security.Security;
public class POST {
public static void main(String[] args){
try {
POSTRequest();
} catch (IOException e) {
System.out.println("Error" + e);
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void POSTRequest() throws IOException {
Security.setProperty("ssl.SocketFactory.provider", "com.ibm.jsse2.SSLSocketFactoryImpl");
Security.setProperty("ssl.ServerSocketFactory.provider", "com.ibm.jsse2.SSLServerSocketFactoryImpl");
System.out.println("Begin Post Request");
final String POST_PARAMS = "{\n" + "\"userId\": 151,\r\n" +
" \"id\": 101,\r\n" +
" \"title\": \"VM Title\",\r\n" +
" \"body\": \"Test Body\"" + "\n}";
System.out.println(POST_PARAMS);
URL obj = new URL("https://jsonplaceholder.typicode.com/posts");
HttpURLConnection postConnection = (HttpURLConnection) obj.openConnection();
postConnection.setRequestMethod("POST");
postConnection.setRequestProperty("userId", "a1bcdefgh");
postConnection.setRequestProperty("Content-Type", "application/json");
postConnection.setDoOutput(true);
OutputStream os = postConnection.getOutputStream();
os.write(POST_PARAMS.getBytes());
os.flush();
os.close();
int responseCode = postConnection.getResponseCode();
System.out.println("POST Response Code : " + responseCode);
System.out.println("POST Response Message : " + postConnection.getResponseMessage());
if (responseCode == HttpURLConnection.HTTP_CREATED) { //success
BufferedReader in = new BufferedReader(new InputStreamReader(
postConnection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in .readLine()) != null) {
response.append(inputLine);
} in .close();
// print result
System.out.println(response.toString());
} else {
System.out.println("POST NOT WORKED");
}
}
}
Post_API.txt显示Post_API.txt。
请指教我解决这个问题。
handshake_failure
通常与不匹配的SSL / TLS协议或密码套件有关。
但是,在这种情况下,如果您查看此站点的Qualys SSL测试程序 ,则返回的4台服务器显示Java 6将因SNI不支持而失败。
所以我猜测Oracle Java 6有一些不同的默认SSL设置,或者设置为覆盖默认行为的东西,或者WebSphere Java 6是旧版本的Java 6,或两个Javas协商TLS的序列级别和密码套件是不同的。
另请注意, WebSphere 7现在已不再受支持 , Java 6也是如此 。
您可以尝试在提交给Web Service的请求中设置协议。
System.setProperty(“https.protocols”, “TLSv1,TLSv1.1,TLSv1.2”);
此外,需要注意的是修订包的版本以及WebSphere中使用的Java版本。 WebSphere使用与安装捆绑在一起的自己的Java版本。
如果WebSphere安装的版本较低,则可能需要升级WebSphere版本的Java版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.