17 October 2020

Explicitly specify actuator endpoints for web

 Actuator endpoints let you monitor and interact with your application. Since Endpoints may contain sensitive information, most of them are exposed to only JMX.. To enable them via web, set following in application.properties:


management.endpoints.web.exposure.include=configprops,beans


List of endpoints can be found from section "2. Endpoints": 

https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html

25 September 2020

Embed OIC-Process in third party application using iframe

here all placeholders are case-sensitive.

https://<oic hostname>/ic/pub/components/pages/startform.html?&startformData={"processDefId":"oracleinternalpcs~<appName>~<procName>", "serviceName":"<procName>.service","operation":"<startOperatoinName>","startType":"START_PCS_FORM"}


Note: it requires existing user's session

22 June 2015

Parsing JSON using gson

Annotations in java made our life easy for development!! In this post, I would explain how to parse JSON string from REST api using GSON, a google json parsing library. use user guide and refer this link to be familiar with more on gson(google json).

Assume, REST service will return following response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
{"Card": [
    {
        "CardNumber": "4544424719784129",
        "CardStatusID": "3",
        "ExpiryDate": "04/2017",
        "CardID": "1",
        "CardTypeID": "1",
        "AccountID": "1",
        "CardNotes": "",
        "GetCash": "1"
    },
    {
        "CardNumber": "4211472898719724",
        "CardStatusID": "3",
        "ExpiryDate": "05/2018",
        "CardID": "2",
        "CardTypeID": "2",
        "AccountID": "3",
        "CardNotes": "",
        "GetCash": "1"
    }]
}

Here, CardNumber, CardStatusID, ExpiryDate, CardID etc will be the primitive types and the block of content in "{}" will represent one object and pushed into java objects. The block "[]" represents an array of elements or start & end of array. The name "Card" is the key/name to the array. Again, curly braces around "Card" represent one object.

So, I have created 2 classes "Card.java" & "CardData.java". class "Card.java" will store all the primitives here and represent each block. "CardData.java" represent the entire block.

GSON can parse only primitive and user-defined types but not arrays etc.. For this to handle, we have to provide de-serializer helper class. A simple example that I have used here is as below:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class CardListDeserializer implements JsonDeserializer<List<Card>> {
  public List<Card> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {
      List<Card> list = new ArrayList<Card>();
      Gson gson = new Gson();
      list.addAll( Arrays.asList(gson.fromJson(json.getAsJsonArray(),Card[].class)) );
    
    return list;
  }
}

Below code snippet is for parsing the json response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class RESTClient {

    private static String LOST_CARDS_GET_URL = "http://server:port/services/json/showallcards";

    public static CardsData getLostCards(){
        CardsData cardsData = null;
        try {

            URL url = new URL(LOST_CARDS_GET_URL);
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");

            if (conn.getResponseCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : " +
                                           conn.getResponseCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));;    

            
            GsonBuilder builder = new GsonBuilder();
            builder.registerTypeAdapter(List.class, new CardListDeserializer());
            Gson gson = builder.create();
            cardsData  = gson.fromJson(br, CardsData.class);

            conn.disconnect();
            System.out.println(cardsData );
        } catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (Exception e) {

            e.printStackTrace();

        }

        return cardsData ;
    }

}

Below are the classes which have annotations to push respective primitives into variables.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import com.google.gson.annotations.SerializedName;

public class Card {

    @SerializedName("CardNumber")
    private String cardNumber;
    @SerializedName("CardStatusID")
    private String cardStatusID;
    @SerializedName("ExpiryDate")
    private String expiryDate;
    @SerializedName("CardID")
    private String cardID;
    @SerializedName("CardTypeID")
    private String cardTypeID;
    @SerializedName("AccountID")
    private String accountID;
    @SerializedName("CardNotes")
    private String cardNotes;
    @SerializedName("GetCash")
    private String getCashFlag;
    
    public Card() {
        super();
    }


    public void setCardID(String cardID) {
        this.cardID = cardID;
    }

    public String getCardID() {
        return cardID;
    }

