Implement service spring whith MuleESB - mule

I have a component that use a service spring, this spring service use a tiers validator. I defined a Interface with boolean isValide(String value), Can'I implement the Interface with MuleESB ?

somethink like
#Autowired
private MuleContext muleContext;
#Override
public boolean isValide(String arg0) {
try {
MuleClient muleClient = new MuleClient(muleContext);
} catch (MuleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
return false;
}
like in http://www.mulesoft.org/documentation-3.2/display/32X/Hello+World+Example

Related

Integrate Extent Reports with AWS Device Farm and Jenkins

I am new to automation and I have been integrating AWS device farm to run my test cases on cloud. I have integrated Jenkins with AWS device farm to run the tests on the go. I want to integrate Extent Reports to see the results of the run inside Jenkins. I can't find any tutorial to do so. Can you please help me with this.
I have installed the HTML publisher in Jenkins and I have implemented Extent Reports for my local run and its working. But, I have no idea how to integrate for the cloud.
Thanks in advance. Stay Safe
Here is my code for local integration of Extent Reports
ExtentTest test;
ExtentReports extent = ExtentReportsBlackstone.getReportObject();
ThreadLocal<ExtentTest> extentTest = new ThreadLocal<ExtentTest>();
AppiumDriver<?> driver ;
#Override
public void onTestStart(ITestResult result) {
test = extent.createTest(result.getMethod().getMethodName()).assignCategory(result.getMethod().getGroups());
extentTest.set(test);
}
#Override
public void onTestSuccess(ITestResult result){
// TODO Auto-generated method stub
extentTest.get().log(Status.PASS, "Test Passed");
Properties prop = UtilityBase.globalProperties();
if(prop.getProperty("captureScreenshotOnTestPass").equals("true")) {
String testMethodName = result.getMethod().getMethodName();
try {
Class clazz = result.getTestClass().getRealClass();
Field field = clazz.getDeclaredField("driver");
field.setAccessible(true);
driver = (AppiumDriver<?>) field.get(result.getInstance());
} catch(Exception e) {
e.printStackTrace();
}
try {
extentTest.get().addScreenCaptureFromPath(getScreenshot(this.driver,testMethodName), result.getMethod().getMethodName());
} catch(IOException e){
e.printStackTrace();
}
}
}
#Override
public void onTestFailure(ITestResult result) {
// TODO Auto-generated method stub
extentTest.get().fail(result.getThrowable());
String testMethodName = result.getMethod().getMethodName();
try {
Class clazz = result.getTestClass().getRealClass();
Field field = clazz.getDeclaredField("driver");
field.setAccessible(true);
driver = (AppiumDriver<?>) field.get(result.getInstance());
} catch(Exception e) {
e.printStackTrace();
}
try {
extentTest.get().addScreenCaptureFromPath(getScreenshot(this.driver,testMethodName), result.getMethod().getMethodName());
} catch(IOException e){
e.printStackTrace();
}
}
#Override
public void onTestSkipped(ITestResult arg0) {
// TODO Auto-generated method stub
}
#Override
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStart(ITestContext context) {
// TODO Auto-generated method stub
try {
UtilityBase.deleteFolder(System.getProperty("user.dir")+"/reports");
}catch(IOException e) {
e.printStackTrace();
}
}
#Override
public void onFinish(ITestContext context) {
// TODO Auto-generated method stub
extent.flush();
}
}
estimate cannot be integrated, aws is a bit limited and for that option we opted for lambatest, where we send it to run in the cloud but the evidence remains in extend report in our aws node
aws asks to compile the project and upload the project which runs on its own server, I don't like that way of execution

ASP.NET Core Interception with Castle.DinamicProxy doesn't throw Exception with Async Methods !!! How can I solve this?

