flex: Unhandled AsyncErrorEvent when connecting to the server - apache-flex

I've created a custom class to handle method calls from the server and I get this error
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetConnection was unable to invoke callback close. error=ReferenceError: Error #1069: Property close not found on MyClient and there is no default value.
code from function that does the connection:
myClient = new MyClient();
myClient.addEventListener(HearEvent.HEARD_SOMETHING,onHear);
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);
nc.client = dasClient;
nc.connect(connectStr.text, p1.text, p2.text, int(p3.text), p4.text);
that's the MyClient class
public class MyClient extends EventDispatcher
{
public function hear(s:String):void
{
trace(s);
dispatchEvent(new HearEvent(s, HearEvent.HEARD_SOMETHING));
}
}

Depending on your requirements, you can either ignore this error by handling the AsyncErrorEvent in an empty function or prevent the error from happening by adding a close method to the MyClient that performs appropriate action.

Related

Triggering Durable Function throws Null Reference exception

I have the following setup to test my Durable Function.
public class TestDurableFunction
{
private readonly ITestRepository _testRepository;
public TestDurableFunction(ITestRepository testRepository)
{
_testRepository = testRepository; // needed for later use
}
[FunctionName("TimerTrigger")]
public async Task Run([TimerTrigger("0 1 * * *", RunOnStartup = true)] TimerInfo myTimer, [DurableClient] IDurableClient starter, ILogger logger)
{
try
{
await starter.StartNewAsync("OrchestrateSavings", null);
}
catch (Exception exception)
{
logger.LogFunctionError(nameof(Run), nameof(TestDurableFunction), exception);
}
}
[FunctionName("OrchestrateTest")]
public async Task<int> OrchestrateTest([OrchestrationTrigger] IDurableOrchestrationContext context)
{
await Task.CompletedTask;
return 10;
}
}
When I start this function locally, then the TimerTrigger function starts with no problems. This function then calls my OrchestrateTest Durable Function.
But that immediately throws the following error in the Command Prompt window:
Microsoft.Azure.WebJobs.Script.WebHost: Unable to load metadata for
function 'OrchestrateTest'. Function 'OrchestrateTest (Orchestrator)'
was aborted. Reason: An internal error occurred while attempting to
execute this function. The execution will be aborted and retried.
Details: System.NullReferenceException: Object reference not set to an
instance of an object.
Anyone any idea what the issue could be?
As per your code the orchestrator function you are invoking is OrchestrateSavings; however there is not orchestrator function registered with that name. As per posted code the orchestrator function name is OrchestrateTest. So change the line to
await starter.StartNewAsync("OrchestrateTest", null);
in the Run method.

Spring Boot ErrorPageFilter block the custom exception handler with #ExceptionHandler

My web app constructed with SpringBoot 2.0.0.M3 and java8, deploy on outer tomcat/8.0.24 war.
My Exception handler:
#ControllerAdvice(annotations = RestController.class)
public class GlobalExceptionHandler extends
ResponseEntityExceptionHandler {
#ExceptionHandler(MyCustomException.class)
public ResponseEntity<String> handlerMyException(
MyCustomException rae) {
String msg = "MyCustomException";
return new ResponseEntity<>(msg ,
HttpStatus.OK);
}
}
I trow a MyCustomException in my Controller but it wasn't handled by handlerMyException() method:
ERROR 1 --- [ajp-nio-8009-exec-372] o.s.b.w.servlet.support.ErrorPageFilter : Forwarding to error page from request [/api/test] due to exception
Then I disable the ErrorPageFilter by:
setRegisterErrorPageFilter(false);
this time no error log occurred, but handlerMyException() still not triggered. Is anyone know this? TIA!

Actually what is the init parameter in servlet?

