Logging from the Spring Integration DSL to the database - spring

I'm doing the application with the Spring Integration Java DSL.
What is the best way to log to the database using the Spring Data JPA from the application?
I have a quite long integration flow with the multiple HTTP gets and posts. I want at least log the sent and responded messages and which URLs were used and possible some other custom values.
I have tried the logging with the method IntegrationFlowBuilder.log. With that my plan would be create some custom logger, which logs to the database.
I have tried the method IntegrationFlowBuilder.enrichHeaders with the method IntegrationFlowBuilder.log to log the URLSs and the other custom values. How to change some header entry inside the IntegrationFlowBuilder? I have added the entry with same key and different value, but the value in the logging doesn't change.

The HeaderEnricherSpec for the enrichHeaders() provides an option like:
/**
* Determine the default action to take when setting individual header specifications
* without an explicit 'overwrite' argument.
* #param defaultOverwrite the defaultOverwrite.
* #return the header enricher spec.
* #see HeaderEnricher#setDefaultOverwrite(boolean)
*/
public HeaderEnricherSpec defaultOverwrite(boolean defaultOverwrite) {
Also each added entry into the headers can be specified with their own override flag:
/**
* Add a single header specification where the value is a String representation of a
* SpEL {#link Expression}.
* #param name the header name.
* #param expression the expression.
* #param overwrite true to overwrite an existing header.
* #return the header enricher spec.
*/
public HeaderEnricherSpec headerExpression(String name, String expression, Boolean overwrite) {

Related

Overriding property name in Api Platform

Oke, so I have the following use case. On some of my entities I use a file entity for example with the organization logo.
Now I want users to post either a link (I will then async get the file) or a base64 has of the file. But when the user does a get I want to present an JSON representation of the file entity (that also includes size, a thumbnail link etc).
The current setup that I have is two different properties on my entity, one for reading and one for posting with different logic. And then an event listener that handels the logic. That’s all fine and all but it causes the user to post a postLogo property in their json file, I would hower like them to post to a logo property in their json file.
Is there an annotation that I can use (for example name on ApiProperty) to achieve this or do I need to override the serializer?
/**
* #var File The logo of this organisation
*
* #ORM\ManyToOne(targetEntity="File")
* #ApiProperty(
* attributes={
* "openapi_context"={
* "type"="#/components/schemas/File"
* }
* }
* )
* #Groups({"read"})
*/
public $logo;
/**
* #var string The logo of this organisation, a logo can iether be posted as a valid url to that logo or a base64 reprecentation of that logo.
*
* #ApiProperty(
* attributes={
* "openapi_context"={
* "type"="url or base64"
* }
* }
* )
* #Groups({"write"})
*/
public $postLogo;
You can add a setter with a SerializedName annotation. Something like this should work
/**
* #Groups({"write"})
* #SerializedName("logo")
*
*/
public function setPostLogo($value)
{
$this->postLogo = $value;
}

owner check not working with JWT auth

I'm following the example / documentation closely trying to set up a resource that only its owner can access, and I get this error:
"hydra:description": "Notice: Undefined property:
ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator::$owner",
JWT authentication per se seems to work fine.
my resource is defined like this:
/**
* #ORM\Entity
* #ApiResource(
* attributes={"access_control"="is_granted('ROLE_USER') and object.owner == user"},
* collectionOperations={"get"},
* itemOperations={"get"},
* )
*/
Security and user provider and everything is set up exactly as in the api-platform or Symfony documentation.
The property owner is defined as:
/**
* #var User The owner
*
* #ORM\ManyToOne(targetEntity=User::class)
*/
public $owner;
What am I doing wrong?
I think this would work on your itemOperation GET, but not on your collectionOperation. The reason is that "object" in this case will the the collection of User objects, which is represented as the Paginator class.
#ahaaje is correct.
But you can still achieve what you're looking for by implementing an "extension". This would allow you to filter the collection with only items that belong to your user.
Official documentation is here.

Turn off setReadOnly action for one component inside binder

I have some components inside binder:
binder.bind(cbClientRating, Client::getRating, Client::setRating);
binder.bind(tfFirstName, Client::getFirstName, Client::setFirstName);
binder.bind(tfLastName, Client::getLastName, Client::setLastName);
binder.bind(dfBirthDate, Client::getBirthDate, Client::setBirthDate);
According my business logic i do not need to change readonly status for one component inside binder, for example Combobox - cbClientRating when i call binder.setReadOnly(false). It should be stay in readonly mode equal true.
Now i call
cbClientRating.setReadOnly(true) after calling binder.setReadOnly(false)
binder.setReadOnly(false);
cbClientRating.setReadoOnly(true);
Is there any other solution?
Source code of Binder#setReadOnly(boolean):
/**
* Sets the read only state to the given value for all currently bound
* fields.
* <p>
* This is just a shorthand for calling setReadOnly for all currently bound
* fields. It means that fields bound after this method call won't be set
* read-only.
*
* #param fieldsReadOnly
* true to set the fields to read only, false to set them to read
* write
*/
public void setReadOnly(boolean fieldsReadOnly) {
getBindings().stream().map(BindingImpl::getField)
.forEach(field -> field.setReadOnly(fieldsReadOnly));
}
So this is only a convenience method. I recommend that you handle the field read only states completly by yourself according to your business logic.

Joomla! 3.xx *onUserLogout* event not working

I have successfully implemented the onUserAuthenticate event to implement my custom authentication API inside the Joomla! site that I am working on.
Now I want to also have some custom code run on the onUserLogout event.
I have added the following code to the custom authentication plugin file.
But this method is not getting fired/invoked while the previous one(onUserAuthenticate) is working just fine.
/**
* Method to handle the SSO logout
*
* #param array $user Holds the user data.
* #param array $options Array holding options (client, ...).
*
* #return boolean Always returns true.
*
* #since 1.6
*/
public function onUserLogout($user, $options = array()) {
if (JFactory::getApplication()->isSite()) {
// Set the cookie to expired date.
setcookie('customAuth', '123', time() - (60 * 60 * 24 * 365), '/', '.customdomain.org');
}
return true;
}
Okay so I was getting it all wrong.
So I was adding the aforementioned method inside the same plugin file that handled the onUserAuthenticate.
For Joomla! the login is a separate process which has its respective events like onUserAuthenticate.
But it seems like the event onUserLogout has to be inside the plugin with the type of user.
So I created a separate plugin inside the user plugin type directory, installed it, and enabled it....And voila!! it worked.
This had me scratching my head for quite a while.

Find error line in AngularJS app

I just started to play with AngularJS and I got error below.
Error: Argument '?' is not a function, got Object
at assertArg (http://localhost/angular/project/scripts/vendor/angular.js:1039:11)
at assertArgFn (http://localhost/angular/project/scripts/vendor/angular.js:1049:3)
at http://localhost/angular/project/scripts/vendor/angular.js:4802:9
at http://localhost/angular/project/scripts/vendor/angular.js:4384:17
at forEach (http://localhost/angular/project/scripts/vendor/angular.js:137:20)
at nodeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4369:11)
at compositeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4015:15)
at compositeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4018:13)
at publicLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:3920:30)
at update (http://localhost/angular/project/scripts/vendor/angular.js:14202:11)
Now, my question is: Is there a way I can find line in .js file where error occurred?
I get line number in angular.js file on raised exception but there is too many files where
error can occur.
I tried with AngularJS Batarang, but this is more for debugging semantic not syntax errors.
Thanks.
It'll be easier if you link to the js files that would have caused this error.
From the angular.js source, https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js
it looks like a problem with instantiating the controller.
Here's the line that's causing assertion failure:
/**
* #ngdoc function
* #name ng.$controller
* #requires $injector
*
* #param {Function|string} constructor If called with a function then it's considered to be the
* controller constructor function. Otherwise it's considered to be a string which is used
* to retrieve the controller constructor using the following steps:
*
* * check if a controller with given name is registered via `$controllerProvider`
* * check if evaluating the string on the current scope returns a constructor
* * check `window[constructor]` on the global `window` object
*
* #param {Object} locals Injection locals for Controller.
* #return {Object} Instance of given controller.
*
* #description
* `$controller` service is responsible for instantiating controllers.
*
* It's just a simple call to {#link AUTO.$injector $injector}, but extracted into
* a service, so that one can override this service with {#link https://gist.github.com/1649788
* BC version}.
*/
return function(constructor, locals) {
if(isString(constructor)) {
var name = constructor;
constructor = controllers.hasOwnProperty(name)
? controllers[name]
: getter(locals.$scope, name, true) || getter($window, name, true);
======> assertArgFn(constructor, name, true);
}
return $injector.instantiate(constructor, locals);
};
It's unable to find the constructor for the controller.

Resources