Spring AOP is being invoked unexpectedly - spring-aop

I have configured Spring AOP for 2 different packages in our application to log exceptions.
There are 2 different configurations for each package:
<aop:config>
<aop:aspect id="aspectLoggging" ref="abcExceptionAspect">
<aop:pointcut id="pointCut"
expression="execution(* com.abc.*.*(..))" />
<aop:before method="logBefore" pointcut-ref="pointCut" />
<aop:after-throwing method="logExceptionABC"
throwing="error" pointcut-ref="pointCut" />
<aop:after method="logAfter" pointcut-ref="pointCut" />
</aop:aspect>
</aop:config>
<aop:config>
<aop:aspect id="aspectLoggging" ref="xyzlogAspect">
<aop:pointcut id="pointCut"
expression="execution(* com.xyz.*.*(..))" />
<aop:before method="logBefore" pointcut-ref="pointCut" />
<aop:after method="logAfter" pointcut-ref="pointCut" />
<aop:after-throwing method="logExceptionXYZ"
throwing="error" pointcut-ref="pointCut" />
</aop:aspect>
</aop:config>
In a service method call, there are calls to the methods of the classes belonging to each of these packages:
public void method()
{
method1(); -> package abc
method2(); -> package xyz
}
Some exception occurs in method2 which invokes logExceptionXYZ method where we are wrapping it in a generic exception, say ExceptionXYZ, and throwing it further.
But some how after this, the logExceptionABC method also gets invoked and throws a generic exception , say ExceptionABC.
I'm not able to understand as why logExceptionABC method is getting invoked?
Please let me know if someone knows about such an issue!
Regards,
Rahul

Same id is being assigned to both the aop:aspect tags. Similar is the case with the aop:pointcut tags as well.
Try with assigning unique IDs.

Related

How to write a Munit test case for an integration that is using a common HTTP request connector for calling 5 different resources of the system layer?

I am calling a system layer from process layer as
first get: /abc
get: /xyz
post: /efg
for all these 3 calls using a common http requestor by setting path, method and host before calling this http requestor.
how to mock this http requestor for each call that give me different responses?
You can just add 3 mock when's to your Munit. Each of them will have the processor 'http:request', but with attributes specific to the call. So in each mock you will provide the AttributeName="method" and AttributeName="path" where the values correspond to the specific call you want to mock. See an example of two mocks below.
<munit-tools:mock-when doc:name="Mock when POST" doc:id="8e3b66fe-b5bb-4f96-97b5-8970c1635b12" processor="http:request">
<munit-tools:with-attributes >
<munit-tools:with-attribute whereValue="POST" attributeName="method" />
<munit-tools:with-attribute whereValue="/post" attributeName="path" />
</munit-tools:with-attributes>
<munit-tools:then-return >
<munit-tools:payload value='#[{"data": "post"}]' mediaType="application/json" />
</munit-tools:then-return>
</munit-tools:mock-when>
<munit-tools:mock-when doc:name="Mock when GET" doc:id="4797dd50-8bc2-428a-9aba-7d03692fc1a2" processor="http:request" >
<munit-tools:with-attributes >
<munit-tools:with-attribute whereValue="GET" attributeName="method" />
<munit-tools:with-attribute whereValue="/get" attributeName="path" />
</munit-tools:with-attributes>
<munit-tools:then-return >
<munit-tools:payload value='#[{"data": "get"}]' mediaType="application/json" />
</munit-tools:then-return>
</munit-tools:mock-when>

Retrieve unity container type registration from configuration file in PRISM 7

The configuration section for the unity container:
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container>
<register type="IProductInfo, Core.Interface" mapTo="Classes.ProductInfo, Core">
<constructor>
<param name="Name" value="Product Name" />
<param name="Version" value="V1.2.65.30865" />
</constructor>
</register>
</container>
The types are registered in the App.xaml.cs file:
public partial class App : PrismApplication
{
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("unity");
section?.Configure(containerRegistry.GetContainer());
}
}
However, because of the container abstraction built in the PRISM 7 version, the container instance doesn't match with the required parameter in the Configure method. The following error is produced by the compiler:
Error CS1503 Argument 1: cannot convert from 'Unity.IUnityContainer' to 'Microsoft.Practices.Unity.IUnityContainer'
Question: How can I retrieve the correct container instance to pass as a parameter of the Configure method
P.s. There is already a similar question on the same issue on StackOverflow. However, the answer doesn't provide a solution to the instantiation problem described above.
You're using incompatible libraries. UnityConfigurationSection expects a Microsoft.Practices.Unity.IUnityContainer (from an old unity version, three-something, most likely), while GetContainer produces a Unity.IUnityContainer (from a rather recent unity).
You should either upgrade your Unity.Configuration package or downgrade Prism...