I have been creating a project with Aspect Oriented Programming paradigm and
I have an "ExceptionLogAspect" class attribute which is used on business methods to log the errors throwing from them.
public class ExceptionLogAspect : MethodInterception
{
private readonly LoggerServiceBase _loggerServiceBase;
private static byte _risk;
public ExceptionLogAspect(Type loggerService, byte risk)
{
if (loggerService.BaseType != typeof(LoggerServiceBase))
{
throw new System.Exception(AspectMessages.WrongLoggerType);
}
_loggerServiceBase = (LoggerServiceBase)Activator.CreateInstance(loggerService);
_risk = risk;
}
protected override void OnException(IInvocation invocation, System.Exception e)
{
var logDetailWithException = GetLogDetail(invocation);
logDetailWithException.ExceptionMessage = e.Message;
_loggerServiceBase.Error(logDetailWithException);
}
}
This Aspect migrates MethodInterception class that I created with Castle.DinamicProxy package. And OnException method included by MethodInterception logs the exception data.
public abstract class MethodInterception:MethodInterceptionBaseAttribute
{
protected virtual void OnBefore(IInvocation invocation){}
protected virtual void OnAfter(IInvocation invocation){}
protected virtual void OnException(IInvocation invocation, System.Exception e){}
protected virtual void OnSuccess(IInvocation invocation){}
public override void Intercept(IInvocation invocation)
{
var isSuccess = true;
OnBefore(invocation);
try
{
invocation.Proceed();//Business Method works here.
}
catch (Exception e)
{
isSuccess = false;
OnException(invocation, e);
throw;
}
finally
{
if(isSuccess)
OnSuccess(invocation);
}
OnAfter(invocation);
}
}
When I run the code and try-catch block doesn't work for Exception. So catch block isn't called and no messages are logged.
If I turn the business method into a syncronous method, exception will be thrown and data will be logged.
How can I solve this asynchronous method problem?
I tried this solution, it works properly.
Intercept method has to be like this to make this process asynchronous.
Otherwise, this method doesn't work properly for async.
There are some other ways, for example Castle CoreAsync Interceptor, you can find it on Github or NuGet.
https://github.com/JSkimming/Castle.Core.AsyncInterceptor
public override void Intercept(IInvocation invocation)
{
var isSuccess = true;
OnBefore(invocation);
try
{
invocation.Proceed(); //Metodu çalıştır
if (invocation.ReturnValue is Task returnValueTask)
{
returnValueTask.GetAwaiter().GetResult();
}
if (invocation.ReturnValue is Task task && task.Exception != null)
{
throw task.Exception;
}
}
catch (Exception e)
{
isSuccess = false;
OnException(invocation, e);
throw;
}
finally
{
if (isSuccess)
OnSuccess(invocation);
}
OnAfter(invocation);
}

How to use ConnectionListner and/or ChannelListner for logging failure/success of message delivery in RabbitMQ

I am trying to log any information or exception that occurs during message sending in RabbitMQ, for that I tried to add ConnectionListener on the existing connection factory.
kRabbitTemplate.getConnectionFactory().addConnectionListener(new ConnectionListener() {
#Override
public void onCreate(Connection connection) {
System.out.println("Connection Created");
}
#Override
public void onShutDown(ShutdownSignalException signal) {
System.out.println("Connection Shutdown "+signal.getMessage());
}
});
kRabbitTemplate.convertAndSend(exchange, routingkey, empDTO);
To test the exception scenario, I unbind and even deleted the queue from RabbitMQ console. But I did not get any exception or any shutdown method call.
Although, When I stopped RabbitMQ service, I got
Exception in thread "Thread-5" org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
But this exception is not from the listener I added.
I want to know
Why I did not get any exception or call from shutdown method
How can I use ConnectionListner and/or ChannelListner for logging failure/success of message delivery.
Can we use the AMQP appender, if yes how can we do that? (any example / tutorial)
What are the other approaches to ensure the message is sent?
Note: I do not want to use the publisher confirm the approach.
Connection Refused is not a ShutdownSignalException - the connection was never established because the broker is not present on the server/port.
You can't use the listeners to confirm delivery or return of individual messages; use publisher confirms and returns for that.
https://docs.spring.io/spring-amqp/docs/current/reference/html/#publishing-is-async
See the documentation for how to use the appenders.
https://docs.spring.io/spring-amqp/docs/current/reference/html/#logging
EDIT
To get notified of failures to connect, you currently need to use other techniques, depending on whether you are sending or receiving.
Here is an example that shows how:
#SpringBootApplication
public class So66882099Application {
private static final Logger log = LoggerFactory.getLogger(So66882099Application.class);
public static void main(String[] args) {
SpringApplication.run(So66882099Application.class, args);
}
#RabbitListener(queues = "foo")
void listen(String in) {
}
// consumer side listeners for no connection
#EventListener
void consumerFailed(ListenerContainerConsumerFailedEvent event) {
log.error(event + " via event listener");
if (event.getThrowable() instanceof AmqpConnectException) {
log.error("Broker down?");
}
}
// or
#Bean
ApplicationListener<ListenerContainerConsumerFailedEvent> eventListener() {
return event -> log.error(event + " via application listener");
}
// producer side - use a RetryListener
#Bean
RabbitTemplate template(ConnectionFactory cf) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(cf);
RetryTemplate retry = new RetryTemplate();
// configure retries here as needed
retry.registerListener(new RetryListener() {
#Override
public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
return true;
}
#Override
public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback,
Throwable throwable) {
log.error("Send failed " + throwable.getMessage());
}
#Override
public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback,
Throwable throwable) {
}
});
rabbitTemplate.setRetryTemplate(retry);
return rabbitTemplate;
}
#Bean
public ApplicationRunner runner(RabbitTemplate template) {
return args -> {
try {
template.convertAndSend("foo", "bar");
}
catch (Exception e) {
e.printStackTrace();
}
};
}
}

