Sunday, October 14, 2012

Configuring KeyStore credentials in JDeveloper


In order to authenticate to https services, the server side public certificate must be acquired and added as a trusted cert entry to a keystore used by the client.  This certificate can be imported using the browser as shown in the screen shot below. This keystore stores a reference to the public certificate of the service and will be using some alias. The certificate for a web service can be obtained from the service WSDL url. Save the imported certificate to local drive.



Import Service certificate to a keystore file
·         keytool -importcert -alias testkey -file servicecertificatefile.cer  -keystore  .\my-keystore.jks -storepass keystorepassword

Tip:  keytool utility can be found the path <jdk_install_dir>/bin

List the contents of a keystore
·         keytool -list -keystore ".\my-keystore.jks"

Steps to specify the keystore that JDeveloper should use for handling https traffic:
·         Go to Tools à Preferences
·         In the LHS tree node select credentials
·         Configure the Client Trusted Certificate Keystore pointing to the my-keystore.jks location created earlier and provide the key store password




Saturday, October 6, 2012

Programmatic approach to insert record in ADF


Best approach to create or insert a row in the table which requires some custom logic to be built which needs to be called and after processing the data is to have the method which inserts/creates the row in the Application Module implementation class. Then create the data control of the method. Then bind the method to the view , where backing bean would call this create method.

Below given code is the one,which will be the method in AppModuleImpl.java. To see this class you will have to go to the AppModule.xml in Overview mode  and then click on the Java tab. Click on the edit icon which looks like a pencil and then generate the classes.



public String create(Integer a, Integer b, Integer c,
                              java.util.Date d) {
    String result="Create Complete!";
    AttributeList at = new AttributeListImpl();
    at.setAttribute("A", a);
    at.setAttribute("B", b);
    at.setAttribute("C", c);
    at.setAttribute("D", d);
    Row row = getCase1View1().createAndInitRow(at);

    at.setAttribute("A", a);
    at.setAttribute("B", b);
    at.setAttribute("C", c);
    at.setAttribute("D", d);
    this.getEmp1View1().getDBTransaction().commit();
   
      return "created";
     
  }


To expose the method as a data control, you need to click on the Client Interface  edit icon and then select the method and save. This process will create a client interface java class which will expose the method as a data control. Which can then be binded to the view.


Then the below given code can be used in the managed bean to call the method binded.

         DCBindingContainer bindings =
        (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();

        OperationBinding op = (OperationBinding)bindings.getOperationBinding("create");
        op.getParamsMap().put("a", 1);
        op.getParamsMap().put("b", 1);
        op.getParamsMap().put("c", 1);
        op.getParamsMap().put("d", new Date());
        op.execute();


Thursday, October 4, 2012

Programmatic Data Retrieval in ADF



// Get the binding context and the binding entry for the current view.
DCBindingContainer bindings =  
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
   
// Get the iterator binding instance from the iterators binded to the view
DCIteratorBinding it = (DCIteratorBinding)bindings.get("UsersView1Iterator");
   
// Retrieve the view object instance from the iterator binding, this would have the result set.
// Set the where clause with the attribute and view name
ViewObject viewObject = it.getViewObject();
viewObject.setWhereClause("USERNAME = '" + username +"'");
   
// Execute the query to retrieve the record
viewObject.executeQuery();
     
   
// Retrieve the Row from the row set retrieved
// viewObject.hasNext() can be used to iterate through the row set.
Row r = viewObject.next();
   
// Now obtain the value from the retrieved row.
String userid = r.getAttribute("AccountId").toString();