10. Sample LTI Java Web Application

Here is a simple Java web application that demonstrates the LTI components based on the LTI specification. This application implements a basic "Hello World" message exchange between a Tool Provider and a Tool Consumer using LTI 1.3.

First, you will need to add the LTI 1.3 libraries to your project dependencies. You can do this by adding the following Maven dependencies to your project's pom.xml file:

<dependency>

    <groupId>org.imsglobal</groupId>

    <artifactId>lti-tool-provider-api</artifactId>

    <version>1.3.4</version>

</dependency>

 

<dependency>

    <groupId>org.imsglobal</groupId>

    <artifactId>lti-tool-consumer-api</artifactId>

    <version>1.3.4</version>

</dependency>

 

Next, create a simple Java class that represents the Tool Provider. This class will handle the launch request from the Tool Consumer and respond with a “Hello World” message. Here’s an example:

 

import org.imsglobal.lti.toolProvider.*;

import org.imsglobal.lti.launch.*;

 

public class HelloWorldProvider implements ToolProvider {

 

    public void onLaunch(LtiLaunch ltiLaunch) {

        String message = "Hello, " + ltiLaunch.getUserName() + "!";

        ltiLaunch.getResponse().setParameter("message", message);

    }

 

}

 

In this example, the HelloWorldProvider class implements the ToolProvider interface from the LTI Tool Provider API. The onLaunch method is called when the Tool Consumer sends a launch request to the Tool Provider. The method constructs a "Hello World" message using the user's name from the launch parameters, and sets the message as a response parameter.

Next, create a simple Java class that represents the Tool Consumer. This class will send a launch request to the Tool Provider and display the response. Here's an example:

import org.imsglobal.lti.toolConsumer.*;

import org.imsglobal.lti.launch.*;

public class HelloWorldConsumer {

    public static void main(String[] args) {

        ToolConsumer consumer = new ToolConsumerImpl();

        LtiLaunch ltiLaunch = consumer.getLtiLaunch("http://localhost:8080/launch");

        String message = ltiLaunch.getResponse().getParameter("message");

        System.out.println(message);

    }

}

 

In this example, the HelloWorldConsumer class creates a ToolConsumerImpl object from the LTI Tool Consumer API. The getLtiLaunch method sends a launch request to the Tool Provider at the specified URL (http://localhost:8080/launch). The response from the Tool Provider is stored in the ltiLaunch object. Finally, the message parameter from the response is retrieved and displayed in the console.

 

To run this example, you will need to deploy the Tool Provider application to a web server and start it up. Then, you can run the Tool Consumer application from the command line, and it will send a launch request to the Tool Provider and display the "Hello World" message.

 

Note that this is a very basic example, and there are many more components and configurations that can be included in an LTI implementation. The IMS Global website has more resources and documentation for developing LTI applications.