Quarkus ExceptionMapper does not handle WebApplicationException

I'm trying to understand if this is a feature or a bug... :-)
For the below controller and exception mapper, for a rest client that will fail with a 401 response, I would expect the exception handler to be invoked for both cases. However it's not invoked for the WebApplicationException. Why is that and how are you meant to register an exception handler for them cases. This is using Quarkus version 0.21.2
#Path("/failable")
public class FailableResource {
#Inject
#RestClient
private SomeHttpClient httpClient;
#GET
#Path("fails")
#Produces(MediaType.TEXT_PLAIN)
public String fails() {
try {
return httpClient.someQuery();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
#GET
#Path("works")
#Produces(MediaType.TEXT_PLAIN)
public String works() {
try {
return httpClient.someQuery();
} catch (Exception e) {
e.printStackTrace();
throw new IllegalStateException("Not a WebApplicationException");
}
}
}
And the ExceptionMapper
#Provider
public class HandleMySillyError implements ExceptionMapper<Throwable> {
#Override
public Response toResponse(Throwable e) {
e.printStackTrace();
return Response.ok("Some handled response").build();
}
}
I found out when running in quarkus:dev mode the exception mapper is not invoked. It seems that this is caused by an exception mapper from quarkus that is only used in DEV mode (see https://github.com/quarkusio/quarkus/issues/7883).
I launched my code local as normal a normal java program, causing my exception handler to work as expected. Also when running the code on Openshift, my custom exception mapper is used as well.
note: I used quarkus version 1.8.3

Spring for android RestTemplate object instantiation failed

I am using spring for android in order to communicate with an existing RestAPI service. I am following this tutorial :
http://spring.io/guides/gs/consuming-rest-android/
I already have my android app, and I integrated this HttpRequestTask in one of my activities
private class HttpRequestTask extends AsyncTask<Void, Void, Greeting> {
protected Greeting doInBackground(Void... params) {
try {
final String url = "http://rest-service.guides.spring.io/greeting";
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
Greeting greeting = restTemplate.getForObject(url, Greeting.class);
return greeting;
} catch (Exception e) {
Log.e("MainActivity", e.getMessage(), e);
}
return null;
}
protected void onPostExecute(Greeting greeting) {
....
}
}
and I then call execute method within the onStart method
#Override
protected void onStart() {
super.onStart();
new HttpRequestTask().execute();
}
Once I access this activity, the app crashes. I debuged it and found that the RestTemplate object fails in the instantiation line:
RestTemplate restTemplate = new RestTemplate();
I'am using spring 1.0.1.RELEASE core and rest jars.
The problem was that the added external jars are not deployed with the app at runtime, this link solves this issue:
How can I use external JARs in an Android project?