getInputStream throws Exception - android

I'm trying to invoke a webservice and parse the returned XML, so my invoke URL is :
http://192.168.1.12/cr.ws/CarCategories.asmx/CarCategoryComparatorRQ?IdUser=1076&IdCurrency=1&IdLanguage=1&IdCarCategory=0&IdPickupRentCarAgencies=3&IdReturnRentCarAgencies=3&PickupDate=6/4/2011&ReturnDate=9/4/2011&Supplier=Prima%20Rent%20a%20Car&b=prima
in my browser I get the desired response :
<CarCategoryComparatorRS>
<CarCategory>
<IdCar>22</IdCar>
<IdCarCategory>22</IdCarCategory>
<Supplier>AvantGarde Rent a Car</Supplier>
<PickupRentCarAgencies>Tunis; Aéroport de Tunis-Carthage</PickupRentCarAgencies>
<IdPickupRentCarAgencies>5</IdPickupRentCarAgencies>
<ReturnRentCarAgencies>Tunis; Aéroport de Tunis-Carthage</ReturnRentCarAgencies>
<IdReturnRentCarAgencies>5</IdReturnRentCarAgencies>
<IdUser>705</IdUser>
<Title>Catégorie A [ex:Kia Rio;Renault Symbol]</Title>
<IdCurrency>1</IdCurrency>
<ImageUrl>Car-22-20090521-125545.jpg</ImageUrl>
<MemberReductionValue>0</MemberReductionValue>
<Rate>150</Rate>
<DelayRate>0</DelayRate>
<ReductionValue>135</ReductionValue>
<DayRate>45</DayRate>
<Reduction>10%</Reduction>
<AccompteValue>67.500</AccompteValue>
<Accompte>50</Accompte>
<TotalRate>0000135000</TotalRate>
</CarCategory>
</CarCategoryComparatorRS>
But this function trows java.io.FileNotFoundException
protected InputStream getInputStream() {
try {
return feedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
Please help me, I wasted couple hours searching but nothing :(
Thanks.

The error is caused by the spaces in this param :"Supplier=Prima Rent a Car", so i replaced this param by UrlEncoder.encode("Supplier=Prima Rent a Car") and it worked.

If you type that URL in your device's browser address bar do you get anything?

It looks like you are trying to request an address on a local machine or LAN. Are you requesting this on the android device? My guess is you need to run your server on the machine on a different interface or open up connections to the required port.

I think your url is being interpreted as a file url.
What about logging your url before you call openConnection as a sanity check:
Log.e("MyApp", feedUrl);
On second thought, could you post the logcat output? I'm skeptical as to how your code could ever throw a FileNotFoundException.

Related

Catch no network error in Angular HttpClient

How to catch a no network (no internet connection) error from Rxjs Observable using Angular HttpClient
RXJS Catch error code
.catch((err: HttpErrorResponse) => {
if (err.error instanceof Error) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', err.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error(`Backend returned code ${err.status}, body was: ${err.error}`);
}
// ...optionally return a default fallback value so app can continue (pick one)
// which could be a default value
// return Observable.of<any>({my: "default value..."});
// or simply an empty observable
return Observable.empty<T>();
});
Same angular error code
I'm trying to catch errors when the user has no network and is trying to post off an API request. In the code above, it says that err.error instanceof Error would catch any network errors but it doesn't.
Using both Ios and Android simulators, whenever there's no network, I would get a error code of 0 and message, Unknown Error. I can just check when error code 0, then return a no internet connection message but I can never be certain it's actually a network error.
Is there any method to guarantee the error is a no internet connection issue?
Sure I could check for a network before getting or posting api requests, but then all my pages with api requests need to continuously monitor for a network connection.
You could use navigator.onLine as an additional check if you get an error code 0.
Though I'm not sure how reliable this variable is.

No authentication challenges found

I tried to use
try {
new TwitterFactory(new ConfigurationBuilder()
.setOAuthConsumerKey(TWITTER_KEY)
.setOAuthConsumerSecret(TWITTER_SECRET)
.setOAuthAccessToken(TWITTER_TOKEN)
.setOAuthAccessTokenSecret(TWITTER_TOKEN_SECRET)
.build()).getInstance().updateStatus("HELLO WORLD!");
} catch (TwitterException e) {
e.printStackTrace();
}
But as soon as I run it, it gives me this error:
this might be a possible answer: In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api#twitter.com — all other applications will receive an HTTP 401 error. from here but his answer is not complete (does not have steps to follow)
How to fix this? Thanks!

Android Browser not consistently return json from ajax call

I'm making an ajax call that repeatedly calls an api for json data. I've never had it fail with other browsers, but something weird is happening to the response within the Android Browser. I put a console log using weinre that catches the returned data. Can anyone make sense of it and how to handle it?
Screenshot:
Everything is running along smoothly until the last one causes an error like this: Uncaught TypeError: Cannot read property 'Requests' of undefined
Why is it not returning like the previous json return from the ajax calls?
I couldn't find anyway to handle this other than wrap the whole result in a try catch. If it does catch something then it just tries again to get the batch and has thus far always been successful on the second attempt.
try {
//ajax returned result
} catch (error) {
console.error(error);
window.setTimeout(function() {
getBatch();
}, 2000);
}

Android How to check URL name or IP is rechable

My code is as follow:
public chkRechable(String hostNameOrIp) {
boolean isRechable = InetAddress.getByName(hostNameOrIp).isReachable(30);
return isRechable;
}
Parameter can be "http://192.168.0.77:8080/ws/api/customer/5" or "http://example.com:8080/ws/api/customer/5"
But everytime it's returning false although I can browse the URL.
What do you mean "reachable"?
If "open the page" means "reachable", you can just try to use an HTTP connection to connect to it. If you got exceptions: your net work might down; you cannot connect to the host;
Then you shall check the http return code, to see if there are 404 or other errors.

Android JDBC error

I had this code that worked well last Thursday (04/19/2012):
Connection conn = null;
Statement inst;
try {
System.out.println("Connected to the database");
Class.forName ("net.sourceforge.jtds.jdbc.Driver");
//217.126.108.151
conn = java.sql.DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/prueba;sa;sa1234");
inst = conn.createStatement();
System.out.println("Connected to the database");
inst.executeUpdate("INSERT INTO TIENDAS (NOMBRE) VALUES ('ZZZZZZZ') ");
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
But after the last update of the Android SDK stopped working.
Now I get this error:
java.lang.RuntimeException: No message resource found for message property prop.servertype
Does anyone know why?
Thanks in advance.
Clean your project and rebuild at again. Still if your getting the same problem
try the following way..
-> Instead of localhost in url use this ip : 10.0.2.2
I'm not sure, but since Android >=3.0, network connection have to run in seperate Thread or Task. But if this is the problem, you should get an other exception.
But give it a try :)
And don't forget to check the permissions in your Manifest.

Categories

Resources