soi-toolkit / soi-toolkit-mule

SOI Toolkit and Mule ESB
Apache License 2.0
6 stars 1 forks source link

Document how to add support for the servlet transport to an integration component if not added from the beginning #153

Open hdahl opened 9 years ago

hdahl commented 9 years ago

Original issue 153 created by soi-toolkit on 2011-06-17T07:03:03.000Z:

Sample explanation

Add support for the servlet transport

  1. Generate web-projects for the IC No good support for that right now... Has to generate a new IC with the same name and manually copy the two web-projects + update the main-parent-pom.xml-file
  2. Add jetty (embedded servlet container used for tests) to the service-projects pom-xml file Add: <dependency> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty</artifactId> <scope>test</scope> <version>6.1.11</version> </dependency>
  3. Add the servlet-transport in common.xml - file Add the line: <servlet:connector name="servletConnector" />
  4. Add a servlet-container to the MuleServer.java - file

    • Change import from: import org.soitoolkit.commons.mule.test.StandaloneMuleServer; to: import org.soitoolkit.commons.mule.test.MuleServerWithServletContainer;
    • Add the following member variables: public static final int HTTP_PORT = ${servletPort}; public static final String CONTEXT_PATH = "/${artifactId}"; public static final String MULE_SERVLET_URI = "/services";
    • Change how the Mule-server is started, i.e. add a servlet-container to it, change: StandaloneMuleServer muleServer = new StandaloneMuleServer(MULE_SERVER_ID, MULE_CONFIG); to: MuleServerWithServletContainer muleServer = new MuleServerWithServletContainer(MULE_SERVER_ID, MULE_CONFIG, HTTP_PORT, CONTEXT_PATH, MULE_SERVLET_URI);
    • Change the implementation of the getAddress() - method, from: String url = rb.getString(serviceUrlPropertyName); logger.info("URL: {}", url); return url; to: String url = rb.getString(serviceUrlPropertyName);

    if (!url.startsWith("servlet://")) { logger.info("Non servlet URL: {}", url); return url; }

    String uri = url.substring("servlet://".length()); url = "http://localhost:&quot; + HTTP_PORT + CONTEXT_PATH + MULE_SERVLET_URI + "/" + uri; logger.info("Servlet URL: {}", url); return url;

  5. Update all integration tests that tests the servlet-transport
    • Add imports: import static org.soitoolkit.commons.mule.mime.MimeUtil.sendFileAsMultipartHttpPost; import static ${javaPackage}.${capitalizedJavaArtifactId}MuleServer.getAddress; import static ${javaPackage}.${capitalizedJavaArtifactId}MuleServer.MULE_SERVER_ID; import static ${javaPackage}.${capitalizedJavaArtifactId}MuleServer.HTTP_PORT; import static ${javaPackage}.${capitalizedJavaArtifactId}MuleServer.CONTEXT_PATH; import static ${javaPackage}.${capitalizedJavaArtifactId}MuleServer.MULE_SERVLET_URI;
    • Change import from: import org.soitoolkit.commons.mule.test.AbstractTestCase; to: import org.soitoolkit.commons.mule.test.AbstractTestCaseWithServletEngine;
    • Change base-class from: AbstractTestCase to: AbstractTestCaseWithServletEngine
    • Initialize the embedded servlet-container in the constructor:

// Initialize servlet engine in baseclass with proper values super(MULE_SERVER_ID, HTTP_PORT, CONTEXT_PATH, MULE_SERVLET_URI);

  1. Change all exposed http(s) - endpoints to the servlet-transport in the config.properties-file

...example...

hdahl commented 9 years ago

Comment #1 originally posted by soi-toolkit on 2011-11-30T13:22:09.000Z:

Moved to 0.5.1

hdahl commented 9 years ago

Comment #2 originally posted by soi-toolkit on 2012-04-06T07:52:37.000Z:

Moved to 0.5.2

hdahl commented 9 years ago

Comment #3 originally posted by soi-toolkit on 2012-04-06T07:53:29.000Z:

Moved to 0.5.2

hdahl commented 9 years ago

Comment #4 originally posted by soi-toolkit on 2012-07-26T16:17:56.000Z:

Move all v0.5.2 issues to v0.6.2