Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

BaSyx / Introductory Examples / Java / Step 4

Step 4: Providing the Submodel in the network via HTTP

In this step, the code of the previous example will be extended to provide the created Submodel through its HTTP/REST interface. Submodels for the same AAS can be created and hosted on different locations in the network. For example, the AAS may be hosted in the central IT infrastructure to ensure its availability. Submodels may be hosted in the infrastructure as well, or on the device. Static information, e.g. a digital nameplate is often hosted in the IT infrastructure as well. Submodels with dynamic data may be hosted closer to the process to prevent a high network load.

Example Code

The Submodel that has been created in the previous step is made available on a HTTP REST interface by the means of the VAB. This is done by wrapping the provider in a Servlet and providing it via e.g. an Apache Tomcat server. To enable clients to connect to this model, it is registered at the registry.

  1. /**
  2.  * Expected console output in this HandsOn:
  3.  * - the heater id
  4.  * - oven is activated and deactivated multiple times
  5.  * - temperature values between 30 and 40
  6.  */
  7. public class SubModelProvider {
  8. 	// Initializes a logger for the output
  9. 	private static final Logger logger = LoggerFactory.getLogger(SubModelProvider.class);
  11. 	public static void main(String[] args) throws Exception {
  12. 		// First, a local model is created that is wrapped by a model provider (see previous step 3)
  13. 		Submodel ovenModel = createMyOvenModel(new Oven());
  14. 		// Now wrap the model in a SubmodelProvider
  15. 		IModelProvider modelProvider = new SubmodelProvider(ovenModel);
  16. 		// Up to this point, everything is known from the previous step example
  19. 		// Now, create the servlet that will provide the http/REST interface for accessing the oven Submodel
  20. 		// => Every servlet that is provided by this node is available at http://localhost:4001/handson/
  21. 		BaSyxContext context = new BaSyxContext("/handson", "", "localhost", 4001);
  23. 		// Now, the model provider is attached to a HTTP servlet that enables access to the model in the next steps through a HTTP rest interface
  24. 		// => The model will be published using an HTTP-REST interface
  25. 		HttpServlet modelServlet = new VABHTTPInterface<IModelProvider>(modelProvider);
  26."Created a servlet for the oven model");
  28. 		// The provider will be available at http://localhost:4001/handson/oven/
  29.                 // And submodel can be accessed at: http://localhost:4001/handson/oven/submodel
  30.    		context.addServletMapping("/oven/*", modelServlet);
  32. 		// Start the local HTTP server
  33. 		BaSyxHTTPServer server = new BaSyxHTTPServer(context);
  34. 		server.start();
  35."HTTP server started");
  36. 	}
  37. }

Back to the top