Saturday, March 22, 2025

Pega Service, Connecor

When the session state in a service package is set to Stateful, the service returns a cookie in the response with the Set-Cookie HTTP header. The cookie contains the Requestor ID of the requestor that processed the first request, with the prefix "PegaRULES." For another request to access the same session data, the external application must include the PegaRULES cookie in the header of that request. 


Subsequent request

It works even if the UserIdentifier and Passwrod not passed to the API. It works by the sticky session





REST-Service

  1. Map from Clipboard doesn't accept PageList.
  2. Map from Clipboard, Key as Page or Property will make the response type as XML.
  3. Map from Clibpard, Key can be Parameter page.
  4. Map from JSON accept Page, PageList

Connect-REST

  1. Map from Clipboard Page expects XMLstream data.
  2. Map from JSON expect json stream data

If the content-type header of the REST response returned from the REST endpoint indicates that the response message body does not contain text, the system handles the message as an array of bytes rather than as an array of characters. To map an array of bytes, complete the following steps:
  1. In the Message data section, in the Map to field, select Clipboard.
  2. In the Map to key field, enter one of the following values:
  • Text property: The system converts the text property to Base64-encoded text before writing it to the clipboard.
  • Java object property: The system converts the java object property to a java byte array before writing it to the clipboard.


Friday, January 24, 2025

Create case

 import javax.net.ssl.*;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.ProtocolException;
import java.net.MalformedURLException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;


public class Main {
    static String createCase() throws IOException, NoSuchAlgorithmException, KeyManagementException {
        String caseId=null;

        String messageContent = "";
        BufferedReader br = new BufferedReader(new FileReader(new File("CreateCase.json")));
        String line=null;
        while((line=br.readLine())!= null){
            messageContent += line;
        }
        // Printing the message
        System.out.println(messageContent);
        // URL of the API or Server
        String url = "<<URL>>";
        URL urlObj = new URL(url);

        TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        }
        };

        // Install the all-trusting trust manager
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        // Create all-trusting host name verifier
        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };

        // Install the all-trusting host verifier
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

        HttpsURLConnection postCon = (HttpsURLConnection) urlObj.openConnection();
        //postCon.setSSLSocketFactory(SSLCertificateSocketFactory.getInsecure(0, null));
        //postCon.setHostnameVerifier(getHostnameVerifier());
        postCon.setRequestMethod("POST");

        // Setting the message content type as JSON
        postCon.setRequestProperty("Content-Type", "application/json");
        postCon.setDoOutput(true);
        // for writing the message content to the server
        OutputStream osObj = postCon.getOutputStream();
        osObj.write(messageContent.getBytes());
        // closing the output stream
        osObj.flush();
        osObj.close();
        int respCode = postCon.getResponseCode();
        System.out.println("Response from the server is: \n");
        System.out.println("The POST Request Response Code :  " + respCode);
        System.out.println("The POST Request Response Message : " + postCon.getResponseMessage());
        if (respCode == HttpURLConnection.HTTP_CREATED)
        {
        // reaching here means the connection has been established
        // By default, InputStream is attached to a keyboard.
        // Therefore, we have to direct the InputStream explicitly
        // towards the response of the server
            InputStreamReader irObj = new InputStreamReader(postCon.getInputStream());
            br = new BufferedReader(irObj);
            String input = null;
            StringBuffer sb = new StringBuffer();
            while ((input = br .readLine()) != null)
            {
                sb.append(input);
            }
            br.close();
            postCon.disconnect();
            // printing the response
            String strResponse=sb.toString();
            caseId=strResponse.substring(strResponse.indexOf(" ")+1,strResponse.indexOf("\","));
        }
        else
        {
            // connection was not successful
            System.out.println("POST Request did not work.");
        }
        return caseId;
    }

    private static HostnameVerifier getHostnameVerifier() {
        HostnameVerifier hostnameVerifier = new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                HostnameVerifier hv =
                        HttpsURLConnection.getDefaultHostnameVerifier();
                return hv.verify("com.example.com", session);
            }
        };
        return hostnameVerifier;
    }

    public static void main(String[] args) throws IOException, NoSuchAlgorithmException, KeyManagementException {
        String caseId = createCase();
        System.out.println("CaseId="+caseId);
    }

}







################CreateCase.json################
{
  "caseTypeID": "ING-WB-PAM-Work-BillableAgreement",
  "content": {
    "Country":"CzechRepublic",
    "AccountDetails":{
      "AccountBIC":"INGBCZPPXXX",
      "AccountName":"NABUURS S.R.O.",
      "AccountNumber":"",
      "AccountStartDate":"20170424",
      "AccountStatus":"O",
      "AccountType":"CACC",
      "BankCode":"3500",
      "Currency":"CZK",
      "StartDate":"20170424T000000.000 GMT",
      "SubAccountType":""
    },
    "AccountIdentifiers":{
      "BBAN":"CZ1535000000001000427519",
      "Currency":"CZK",
      "IBAN":"CZ1535000000001000427519"
    },
    "GridDetails":{
      "GRIDID":"479527870",
      "IBSSRNr":"",
      "pyID":"47952787"
    }
  }
}