    public void setAccountID(String accountID) {
        this.accountID = accountID;
    }

    public String getAccountID() {
        return accountID;
    }

    public void setCardNotes(String cardNotes) {
        this.cardNotes = cardNotes;
    }

    public String getCardNotes() {
        return cardNotes;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }

    public String getCardNumber() {
        return cardNumber;
    }

    public void setExpiryDate(String expiryDate) {
        this.expiryDate = expiryDate;
    }

    public String getExpiryDate() {
        return expiryDate;
    }

    public void setCardStatusID(String cardStatusID) {
        this.cardStatusID = cardStatusID;
    }

    public String getCardStatusID() {
        return cardStatusID;
    }

    public void setCardTypeID(String cardTypeID) {
        this.cardTypeID = cardTypeID;
    }

    public String getCardTypeID() {
        return cardTypeID;
    }

    public void setGetCashFlag(String getCashFlag) {
        this.getCashFlag = getCashFlag;
    }

    public String getGetCashFlag() {
        return getCashFlag;
    }
}

Here is the wrapper class which holds the list of "Card" objects.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
public class CardData {
    
    @SerializedName("Card")
    private List<Card> cardsList;
    public CardList() {
        super();
    }


    public void setCardsList(List<Card> cardsList) {
        this.cardsList = cardsList;
    }

    public List<Card> getCardsList() {
        return cardsList;
    }
}

22 May 2015

Configure EM for RightNow Adapter

This post is useful to make necessary configuration changes in Oracle Enterprise Manager to run the applications which are using RightNow adapter.
Here I'm using EM 12c:

1. Adding Permissions
You must grant permissions to access the credentials store. This task only needs to be performed once for any Oracle Weblogic Server domain.

a. Login to Oracle Enterprise Manager
b. Expand "Weblogic Domain"
c. Right click on ofm_domain(the domain name that was configured) then Select "Security" -> "System Policies"

d. From right-part of the window, search for following:
Type: Codebase
Name: Includes: jca
then Click "Search" icon(play button) as shown below:


e. Clik on the row which is having jca*****.jar then click "Edit"
f. Click "Add" button as shown below:
g. On the Add Permission page, click Select here to enter details for a new permission and enter the following details for a new permission:
Permission Class: oracle.security.jps.service.credstore.CredentialAccessPermission
Resource Name: context=SYSTEM,mapName=oracle.wsm.security,keyName=*
Permission Action: *

That's it!!

2. Adding Certificate to Weblogic Server

We have to import security certificate into weblogic where our application will be running. This is required since we are going to connect with Service Cloud which runs on https.

2.1 Downloading certificate
a. Open your web browser and type the following URL, replacing the host_name and interface details.
example: http://integration-test.rightnowdemo.com/cgi-bin/integration_test.cfg/services/soap?wsdl=typed
Where host_name is integration-test.rightnowdemo.com and interface is integration_test

b. Click the lock icon in address bar -> "Connection" tab -> click on "Certificate information".


c. A dialog box "Certificate" appears. Goto "Details" tab -> "Copy to File...". Then "Certificate Export Wizard" will be displayed. Click Next.


d. Select "Base-64 encoded X.509 (.CER)" and click Next.
e. Click "Browse.." and provide file name to store the certificate and then click "Save" -> "Next"


f. Click "Finish" then the certificate will be exported into the selected directory and with the filename.



2.2 Import Certificate into Weblogic Server
a. Login to Oracle Enterprise Manager
b. Expand "Weblogic Domain"
c. Right click on ofm_domain(the domain name that was configured) then Select "Security" -> "Keystore"


d. From the right panel of the window, Expand "system" -> Select "trust" -> click on Manage


e. Screen navigates to "Manage Certificates: system/trust". Then click "Import" and then a dialogue box appears as shown below.



Provide the details as below:
Certificate Type :  "Trusted Certificate" :
Alias : IntegrationTestServiceCloud ( can be any name for naming the certificate)
Choose "Select a file that contains the Certificate or Certificate Chain"
File Name: select the imported certificate as in previous step from the file dialogbox

