2 Replies Latest reply: Sep 21, 2012 3:51 AM by User572846-OC RSS

    please help me ~ use WSDL file and Java Querypage Class

    900434
      First, i can't write english very well. so before read this you know.

      i have a project. and oracle suggest "http://www.webbasedcrmsoftware.com.au/crm-on-demand-tutorials/65-java-access-to-crm-on-demand#_Toc224720963 " . Do you know this URL?

      anyway I Along the this URL Explanation. but i have a problem.

      First, please look this source.(that URL same source)

      <Java Source Start(QueryPage(Select?))>

      package crmod;

      import java.net.HttpURLConnection;
      import java.net.URL;
      import java.util.StringTokenizer;

      public class CRMOD {
      public CRMOD() {
      }

      public static void main(String[] args) {
      String jsessionid, jsessionid_full;
      String endpoint;
      try
      {
      CRMOD crmod = new CRMOD();
      System.out.println("Loggin In");
      jsessionid_full = crmod.logon("https://secure-ausomxana.crmondemand.com/Services/Integration", "MY ID", "MY PASSWORD");
      jsessionid = getSessionId(jsessionid_full);
      System.out.println(jsessionid);


      endpoint = "https://secure-ausomxdsa.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_ContactQueryPage_Input contactlist = new crmondemand.ws.contact.ContactWS_ContactQueryPage_Input();
      crmondemand.ws.contact.ContactWS_ContactQueryPage_Output outlist = new crmondemand.ws.contact.ContactWS_ContactQueryPage_Output();

      crmondemand.xml.contact.Contact[] contacts = new crmondemand.xml.contact.Contact[1];
      crmondemand.xml.contact.Contact contact = new crmondemand.xml.contact.Contact();
      crmondemand.xml.contact.Activity[] activities = new crmondemand.xml.contact.Activity[1];
      crmondemand.xml.contact.Activity activity = new crmondemand.xml.contact.Activity();

      activity.setSubject("");
      activity.setType("");
      activity.setRowStatusOld("");
      activities[0] = activity;


      contact.setContactLastName("='Lee'");
      contact.setContactFirstName("");
      contact.setContactId("");
      contact.setListOfActivity(activities);



      contacts[0] = contact;
      contactlist.setPageSize("10");
      contactlist.setUseChildAnd("false");
      contactlist.setStartRowNum("0");
      contactlist.setListOfContact(contacts);
      System.out.println("contactlist =" +contactlist);
      System.out.println("==1==");

      outlist = stub.contactQueryPage(contactlist);
      System.out.println("==2==");
      crmondemand.xml.contact.Contact[] results =
      new crmondemand.xml.contact.Contact[1];
      results = outlist.getListOfContact();
      crmondemand.xml.contact.Activity[] activitiesout =
      new crmondemand.xml.contact.Activity[1];
      int lenC = results.length;
      if (lenC > 0) {
      for (int i = 0; i < lenC; i++) {
      System.out.println(results.getContactFirstName());
      System.out.println(results[i].getContactLastName());
      System.out.println(results[i].getContactId());
      int lenA = results[i].getListOfActivity().length;
      if (lenA > 0) {
      for (int j = 0; j < lenA; j++) {
      activitiesout = results[i].getListOfActivity();
      System.out.println(" " + activitiesout[j].getSubject() + ", " + activitiesout[j].getType());
      }
      }
      }
      }


      crmod.logoff("https://secure-ausomxdsa.crmondemand.com/Services/Integration", jsessionid_full);
      System.out.println("Loggin Out");
      }
      catch (Exception e)
      {
      System.out.println(e);
      }

      }

      private static String logon(String wsLocation, String userName, String password) {
      String sessionString = "FAIL";

      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();
      }

      }

      this source excute, print this error message.

      Loggin In
      281e56bb61372daba8c0a7db2d85d403536cf7645ee1247f527466c281cf1f30.e34QbhuQbNqSci0LbhiKaheTaNyKe0
      - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
      contactlist =crmondemand.ws.contact.ContactWS_ContactQueryPage_Input@702c65ba
      ==1==
      java.net.ConnectException: Connection refused: connect
      Process exited with exit code 0.

      i found many internet homepage, but i can't solve this problem.

      help me~~~ T.T

      p.s: I set My host file -> 127.0.0.1 some-proxy.com
      JDeveloper version = 11g Release 2
      OS = windows XP