camel - spring:bean syntax with dynamic class casting

I'm attempting to convert the following Java object initalization with dynamic class casting to camel spring bean syntax. I'm adding my broken spring bean sample as well. I dont have much familiarity with spring beans, so would very much appreciate some input. The Java syntax is:
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
STSAssumeRoleSessionCredentialsProvider credentials = new STSAssumeRoleSessionCredentialsProvider.Builder(
"arn:aws:iam::***:role/myRole-QA", "sessionName").build();
and broken spring bean:
<spring:bean id="sqsCredentials" class="com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider.Builder" >
<spring:constructor-arg index="0" value="arn:aws:iam:***:role/myRole-QA" />
<spring:constructor-arg index="1" value="sessionName" />
<spring:property name="targetMethod">
<spring:value>build</spring:value>
</spring:property>
</spring:bean>
I'm not sure if what I have for method build is correct, but there are two classes at play: .Builder and just STSAssumeRoleSessionCredentialsProvider. So Builder class returns STSAssumeRoleSessionCredentialsProvider. Most likely i have more then one issue to solve here, but the error I think is related to class mismatch ... much appreciate your time:
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'targetMethod' of bean class
[com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider$Builder]: Bean property 'targetMethod' is not writable
or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Mule CXF Marshall Response

I am using cxf:jaxws-client in Mule 3 and the response I get from my web service call is of type ReleasingInputStream. I have tried adding the http-response-to-message-transformer, but that generates an error - does anyone know how I can retrieve the response as an object as opposed to a ReleasingInputStream?
Many thanks.
To solve the issue put the <cxf-client> inside the <outbound-endpoint> section (NOT BEFORE IT), by modifying the following code
<cxf:jaxws-client
clientClass="com.xyz.services.WSServices"
port="WSServicesSoap"
wsdlLocation="classpath:wsdl-file.wsdl"
operation="GimmeDataOperation" />
<outbound-endpoint exchange-pattern="request-response" address="http://localhost:8083/OutboundService" />
which produces a ReleasingInputStream output to
<outbound-endpoint exchange-pattern="request-response" address="http://localhost:8083/OutboundService" >
<cxf:jaxws-client
clientClass="com.xyz.services.WSServices"
port="WSServicesSoap"
wsdlLocation="classpath:wsdl-file.wsdl"
operation="GimmeDataOperation" />
</outbound-endpoint>
that returns the expected object.
I was just having this same problem. I solved it by adding an ObjectToString transformer to the response side of the outbound endpoint like this:
<mule>
<object-to-string-transformer name="ObjectToString"/>
<flow>
...
...
...
<cxf:jaxws-client clientClass="com.my.ClientClass"
port="MyPort"
wsdlLocation="classpath:MyWsdl.wsdl"
operation="MyOperation" />
<outbound-endpoint address="http://some.address/path/to/service"
exchange-pattern="request-response"
responseTransformer-refs="ObjectToString" />
...
...
...
</flow>
</mule>
The whole point of jaxws-client is to receive the unmarshaled Java object, so getting the WS response as a String or ReleasingInputStream should not even be an option.
To make the <cxf:jaxws-client> "work" as one would expect the WS client to work - put the INSIDE of the <outbound-endpoint> you will be getting a correct Java object as a payload.

mybatis config problem

I'm new to MyBatis.
Ive been trying to configure mybatis in a webservice I'm writing but with no luck yet.
What I've done already is,
UserInfoMapper interface
UserInfoMapper.xml with mapper namespace with my UserInfoMapper interface and a select
mybatis-config.xml with typeAlias to use as result type in UserInfoMapper.xml
dataSource bean for oracle (I get connected) in datasourceContext.xml
org.mybatis.spring.mapper.MapperScannerConfigurer bean with basePackage pointing to my UserInfoMapper interface in datasourceContext.xml
sqlSessionFactory bean ie. org.mybatis.spring.SqlSessionFactoryBean with property for my dataSource and configLocation
userInfoMapper bean ie. org.mybatis.spring.mapper.MapperFactoryBean with property mapperInterface (value="is.simnn.act.web.ngs.persistence.UserInfoMapper") and sqlSessionFactory property (ref="sqlSessionFactory") in datasourceContext.xml
then in my applicationContext.xml I have following,
<import resource="classpath:META-INF/wsContext.xml" />
<import resource="classpath:META-INF/db/datasourceContext.xml" />
In my test case I keep getting NullPointerException when I call jaxws:endpoint and it leads me to my UserInfoMapper interface.
Any idea or hints to what might be wrong with my config?
Thanks,
Gunnlaugur
It is hard to comment without having more information. Can you post your UserInfoMapper.java interface, your UserInfoMapper.xml and your stack trace, please? Are you certain that the method name in your interface matches the ID of your SELECT in the XML?

Resources