Skip to Content

Integrating External Portal Services, when no web service is exposed. At certain instances, we might face the issue of re-using services provided by external web applications but there would not be any web service available for this. In scenarios where in we need to reuse some legacy web application services, this method is the best suggestion.

In the following example I would be illustrating how we can reuse an authentication mechanism provided by an external portal application using Http Client framework.

The following method can also be used even if a webservice is exposed, but in that case a web service client will be easy to use. First let us check the external application:

image

This application has an authentication mechanism wherein an user can register and login with his/her password into the application. On successful authentication the user can continue using the application. The session now being active, the user can navigate to different pages.

image

Now the point of concern arises, as we need to reuse this authentication Service in our Enterprise Portal. In our portal application, a couple of things are necessary.

1.Parameters to be passed (In this example – username and password).
2.Which page to be hit for the service. (In this example – register.jsp).
3.On successful login the parameters that will be returned by the service.

Now we try to create an Http Request from our application with the necessary parameters and get the Http response from the external application, parse and judge the result.

The over head here lies in creating an Http Request and Http Response.

There is a simple framework called HttpClient available from Apache. For more internal details of HttpClient.
http://jakarta.apache.org/commons/httpclient/

Now the next task lies in delegating the process to the Http Client, for which we need to add the specific jar to the project

Now we try to establish the connection to the external web application and pass the necessary parameters.

In the above example; we are passing the parameter register.jsp, wherein the username and password are taken for the process and HttpReponse is generated for the response.

Now we have the string which has the HTML response of the page shown after the authentication. This HTML is parsed and all the necessary information required is got.

Here we parse the HTML using the html parser. Any parser can be used but html parsers are suggested since we can the content is taken based on tags.

So let’s first look for the “Hi” ticket which means the user has logged into the application. If not found the user is alerted that he/she was not authenticated successfully.

Next since it’s a webdynpro application all the contents are retrieved and the context variables are set as shown in the view. This can be used with any portal application, not necessary in webdynpro. The output would be like below as in a webdynpro application.

image

example shown by reusing the authentication service in webdynpro application

image

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. hi Vivek i tried to follow the code in my application. I downloaded the jar of HttpClient from Apache and added it to externakl jars. An then tried to execute the code but it was giving following error…any idea

       java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod

    why this is so..what to do for resolving it.

    (0) 
    1. Hi,
      Thanks for trying my code.
      This problem is because of the jar files not found in the classpath. Also you need to add common-codec.jar to the path.
      (0) 

Leave a Reply