APN is not specified? - blackberry

iam creating httpConnection ,but when run the application it gives following exception ?
java.io.IOException
APN is not specified ?

I think the See the Developer Knowledge Base article: link can solve your problem
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0
also see this sample code
private static String getConnectionString(){
String connectionString="";
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
connectionString="?;interface=wifi";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
connectionString = "?;&deviceside=false";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){
String carrierUid=getCarrierBIBSUid();
if(carrierUid == null) {
connectionString = "?;deviceside=true";
}
else{
connectionString = "?;deviceside=false?;connectionUID="+carrierUid + "?;ConnectionType=mds-public";
}
}
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
}
return connectionString;
}

More to the point,
http://supportforums.blackberry.com/t5/Java-Development/How-to-get-APN-Settings/td-p/1704995
It is not completely possible to put the APN settings in your url eg. there is no way to get the username and password.

Related

How to resolve Xamarin iOS SecKeyChain InteractionNotAllowed issue?

In my Xamarin.iOS project I used SecRecord/SecKeyChain to store my token values and app version. From production log I found keychain related exceptions with status code 'InteractionNotAllowed' when try to write/read items in keychain. Apple documents states that to resolve InteractionNotAllowed error we need to change the default kSecAttrAccessible attribute value from ‘WhenUnlocked' to ‘Always’.
But in my existing code when I changed accessible attribute to 'Always' app log out because it failed to read token from keychain. It return’s 'Item not found' when read. But when I tried to save token again it returns 'Duplicate item'. So again I tried to remove same item but this time it again returns 'Item not found'. That’s really strange I can’t delete it and I can’t read it with same key.
Below is the code snippet -
private SecRecord CreateRecordForNewKeyValue(string accountName, string value)
{
return new SecRecord(SecKind.GenericPassword)
{
Service = App.AppName,
Account = accountName,
ValueData = NSData.FromString(value, NSStringEncoding.UTF8),
Accessible = SecAccessible.Always //This line of code is newly added.
};
}
private SecRecord ExistingRecordForKey(string accountName)
{
return new SecRecord(SecKind.GenericPassword)
{
Service = App.AppName,
Account = accountName,
Accessible = SecAccessible.Always //This line of code is newly added.
};
}
public void SetValueForKeyAndAccount(string value, string accountName, string key)
{
var record = ExistingRecordForKey(accountName);
try
{
if (string.IsNullOrEmpty(value))
{
if (!string.IsNullOrEmpty(GetValueFromAccountAndKey(accountName, key)))
RemoveRecord(record);
return;
}
// if the key already exists, remove it before set value
if (!string.IsNullOrEmpty(GetValueFromAccountAndKey(accountName, key)))
RemoveRecord(record);
}
catch (Exception e)
{
//Log exception here -("RemoveRecord Failed " + accountName, e,);
}
//Adding new record values to keychain
var result = SecKeyChain.Add(CreateRecordForNewKeyValue(accountName, value));
if (result != SecStatusCode.Success)
{
if (result == SecStatusCode.DuplicateItem)
{
try
{
//Log exception here -("Error adding record: {0} for Account-" + accountName, result), "Try Remove account");
RemoveRecord(record);
}
catch (Exception e)
{
//Log exception here -("RemoveRecord Failed after getting error SecStatusCode.DuplicateItem for Account-" + accountName, e);
}
}
else
throw new Exception(string.Format("Error adding record: {0} for Account-" + accountName, result));
}
}
public string GetValueFromAccountAndKey(string accountName, string key)
{
try
{
var record = ExistingRecordForKey(accountName);
SecStatusCode resultCode;
var match = SecKeyChain.QueryAsRecord(record, out resultCode);
if (resultCode == SecStatusCode.Success)
{
if (match.ValueData != null)
{
string valueData = NSString.FromData(match.ValueData, NSStringEncoding.UTF8);
if (string.IsNullOrEmpty(valueData))
return string.Empty;
return valueData;
}
else if (match.Generic != null)
{
string valueData = NSString.FromData(match.ValueData, NSStringEncoding.UTF8);
if (string.IsNullOrEmpty(valueData))
return string.Empty;
return valueData;
}
else
return string.Empty;
}
}
catch (Exception e)
{
// Exception logged here -("iOS Keychain Error for account-" + accountName, e);
}
return string.Empty;
}
Any help would be great! Thanks
The property Service is also an unique identification when we store or retrieve data using KeyChain. You didn't post your GetValueFromAccountAndKey() method, so we don't know what is the key used for? But in your case, you should use the same Service to retrieve value:
string GetValueFromAccountAndKey(string accoundName, string service)
{
var securityRecord = new SecRecord(SecKind.GenericPassword)
{
Service = service,
Account = accoundName
};
SecStatusCode status;
NSData resultData = SecKeyChain.QueryAsData(securityRecord, false, out status);
var result = resultData != null ? new NSString(resultData, NSStringEncoding.UTF8) : "Not found";
return result;
}
Since you just make a hard code in your CreateRecordForNewKeyValue()( the Service has been written as a constant ), if you want to retrieve your value you should also set the Service as App.AppName in the method GetValueFromAccountAndKey().
It return’s 'Item not found' when read. But when I tried to save token
again it returns 'Duplicate item'.
This is because when we use the same Account but different Service to retrieve data, KeyChain can't find the corresponding SecRecord. This made you thought the SecRecord didn't exist, then use the same Account to store value. The Duplicate item result throws out. For a SecRecord, the Account and Service must both be unique.

Grails Spring Security Core - Generating password manually

