Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Importing Types From Other Modules

Every Module can declare a certain set of Types that are part of their API, which can be then used by other Modules as a way of @Import, but keeping its original namespace definition.

Cases for this may be to reuse the logic bundled inside that type (for example, a certain type of authentication), or because you want to expose the user the exact same API for configuring the same properties (like having to configure the same parameters, in the same order, with the same descriptions).

How do you do this? It’s simple, first add the dependency in your pom to the mule-plugin whose API you want to use:


       
    
1
2
3
4
5
6
    <dependency>
        <groupId>org.mule.connectors</groupId>
        <artifactId>mule-sockets-connector</artifactId> (1)
        <version>${muleSocketsConnectorVersion}</version>
        <classifier>mule-plugin</classifier> (2)
    </dependency>
1 The module where the Type is declared
2 Remember to add the mule-plugin classifier in the dependency

Then, just declare an @Import in the Extension class referencing the type you want to import:


       
    
1
2
3
4
5
6
@Extension(name = "HTTP")
@Import(type = TcpClientSocketProperties.class)
@Import(type = TcpServerSocketProperties.class)
public class HttpConnector {

}

Then, use those types in your parameters declaration:


       
    
1
2
3
4
5
6
7
@Alias("request")
public class HttpRequesterProvider implements CachedConnectionProvider<HttpExtensionClient> {

  @Parameter
  private TcpClientSocketProperties clientSocketProperties;

}

And finally see how this changes the DSL declaration, since now your extension (in this case http) can receive parameters declared in another namespace (in this example, sockets):


       
    
1
2
3
4
5
<http:request-connection>
  <http:client-socket-properties>
      <sockets:tcp-client-socket-properties connectionTimeout="1000" keepAlive="true" receiveBufferSize="1024"/>
  </http:client-socket-properties>
</http:request-connection>