Forum Stats

  • 3,734,720 Users
  • 2,247,031 Discussions
  • 7,857,468 Comments

Discussions

Oracle CRM web services

2629471
2629471 Member Posts: 2

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? and 500 Internal error

"

This is the error I am getting, whenever I run the program. I have put dummy credentials

package crmod;

import com.sun.net.httpserver.Authenticator;

import crmondemand.xml.contact.Contact;

import java.io.IOException;

import java.net.HttpURLConnection;

import java.net.PasswordAuthentication;

import java.net.URL;

import java.security.Security;

import java.util.StringTokenizer;

import org.apache.axis.session.Session;

public class CRMOD {

    public CRMOD() {

    }

   

    public static void main(String[] args) {

    //  System.getProperties().put( "proxyHost", "172.17.24.24");

     // System.getProperties().put( "proxyPort", "8003");

  

   //   System.getProperties().put("proxySet", true);

     //            System.setProperty("http.proxyHost", "172.17.24.24");

     //            System.setProperty("http.proxyPort", "8003");

      //           System.setProperty("https.proxyHost", "172.17.24.24");

    //             System.setProperty("https.proxyPort", "8003");

      //           System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

      //           Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

  

    

      System.setProperty("javax.net.ssl.trustStore","C:\\Oracle\\Middleware\\jdk160_21\\jre\\lib\\security\\cacerts");

     

    System.setProperty("https.proxyHost", "172.17.24.24 ");

    System.setProperty("https.proxyPort", "8003");

       System.setProperty("mail.smtp.socketFactory.fallback", "true");

 

      String jsessionid;

             String endpoint;

             try

             {      

                

              

                                      CRMOD crmod = new CRMOD();

                                      System.out.println("Logging In");

                                      jsessionid = crmod.logon("https://secure-slsomxvka.crmondemand.com/Services/Integration", "CRM", "Ondemand");

                                      System.out.println(jsessionid);

              

               endpoint =  "https://secure-slsomxvka.crmondemand.com/Services/Integration" + ";jsessionid=" + jsessionid;

               URL urlAddr =  new java.net.URL( endpoint);

              

               crmondemand.ws.contact.Contact service = new crmondemand.ws.contact.ContactLocator();

               crmondemand.ws.contact.Default_Binding_Contact stub = service.getDefault(urlAddr);

               crmondemand.ws.contact.ContactWS_ContactInsert_Input contactlist = new crmondemand.ws.contact.ContactWS_ContactInsert_Input();

               crmondemand.ws.contact.ContactWS_ContactInsert_Output outlist = new crmondemand.ws.contact.ContactWS_ContactInsert_Output();

               crmondemand.xml.contact.Contact[] contacts = new crmondemand.xml.contact.Contact[1];

               crmondemand.xml.contact.Contact contact = new crmondemand.xml.contact.Contact();

                  

               contact.setContactFirstName("Joy");

               contact.setContactLastName("Jose");

               contact.setExternalSystemId("72134");

              

               contacts[0] = contact;

               contactlist.setListOfContact(contacts);

               contactlist.setEcho("off");  // Don’t forget this line, as the Web service call would fail!

               outlist = stub.contactInsert(contactlist);

              

               crmondemand.xml.contact.Contact[] results = new crmondemand.xml.contact.Contact[1];

               crmondemand.xml.contact.Contact result = new crmondemand.xml.contact.Contact();

               results = outlist.getListOfContact();

               result = results[0];

               System.out.println(result.getContactId());

              

              

                                      crmod.logoff("https://secure-slsomxvka.crmondemand.com/Services/Integration", jsessionid);

                                      System.out.println("Log Out");

             }

             catch (Exception  e)

             {

                     System.out.println(e);

             } 

    }

       

        

  private static String logon(String wsLocation, String userName,

                                 String password) {

         String sessionString = "FAILURE";

         try {

             // create an HTTPS connection to the On Demand webservices

             URL wsURL = new URL(wsLocation + "?command=login");

             HttpURLConnection wsConnection =

                 (HttpURLConnection)wsURL.openConnection();

             // we don't want any caching to occur

             wsConnection.setUseCaches(false);

             // we want to send data to the server

             // wsConnection.setDoOutput(true);

             // set some http headers to indicate the username and passwod we are using to logon

             wsConnection.setRequestProperty("UserName", userName);

             wsConnection.setRequestProperty("Password", password);

             wsConnection.setRequestMethod("GET");

             // see if we got a successful response

             if (wsConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {

                 // get the session id from the cookie setting

                 sessionString = getCookieFromHeaders(wsConnection);

             }

         } catch (Exception e) {

             System.out.println("Logon Exception generated :: " + e);

         }

         return sessionString;

     }

     /*

     * log off an existing web services session, using the sessionCookie information

     * to indicate to the server which session we are logging off of

     * @param wsLocation - location of web services provider

     * @param sessCookie - cookie string that indicates our sessionId with the WS provider

     *

     */

 

     private static void logoff(String wsLocation, String sessionCookie) {

         try {

             // create an HTTPS connection to the On Demand webservices

             URL wsURL = new URL(wsLocation + "?command=logoff");

             HttpURLConnection wsConnection =

                 (HttpURLConnection)wsURL.openConnection();

             // we don't want any caching to occur

             wsConnection.setUseCaches(false);

             // let it know which session we're logging off of

             wsConnection.setRequestProperty("Cookie", sessionCookie);

             wsConnection.setRequestMethod("GET");

             // see if we got a successful response

             if (wsConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {

                 // if you care that a logoff was successful, do that code here

                 // showResponseHttpHeaders(wsConnection);

             }

         } catch (Exception e) {

             System.out.println("Logoff Exception generated :: " + e);

         }

     }

     /*

     * given a successful logon response, extract the session cookie information

     * from the response HTTP headers

     *

     * @param wsConnection successfully connected connection to On Demand web services

     * @return the session cookie string from the On Demand WS session or FAIL if not

     found*

     */

 

     private static String getCookieFromHeaders(HttpURLConnection wsConnection) {

         // debug code - display all the returned headers

         String headerName;

         String headerValue = "FAIL";

         for (int i = 0; ; i++) {

             headerName = wsConnection.getHeaderFieldKey(i);

             if (headerName != null && headerName.equals("Set-Cookie")) {

                 // found the Set-Cookie header (code assumes only one cookie is being set)

                 headerValue = wsConnection.getHeaderField(i);

                 break;

             }

         }

         // return the header value (FAIL string for not found)

         return headerValue;

     }

  private static String getSessionId(String cookie) {

            StringTokenizer st = new StringTokenizer(cookie, ";");

            String jsessionid = st.nextToken();

            st = new StringTokenizer(jsessionid, "=");

            st.nextToken();

           

            return st.nextToken();

        }

  

}

Answers

This discussion has been closed.