I am trying generate a password manually to insert it directly into the database. But unfortunatelly I doesn´t work.
Spring security core is set to use MD5 encoding. I generate a new password in a md5 hash generation webpage, update the bbdd but I can not log in with that user.
I guess it has some specific structure before enconding but I don´t know it.
Just have a look in the source code of the basespasswordencoder class.
protected String mergePasswordAndSalt(String password, Object salt, boolean strict) {
if (password == null) {
password = "";
}
if (strict && (salt != null)) {
if ((salt.toString().lastIndexOf("{") != -1) || (salt.toString().lastIndexOf("}") != -1)) {
throw new IllegalArgumentException("Cannot use { or } in salt.toString()");
}
}
if ((salt == null) || "".equals(salt)) {
**return password**;
} else {
**return password + "{" + salt.toString() + "}"**;
}
}
}
http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.security/spring-security-core/3.0.1.RELEASE/org/springframework/security/authentication/encoding/BasePasswordEncoder.java#BasePasswordEncoder.mergePasswordAndSalt%28java.lang.String%2Cjava.lang.Object%2Cboolean%29

Download file Server Error: The handle is invalid?

public ActionResult FileLink(string hashname)
{
try
{
const string basePath = #"\\WINDHOVERDOCUMENTS\";
const string adminSamples = #"Beta\students\";
return File(basePath + adminSamples + hashname, "application/force-download", hashname);
}
catch (Exception)
{
return null; //no file
}
}
This action simple force user to download the file when the action is triggered. Everything works fine locally. But after publishing to server, it gives me this error. Below is the screenshot. Can anyone help? Thank you. please zoom in to see the screenshot. Sorry.
I solved that by reading the file to byte array then return file content result
var fileBytes = System.IO.File.ReadAllBytes(#"\\path\fileP12.zip");
return File(fileBytes, "application/zip", "package.zip");

Check wifi condition in Blackberry application

I have developed an application for blackberry devices. The application is working fine if it uses internet via data service provider.
I have BB 9550 and I want to use my application using wifi. I tried a lot but I cant get proper answer to check wifi condition.
How we can differentiate to run our application for wifi or data service provider?
For checking wifi is connected or not the following method will help you.
public static boolean isWifiConnected()
{
try
{
if (RadioInfo.getSignalLevel(RadioInfo.WAF_WLAN) != RadioInfo.LEVEL_NO_COVERAGE)
{
return true;
}
}
catch(Exception e)
{
System.out.println("Exception during get WiFi status");
}
return false;
}
if wifi is not connected the following methods will help to add data service.
public static String getConnParam(){
String connectionParameters = "";
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
// Connected to a WiFi access point
connectionParameters = ";interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null
&& (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage and a WAP 2.0 service book record
connectionParameters = ";deviceside=true;ConnectionUID="
+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
connectionParameters = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book record
connectionParameters = ";deviceside=true";
}
}
return connectionParameters;
}
private static ServiceRecord getWAP2ServiceRecord() {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.getRecords();
for(int i = 0; i < records.length; i++) {
String cid = records[i].getCid().toLowerCase();
String uid = records[i].getUid().toLowerCase();
if (cid.indexOf("wptcp") != -1 &&
uid.indexOf("wifi") == -1 &&
uid.indexOf("mms") == -1) {
return records[i];
}
}
return null;
}
Example to use above methods.
String connParams=(isWifiConnected())?";interface=wifi":getConnParam();
Hope This will help you
try this:
private static String getParameters() {
if (GetWiFiCoverageStatus()) {
return ";deviceside=true;interface=wifi";
}
else {
return yourParametersForEdge
}
}
private static boolean GetWiFiCoverageStatus() {
if((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)) {
return true;
}
else
return false;
}
And when you need to connect, you'll have to add the parameters to the URL:
yourUrl = yourUrl + getParameters();

Critical tunnel failure error blackberry

I have developed a app for blackberry ,its approved from appworld but it gives following error
on 4.6
Critical tunnel failure
and
on 5.0 and 6.0
ava.io APN not specified
please help why this error is coming and how to solve it
I think Problem is you didn't add appropriate connection suffix to the url.
Follow the link can solve your problem:http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0
And also ou can use the following sample code:
private static String getConnectionString(){
String connectionString="";
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
connectionString=";interface=wifi";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
connectionString = ";deviceside=false";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){
String carrierUid=getCarrierBIBSUid();
if(carrierUid == null) {
connectionString = ";deviceside=true";
}
else{
connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public";
}
}
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
{
}
return connectionString;
}
Just to clear up some issues.
#Jisson your answer was helpful
But you did not include code for the method getCarrierBIBSUid()
/**
* Looks through the phone's service book for a carrier provided BIBS network
* #return The uid used to connect to that network.
*/
private static String getCarrierBIBSUid()
{
ServiceRecord[] records = ServiceBook.getSB().getRecords();
int currentRecord;
for(currentRecord = 0; currentRecord < records.length; currentRecord++)
{
if(records[currentRecord].getCid().toLowerCase().equals("ippp"))
{
if(records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0)
{
return records[currentRecord].getUid();
}
}
}
return null;
}
Also it might be helpful to include
if (DeviceInfo.isSimulator()){
return ";deviceSide=true";
}
At the beginning of the getConnectionString() method
For more info see Melick's Blog
Solved this issue by setting the APN values on the phone its self and using the connection string code suggested in the other answers.
Change your APN settings (in South Africa)
On Home screen, click Options
Click Advanced Options and then TCP
Enter the APN: **internet**
username: **guest**
password: **guest**
Press the Menu key and select Save
(for rest of the world find your settings here)
From http://www.blackberrytune.com/blackberry-tcp-ip-apn-settings/
and
http://www.blackberryfaq.com/index.php/Carrier_specific_APN/TCP_settings

Resources