How to access application properties from controller/service with jhipster? - jhipster

Into my application.yml there is a property : eureka.instance.appname
How can i access it from my Rest Controller?

In the parameters of you controller method you can add
#Value("${eureka.instance.appname}") String eurekaName
which you can use further.

Related

Apache Camel paho socketFactory setting

I am have created the camel route which use camel-paho component to consume MQTT stream. It is enabled with SSL and i need to pass the socket-factory. I went through the documentation od camel-paho and below parameter is available
socketFactory (security)
Sets the SocketFactory to use. This allows an application to apply its own policies around the creation of network sockets. If using an SSL connection, an SSLSocketFactory can be used to supply application-specific security settings.
I have passed the custom socket-factory in the URL by setting the above parameter to the class name as below
from("paho:"test?brokerUrl="+MQTT_BROKER_URL+"&clientId=subX4&cleanSession=false&socketFactory=com.sample.mqttCustomSocketFactory.java")
Above setting is not working. Is that the correct way of passing the parameter ?
Whenever you set a complex object to the Camel endpoint parameter, it needs to be a bean reference. So in your case, the endpoint should look something like this:
from("paho:test?...&socketFactory=#mySocketFactory")
where the #mySocketFactory is defined in the Camel bean registry like this:
SocketFactory mySocketFactory = ...
context.getRegistry().bind("mySocketFactory", mySocketFactory);
or in Spring context XML:
<bean id="mySocketFactory" ...>

How to declare and use global variables?

i have a console application.i want to read some configuration settings from DB. And these settings should be stored in a global or session variable so
i can use the variable through out the application ,
how can i implement it ? what are the ways ? which channels do i need to use ? and how payload should be stored?
It's not at all clear what you mean, but you can declare a Map object as a #Bean (or <bean/>) and load it up during initialization.
You can then reference it directly in your components by #Autowired or via SpEL in expressions in integration components: #mapBean['foo'].

Action filters in Azure mobile services

How does one go about creating action filters in Azure Mobile Service? And, yes I do wish use Autofac constructor injection of dependencies.
Glad for any help and pointers!
Thanks
Are you looking to register global ActionFilters? It should work very similarly to Web API. So you can do something like:
HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));
config.Filters.Add(new MyFilter());
See this post for details on registering new services with Autofac: http://blogs.msdn.com/b/azuremobile/archive/2014/03/28/making-it-yours-configuring-mobile-services-net-backend.aspx. You'd use the ConfigBuilder constructor overload that takes a parameter named dependencyInjectionConfig.

Access HttpConfiguration in Orchard CMS

I would like to enable CORS (Cross-Origin Request) in Orchard 1.8.1. I followed this article for the purpose. However, I don't know how to access HttpConfiguration for my WebAPI Controller. I tried to use ControllerContext.Configuration, but it seems to be always NULL.
What is the proper method to access HttpConfiguration in Orchard and to call EnableCors()?
Thank you in advance.
As I figured Orchard uses GlobalConfiguration, I created a shell hook impelmenting the IOrchardShellEvents in my module, and inside the Activated method implementation I called System.Web.Http.GlobalConfiguration.Configuration.EnableCors();

How to use Custom Routes with Auto Query

Using the first example in the ServiceStack Auto Query documentation in a project structured similar to the EmailContacts sample project (i.e. separate projects for the ServiceModel and ServiceInterface), how would one register the custom route "/movies" defined by the Route attribute?
[Route("/movies")]
public class FindMovies : QueryBase<Movie>
{
public string[] Ratings { get; set; }
}
Normally, custom routes such as these can be register by passing the ServiceInterface assembly when instantiating AppHostBase:
public AppHost() : base("Email Contact Services", typeof(ContactsServices).Assembly) {}
However, the FindMovies request DTO does not have an associated service and therefore won't be included. No routes are registered.
If I pass typeof(FindMovies).Assembly instead of or in addition to typeof(ContactsServices).Assembly, then the pre-defined route will be registered (i.e. shows up in the metadata, postman, etc.) but the custom route is still not registered (i.e. does not show up in the metadata, postman, etc.).
What is the best way to register the custom route using attributes when there is no service and the ServiceModel and ServiceInterface are in separate projects?
These issues should be resolved in v4.0.24+ that's now available on MyGet.
There's a new AutoQueryFeature.LoadFromAssemblies property to specify an additional list of assemblies to scan for IQuery Request DTO's. This automatically looks in the assemblies where your other Request DTO's are defined so in most cases nothing needs to be done as it will automatically be able to find your query services.
The routes for Query DTO's should now appear on the metadata pages as well as Swagger and Postman metadata API's.

Resources