Trying to connect via Wi-Fi and I have an issue with the OS6 cd variable is null but it works on OS5
This is the url Strng: https://api3.popfax.com/index.php?service=Popfax;interface=wifi;interface=wifi
public ServiceConnectionBlackBerry(String s) throws IOException {
ConnectionFactory cf = new ConnectionFactory();
ConnectionDescriptor cd = cf.getConnection(s);
if (cd!=null){
connection = (HttpConnection) cd.getConnection();
}else {
System.out.println("Strng: "+s);}
}
can someone help please.
When using ConnectionFactory you should not append any connection information to your URL. So instead you should just pass https://api3.popfax.com/index.php?service=Popfax to your method.
Open a Wi-Fi HTTPS connection may help you.
thanks
Related
I've used the sample to check how atmosphere works and a little modified it: add a service to send messages:
def sendMessage(String message){
String mapping = "/jabber/chat/12345"
Broadcaster b = BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, mapping)
println("Broadcast resources size:" +b.getAtmosphereResources().size())
def resp = [type: "chat", resource: mapping, message: message] as JSON
b.broadcast(resp)
}
But looks like when I call the function some times AtmosphereResource for my connection in broadcaster is missed and client didn't recieve a message. Does anyone know what the problem is? Thanks for help.
First of all what transport protocol you are using ?
If it is 'long-polling'(default) or 'polling' atmosphere try to reconnect after 5 minutes(default) if no message (or event) are sent or received.
Maybe one of reconnections is field ?
I have some similar issue system was reconnecting only 5 times. So after 5x5minutes no connection was between client and server.
Check browser log/established connections to see do your browser have valid connection to server.
Also try to play with atmosphere props (reduce value of timeout conf to 10000 and try to reproduce problem.)
After some debugging switched to SimpleBroadcaster implementation and now code works pretty fine:
Handler class
#Override
void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String mapping = "/jabber/chat" + request.getPathInfo()
Broadcaster b = BroadcasterFactory.getDefault().lookup(SimpleBroadcaster.class, mapping, true)
Meteor m = Meteor.build(request)
m.setBroadcaster(b)
}
Service
def sendMessage(String message){
String mapping = "/jabber/chat/12345"
Broadcaster b = BroadcasterFactory.getDefault().lookup(mapping)
println("Broadcast resources size:" +b.getAtmosphereResources().size())
def resp = [type: "chat", resource: mapping, message: message] as JSON
b.broadcast(resp)
}
I want to download a file from a server via the internet with a BlackBerry app.
It is not important which protocol is used: FTP, HTTP or something else would be fine. I just need the user to click "download" button and then the app downloads this file from a server.
I have no idea how it can be done. I have tried a few solutions. In one I need a HttpConnectorFactory but this is not in my API.
I have searched for an answer to my question for days, but I haven't found a solution that works.
Links to solutions I have tried:
How to download an html file in a BlackBerry application
https://stackoverflow.com/questions/6290988/downloading-a-pdf-file-from-a-webserver-in-blackberry-java-application
Networking Helper Class
try this -
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc = connFact.getConnection(your_url);
HttpConnection httpConn = (HttpConnection) connDesc.getConnection();
try {
httpConn.setRequestMethod(HttpConnection.GET);
InputConnection inputConn = (InputConnection) httpConn;
InputStream is = inputConn.openInputStream();
byte[] data =IOUtilities.streamToBytes(is);
//the value in data will be the bytes of your file.
// now if you want to save the file, you can do it here......
} catch (IOException e) {
e.printStackTrace();
}
I want to download data using HttpConnection , see the example below
class ConnectionThread extends Thread
{
public void run()
{
try{
showToast("in the run method");
HttpConnection conn = null;
String URL = "http://xxxxxxx.com/api/api.php?func=showAllCountries;interface=wifi";
conn = (HttpConnection)Connector.open(URL);
}catch(Exception e){
showToast(e+"");
}
}
while running above code , on simulator it says Java.io.IOException No Wi-Fi connection found , Though in manage connection i can see simultor is conncted with Wifi ,
please why this is happening
Please
use deviceside= false;
in simulator wifi is not possible, simulator will access your system network , once you are on real device wifi will work if it is enabled in device.
Follow this link on how to make connections.
The application is running perfect in device and simulator when i do use via eclipse, but when i will give cod file to client, it gives the following error, any idea?
this is the error:
net,rim.device.internal.io.CriticallOException: Critical tunnel failure
Create your network connection in another thread
new Thread(){
public void run(){
//connection stuff
}
}.start();
And add these settings to your url
String url += ";deviceside=true"
if(apn != null && !apn.trim.equals("")){
url += ";apn="+apn;
}
More information here http://supportforums.blackberry.com/t5/Java-Development/Critical-tunnel-failure/td-p/416396
I am trying to build a simple application for testing purpose in which I am making a simple Http connection .The code is running perfectly on the simulator but when I am testing the app on the real device it is not returning any response code. I think there is some error in http connection .
Here is the code that I am using for http connection:
httpConnection = (HttpConnection)Connector.open("http://www.google.com");
The device that I am using is Blackberry 8520 v5.0.0.592
Also give me some tips on how to do the debuging of any app from real device using eclipse plugin.
Thanks in advance.
If it is enough that your program works with OS 5.0+, then try using Network API:
ConnectionFactory f = new ConnectionFactory();
ConnectionDescriptor descr = f.getConnection("http://www.google.com");
HttpConnection connection = (HttpConnection) descr.getConnection();
That piece of code tries to use the first available connection type. You can fine tune it if you want.
Regarding debugging, just install BlackBerry Desktop Software, connect your 8520 with the USB cable and from eclipse, click Run -> Debug As... -> BlackBerry Device.
The connection factory worked perfectly on the new devices, but didn't work with some of the older ones like the curve and bold. This is what solved it for me:
BrowserField browserField = new BrowserField();
BrowserFieldRequest Req = new BrowserFieldRequest("http://www.yourserver.com/");
InputStream inputStream = browserField.getConnectionManager().makeRequest(Req).openInputStream();
Try to redirect the link using following code:
HttpConnection hc = (HttpConnection) Connector.open(url1);
hc.setRequestMethod(HttpConnection.GET);
hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
InputStream is = null;
String location =hc.getHeaderField("Location");
HttpConnection hcc = (HttpConnection) Connector.open(location);
is = hcc.openDataInputStream();
Try to add transport to address
For example for connect via wi-fi :
httpConnection = (HttpConnection)Connector.open("http://www.google.com;interface=wifi");