Friends tell me what is the core meaning of init parameter in case of a servlet.
I know that how to initialize it in a web.xml but I don't know what is the actual purpose of it why it is required? Please tell me with a good example.
The Javadoc says: "A convenience method which can be overridden so that there's no need to call super.init(config)."
The init method's main purpose is to allow customization while you are initializing the servlet.
The simplest implementation is when you don't want to do any customization according to your application you can always call super.init method.
To understand meaning of what different init params can be there and how init method is useful:
Imagine a system Of BookManagement system, here for adding books and removing books from db you will be needing Database connection over which you can access the data. Now as Servlet's init method is called for the first request and database connection also needs be created only once(or n number of time if doing connection pooling) then initializing the database connection is something that you should do in init method.
A code snippet from Softlab example , let's assume that getInitParameter method reads the databaseUrl and other properties from web.xml
public class DBServlet ... {
Connection connection = null;
public void init() throws ServletException {
// Open a database connection to prepare for requests
try {
databaseUrl = getInitParameter("databaseUrl");
... // get user and password parameters the same way
connection = DriverManager.getConnection(databaseUrl,
user, password);
} catch(Exception e) {
throw new UnavailableException (this,
"Could not open a connection to the database");
}
}
...
}
One more example of counting the number of time servlet was accessed: https://docstore.mik.ua/orelly/java-ent/servlet/ch03_03.htm
So in Summary: To do customization like read the initial values of variable or to initialize resources(like db connection) you can use init method.
Below is the source code of init methods :
public void init(ServletConfig config)throws ServletException
{
this.config = config;
int();
}
public void init() throws ServletException;
It is recommended to override to init() method, not init(ServletConfig).
When overriding init(ServletConfig), the first thing that must be done is to call:
super.init(config);
If you do this then calling directly to getServletContext() in your method will no longer result in an NPE.

Error managment in ControllerAdvice lead to duplication in URI and 404

I have a simple rest controller :
#RestController
#RequestMapping("/api/v1/")
public class OrderController {
#RequestMapping(value = "/orders2", method = RequestMethod.POST)
public OrderDto createOrder2(#RequestBody OrderDto order) throws Exception {
throw new Exception("Bouh!");
}
}
And I want to manage exceptions globally. From what I read it can be done with something like :
#ControllerAdvice
public class ErrorController {
#ExceptionHandler(Exception.class)
#ResponseStatus(value = HttpStatus.BAD_REQUEST)
public ErrorDto handleConflict(HttpServletRequest request, Exception e) throws Exception {
ErrorDto o = new ErrorDto ();
o.setMessage(e.getMessage());
return o;
}
}
But when I make a post on my request, I get the following error :
26/10/2016 17:26:08.187 [http-nio-8080-exec-12] WARN o.s.web.servlet.PageNotFound -
No mapping found for HTTP request with URI [/duorest/api/v1/api/v1/orders2]
in DispatcherServlet with name 'rest'
I don't know why the uri change to /duorest/api/v1/api/v1/orders2
Some facts :
I checked in debug, my code is executed
If I move the method in the rest controller, I get no error and what I expect (my ErrorDto object)
Spring framework version 4.3.3.RELEASE
Spring-data-rest-webmvc version 2.5.4.RELEASE
Anybody already had this problem ? Or any hint ?
Is it resolved? if not please try to execute with #ResponseBody is missing on the handleConflict method.

Symfony2: Problems using logger in a service (passed as as parameter)

I'm developing a project using Symfony 2.1.
I have created a service that is being called from a controller, and it's working ok.
Now I need that the service generates log, and I'm trying to pass logger this way:
soap.client:
class: MyFirm\MyAppBundle\Service\SOAPClient
arguments:
logger: "#logger"
My service is defined this way:
namespace MyFirm\MyAppBundle\Service;
use \SoapClient as SoapClient;
use Monolog\Logger;
class SOAPClient
{
private $logger;
function __construct (Logger $logger)
{
$this->logger = $logger;
}
function sendMessage ($message, $wsdl_url)
{
$webServResult = "ERROR";
try{
$client = new SoapClient($wsdl_url, array("trace"=>true,
"exceptions"=>true));
$webServResult=$client->sendMessage($data);
}
catch(\Exception $ex){
$webServResult="ERROR";
$message=$ex->getMessage();
$log_text = print_r($ex, true)."\n".
$client->__getLastRequest()."\n".
$client->__getLastResponse();
$this->logger->err("ERROR: ".$log_text);
}
return $webServResult;
}
}
However, when I use the logger (if the wsdl doesn't exist, for example), the application hangs.
Am I doing anything wrong? Thanks a lot.
This is not a problzm from logger but from SoapClient that doesn't throw any Exception in case of unreachable WSDL... It waits until a Fatal error is thrown...
You have to check if WSDl exists before calling SoapClient ;)
Sorry, the problem wasn't at logger, but in the lines:
$log_text = print_r($ex, true)."\n".
$client->__getLastRequest()."\n".
$client->__getLastResponse();
If I remove these lines and log only the Exception message all goes right.
SoapClient does generate an Exception if the WSDL is not found:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/unknown.wsdl' :
failed to load external entity "http://localhost/unknown.wsdl"
Solved and fixed. Sorry for the spam.

Resources