Quantcast
Channel: Forums - ArcGIS Viewer for Flex
Viewing all articles
Browse latest Browse all 2097

NOAA.gov Crossdomain issue for custom Magnetic Declination Widget

$
0
0
Hello All,

I created a custom widget that works well developed from my pc but when I push it to the server it fails--. I know there are potential proxy/php work arounds but I think it may be useful to others so if I could fix it and share it like the other widgets. Here is the source code.

<?xml version="1.0" encoding="utf-8"?>
<!--
///////////////////////////////////////////////////////////////////////////
// Copyright (c) 2010-2011 Esri. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

creationComplete="userRequest.send()"


<s:HTTPService id="userRequest" url="http://www.ngdc.noaa.gov/geomag-web/#declination"
useProxy="false" method="GET">
<mx:request xmlns="">
<lat1>{username.text}</lat1>
<lon1>{emailaddress.text}</lon1>
<resultFormat>xml</resultFormat>
</mx:request>
</s:HTTPService>

userRequest.send();
<mx:DataGrid id="dgUserRequest" x="200" y="300" width="300"
dataProvider="{userRequest.lastResult.maggridresult.result}">
<mx:columns>
<mx:DataGridColumn headerText="Declination (Retain Negative)" dataField="declination"/>
<mx:DataGridColumn headerText="Date" dataField="date"/>
</mx:columns>
</mx:DataGrid>


///////////////////////////////////////////////////////////////////////////
-->



<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:viewer="com.esri.viewer.*"
widgetConfigLoaded="init()"
creationComplete="userRequest.send()"
>
<fx:Script>
<![CDATA[
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.utils.WebMercatorUtil;
import flash.net.*




//this function called when the widget's configuration is loaded

private function init():void
{
if (configXML) // checking for valid content in the configuration file
{
lbl.text = configXML.content || getDefaultString("helloContent");
}
}
private function helloWorld_openHandler (event:Event):void
{
map.addEventListener(MapMouseEvent.MAP_CLICK,mapClicked);
}

private function mapClicked (event:MapMouseEvent) :void
{
var content:Object = {};
content.wm = event.mapPoint;
content.ll = WebMercatorUtil.webMercatorToGeographic(event.mapPoint) as MapPoint;
username.text= ""+content.ll.y;
emailaddress.text= ""+content.ll.x;
userRequest.send();

}
protected function helloWorld_closedHandler(event:Event):void
{
map.removeEventListener(MapMouseEvent.MAP_CLICK,mapClicked);
}
public function handleLink():void
{
var newLink:URLRequest = new URLRequest(url.text);
navigateToURL(newLink,"_blank");
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="userRequest" url="http://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination.xml"
useProxy="false" method="GET">
<mx:request xmlns="">
<lat1>{username.text}</lat1>
<lon1>{emailaddress.text}</lon1>
<resultFormat>xml</resultFormat>
</mx:request>
</s:HTTPService>
</fx:Declarations>
<viewer:WidgetTemplate id="helloWorld"
width="400" height="300" open="helloWorld_openHandler(event)" closed="helloWorld_closedHandler(event)">
<viewer:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>
</viewer:layout>

<s:Label id="lbl"
width="100%"
fontSize="18"
fontStyle="italic"
fontWeight="bold"/>
<mx:Form x="200" y="200" width="400">
<mx:FormItem>
<s:Label text="Latitude" />
<s:TextInput id="username" />
</mx:FormItem>
<mx:FormItem>
<s:Label text="Longitude" />
<s:TextInput id="emailaddress" />
</mx:FormItem>

</mx:Form>
<mx:Text id="url" text="http://www.ngdc.noaa.gov/geomag-web/#declination"/>
<mx:Button label="Open New Window" click="handleLink()"/>
<mx:DataGrid id="dgUserRequest" x="200" y="300" width="300"
dataProvider="{userRequest.lastResult.maggridresult.result}">
<mx:columns>
<mx:DataGridColumn headerText="Declination (Retain Negative)" dataField="declination"/>
<mx:DataGridColumn headerText="Date" dataField="date"/>
</mx:columns>
</mx:DataGrid>
</viewer:WidgetTemplate>
</viewer:BaseWidget>

The widget config.xml is based off HelloWorld widget
<configuration>

<content>Magnetic Declination</content>

</configuration>
Attachment 33279

Error after compiling:

[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://localhost:37813/geomag-web/calculators/calculateDeclination.xml?lon1=&resultFormat=xml&lat1=?hostport=www.ngdc.noaa.gov&https=N&id=B5EFDE74-0635-BB88-74DF-8FADD75AACE2"]. URL: http://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination.xml"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()
at mx.rpc::Responder/fault()
at mx.rpc::AsyncRequest/fault()
at DirectHTTPMessageResponder/errorHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Fiddler on the server just hangs I think it might be a security issue but it still works on my PC.
Attached Thumbnails
Click image for larger version

Name:	nativewidget.JPG‎
Views:	N/A
Size:	95.0 KB
ID:	33279  

Viewing all articles
Browse latest Browse all 2097

Trending Articles