I've inherited a legacy Spring3 application, and I'm trying to add Lightstep instrumentation to it. I'm having trouble converting the instructions for manually configuration found here.
https://github.com/opentracing-contrib/java-spring-web
In short, I need to convert the code block below to the xml equivalent.
#Configuration
#Import({TracingHandlerInterceptor.class})
public class MVCConfiguration extends WebMvcConfigurerAdapter {
#Autowired
private Tracer tracer;
#Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TracingHandlerInterceptor(tracer));
}
#Bean
public FilterRegistrationBean tracingFilter() {
TracingFilter tracingFilter = new TracingFilter(tracer);
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(tracingFilter);
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.setOrder(Integer.MIN_VALUE);
filterRegistrationBean.setAsyncSupported(true);
return filterRegistrationBean;
}
}
I've successfully created my Lightstep Tracer bean using the following dependencies.
compile group: 'com.lightstep.tracer', name: 'lightstep-tracer-jre', version: '0.14.8'
compile group: 'com.lightstep.tracer', name: 'tracer-okhttp', version: '0.15.10'
//https://mvnrepository.com/artifact/io.opentracing.contrib/opentracing-spring-web-starter
compile group: 'io.opentracing.contrib', name: 'opentracing-spring-web-starter', version: '0.3.3'
Related
I'm working on a solution that interacts with Redis, using the servicestack.net library.
I have a class that inherits from ServiceStack.AppHostBase and asks me for an override of the Configure method. This method has as a parameter a Funq.Container that I see is an implementation of IServiceProvider, IResolver and IContainer, and none of these interfaces have the AddHttpClient method that is provided by the IServiceCollection. Method I need to be able to inject the IHttpClientFactory. Any idea how to solve my problem?
To do it in ASP.NET (not .NET Core), the quick way would be to:
install Microsoft.Extensions.DependencyInjection package and call .AppHttpClient() extension
Build the Service Provider you would normally see in .NET Core
Get the instance of IHttpClientFactory from the Service Provider
Register the instance of IHttpClientFactory with Funq.Container again
using Microsoft.Extensions.DependencyInjection;
public class AppHost : AppHostBase
{
public override void Configure(Container container)
{
...
RegisterHttpClientFactory(container);
}
private container RegisterHttpClientFactory(Container container)
{
var services = new ServiceCollection()
.AddHttpClient();
// You can kind of inspect services returned.
// You can see this extension registers lot of other things too beside
// IHttpClientFactory.
// Also you can see the lifetime of IHttpClientFactory is Singleton.
var serviceProvider = services.BuildServiceProvider();
container.AddSingleton(serviceProvider.GetService<IHttpClientFactory>());
return container;
}
}
If you happen to use Unity Adaptor
Unity has a package to give you an extension as well to build the Service Provider directly into the Unity Container:
using Microsoft.Extensions.DependencyInjection;
using Unity;
using Unity.Microsoft.DependencyInjection;
public static class UnityConfig
{
public static void RegisterTypes(IUnityContainer container)
{
...
container.RegisterServices();
container.RegisterHttpClientFactory();
}
private static IUnityContainer RegisterHttpClientFactory(
this IUnityContainer unityContainer)
{
new ServiceCollection()
.AddHttpClient()
.BuildServiceProvider(unityContainer);
return unityContainer;
}
}
This is the interface definition of IServiceCollection from IServiceCollection.cs:
public interface IServiceCollection : IList<ServiceDescriptor>
{
}
AddHttpClient is just an extension method from Microsoft.Extensions.DependencyInjection that wraps adding a number of additional dependencies to ASP.NET Core IOC.
So you should continue to register it on ASP.NET Core IOC, i.e:
public class Startup : ModularStartup
{
public new void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseServiceStack(new AppHost
{
AppSettings = new NetCoreAppSettings(Configuration)
});
}
}
As any dependencies registered .NET Core Startup are also available to ServiceStack.
My Azure function doesn't calls the startup class localy.
When running the project, my brekpoint doesn't hit the DependencyRegistrations.Register function.
Package Microsoft.Azure.Functions.Extensions is correctly installed
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]
namespace MyNamespace
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
DependencyRegistrations.Register(builder.Services);
}
}
}
Why is the startup class not called?
Two things I'm not seeing in your code snippet.
1- [assembly: FunctionsStartup(typeof(MyNamespace.Startup))]
2- Are you sure the nuget package was properly installed? (Microsoft.Azure.Functions.Extensions)
The final startup code should look like the following:
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]
namespace MyNamespace
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddHttpClient();
builder.Services.AddSingleton<IMyService>((s) => {
return new MyService();
});
builder.Services.AddSingleton<ILoggerProvider, MyLoggerProvider>();
}
}
}
Just in case you're running v4, Startup is not used.
Perform the dependency injection setup in Program.cs:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(builder =>
{
builder.AddTransient<IUserService, UserService>();
builder.AddTransient<ICompetitionService, CompetitionService>();
builder.AddTransient<ICompetitionRepository, CompetitionRepository>();
})
.Build();
host.Run();
I face the same issue, i have to remove my project from my solution and recreate an new to have the statup to be called...
I suspect a version mistake somewhere
I’m new in xamarin ios and I need to add view in existing project. Project use mvvmcross framework.
I’ve done:
Created PerevozkiViewModelClass :MvxViewModel in Core project
Add UI View controller with storydoard (P.S. BaseView extends MvxViewController)
public partial class PerevozkiView : BaseView
{
public PerevozkiView() : base("PerevozkiView", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var set = this.CreateBindingSet<PerevozkiView, PerevozkiViewModel>();
set.Apply();
}
}
Delete PerevozkiView.Storyboard
4.Add PerevozkiView.xib and in file owner specify PerevozkiView (I cant choose it from list, so I just hardcode “PerevozkiView as file owner)
After deploy in IOS simulator I’ve got exception:
Foundation.MonoTouchException
Сообщение = Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: -[UIViewController _loadViewFromNibNamed:bundle:] loaded the "PerevozkiView" nib but the view outlet was not set here in Main:
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
I have no idea what is wrong. Pls help
How can I add a custom portlet to the Control Panel section? I saw various tutorials but all are of liferay 6.2. How to accomplish it in liferay 7? Thanx in advance..
In Liferay 7, if you are using bundles (for example, created via the Blade tools), you can get it working with panel apps. A panel app maps a portlet to a position in the Control Panel.
Suppose you have a portlet generated by Blade, like the one below:
#Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=false",
"javax.portlet.name=cpportlet",
"javax.portlet.display-name=Control Panel Portlet",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class CpPortlet extends GenericPortlet {
#Override
protected void doView(
RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
PrintWriter printWriter = renderResponse.getWriter();
printWriter.print("cp-portlet Portlet - Hello World!");
}
}
Now you just create another OSGi component implementing the PanelApp service:
#Component(
immediate = true,
property = {
"panel.app.order:Integer=10000", // Defines position in list
"panel.category.key=" + PanelCategoryKeys.SITE_ADMINISTRATION_CONTENT // To appear in the "Content" session
},
service = PanelApp.class
)
public class CpPanelApp extends BasePanelApp {
#Override
public String getPortletId() {
return "cpportlet"; // Same name of the portlet.
}
#Override
#Reference(
target = "(javax.portlet.name=cpportlet)",
unbind = "-"
)
public void setPortlet(Portlet portlet) {
super.setPortlet(portlet);
}
}
To compile that, you will depend on the "Application List app" API - It is there that we find the PanelApp class. So, just add this dependency to your build.gradle, as below:
dependencies {
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
compileOnly group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
compileOnly group: "com.liferay", name: "com.liferay.application.list.api", version: "2.0.0" // Dependency added
}
Now deploy it and the portlet will appear in the listing:
This is just the basic idea — the documentation is very instructive about it.
You can define control-panel category by properties for Component:
com.liferay.portlet.control-panel-entry-category=<String>
com.liferay.portlet.control-panel-entry-weight=<double>
Please refer mapping listed here:
https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/portlet-descriptor-to-osgi-service-property-map
I would like to disable/limit auditing (CustomAuditEventRepository) in an application generated using jhipster.
How can I do this?
Modify CustomAuditEventRepository so that it does nothing in add(), this is generated code, it's yours so you can do whatever you want with it.
Options 1: Disable audit event of spring actuator. Adding config properties to application.yml file:
management:
auditevents:
enabled: false
Refer: AuditAutoConfiguration
#Configuration(proxyBeanMethods = false)
#ConditionalOnBean(AuditEventRepository.class)
#ConditionalOnProperty(prefix = "management.auditevents", name = "enabled", matchIfMissing = true)
public class AuditAutoConfiguration {
...
}
Options 2: Add custom AuditListener bean
#Bean
public MyAuditListener auditListener() {
return new MyAuditListener();
}
public class MyAuditListener extends AbstractAuditListener {
private static final Log logger = LogFactory.getLog(MyAuditListener.class);
public MyAuditListener() {
...
}
#Override
protected void onAuditEvent(AuditEvent event) {
...
}
}