Flex Webservice and Android - apache-flex

I have a problem when I try to access to a webservice from a mobile application.
When I try the address of the webservice on my browser, it works, when I try in my application on the emulator of Flash Builder, it works.
But when I try it on my phone, it doesn't work!
I have access to the web in my application.
I just create the webservice in a view in MXML.
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="WebService">
<fx:Declarations>
<s:WebService id="webService" wsdl="http://serverweb/Service.asmx?WSDL">
</s:WebService>
</fx:Declarations>
</s:View>
I got this exception
[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL (http://serverweb/Service.asmx?WSDL)"]
at mx.rpc.wsdl::WSDLLoader/faultHandler()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\wsdl\WSDLLoader.as:103]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:993]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:350]
at mx.rpc::Responder/fault()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\Responder.as:68]
at mx.rpc::AsyncRequest/fault()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:113]
at DirectHTTPMessageResponder/errorHandler()[E:\dev\hero_private_beta\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:410]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Can someone help me?
Thank you

I have found and fix my problem. I use a local web server and the phone doesn't translate the hostname into the IP address. So instead of http://serverweb/Service.asmx?WSDL, I put http://192.168.0.5/webservice.asmx?wsdl (where 192.168.0.5 is the ip of serverweb)

You probably forgot to add the internet permission in the manifest. Add this in your app.xml:
<android>
<manifestAdditions>
<![CDATA[
<manifest>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
]]>
</manifestAdditions>
</android>

Related

Problems with Spring Integration HTTP outbound channel adapter

I am using spring integration 2.2.4 and am trying to add HTTP outbound channel adapter for invoking GET/POST REST services. Currently the adapter is getting displayed in the graph view but when I am trying to drag and use it in the code , it is not getting created.
I have added the HTTP namespaces URI as required.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.springframework.org/schema/integration/http"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/http
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<http:outbound-channel-adapter channel=""/>
If I am trying to add this manually in the source XML then I am getting error as "The matching wildcard is strict , but no declaration could be found for element http:outbound-channel-adapter"
Can anyone help me out here with a sample http-outbound channel adapter? Am I missing something here.

how to call java method from actionscript

I've just now started working on Flex. May be its basic question but I’m not aware of it – how can I call a java method from actionscript. I want to call some java method on double click of a event. Can you please let me know how to proceed on this?
In Flash Builder, under the Data menu, there are data service wizards:
These wizards auto-generate code and are convenient for connecting to WSDL:
Or HTTP Services:
Accessing data services overview has example implementations, such as this example calling a restaurant web service with responder returning value objects from service.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:employeesservice="services.employeesservice.*"
xmlns:valueObjects="valueObjects.*">
<fx:Declarations>
<s:WebService id="RestaurantSvc"
wsdl="http://examples.adobe.com/flex3app/restaurant_ws/RestaurantWS.xml?wsdl" />
<s:CallResponder id="getRestaurantsResult"
result="restaurants = getRestaurantsResult.lastResult as Restaurant" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
protected function b1_clickHandler(event:MouseEvent):void
{
getRestaurantsResult.token = RestaurantWS.getRestaurants();
}
]]>
</fx:Script>
<s:Button id="b1"
label="GetRestaurants"
click="button_clickHandler(event)" />
</s:Application>
References:
Accessing data services overview
Building data-centric applications with Flash Builder
Use the Data Services wizard to connect to a service

understanding AMFChannel in flex and message broker

