Einzelnen Beitrag anzeigen

meierg

Registriert seit: 8. Jul 2010
Ort: Mühlacker
1 Beiträge
 
Delphi 2010 Professional
 
#1

Webservice Java nach Delphi

  Alt 8. Dez 2014, 09:21
Hallo ...

ich möchte einen WS Service nutzen und habe von dort die unten stehenden java Zeilen bekommen.
Es ist mir zum Beispiel nicht klar, welche properties der IdHTTP ich setzen muss bzw. welche Methoden HTTP Methoden ich einsetzen soll. (IdHHTP.post oder get usw.)

Leider fehlt mir der Durchblick die SOAP request in Delphi 2010/Indy 10.1.5../IdHTTP umzusetzen.

Kann mir jemand einen Tipp geben - oder besser mehrere?

Danke!!!!



Delphi-Quellcode:
/**
       * logs the user in and gets the token
       * @param loginId
       * @param password
       * @return
       */


       private String login(String loginId, String password) {
              try {
            String httpsURL = "https://kon.saneke.....com:443/services/LandingPagesWS";
           
            URL myurl = new URL(httpsURL);
            HttpsURLConnection connection = (HttpsURLConnection)myurl.openConnection();
           
            String userpass = loginId + ":" + password;
            String encodedAuthorization = Base64.encode(userpass.getBytes()).toString();
            connection.setRequestProperty("authorization", "Basic " + encodedAuthorization);
           
            ResourceBundle bundle = ResourceBundle.getBundle("soapMessageTemplate");
            String soapTemplate = bundle.getString("landingpagesws.login");
           
            connection.setAllowUserInteraction(true);
            connection.setRequestProperty("POST", "https://kon.saneke.....com:443/services/LandingPagesWS HTTP/1.1");
            connection.setRequestProperty("Host", "kon.saneke....com:443");
            connection.setRequestProperty("Content-Length", Integer.toString(soapTemplate.length()) );
            connection.setRequestProperty("Content-Type","text/xml;charset=UTF-8");
            connection.setRequestProperty("SOAPAction", "");
            connection.setRequestProperty("Connection", "Keep-Alive");
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.connect();
           
            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
            out.write(soapTemplate);
            out.flush();
            out.close();
           
            connection.getResponseCode();
           
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String outputString;
            StringBuffer sb = new StringBuffer();
            while ((outputString = in.readLine()) != null) {
                System.out.println(outputString);
                sb.append(outputString);
            }

            in.close();
            connection.disconnect();
            String returnString = sb.toString();
            
            int start = returnString.indexOf("<return>");
            int end = returnString.indexOf("</return>");
            String responseJSON = "";
              
            if ( start > 0 && end > 0 && end > start ) {
              responseJSON = returnString.substring(start, end);
            }

            
            try {
                // Convert the input which is in XML format to a JSON object.
              WebServiceResponse respJSON = new ObjectMapper().readValue(responseJSON, WebServiceResponse.class);
              String token = respJSON.getToken();
              if ( token != null && token != "" ) {
                    return respJSON.getToken();
              }
 else {
                    return "ERROR";
              }

            } catch (Exception e) {
                e.printStackTrace();
            }

              } catch (Exception e) {
                    e.printStackTrace();
              }

              return "ERROR";

Geändert von mkinzler ( 8. Dez 2014 um 09:25 Uhr) Grund: Delphi-Tag eingefügt
  Mit Zitat antworten Zitat