Mapping IP Address

smms
User offline. Last seen 2 years 26 weeks ago. Offline
Joined: 05/22/2009
Points: 10

I recently downloaded Presto 2.7.  I am still learning.  I have been tasked to map IP addresses.  I have a simple XML file that contains a few columns of data, one of them being an IP address.  I want to show this data on a MAP.  I could probably achieve this on a web page using .NET, but have no clue where to start in Presto.  I was able to publish a service in presto using this data.  I also installed the Presto Mashup Studio and Eclipse.  Can someone point me in the right direction?

Thanks

0
Your rating: None
smitchell
smitchell's picture
User offline. Last seen 3 days 13 hours ago. Offline
Joined: 08/29/2008
Points: 34

Does this data include latitude and longitude information for each IP address? 

If so, you can create a mashlet from your service that uses the Google Map view to show the IP addresses on a map. Basically, the service is supplying the data and the mashlet ties in a UI (a view).

You can find information in the Documentation on using Mashlet Maker to create a mashlet from a service. The docs are available at: 

http://www.jackbe.com/prestodocs/v2.7.0/prestolibrary/index.html

Search for mashlets or look in the table of contents for Working with Mashlets.

If your data contains address information, you need to be able to convert that to latitude and longitude -- probably with a web service. There are several that may be able to help, I'm just not the right person to direct you to them. You create a mashup that invokes your IP service, potentially transforms the data and sends it to the geographic conversion service. Then use the mashup to create the mashlet with the Google Map view.

Hope this helps,

Sara, technical writer/jackbe

 

smms
User offline. Last seen 2 years 26 weeks ago. Offline
Joined: 05/22/2009
Points: 10

This data does not include latitude and longitude.  However, I created a Mashup called [IPInfo].  IpInfo invokes a web resource that accepts a parameter (IP) and returns an XML result set that includes latitude and longitude.

Now I am trying to "Mash" together IPInfo and my original service that included IP's.  I am not sure how to pass the IP to IPinfo as a parameter and Mash this data together.

 

Current Service/Mashup:

Service:  [IPDataSource]  A REST Service with operation getData

Mashup:  [IPInfo]     Input --> Direct Invoke (IP Web Resource) --> Mashup Output

 

smitchell
smitchell's picture
User offline. Last seen 3 days 13 hours ago. Offline
Joined: 08/29/2008
Points: 34

In Wires, there is an Input action that defines an input for the mashup. In EMML, this is equivalent to the <input> statement. What you need then is to have the output from your original service act as the input to IPInfo.

If there are multiple IPs (and I'm assuming that there are), you probably need to do this in EMML and use one of the looping statments to loop through the multiple IP addresses and feed them one by one into IPInfo.

There are many sample mashups that use <foreach>. Or try the documentation ;-) at: 

http://www.jackbe.com/prestodocs/2.7.0/prestolibrary/index.html and search for <foreach>.

 

Sara, technical writer/jackbe

 

smms
User offline. Last seen 2 years 26 weeks ago. Offline
Joined: 05/22/2009
Points: 10

 

Ok. I think I have all the pieces, but I am having problems putting them together.
I have an IPLookup.emml script. This Mashup has an input parameter "ip". Performs a direct invoke and the result returns latitude and longitude:
<constructor outputvariable='result'>
                <result>
                                <lat>{$latHolder}</lat>
                                <lon>{$lonHolder}</lon>
                </result>
</constructor>
 
I am working on another emml script. This one gets the xml through a directinvoke, pulls out the IP address, builds a comma-separated string of IP's, and loops through them.
I want to pass each IP to IPLookup to get the corresponding latitude and longitude. Then I want to append the results to my original xml.
Is this the right way to go about this? Within my foreach loop, how do I pass my IP as an input variable into IPLookup.emml.
 
                <output name="result" type="document" />
                <variable name="directinvoke_out" type="document" default="" />
                <variable name="output_IP" type="string" service="" />
 
                <directinvoke outputvariable="directinvoke_out"
                                endpoint="http://..."
                                method="GET" ot="xml" emmlType="directinvoke" />
 
                <assign name="assign_5"
                                fromexpr="string-join($directinvoke_out/*:keyIndicator/*:item/*:subcategory/*:ip/string(),',')"
                                outputvariable="output_IP" />
 
                <foreach variable="token" items="tokenize($output_IP, ',')">
                                <annotate variable="result" expr=".">
                                                                element item {$token}
                                                </annotate>
                </foreach>

smitchell
smitchell's picture
User offline. Last seen 3 days 13 hours ago. Offline
Joined: 08/29/2008
Points: 34

If you have published IPInfo to Presto, you use the <invoke> statement to invoke the mashup. <invoke> allows you to pass inputvariables -- but they must be entered in the order in which they are defined in your mashup script. If there is only one <input>, then it's fairly simple.

You also need to know the operation name for the mashup. Look in Service Explorer to see whether the operation name is "runMashup" or "Invoke" (most likely if you did not specify <operation> in the mashup script).

Assuming an operation name of runMashup, something like this should work: 

<invoke service="IPInfo" operation="runMashup" inputvariables="token" outputvariable="result"/>

will create $result with the output from IPInfo.

 

Sara, technical writer/jackbe

 

Karthic Thope
Karthic Thope's picture
User offline. Last seen 7 weeks 6 days ago. Offline
Joined: 09/22/2008
Points: 61

Assuming you have already published your IPLookup mashup, here is how you can pass parameters to it in EMML:

<invoke service="IPLookup" operation="OpName" inputvariable="ipToken" outputvariable="result" />

You should be able to do this directly inside the foreach call. Also, take a look at the parallel attribute of foreach to execute the IPLookup calls in parallel.

mtriner
mtriner's picture
User offline. Last seen 14 hours 42 min ago. Offline
Joined: 10/13/2008
Points: 47