I need to use AMFChannel in order to connect to RemoteObject in flex tried searching a lot but couldn;t get source to understand the two parameters being passed to the constructor ... I am using spring framework as a backend for my GUI created using flex .... canm some one explain me this integration of flex with spring or guide me to a proper resource to understand it... through which I can understand the overall scenerio... or atleast understand how this call is being made using message broker . PLEASE SOME ONE HELP ME BY TELLING ME WHAT IS THE MEANING OF URL WE ARE PASSING TO THE AMF CHANNEL CONSTRUCTOR
This link might help some one.
The MessageBroker transparently handles the process of serialization and deserialization between the Flex AMF data format and Java.
This link explains everything with help of example which was exactly what I was looking for
some important setup information is as follows
Server side has following files
* testdrive/src/main/webapp/WEB-INF/spring/app-config.xml
* testdrive/src/main/webapp/WEB-INF/flex-servlet.xml
* testdrive/src/main/java/flex/spring/samples/product/ProductDAO.java
Client side has one file which looks like this
Step1) Initialize a messagebroker in flex-servlet.xml
<flex:message-broker>
<flex:message-service
default-channels="my-streaming-amf,my-longpolling-amf,my-polling-amf" />
<flex:secured />
</flex:message-broker>
Step2) In the same flex-servlet.xml specify one tag
<flex:remoting-destination ref="productService" />
Step 3) In app-config.xml
<bean id="contactService" class="org.springframework.flex.samples.product.ProductDAO">
<constructor-arg ref="dataSource" />
</bean>
Step 4) ProductDAO.java is the class which will exposed for the remoting
Client side can call the remote object as follows
Step 5)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<!-- "productService" is defined in Spring's configuration file WEB-INF/config/web-application-config.xml
and provides remote access to the org.springframework.flex.samples.product.ProductDAO class -->
<mx:RemoteObject id="ro" destination="productService"/>
<mx:DataGrid dataProvider="{ro.findAll.lastResult}" width="100%" height="100%"/>
<!-- the findAll() method is defined in org.springframework.flex.samples.product.ProductDAO -->
<mx:Button label="Get Data" click="ro.findAll()"/>
</mx:Application>

Security Sandbox Violation: Lack of Policy File Permissions

I'm using as3httpclientlib to post data to my web service, but I'm continually
getting the following security violation. Does anyone know how to resolve this?
My crossdomain.xml file is below the security violation notice.
NOTE: I'm using apache to proxy requests to the web service, therefore the target url/port and the url/port serving the applet are the same -- i.e. http://192.168.100.101. Also, the crossdomain.xml file is located in the root of the web app which serves the applet rather the web service; however, since the requests are proxied the url for the file is http://192.168.100.101/crossdomain.xml
* Security Sandbox Violation * Connection to 192.168.100.101:80
halted - not permitted from
http://192.168.100.101/com-web/flex/ComUi.swf Error: Request for resource at
xmlsocket://192.168.100.101:80 by
requestor from
http://192.168.100.101/com-web/flex/ComUi.swf
is denied due to lack of policy file
permissions.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*" secure="false" />
<allow-access-from domain="*" to-ports="80, 8080" />
</cross-domain-policy>
Thanks.
Did you tried to debug it with WireShark, see if the app sends the request on port 843 and if the server sends back the response via socket? It was not totally clear in your post if you already use a server app to serve the policy file, if not, you should, either the way, the link below should help.
If you need more info about how things work, you can check out this

Flash Security Error Accessing URL with crossdomain.xml

I recently deployed a Flash application to a server, and am now experiencing errors when making HTTPService requests. I have put what I believe to be the most permissive crossdomain.xml possible in the wwwroot folder, and still get the errors.
Interestingly enough, the error only seems to occur when the request is made from a direct user interaction (i.e. button click). The application makes other requests that are initiated by other means(i.e creationComplete) , and they seem to work as expected.
Anyone see anything wrong with the crossdomain.xml, or have any other suggestions?
ERROR MESSAGE
[RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTP"]
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/securityErrorHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/redirectEvent()
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all" />
<allow-access-from domain="*" secure="false" />
<allow-http-request-headers-from domain="*" headers="*" secure="false" />
</cross-domain-policy>
You need to be careful with those crossdomain policy files because they can open up some serious security holes. You should never use a * policy on a site that uses cookie or basic auth and you should never put a * policy on an intranet server.
The easiest way to avoid those security problems and make things work is to make sure that the URL the SWF is loaded from and the URL the requests are being made to is the same protocol, hostname, and port (if specified). If they are different then you should look into using a proxy so that they are the same. BlazeDS or Apache ban easily be setup as a proxy.
try this
open config file with notepad
replace
http://servername/arcgis/rest/services/BaseMap/MapServer/#
with
http://serverip/arcgis/rest/services/BaseMap/MapServer/#

Resources