Starting Server Transports  Locate

Server transports can be started with the org.systinet.wasp.Wasp class. If WSO2 SOA Enablement Server has not been initialized, initialization will be done automatically. The endpoint where the server should be started is either a string such as: https, which starts the HTTPS server on the port set by its configuration, or it is a string such as http://<hostname>:8080/wasp/, which means that the HTTP server should be started on port 8080 with the context /WSO2 SOA Enablement Server.

You can also pass your own configuration (created at runtime) when you start the server transport. Each transport is uniquely identified by its endpoint (absolute path) and only one transport per endpoint may be started.

Example 225 shows how to start transport servers and their absolute paths.

Example 225. Embedding: Start of Transport

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.basics.embedding;

import org.idoox.config.Configurable;
import org.idoox.config.Configurator;

import org.idoox.transport.TransportStartException;
import org.idoox.transport.config.HttpServerConfig;
import org.idoox.transport.config.MailConfig;

import org.idoox.wasp.WaspInternalException;

import org.systinet.wasp.Wasp;

import java.net.MalformedURLException;

import java.util.Arrays;


public class ServerTransports {
    public static void main(String[] args)
        throws TransportStartException, 
            MalformedURLException, 
            WaspInternalException {
        // start HTTP server on 8080 port
        System.out.println("Starting HTTP server on 8080 ...");
        Wasp.startServer("http://localhost:8080");

        // start HTTP server on 8081 port with special configuration
        System.out.println("Starting HTTP server on 8081 ...");

        Configurable config = Configurator.newRuntimeConfigurable();
        HttpServerConfig httpConfig =
            (HttpServerConfig) config.narrow(HttpServerConfig.class);
        httpConfig.setPort(8081);
        httpConfig.setMaxReadTime(0);
        httpConfig.setMaxThreads(5);
        httpConfig.setMinThreads(0);
        Wasp.startServer("http", config);

        // start MAIL server
        System.out.println("Starting MAIL server ...");
        config = Configurator.newRuntimeConfigurable();

        MailConfig mailConfig = (MailConfig) config.narrow(MailConfig.class);
        mailConfig.setInput(mailConfig.newInput());
        mailConfig.getInput()
                  .setServer("pop://wasp@pop.changeit.com");
        mailConfig.getInput()
                  .setPassword("changeit");
        mailConfig.setOutput(mailConfig.newOutput());
        mailConfig.getOutput()
                  .setFrom("wasp@changeit.com");
        Wasp.startServer("mailto", config);

        // print all endpoints for '/hello' path
        System.out.println("Absolute path for '/hello': "
            + Arrays.asList(Wasp.getAbsolutePath("/hello")));
    }
}