odata model Cannot read property 'jsonHandler' of undefined sapui5 - properties

I am trying to access my odata service on an android device application on cordova getting the following error :
Uncaught TypeError: Cannot read property 'jsonHandler' of undefined
For the following code:
var sServiceUrl = "https://host:port/sap/opu/odata/sap/ServiceName";
var sCredentials = oUsernameControl.getValue() + ':' + oPasswordControl.getValue();
var sCredentialsEncode = btoa(sCredentials);
var sAuthenticationToken = "Basic " + sCredentialsEncode ;
var mRequestHeader = {};
mRequestHeader["Authorization"] = sAuthenticationToken;
//create object with ODATA model constructor parameters
var oConstructorParams = {};
oConstructorParams["json"] = true;
oConstructorParams["headers"] = mRequestHeader;
oConstructorParams["tokenhandling"] = true;
var oDataModel = new sap.ui.model.odata.ODataModel(sServiceUrl,oConstructorParams);
And when I set the JSON Parameter to false I get the following error :
Cannot read property 'atomHandler' of undefined
Where am I going wrong?

Related

In.net Framework 4.5 using RestSharp version 105.2.3 getting System.MissingMethodException when I try to use request.AddJsonBody() method

I am using RestSharp version 105.2.3 in .Net MVC framework 4.5 project to integrate external API, when I use request.AddJsonBody(obj) I get the runtime exception as System.MissingMethodException
Following are the code I used to call API
```
public string CheckCMSUser(RequestObjectModel requestObject)
{
RestClient client = new RestClient(requestObject.BaseURL + "CheckCMSUser");
RestRequest request = new RestRequest();
var payload = new RequestObjectCMSModel()
{
CompanyNumber = requestObject.CompanyNumber,
UserAccountEmail = requestObject.UserAccountEmail,
IncludeAllSubs = requestObject.IncludeAllSubs
};
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(payload);
request.AddHeader("WebAPI-Version", requestObject.WebAPIVersion);
request.AddHeader("Authorization", requestObject.Token);
var response = client.get(request);
return response.Content;
}
public void CheckCMSUser()
{
requestObj.CompanyNumber = "9999";
requestObj.UserAccountEmail = "user#example.com";
requestObj.IncludeAllSubs = "N";
requestObj.Token = _workContext.Token;
ValidUserResponseModel response = JsonConvert.DeserializeObject<ValidUserResponseModel>(_externalApiService.CheckCMSUser(requestObj));
}
```
Please help me to solve this
Thanks in Advance

Azure storage SAS failed to authenticate

Hi I am trying to create SAS token for my file on Azure. I am getting "Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature" error. Following is my code.
public async Task<IActionResult> TestBlobClient()
{
try
{
string storageAccount = "myaccount";
string password = "mykey";
var sharedKeyCredential = new StorageSharedKeyCredential(storageAccount, password);
var shareClient = new ShareClient(new Uri("https://aaa.file.core.windows.net/zttsox20201027154501"), sharedKeyCredential);
ShareDirectoryClient directory = shareClient.GetDirectoryClient("Output/14");
ShareFileClient file = directory.GetFileClient("637655759841727494_main.wav");
var shareSasBuilder = new ShareSasBuilder
{
ShareName = "aaa",
Protocol = SasProtocol.None,
ExpiresOn = DateTime.UtcNow.AddYears(50),
Resource = "b"
};
shareSasBuilder.SetPermissions(ShareFileSasPermissions.Read);
var url = new Uri(file.Uri + "?" + shareSasBuilder.ToSasQueryParameters(sharedKeyCredential).ToString());
return Ok(url);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status400BadRequest, ex.Message);
}
The issue is with Resource = "b". When you set the resource as b, that means you are getting a SAS token for a blob. Considering you're getting a SAS token for a file share, the value of this parameter should be s.
Please try something like:
var shareSasBuilder = new ShareSasBuilder
{
ShareName = "zttsox20201027154501",
Protocol = SasProtocol.None,
ExpiresOn = DateTime.UtcNow.AddYears(50),
Resource = "s"
};
For more details, please see this link: https://learn.microsoft.com/en-us/dotnet/api/azure.storage.sas.sharesasbuilder.resource?view=azure-dotnet#Azure_Storage_Sas_ShareSasBuilder_Resource.

.Net-Core get HttpBrowserCapabilities from httpContext

I want to use the HttpBrowserCapabilities in .net-core. I tried it following way:
var userAgent = httpContext.Request.Headers["user-agent"];
var userBrowser = new HttpBrowserCapabilities { Capabilities = new Hashtable { { string.Empty, userAgent } } };
var factory = new BrowserCapabilitiesFactory();
factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
var mobileString = userBrowser.IsMobileDevice ? "(mobil)" : string.Empty;
var browserString = $"{userBrowser.Browser} version {userBrowser.Version} {mobileString} OS: {userBrowser.Platform}";
But an InvalidCastException is thrown. How ca i get this code retun the right values?
Got it!
userAgent is of the type Microsoft.Extensions.Primitives.StringValues.
But HttpBrowserCapabilities expects a string as input parameter.
Therefore i had to check if userAgent contains a value (userAgent.Any()) and use the following code
var userBrowser = new HttpBrowserCapabilities {Capabilities = new Hashtable {{string.Empty, userAgent.First()}}};

FileStream openAsync throws Error #1009

hi I have a problem regarding FileStream openAsync read file, I have a listener and waiting on complete
var file:File = File.applicationStorageDirectory.resolvePath(fName+'.'+EXT);
var fileStream:FileStream = new FileStream();
if (!file.exists) {
this.dispatchEvent(new AppEvent(AppEvent.DATA, null, false));
}else {
fileStream.addEventListener(Event.COMPLETE, fileReadCompleteHandler);
fileStream.openAsync(file, FileMode.READ);
fileStream.addEventListener(Event.CLOSE, fileClosedHandler);
fileStream.addEventListener(IOErrorEvent.IO_ERROR, IOErrorHandler);
}
private function fileReadCompleteHandler(event:Event):void {
var ob:Object;
var fileStream:FileStream = FileStream(event.currentTarget);
try {
ob.source = fileStream.readObject();
}catch (e:Error) {
trace('error:' + e.message)
}
fileStream.removeEventListener(Event.COMPLETE, fileReadCompleteHandler);
fileStream.close();
}
on fileReadCompleteHandler I get error: "Error #1009: Cannot access a property or method of a null object reference."
what I am missing, how can I read object from openAsync?
thanks
You never initialize object ob, of course accessing fields of a null object gives you #1009:
var ob:Object;
var fileStream:FileStream = FileStream(event.currentTarget);
try {
ob.source = fileStream.readObject();
You need to:
var ob:Object = new Object;
var fileStream:FileStream = FileStream(event.currentTarget);
try {
ob.source = fileStream.readObject();

OAuth2 grant_type missing

I am getting error that required parameter grant_type is missing in the request.
Using OAuth2 for Webserver application.
Please see below the code:
var httpClient : HTTPClient = new HTTPClient();
httpClient.setTimeout(3500);
httpClient.setRequestHeader("ContentType", "application/x-www-form-urlencoded");
httpClient.open("POST", "https://accounts.google.com/o/oauth2/token");
var param1:String = "code="+Encoding.toURI(pdict.CurrentHttpParameterMap.code.value.split('.')[0]);
var param2:String = "client_id="+pdict.session.custom.client_id;
var param3:String = "client_secret="+pdict.session.custom.client_secret;
var param4:String = "redirect_uri="+Encoding.toURI(pdict.session.custom.redirect_uri);
var param5:String = "scope=";
var param6:String = "grant_type=authorization_code";
Using below syntax i.e. passing variables as part of Request body solved it.
var client_secret : HTTPRequestPart = new HTTPRequestPart("client_secret", pdict.session.custom.client_secret);