I assume this is Branden since we have communiated previously.

Here is an EMML script that should accomplish what you want:

 

<mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jackbe.com/2008-03-01/EMMLSchema ../src/schemas/EMMLSpec.xsd"
    xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema" xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro"
    name="AMNGIpLoop">

    <operation name="invoke">
        <input name="IPs" type="string" default="33.22.12.22,33.220.21.10" />
        <variable name="IPList" type="document" />
        <variable name="currentIp" type="string" />
        <variable name="tempResult" type="document" />
        <output name="result" type="document" />

        <assign outputvariable="IPList" fromexpr="tokenize($IPs,',')" />
        <display message="IPList" expr="count($IPList)" />

        <for variable="i" startcountervalue="1" finalcountervalue="count($IPList)">       
        <assign fromexpr='$IPList[$i]' outputvariable='currentIP'/>   
        <invoke service="AMNGIPLookup" operation="invoke"
            inputvariables="currentIP" outputvariable="tempResult" />         
            <appendresult outputvariable="result">
                $tempResult
             </appendresult>

        </for>

    </operation>
</mashup>

 

Hope this helps!

 

Matt
 

smms
User offline. Last seen 2 years 26 weeks ago. Offline
Joined: 05/22/2009
Points: 10

 

Thanks to everyone’s input I was able to create the Mashlet I needed. This is what I was able to come up with. If anyone sees room for improvement, please let me know.
 
I was given an xml document that contained some data that included IP addresses. I needed to Map these IP addresses.
 
This Mashup accepts parameter (ip) and returns information about that IP; specifically latitude and longitude.
GeoIpLookUp.emml:
            <!-- Define variables -->
            <output name="result" type="document" />
            <input name="ip" type="string" />
            <variable name='filterResult' type='string' />
            <variable name='ipHolder' type='string' />
            <variable name='latHolder' type='string' />
            <variable name='lonHolder' type='string' />
            <variable name='countryHolder' type='string' />
            <variable name='regionHolder' type='string' />
            <variable name='cityHolder' type='string' />
            <variable name='zipHolder' type='string' />
            <variable name='url' type='string' default="http://ipinfodb.com/ip_query.php?ip=" />
 
            <assign fromvariable="$ip" outputvariable="ipHolder" />
 
            <!-- Concat the input IP with the static URL -->
            <assign fromexpr="concat($url,$ip)" outputvariable="ip" />
 
            <!-- Invoke the endpoint with the URL that is now created for the request -->
            <directinvoke endpoint="$ip" method="GET" outputvariable="filterResult" />
 
            <!-- Filter out nodes for the data needed -->
            <assign fromexpr="$filterResult/*:Response/*:Ip/string()" outputvariable="ipHolder" />
            <assign fromexpr="$filterResult/*:Response/*:Latitude/string()" outputvariable="latHolder" />
            <assign fromexpr="$filterResult/*:Response/*:Longitude/string()" outputvariable="lonHolder" />
            <assign fromexpr="$filterResult/*:Response/*:CountryName/string()" outputvariable="countryHolder" />
            <assign fromexpr="$filterResult/*:Response/*:RegionName/string()" outputvariable="regionHolder" />
            <assign fromexpr="$filterResult/*:Response/*:City/string()" outputvariable="cityHolder" />
            <assign fromexpr="$filterResult/*:Response/*:ZipPostalCode/string()" outputvariable="zipHolder" />
 
            <!-- Construct output -->
            <constructor outputvariable="result">
                  <item>
                        <Ip>{$ipHolder}</Ip>
                        <Latitude>{$latHolder}</Latitude>
                        <Longitude>{$lonHolder}</Longitude>
                        <CountryName>{$countryHolder}</CountryName>
                        <RegionName>{$regionHolder}</RegionName>
                        <City>{$cityHolder}</City>
                        <ZipPostalCode>{$zipHolder}</ZipPostalCode>                                                                                        
                  </item>
            </constructor>
 
 
This Mashup takes a URL and feeds its IP’s to the Mashup above.
GeoIpGet.emml
            <!-- Define variables -->
            <output name="result" type="document" />
            <input name='url' type='string' default="http://...xml" />
     
            <variable name="directinvoke_out" type="document" default="" />
            <variable name="output_IP" type="string" service="" />
            <variable name="IPList" type="document" />
            <variable name="currentIP" type="string" />
            <variable name="tempResult" type="document" />
           
            <!-- Invoke the endpoint with the URL -->
            <directinvoke outputvariable="directinvoke_out" endpoint="$url"
                  method="GET" ot="xml" emmlType="directinvoke" />
 
            <!-- create comma-separated string of IP's -->
            <assign outputvariable="output_IP"
                  fromexpr="string-join($directinvoke_out/*:keyIndicator/*:item/*:subcategory/*:ip/string(),',')" />
 
            <!-- Breaks the $input string into a sequence of strings -->
            <assign outputvariable="IPList" fromexpr="tokenize($output_IP,',')" />
            <!-- <display message="IPList" expr="count($IPList)" /> -->
 
            <!-- Loops through the IP's and passing each to GeoIpLookUp to retrieve lat/lon -->
            <for variable="i" startcountervalue="1" finalcountervalue="50"><!-- count($IPList) -->
 
                  <assign fromexpr='$IPList[$i]' outputvariable='currentIP' />
 
                  <invoke service="GeoIpLookUp" operation="invoke"
                        inputvariables="currentIP" outputvariable="tempResult" />
                       
                  <!-- <display message="" expr="$tempResult" /> -->
                 
                  <appendresult outputvariable="result">
                        $tempResult
                   </appendresult>
 
            </for>
 
Then I used Wires to Join GeoIPGet to my REST xml Service on IP.