Friday, March 27, 2015

VTU Distributed Computing Lab - Web Services

 Design and implement business logic and bind it as service using SOAP (Simple Object Access Protocol), also implement client to call service.

Right Click ->New Project
Select from Categories Java Web and Projects Web Application
Provide Project Name : TaxCalWebService
Click on next
Click on Finish
(New Project will be created)
Right click on project (TaxCalWebService) -> New -> WebService

Provide the Web Service Name (CalculateTaxService) and package name : ws. click on Finish
New Web Service class will created
Right click on CalculateTaxService -> Add web service operation



Provide name and parameters
New Method will be create in CalculateTaxService
Make the following code modifications in calculateTaxAmount method





We are done with the web service, Right click on the project and run.

Creating web service client project:

Right click project explorer -> New Project -> Java Web (Web Application)
Provide name of the project and click on Next
Click on Finish
Expand the client project -> Source page -> Right Click -> New -> Servlet
Provide : Class name : TaxCalServlet, package name : ws

Click on Next

Click on Finish.
In index.html page add new form in the body tag

Open the Serlvet class (TaxCalServlet) -> Right click -> Call Web Service Operation….
Then the follow Screen appears select the web service ( calculateTaxAmount) and click OK.
New private method will be added to TaxCalServlet.
Add the following code snippet in TaxCalSerlvet

We are done with the Client
Run the client program.
Source code: Download




Tuesday, March 24, 2015

Recursive methods in java

Recursion:

Recursion is a programming technique that allows the programmer to express operations in terms of themselves.


Recursive method to find the factorial of the number

public static int factorial(int num) {
          if (num == 0 || num == 1)
                   return 1;
          else
                   return num * factorial(num - 1);
}

Recursive method to find the sum of first N natural numbers

public static int sumofNnumber(int N) {
          if (N == 1)
                   return 1;
          else
                   return N + sumofNnumber(N - 1);
}




Recursive method to find the GCD of two numbers

public static int gcdOfNumbers(int num1, int num2) {
          if (num1 == num2)
                   return num1;
          else if (num1 > num2)
                   return gcdOfNumbers(num1 - num2, num2);
          else
                   return gcdOfNumbers(num1, num2 - num1);
}

Recursive method to multiply two numbers using Russian Peasant algorithm

public static int russianPeasantMultiply(int num1, int num2) {
          if (num1 == 1)
                   return num2;
                   else if (num1 % 2 == 1)
                             return num2 + russianPeasantMultiply(num1 / 2, num2 * 2);
                    else
                             return russianPeasantMultiply(num1 / 2, num2 * 2);

}

Recursive method to find the M^N

public static int power(int m, int n) {
                   if (n == 1)
                             return m;
                   else
                             return m * power(m, n - 1);
}

Recursion method to find the reverse of the given number

public static long reverse(long num){
          return reverse(num,0);
}
private static long reverse(long n, long m) {
          if (n == 0)
                   return m;
          else
                   return reverse(n / 10, m * 10 + n % 10);
}



Saturday, March 14, 2015

VTU Distributed Computing Lab - Program 2 (EJB)

2. Design and implement EJB (Enterprise Java Beans) session bean business logic to calculate income tax and invoke the service using stub, i.e., client side proxy object.
Categories -> java and select Java Class Library and click on next

Provide name it-remote click on finish
Then screen window appears:

Create new Project:
In categories select Java EE and select Enterprise Application in Projects  
Click on next
Unselect the Create web Application Module and click on finish
Then the following project will be created in the work space…

Right click on it-sb-eap2-ejb -> new Session Bean



Provide EJB Name:

Do the following:
EJB Name: ITService
Package: ejb
Session Type:
Select only: Stateless
Create Interface:
Select only: Remote in Project


Click on Finish
Then following screen appears:

Right click on “ITService” class and click Insert Code
Select Add Business Method
Provide:
Name: calculateTax
Return Type: double
Click on Add 3 times
Change the name, type of the parameters and mark all variables as final

Note: you may get error, if it happens click on Save button

Give the implementation for “calculateTax( )” method.
Add new method to get slabRates:
Write your logic to return tax percentage based on given input.
Finally the class “ITService”  looks:

We are done with Server side.
Client Project:
Create new Project ->  Java EE -> Enterprise Application Client
Click on Next

Click on Next
Click on Finish

Right click -> Insert Code



Select Call To Enterprise Bean

Select the Project
Click on OK

Create inner class in Main:

Create constructor TaxInformation class

Right-click -> insert code ( TaxInformation class)-> Constructor…

Select all the fields

Click on Generate.


Then inner class looks

Invoke the it calculateTax method by using itService (main method)


To display information:

We are done with client.
To Run the application:
Rght-click on “it-sb-eap2” and run

Application is deployed successful, now run the client class
Right-click on “it-sb-client” and run:
Then output on the console looks:


Spring Boot 3 : JWT with SecurityFilterChain, AuthorizeHttpRequests, RequestMatchers

pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"...