Server Error screen shot com.sun.xml.ws.client.ClientTransportException:HTTP传输错误:javax.net.ssl.SSLHandshakeException:收到致命警报:certificate_unknown
如何解决这个问题? Iam尝试使用WebService表单SAP设计到java Web应用程序
package com.example.Servelet;
import com.example.Utilities.CalenderX;
import com.example.bean.EmployeeDetailsBean;
import com.sap.xi.a1s.global.EmployeeBasicDataByIdentificationQueryMessageSync;
import com.sap.xi.a1s.global.EmployeeBasicDataResponseMessageSync;
import com.sap.xi.a1s.global.EmployeeBasicDataSelectionByIdentification;
import com.sap.xi.a1s.global.EmployeeSelectionByChangedSinceDate;
import com.sap.xi.a1s.global.QueryEmployeeIn;
import com.sap.xi.a1s.global.Service;
import com.sap.xi.a1s.global.StandardFaultMessage;
import com.sap.xi.ap.common.gdt.QueryProcessingConditions;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.BindingProvider;
public class ReadEmployeeDetialsFromBydSystem extends HttpServlet {
static PrintWriter out;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, ParseException, DatatypeConfigurationException, StandardFaultMessage {
response.setContentType("text/html;charset=UTF-8");
out = response.getWriter();
EmployeeDetailsBean employeeDetailsString=new EmployeeDetailsBean();
employeeDetailsString.setFromDateToImportEmployee( request.getParameter("fromdate"));
XMLGregorianCalendar date= CalenderX.stringToXMLGregorianCalendar(employeeDetailsString.getFromDateToImportEmployee());
EmployeeSelectionByChangedSinceDate changeSinceDate=new EmployeeSelectionByChangedSinceDate();
changeSinceDate.setInclusionExclusionCode("I");
changeSinceDate.setIntervalBoundaryTypeCode("1");
changeSinceDate.setLowerBoundaryEmployeeChangedSinceDate(date);
EmployeeBasicDataSelectionByIdentification employeeDetailsRequest=new EmployeeBasicDataSelectionByIdentification();
employeeDetailsRequest.getSelectionByChangedSinceDate().add(changeSinceDate);
QueryProcessingConditions condtion=new QueryProcessingConditions();
condtion.setQueryHitsMaximumNumberValue(1000);
condtion.setQueryHitsUnlimitedIndicator(false);
EmployeeBasicDataByIdentificationQueryMessageSync finalreq=new EmployeeBasicDataByIdentificationQueryMessageSync();
finalreq.setEmployeeBasicDataSelectionByIdentification(employeeDetailsRequest);
finalreq.setProcessingConditions(condtion);
out.println("file:///F:\\Netbeans\\BydTest/WSDL/StandardEmployee.wsdl");
ReadEmployeeDetialsFromBydSystem.findBasicDataByIdentification(finalreq);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (ParseException | DatatypeConfigurationException | StandardFaultMessage ex) {
Logger.getLogger(ReadEmployeeDetialsFromBydSystem.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (ParseException | DatatypeConfigurationException | StandardFaultMessage ex) {
Logger.getLogger(ReadEmployeeDetialsFromBydSystem.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
private static EmployeeBasicDataResponseMessageSync findBasicDataByIdentification(com.sap.xi.a1s.global.EmployeeBasicDataByIdentificationQueryMessageSync employeeBasicDataByIdentificationQuerySync) throws StandardFaultMessage {
Service service = new Service();
QueryEmployeeIn port = service.getBinding();
String EndPointURL="https://my337603.sapbydesign.com/sap/bc/srt/scs/sap/queryemployeein";
Map<String, Object> context = ((BindingProvider)port).getRequestContext();
context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, EndPointURL);
context.put(BindingProvider.USERNAME_PROPERTY, "_BYDHRMS");
context.put(BindingProvider.PASSWORD_PROPERTY, "Welcome1");
try{
**EmployeeBasicDataResponseMessageSync responses= port.findBasicDataByIdentification(employeeBasicDataByIdentificationQuerySync);**
for(int i=0;i<responses.getBasicData().size();i++)
{
out.println("Employee ID :"+responses.getBasicData().get(i).getEmployeeID().getValue());
for(int j=0;j<responses.getBasicData().get(i).getBiographicalData().size(); j++)
{
out.println("Employee Name :"+responses.getBasicData().get(i).getBiographicalData().get(j).getGivenName());
}
}
out.println(responses.getProcessingConditions().getLastReturnedObjectID().getValue());
}catch(StandardFaultMessage e)
{
System.out.println("EXception : "+e);
}
return null;
}
}
答案 0 :(得分:0)
您正在尝试创建与没有官方ssl证书的服务器的SSL连接。您可以通过将服务器证书导入Java证书库来解决此问题。看这里 SSL Exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown 或者在这里 https://docs.oracle.com/javase/tutorial/security/toolsign/rstep2.html 了解更多信息
答案 1 :(得分:0)
此问题已解决
EmployeeBasicDataResponseMessageSync responses= port.findBasicDataByIdentification(employeeBasicDataByIdentificationQuerySync);
**在上面提到的行**
之前添加此代码SSLContext sc = SSLContext.getInstance("SSL");
TrustManager[] trustAllCerts = null;
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());