Skip to content

Instantly share code, notes, and snippets.

@Processor
public String getDistance(@Optional @Default("San+Francisco") String origin,
String destination) throws Exception
{
String effectiveUrl = String.format(PROTOTYPE_URL, origin, destination, distanceUnit);
InputStream responseStream = new URL(effectiveUrl).openConnection().getInputStream();
try
{
return getXPath(responseStream, DISTANCE_XPATH);
}
@Module(name="googlemaps", schemaVersion="1.0")
public class GoogleMapsModule
{
private static final String PROTOTYPE_URL =
"http://maps.googleapis.com/maps/api/distancematrix/xml?origins=%s&destinations=%s&units=%s&sensor=false";
private static final String DISTANCE_XPATH = "//DistanceMatrixResponse/row/element/distance/text/text()";
@Configurable
private DistanceUnit distanceUnit;
@Processor
@Test
public void testFlow() throws Exception
{
runFlowAndExpect("testFlow", "23.8 km");
}
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:googlemaps="http://www.mulesoft.org/schema/mule/googlemaps"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/googlemaps http://www.mulesoft.org/schema/mule/googlemaps/1.0/mule-googlemaps.xsd">
<googlemaps:config distanceUnit ="KM"/>
<flow name="testFlow">
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:googlemaps="http://www.mulesoft.org/schema/mule/googlemaps"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/googlemaps http://www.mulesoft.org/schema/mule/googlemaps/1.0-SNAPSHOT/mule-googlemaps.xsd">
<googlemaps:config myProperty="Some string"
@Module(name="googlemaps", schemaVersion="1.0")
public class GoogleMapsModule
{
private static final String PROTOTYPE_URL =
"http://maps.googleapis.com/maps/api/distancematrix/xml?origins=%s&destinations=%s&units=%s&sensor=false";
private static final String DISTANCE_XPATH = "//DistanceMatrixResponse/row/element/distance/text/text()";
@Configurable
@Optional
@Default("MI")
private DistanceUnit defaultDistanceUnit;
package org.mule;
import org.mule.api.annotations.Module;
import org.mule.api.ConnectionException;
import org.mule.api.annotations.Configurable;
import org.mule.api.annotations.Processor;
@Module(name="googlemaps", schemaVersion="1.0")
public class GoogleMapsModule
{
mvn archetype:generate -DarchetypeGroupId=org.mule.tools.devkit -DarchetypeArtifactId=mule-devkit-archetype-generic -DarchetypeVersion=3.0.1 -DarchetypeRepository=http://repository.mulesoft.org/releases/ -DgroupId=org.mule -DartifactId=google-maps-connector -Dversion=1.0 -DmuleVersion=3.2.0 -DmuleModuleName=GoogleMaps
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jira="http://www.mulesoft.org/schema/mule/jira"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
http://www.mulesoft.org/schema/mule/jira http://www.mulesoft.org/schema/mule/jira/1.0/mule-jira.xsd">
<jira:add-comment issueKey="XYZ-123" commentAuthor="Federico" commentBody="This is the comment for the issue"/>