-1

Server Error screen shotcom.sun.xml.ws.client.ClientTransportException: HTTP transport error: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown

How to resolve this Excepection?? Iam trying to consume webService form SAP By design to java web application

      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

2 Answers 2

1

you are trying to create an SSL connection to a server that doesn't have an official ssl certificate. You can work around this by importing the servers certificate into the java cert store. See here SSL Exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown or here https://docs.oracle.com/javase/tutorial/security/toolsign/rstep2.html for more information

Sign up to request clarification or add additional context in comments.

Comments

-1

this issue resolved

EmployeeBasicDataResponseMessageSync responses= port.findBasicDataByIdentification(employeeBasicDataByIdentificationQuerySync);

**add this code before above mentioned line **

SSLContext sc = SSLContext.getInstance("SSL");
                        TrustManager[] trustAllCerts = null;
                        sc.init(null, trustAllCerts, new java.security.SecureRandom());
                    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.