Pages

Monday, December 3, 2007

11g web services and policies

Creating web service in jdeveloper 11G with logging, security and mtom policies is a lot easier then in 10.1.3 . 11G support version 2 of JAX-RPC named JAX-WS. You can make a web service now by just putting some annotations like @WebService before the class name. JDeveloper automatically assist you by making the project web service enabled. We have a working web service with only one class. The oc4j container handles the rest. Here you have a simple example

package nl.ordina.ws;

import javax.jws.WebService;

@WebService
public class Welcome {

public String WelcomeText() {
return "hello";
}
}

you can configure it a little bit more

package nl.ordina.ws;

import javax.jws.WebService;

import oracle.webservices.annotations.AddressingPolicy;
import oracle.webservices.annotations.Deployment;
import oracle.webservices.annotations.ManagementPolicy;
import oracle.webservices.annotations.ReliabilityPolicy;

@WebService(name = "WebService", serviceName = "WebService", portName = "WebServicePort")
@Deployment(restSupport = true)
@ReliabilityPolicy("oracle/wsrm11_policy")
@AddressingPolicy("oracle/wsaddr_policy")
@ManagementPolicy( { "oracle/log_policy" })
public class Welcome {

public String WelcomeText() {
return "hello";
}
}

You can see that I use annotations for applying policies. Oracle provides a good example for this where for example the username_token_service_policy is explained. Too bad on the other security policies there is in this TP2 release no documentation or examples providid. In 10.1.3 there was a wizard which does the same but it's generate a lot of code. The policies are located at
j2ee\home\gmds\owsm\policies.
You can always use the option of creating web service the old fashion way ( jax-rpc annotated web service). This generates the wsdl and some more xml's but here you can use the same policies. This time the policies are stored in the oracle-webservices.xml file. see the xml file below

Sunday, December 2, 2007

ADF taskflow with WS method call + router

ADF taskflow supports indirect web services. This gives us new possibilities such as calling esb and bpel web services or integrating a normal web service in our flow. Integrating web services in our taskflow is easy. You can do it in 3 steps. The first step is done by making a web service proxy or much easier an web service datacontrol. The second step is making a taskflow method call (drop the datacontrol method on the taskflow) and the last step evaluating the result of the method call by using a taskflow router.
This blog gives you a guide to do this. This example is a credit check if you put in the start page a value below 200 then it is approved and above 200 it is declined. The credit is done with a router and with a method call /router.
First we create a fusion project. Now we have an empty adfc-config.xml, this is the unbounded taskflow. In this taskflow I create 3 views start, approved and declined. On the pages approved and declined I only put in an outputtext with approved or declined.
This is the start page.


In the taskflow routing and in the start page I use the following simple backing bean.

I put this bean in the adfc-config as a pageFlow managed bean. The price variable is used for the start page inputtext and the isapproved method for the router priceCheck. We are ready to drop now a router on the adfc-config.xml

In this taskflow you are already see the web server method call. I will explain this later in this blog. Let's look at the properties of the router priceCheck.

The default outcome is declined, this value is used when StartPage.approved = false when this is true then the outcome is approved. We are ready with the router example.

Let's make it a little bit interesting by calling a web service which does the credit check. We make a new empty project in the same workspace. Make a java class with a method which has 1 parameter price and it returns true when the price is below 200 else false. Create a web service on this method and deploy this on the oc4j server in the jdeveloper home. We go back to the viewcontroller project where we create a web service datacontrol on this web service. We drop the created datacontrol on the taskflow. Now automatically a method call with a pagedef is created.
I only have to fill in the fixed outcome so the control flow case goes the router where the result of the ws is evaluated.

We have the store the result of the web service in a variable so the router can used it.

The router is almost the same as the first router. We are ready to test it.

Here you have the example project. To run it you have to deploy the web service to the jdeveloper oc4j server first.

Thursday, November 29, 2007

ADF security in action

In my previous blog we enabled the project for adf security. Now is time to see it in action. I will show how you can add security to a page and to specific button actions. I use in this example the system-jazn-data.xml of the embedded oc4j. You can edit this from the menu tools / embedded oc4j server preferences.


First we make a region with security info so we can see on every page what the security settings are. This region also contains a login and logout button.

I use a backing bean to do this. The login action is done redirecting to this url /adfAuthentication?succes_url=/faces/dept.jspx and the logout is done by this /adfAuthentication?logout=true&end_url=/faces/start.jspx


public class SecurityBean {
public SecurityBean() {
}

public String getSecurityEnabled() {
if (ADFContext.getCurrent().getSecurityContext().isAuthorizationEnabled()){
return "true";
}
return "false";
}

public String getIsAuthenticated() {
if (ADFContext.getCurrent().getSecurityContext().isAuthenticated()){
return "true";
}
return "false";
}

public boolean isAuthenticated() {
return ADFContext.getCurrent().getSecurityContext().isAuthenticated();
}


public String getCurrentUser() {
return ADFContext.getCurrent().getSecurityContext().getUserName();
}

public String doLogOut() throws IOException{
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
String url = ectx.getRequestContextPath()+"/adfAuthentication?logout=true&end_url=/faces/start.jspx";
response.sendRedirect(url);

return null;
}

public String doLogIn() throws IOException{
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
String url = ectx.getRequestContextPath()+"/adfAuthentication?succes_url=/faces/dept.jspx" ;
response.sendRedirect(url);

return null;
}


}

In this example I have two pages , the first page start.jspx doesn't have any security so adf security uses the anomynous account.



the second page have security on the page , you need to have the role users to see this page and the navigation buttons are enabled if the user belows to the oc4j-administrators role.

Now let see how we can add page security to a page. To view this page you need to have view right. We can do this by opening the pagedef.

the next step is to add the view rights to the roles users and oc4j-administrators. We now go the pagedef structure window and select the pagedef node and with the right button we open the authorization window.


These security entries are put in system-jazn-data.xml and jazn use the pagedef name as unique entry so make sure you don't have the same pagedef twice on the production server else both pages has the same security.
You can do this also for the binding actions like next, first etc. Now we make sure that you need to have oc4j-administrator role to press next etc.

and we ready to test it.

Here you have the example project and the system-jazn-data.xml which you have to put in the config dir of the embedded oc4j . this are the users oc4jadmin / welcome , test / test