f. Click "OK".

That's it!!

3. Adding credential pair
a. Login to Oracle Enterprise Manager
b. Expand "Weblogic Domain"
c. Right click on ofm_domain(the domain name that was configured) then Select "Security" -> "Credentails"

d. Click on "Create Map"
e. In the dialog, provide Map Name as "oracle.wsm.security" (without quotes) then click "OK". Because, this is the map we have configured in previous step(Adding Permissions) to be accessible by jca.

 f. Select the row "oracle.wsm.security" then click on "Create Key" and provide details as below:

Note: Credentials which will be used by RightNow Adapter. The key should be the same while configuring RightNow Adapter wizard in JDeveloper. The deployed application/soa composite will look for this name during runtime.

g. Click OK
That's it!!

20 May 2015

Installing RightNow adapter

In this post, I will explain the detailed steps of installing RightNow adapter in weblogic server. The steps are same for installing it in JDeveloper as well.

To check whether RightNow is installed: 
Goto {MIDDLEWARE_HOME}/soa/plugins/jdeveloper/extensions and check for the following jar file. oracle.cloud.adapter.rightnow.jar
If you are not able to verify in the above steps, your installation has not been successful or yet to be installed. Try to install the patch again.

1. download adapter:
a. Goto http://www.oracle.com/technetwork/middleware/adapters/downloads/index.html
b. Accept License Agreement and then Download "Oracle Cloud Adapters"
c. Or download RightNowAdapter_121300_Patch.zip from https://support.oracle.com/

2. Extract the patch file 
a. I have extracted to "D:\RN_121300_Patch"
b. Extract "p19479397_121300_Generic.zip" and the zip files under "D:\RN_121300_Patch\Prereq_patches" in their parent folder only.

3. set environment variables:
a. Point ORACLE_HOME variable to oracle's home directory. In my case it is: 
set ORACLE_HOME=D:\Oracle12c\Middleware\Oracle_Home

b. Set path variable to ORACLE_HOME/OPatch as below:
set PATH =%PATH%;%ORACLE_HOME%/OPatch;

4. Login to windows as an Administrator and start command prompt (cmd.exe) in Administrator mode
otherwise, you will get following error:
OPatch will sleep for few seconds, before re-trying to get the lock 

5. Goto patch folder:
cd D:\RN_121300_Patch

6. apply patches in following order:
a. Install patch for bug# 18706071 (SUPPORT FOR CREDENTIAL STORE FOR CLOUD CONNECTORS).
b. Install patch for bug# 18858892 (ADD CHECK FOR CLOUD JNDI IN JCA FRAMEWORK)

c. Install patch for bug# 19248641 (ERROR IN GENERATING JCA SERVICE FOR ROQL WITH PARAMETRIZED QUERY)

d. Optionally install patch for bug# 19423468 (TRACKING BUG TO PACKAGE CSF TO OSB) if your Weblogic domain has OSB.

e. Optionally install patch for bug# 19769394 (SUPPORT FOR CREDENTIAL STORE FOR CLOUD CONNECTORS FOR OSB ONLY INSTALLATION) if your  Weblogic domain has OSB only (i.e. does not include rest of SOA Suite components like BPEL etc).


7. Apply main patch 19769397

8. start jdeveloper with "-clean" option. You can right click on jdeveloper shortcut on desktop and add "-clean"(without quotes) then click OK. Then start JDeveloper normally by double clicking on the icon.

19 April 2015

Access attribute of list in ADF

I want to display 2 rows/records using PanelForm side-by-side in ADF. The records are something like this:  1st record will have old version of the data and 2nd record will have new version of the data. Both versions of data has to be displayed side-by-side to give a view to user for verifying it.

Solution:
1. Assume the data control is having the rows under "list" element.
2. Drag-and-Drop "list" element to ADF form.
3. You will get a popup for to select the UI Control. Select "Table/List view" -> ADF Table(readonly). This will create bindings for "list"


4. Now, use the following expression to access the 2nd row's attribute "col1"

bindings.list.children[1].col1


5. Now the output looks like this: