J2me application showing error in some mobile - web-services

i have a j2me application with web service stub.
it worked in some mobiles.
but in some mobiles "Application Error" comes up.
i tried creating package making versions MIDP 2.0 and CLDC 1.0(made stub for CLDC 1.0 also)
still it is showing "Application Error"
if I create the package without stub the application works properly.
The stub was generated using "Sun Java Wireless Toolkit 2.5.2 for CLDC"
can anyone help?
new Thread(new Runnable(){
public void run()
{
try {
MobiService_Stub ms = new MobiService_Stub();
resultBox.setString(ms.sendString( textbox.getString()));
}catch (JAXRPCException cnfe){
resultBox.setString("No connection found");
} catch (RemoteException e) {
// TODO Auto-generated catch block
resultBox.setString(e.getMessage());
}
}
}).start();
resultBox.addCommand(cmd_Cancel);
}

I have come up with "Application Error" messages when I try to run a Midlet that uses a JSR not available in that device. You should verify that the JSR or APIs you import are supported by your testing devices.

Related

What happened to addLifeCycleListener in Jetty 10?

We used to have code that would bootstrap Google Guice on the startup of our jetty embedded server.
// add a lifecycle listener to bootstrap injector on startup
svr.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {
#Override
public void lifeCycleStarted(LifeCycle event) {
System.out.println("Bootstrapping Guice injector ...");
Guice.createInjector(new GreeterServletModule(), new GreeterAppModule());
}
});
Now when we try to upgrade to Jetty 10 it says addLifeCycleListener no longer exists.
AbstractLifeCycle.AbstractLifeCycleListener is an EventListener.
use LifeCycle.addEventListener(listener).
Incidentally, the normal way to bootstrap Guice is to extend the com.google.inject.servlet.GuiceServletContextListener and add your extension to the ServletContext listeners?
This is how Google recommends it be done, and is also the way that Google themselves initialize Guice within their own frameworks (like Google App Engine).
Example from Google Cloud Platform Java Samples Project - EchoGuiceListener.java
package com.mycompany;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
public class GreeterGuiceListener extends GuiceServletContextListener {
#Override
protected Injector getInjector() {
return Guice.createInjector(new GreeterServletModule(), new GreeterAppModule());
}
}
with ...
ServletContextHandler contextHandler = new ServletContextHandler()
contextHandler.addEventListener(new GreeterGuiceListener());
// ... other init ...
server.start();

Unit tests for ASP.NET Core failing in VSTS pipeline due to HttpStatusCode.TemporaryRedirect

I have an ASP.NET Core 2.2 WebAPI that uses xUnit and FluentAssertions frameworks. It creates a Microsoft.AspNetCore.TestHost.TestServer and from that server object we create an HttpClient using Microsoft.AspNetCore.TestHost.TestServer.CreateClient() API.
The unit tests work great on my local Windows 10 machine using Visual Studio 2017 Pro. I committed the code, then did a pull request. The pull request automatically kicks off a build process to ensure it builds. Once it builds, it looks for then runs the unit tests. At this point it fails. I have 242 unit tests. All 242 unit test fail with the exact same error reported by the agent:
Expected resp.StatusCode to be OK, but found TemporaryRedirect.
All 242 unit tests make a request to the test server, so they all expect an HttpStatusCode.OK (or similarly expected) response. I should never expect a HttpStatuscode.TemporaryRedirect so I really don't want to add a test case for this.
The build server is running in VSTS as Microsoft Server 2012 R2 with Visual Studio 2017 Pro installed.
Why would the TestServer object return a Redirect ever?
If there is no way around this, can I force the HttpClient to auto-redirect when it receives this status so I only get the result of the API call?
Here is the code I am using to create the server and the client:
var config = new ConfigurationBuilder()
.SetBasePath(Path.GetFullPath("../../../../XXXXXXXXService/"))
.AddJsonFile("appsettings.json", optional: false)
.Build();
_server = new TestServer(new WebHostBuilder().UseStartup<Startup>().UseConfiguration(config));
TestHttpClient = _server.CreateClient();
An example unit test that is failing:
private string DeriveHttpPath(string path) =>
$"/{_rootPath.Trim('/')}/{path.TrimStart('/')}";
private static async Task<TResult> ValidateAndReadResponseAsync<TResult>(
HttpResponseMessage resp, HttpStatusCode statusShouldBe, Func<TResult> defFactory = null)
{
(resp.IsSuccessStatusCode ? HttpStatusCode.OK : resp.StatusCode).Should().Be(statusShouldBe);
try
{
return await resp.Content.ReadAsAsync<TResult>();
}
catch (Exception ex)
{
return defFactory != null ? defFactory.Invoke() : throw ex;
}
}
public async Task<TResult> GetDocumentDataAsync<TResult>(string documentId,
string path = null, HttpStatusCode statusShouldBe = HttpStatusCode.OK)
{
using (var msg = new HttpRequestMessage(HttpMethod.Get,
DeriveHttpPath($"{_collectionId}/{documentId}?path={path}")))
using (var resp = await _httpClient.SendAsync(msg))
{
return await ValidateAndReadResponseAsync<TResult>(resp, statusShouldBe);
}
}
_rootPath will be the root of the controller, i.e.: /api/MyController
Thank you for any help.
The issue I was having was because this was defined in the startup.cs:
#if !DEBUG
app.UseHttpsRedirection();
#endif
So when I was running the unit tests locally, it was compiled as Debug, where when it was pushed to the build server, it compiled as Release and the Https-Redirection was turned on.
I took that code out and made my WebAPI HTTPS-Only by setting it in Azure.

Unit Test not longer work after update from Kentico 9 to Kentico 10

My unitTests not longer work after Update from Kentico 9 to Kentico 10.
I have a UnitTest like this. (worked fine on Kentico 9)
[SetUp]
public void setUp()
{
this.pageCreator = new PageCreator();
this.fixture = new Fixture();
this.fixture.Customize(new AutoMoqCustomization());
}
[Test]
public void execute()
{
this.pageCreator.Execute(null);
}
I just try to call this Function
public class PageCreator : ITask
{
public string Execute(TaskInfo task)
{
try
{
this.treeProvider = new TreeProvider(MembershipContext.AuthenticatedUser);
this.createPages(this.treeProvider);
return successMessage;
}
catch (Exception ex)
{
this.sendMailToDeveloper(ex.Message);
return "Fail";
}
The Problem is, when I try run my test, I get an Error (because of MembershipContext.AuthenticatedUser [CMS.Membership.MembershipContext.AuthenticatedUser" hat eine Ausnahme vom Typ "System.InvalidOperationException" verursacht])
When I try to make the same in debugMode, everything is working fine.
What can be the problem and how can I fix it ?
I have load all the new Dll from Kentico 10 but nothing changed.
Thanks for your help
try updating your references on the test project to use the Kentico10 nuget packages. the release notes have a section on Automated Tests - https://docs.kentico.com/k10/release-notes-kentico-10
"Automated testing – New Kentico.Libraries.Tests integration package, which separately provides all functionality related to automated testing of the Kentico API. The testing API is no longer available directly within Kentico projects or the main Kentico.Libraries integration package."

Windows Store App Unit Testing a USB device

I'm writing a USB device API for Windows Store Apps that uses Windows.Devices.USB API from Windows 8.1 to connect and communicate with the custom USB device. I'm using the Visual Studio 2013 dev preview IDE.
The following function in the library is used to connect to the USB device.
(Simplified for clarity)
public static async Task<string> ConnectUSB()
{
string deviceId = string.Empty;
string result = UsbDevice.GetDeviceSelector(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(result, null);
if (myDevices.Count > 0)
{
deviceId = myDevices[0].Id;
}
UsbDevice usbDevice = null;
try
{
usbDevice = await UsbDevice.FromIdAsync(deviceId);
}
catch (Exception)
{
throw;
}
if (usbDevice != null)
return "Connected";
return string.Empty;
}
When called from the Windows Store App project, this function connects to the device flawlessly. However, when called from the Unit Test Library for Windows Store Apps project, the statement in the try block throws an exception.
A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)
from what I've looked around, this happens when an Async function is called without the await keyword. But I'm using the await keyword alright!
Some more info, I am unable to use NUnit to write unit tests for Store Apps so am using the MSTest Framework.
[TestClass]
public class UnitTest1
{
[TestMethod]
public async Task TestMethod1()
{
await ConnectToUSB.ConnectUSB();
}
}
Also, I've included the following capability tags in the manifest files of both the App store projects too without which it's impossible for the Store Apps to connect to devices.
<m2:DeviceCapability Name="usb">
<m2:Device Id="vidpid:ZZZZ XXXX">
<m2:Function Type="name:vendorSpecific" />
</m2:Device>
</m2:DeviceCapability>
Is there something I'm missing or is this a bug in the MSTest Framework?
I think the problem is that
await UsbDevice.FromIdAsync(deviceId);
must be called on the UI thread because the app has to ask the user for access.
You have to CoreDispatcher.RunAsync to ensure you're on the UI thread or actually be in the code behind for a page.
I had the same problem with Unit Test App (Universal Windows) in VS 2017.
I verify answer of my predecessor Greg Gorman(see below). And I found this is true.
If you uses inside method body this construct:
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
Windows.UI.Core.CoreDispatcherPriority.Normal,
async () =>
{
...
UsbDevice usbDevice = await UsbDevice.FromIdAsync(deviceId);
...
}).AsTask().Wait();
the FromIDAsync will work as you expect.
For your example change the test method to this:
[TestClass]
public class UnitTest1
{
[TestMethod]
public async Task TestMethod1()
{
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
Windows.UI.Core.CoreDispatcherPriority.Normal,
async () =>
{
await ConnectToUSB.ConnectUSB();
}).AsTask().Wait();
}
}

Integrating NUnit to test asynchronous web services in windows phone 7

I am trying to integrate NUnit in my windows phone project to test asynchronous web service calls. I am referring to NUnitTestRunnerWP7 dll. Here is what I did.
But the asynchronous callback method is called after the Assert statement, hence it does not work. How can I execute the Assert after my callback? If I write the failed Assertion in callback, my application crashes.
[Test]
public void TestAsyncFunc(){
string result;
ManualResetEvent manualReset = new ManualResetEvent(false);
MyWebServiceClient client = GetMyWebServiceClient(); //added a service reference for asmx services
client.LoginCompleted += delegate(object sender, EventArgs args)
{
result = args.Result.ToString();
manualReset.Set();
};
client.LoginAsync("username", "password");
if (!manualReset.WaitOne(5000))
Assert.Fail();
Assert.AreEqual("", result);
}
I don't understand what am I missing. Any help would be appreciated.
Thanks in advance.