i am atg beginner
I have to add few processes to payment pipeline(paymentpipeline.xml) as I have to do some integration stuff. Please let me know how to add processes to payment pipeline and how to invoke them ?
Also, i am not able to find paymentpipeline.xml in my project. Do i need to create it or do changes in commercepipeline.xml? Thanks
You can find paymentpipeline.xml in %DYNAMO_HOME%\..\DCS\src\config\atg\commerce\payment
To create a new process you need to implement PipelineProcessor.
import atg.nucleus.logging.ApplicationLoggingImpl;
import atg.service.pipeline.PipelineProcessor;
public class MyProcessor extends ApplicationLoggingImpl implements PipelineProcessor
{
public int[] getRetCodes()
{
return new int{1,2};
}
public int runProcess(final Object pParam, final PipelineResult pResult) throws Exception
{
// do what ever you wish to do here
//1 is transaction status
return 1;
}
}
This creates a class that will be called when the pipeline chain is called. Next thing required is you need to create a properties file to create a component. It may typically look like this.
$class=/demo/atg/order/processor/MyProcessor
$scope=global
Modify PipelinePayment.xml and add a new pipelinechain. To invoke an individual processor in chain call PipelineManager.runProcess and pass chained of the created processor.
<pipelinechain name=" lastExistingchain" transaction="TX_REQUIRED" headlink="sampleDemoLink">
<pipelinelink name="sampleDemoLink" transaction="TX_REQUIRED">
<processor jndi="demo/atg/order/processor/MyProcessor"/>
</pipelinelink>
</pipelinechain>
Depending on your requirement you may have to add this pipeline link in an existing pipelinechain insttead of creating a new chain.
Related
I am currently working on a project to manage the reservation system.
There is a new requirement, which is to be able to keep track of all booking status changes.
I hope this does not affect the existing logic and exists as an independent module.
At first I thought of AOP, but there are some problems.
This request should record how what data was changed by what action.
I thought that I could extract the different data by applying AOP to the save method of the repository.
However, this is not possible because there are many different actions that update data.
For example, for reservation, the update by using the save method in the repository, but this method is used in various actions such as check in, check out and etc..
Therefore, the difference in data can be obtained, but it is not possible to tell which action the data was updated.
#Service
public class BookingService {
#Autowired
private BookingRepository bookingRepository;
public Booking create(Booking booking) {
return bookingRepository.save(booking);
}
public void update(Booking booking) {
Booking oldBooking = bookingRepository.findById(booking.getId()).orElseThrow(() -> new RuntimeException("Entity not found"));
oldBooking.update(booking);
bookingRepository.save(oldBooking);
}
public void checkIn(long id) {
Booking booking = bookingRepository.findById(id).orElseThrow(() -> new RuntimeException("Entity not found"));
booking.setStatus(Booking.Status.CheckIn);
bookingRepository.save(booking);
}
}
And since I use AOP, I don't want the parameters or result values of the existing logic to fit in a certain form.
While contemplating how to solve this, how about using the method used by Mockito.
In Mockito, We can know when a method is executed within a method.
Wouldn't it be possible to create a method like this, for example?
#Aspect
public class BookingHistory {
#Autowired
private BookingRepository bookingRepository;
#Around("execution(* *Service.update(..))")
public void update(ProceedingJoinPoint proceedingJoinPoint) {
long id = getBookingId(proceedingJoinPoint);
Booking origin = getBooking(id);
final DiffData diffData;
when(bookingRepository::save).thenReturn(result -> diffData = diff(origin, result));
saveHistory("UPDATE", "Booking", diffData);
}
}
But I have no idea how to implement "when", "thenReturn" etc in Mockito.
Could I get some hints to implement Mockito?
And if not this way, is there any other good way?
Mockito is a testing framework and should only be used for unit testing. If you want to keep track of which method changes the data using Spring's AOP, you can use custom annotations. With custom annotations, you can just pass the value which identifies the action and do whatever you want to it, e.g.: log it, publish it to MQ for analytics, etc. Try the following article on creating custom annotations and this on how to get the method's caller information.
I have a number of REST API endpoints and I would like to measure the timing metrics for each separately. Annotating the methods with #PerformanceMonitor works, but the recorderSource field takes a class and there's no way to pass a unique forWhat descriptor for each method. Do I need to create a child class for every endpoint + HTTP method just to define a unique forWhat string? That does not seem scalable. Am I missing something?
Here's an example of a specific recorder source:
import org.spf4j.annotations.RecorderSourceInstance;
import org.spf4j.perf.MeasurementRecorderSource;
import org.spf4j.perf.impl.RecorderFactory;
public static final class GetAllProductsRecorderSource extends RecorderSourceInstance {
public static final MeasurementRecorderSource INSTANCE;
static {
Object forWhat = "GetAllProducts";
INSTANCE = RecorderFactory.createScalableMinMaxAvgRecorderSource(forWhat, unitOfMeasurement, sampleTimeMillis);
}
}
Here's the REST endpoing with annotation:
import org.spf4j.annotations.PerformanceMonitor;
#PerformanceMonitor(warnThresholdMillis=1, errorThresholdMillis=100, recorderSource=GetAllProductsRecorderSource.class)
#GetMapping("/products")
public List<Product> getAllProducts() throws IOException {
return productRepository.findAll();
}
If you use recorderSource=RecorderSourceInstance.Rs15m.class
The forWhat in your case will be "RecorderSourceInstance.Rs15m, YourClassName.getAllProducts"
So you would not need to create custom RecorderSourceInstance's for every method.
Another option you have is to measure your metrics at a lower level, in a servlet filter like at. This will get you a more complete picture of the server side execution time (will include ser/deser, io...).
You can see this metric in action at or in prometheus format. This live demo is running on GKE, and the source code is at. See the wiki's for more details on some of the ideas demonstrated in this demo.
Here is snippet of intrested case:
We have some configuration class it can have multi instances. It suppose that we supply several configurations in one bundle. It's one scope.
#Service
#Component
public class SampleConfigurationImpl implements SampleConfiguration {
// declaration of some properties, init method and etc...
}
Also we have a service which uses these configurations:
#Service
#Component
public class SampleServiceImpl implements SampleService {
#Reference(
referenceInterface = SampleConfiguration.class,
cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
policy = ReferencePolicy.DYNAMIC)
private Map<String, SampleConfiguration> sampleConfigurations = new ConcurrentHashMap<>();
private void bindSampleConfigurations(SampleConfiguration sampleConfiguration) {
sampleConfigurations.put(sampleConfiguration.getName(), sampleConfiguration);
}
private void unbindSampleConfigurations(SampleConfiguration sampleConfiguration) {
sampleConfigurations.remove(sampleConfiguration.getName());
}
#Activate
private void init() {
System.out.println(sampleConfigurations.size());
}
}
So, can I get some guarantees that on invocation of init method all configurations are injected (at least of current bundle)? Maybe there is some alternative way to do this. I understand that another bundles can bring new configurations and it's unreal to get guarantees but it's intrested in case of only one bundle.
On practice it can be case when in init method there are only part of configurations. Especially if it's more difficalt case when you have several types of configuration or one service uses another one which has dynamic references and first service relies on fact that everything is injected.
The most unpleasant is that it can bind/unbind configurations both before and after init method.
Maybe there is some way to guarantee that it bind always after init method...
I'm interested in any information. It will be great to get answer on two questions (guarantees before or after). Probably someone has experience how to resolve such problem and can share with me.
Thanks.
No, not that I know of. What I usually do in that case (depending on your use case, it depends on if your activation code is ok with running multiple times) is to create a 'reallyActivate' method I call both from the regular activate and from the bindSampleConfigurations (+ setting an isActivated flag in activate). Then I can perform some logic every time a new SampleConfiguration gets bound, even if it's after the activation. Does that help for your case?
I'm using cucumber with java in order to test my app ,
I would like to know if it is possible to take an object returned from first scenario step and use it in other steps.
Here is an example for the desirable feature file and Java code :
Scenario: create and check an object
Given I create an object
When I am using this object(#from step one)
Then I check the object is ok
#Given("^I create an object$")
public myObj I_create_an_object() throws Throwable {
myObj newObj = new myObj();
return newObj;
}
#When("^I am using this object$")
public void I_am_using_this_object(myObj obj) throws Throwable {
doSomething(obj);
}
#Then("^I check the object is ok$")
public void I_check_the_object_is_ok() throws Throwable {
check(obj);
}
I rather not to use variables in the class
(Because then all method variables will be in class level)
but i'm not sure it's possible.
Is it possible to use a return value in a method as an input in the next step?
There is no direct support for using the return values from step methods in other steps. As you said, you can achieve sharing of state via instance variables, which works fine for smaller examples. Once you get more steps and want to reorganize them into separate classes you might run into problems.
An alternative would be to encapsulate the state into its own class which manages it using ThreadLocals, you would have to make sure to initialize or reset this state, maybe using hooks.
If you are using a dependency injection framework like spring you could use the provided scenario scope.
#Component
#Scope("cucumber-glue")
public class SharedContext { ... }
This context object could then be injected into multiple classes containing the steps.
So I'm writing a web service architecture which includes FunctionProvider classes which do the actual processing of requests, and a main Endpoint class which receives and delegates requests to the proper FunctionProvider.
I don't know exactly the FunctionProviders available at runtime, so I need to be able to 'register' (if that's the right word) them with my main Endpoint class, and query them to see if they match an incoming request.
public class MyFunc implements FunctionProvider{
static {
MyEndpoint.register(MyFunc);
}
public Boolean matchesRequest(Request req){...}
public void processRequest(Request req){...}
}
public class MyEndpoint{
private static ArrayList<FunctionProvider> functions = new ArrayList<FunctionProvider>();
public void register(Class clz){
functions.add(clz);
}
public void doPost(Request request){
//find the FunctionProvider in functions
//matching the request
}
}
I've really not done much reflective Java like this (and the above is likely wrong, but hopefully demonstrates my intentions).
What's the nicest way to implement this without getting hacky?
Do not let the FunctionProviders self register. Bootstrap the endpoint through some application init. call with a list of FunctionProviders. That way you can configure priority (what if two providers both claim they can process a request?). The way you set it up now you need to invoke the class somehow to trigger the static constructor, too indirect.
If detecting whether or not a FunctionProvider supports a given request is trivial consider making it part of configuration. If this is in the request map it to that FunctionProvider. This would seperate concerns a bit better. If the detection is complicated consider doing it in seperate classes from the FunctionProvider.
By configuring a delegate/function pointer you can possibly prevent from needing a FunctionProvider altogether (not sure if/how Java supports delegates).