in unix we put public key under /.ssh/authorized_keys
but in case of windows, where should I put or import public key?
Related
I have an existing groovy micronaut app I'm trying to change where it loads its config from. I don't understand what code to write so I can set the location of the micronaut configuration. I know you can use micronaut.config.files system variable or MICRONAUT_CONFIG_FILES environment variable, but this is a terrible idea because micronaut is built into grails and therefore every grails app you have running in tomcat will pick up the same config and crash.
Nor do I know where in the code to set the config file. There's an Application class with a run() method, but I don't know if this is only called during development, or whether it gets called when deploying in Tomcat. When setting the config in a Grails app, there is an Application class extending EnvironmentAware, and you can override setEnvironment, and load external configs there, but there is no hint of that for micronaut apps.
The micronaut doco says it can load a configuration from "application.{extension}", but it doesn't say what "application" is, or what directory it expects that in, or whether you can change the directory. Is "application" the value of micronaut.application.name in one's application.yml? I couldn't seem to get it to load based on that.
Then the documentation talks about loading from a PropertySource, which is fine and all, but doesn't tell you where you can put that code to load from a PropertySource. There is mention you can pass the PropertySource to ApplicationContext.run(xx), but in this app I inherited, there is no mention of ApplicationContext, and the micronaut documentation isn't very clear what I'm supposed to do with ApplicationContext. This app I've inherited has an Application class with a main() calling Micronaut.run() which apparently returns an ApplicationContext, but it's not clear if main() is called when running in Tomcat, or whether I should be calling run() on that, when it works as is, and I'm just trying to change where it loads its config.
The question is, how do I get my micronaut app to load its config from
where I tell it to, and not from micronaut.config.file system variable
location.
I don't think we have a specific feature in the framework that allows you to tell the framework to ignore micronaut.config.files. If you would like such a feature you can request it at https://github.com/micronaut-projects/micronaut-core/issues. If that is of interest I suggest you open it up for discussion at https://github.com/micronaut-projects/micronaut-core/discussions first.
You can load external config files, from a path not set as micronaut.config.files, in the main method of the Application class before running the application. Take a look at below class which accepts a config folder location as a system property demo.config.path(can be something else) and loads yaml config files from that folder:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import io.micronaut.context.env.PropertySource;
import io.micronaut.context.env.yaml.YamlPropertySourceLoader;
import io.micronaut.core.io.ResourceLoader;
import io.micronaut.core.io.file.DefaultFileSystemResourceLoader;
import io.micronaut.runtime.Micronaut;
public class Application {
private static final String PROP_CONFIG_LOCATION = "demo.config.path";
public static void main(String[] args) throws IOException {
if (System.getProperty(PROP_CONFIG_LOCATION) != null) {
List<PropertySource> propertySources = new ArrayList<>();
YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader();
ResourceLoader resourceLoader = new DefaultFileSystemResourceLoader();
Files.newDirectoryStream(Paths.get(System.getProperty(PROP_CONFIG_LOCATION))).forEach(file -> {
String fileName = file.toString();
String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.'));
propertySourceLoader.load(fileNameWithoutExtension, resourceLoader).ifPresent(propertySources::add);
});
Micronaut.build(args)
.classes(Application.class)
.propertySources(propertySources.toArray(new PropertySource[1]))
.start();
} else {
Micronaut.run(Application.class, args);
}
}
}
As is, this code works for yaml config files(with snakeyaml in classpath). With minor changes, it can be made to work for properties files and to read config location from environment variable instead of system property. Full sample application present in github
I am doing some stuff in Service Stack self host in windows service. The link gave me some hint. But in the code, what is StarterTemplateAppListenerHost then?
It is a class which extends AppHostHttpListenerBase (Source here) which is used to provide the http listener and application configuration.
public class StarterTemplateAppListenerHost : AppHostHttpListenerBase
{
static readonly IAppSettings AppSettings = new AppSettings();
public StarterTemplateAppListenerHost()
: base(AppSettings.GetString("ServiceName") ?? "StarterTemplate HttpListener", typeof(HelloService).Assembly) { }
public override void Configure(Funq.Container container)
{
container.Register(new TodoRepository());
}
}
This is demonstrated also in the official documentation here.
I just wonder why the link doesn't have OnStart() etc
The example has two different compilation modes. When it's run in debug, it will not run as a service, and solely uses StarterTemplateAppListenerHost.
When it is run in release mode then it will create a service around the instance of StarterTemplateAppListenerHost. The WinService class provides the OnStart and OnStop methods which are expected of Windows Services by extending System.ServiceProcess.ServiceBase.
So to get it running as a Windows Service you will need to include these 3 files:
Program.cs
WinService.cs
StarterTemplateAppListenerHost.cs
I am trying to use Apache Wink to get Service Document from an IBM host but I always get error 403 Forbidden. Here is my code :
import org.apache.wink.client.Resource;
import org.apache.wink.client.RestClient;
public class CommunityEvents {
private String uri = "https://w3-connections.ibm.com/profiles/atom/search.do?name=Nam,+Vu+Hoai";
public CommunityEvents() {
RestClient restClient = new RestClient();
Resource resource = restClient.resource(uri);
System.out.println(resource.get().getMessage());
}
public static void main(String[] args) {
new CommunityEvents();
}
}
The link is working fine when I put it into browser address. I have tried with other https and they worked.
Can someone correct my code or tell me what I missed ? what I need to do to access the link above ?
Thank you so much !
is the URL trusted by your JVM? I imagine it's a CACERTS issue. You'll want to extract the certificate using your browser, and use the keytool to import it into your JVM CACERTS.
Also Wink supports JSON and other resource styles, make sure you have the right library for ATOM+XML which is the current resource URL you selected.
The basic architecture of my project (JBoss MSC version 1.0.2.GA-redhat-2) is like this
(VWebProj) --- >compile dependency ---> service project (QServiceProj)
(QServiceProj) ---->compile dependency ---> proxy project(VProxyProj)
(VProxyProj) ---->compile dependency ---> Manager project(VQManagerProj)
Manager project(VQManagerProj)
I have a manger class inside a Manager Project (VQManagerProj) which extends a class JDAO which in turn implements a interface VDAO
#Named("qManager")
#ApplicationScoped
public class QManager extends JDAO {...}
JDAO implements VDAO
Proxy Project (VProxyProj)
I have a proxy class inside Proxy Project (VProxyProj) which implements an interface VProxy and has the manager injected to it
#Named("vProxyImpl")
#ApplicationScoped
public class VProxyImpl implements VProxy {
#Inject #Named("qManager")
private VDao vdao;
}
Sevice Project (QServiceProj)
I have a service class inside Sevice Project (QServiceProj) which extends an abstract class
#Named
#ApplicationScoped
public class QService extends AbstractService {..}
Inside the abstract class I have the proxy injected
public abstract class AbstractService{
#Inject #Named("vProxyImpl")
private static VProxy proxy;
}
and using this proxy object the service class makes calls to the manager etc
Web Project (VWebProj)
Now I have a servlet inside the web Project (VWebProj) in which the service class is injected
#Inject
private QService qService;
The problem is that except qService none of the other injections work i.e inside QService proxy instance is null
however if I add all the injections directly in the servlet class like this
#Inject #Named("qManager")
private VDao vdao;
#Inject #Named("vProxyImpl")
private static VProxy proxy;
They are all initialized but if I go via QService they are null
I have put beans.xml in all the projects,
Thanking in advance
Charlie
As far as I know Injector can only inject objects into instances and their fields - You are trying to "inject" dependencies into static fields.
I suggest using #Singleton annotation instead - create separate instance that would hold all your current static references, and inject that singletons into Your instances instead.
#Singleton
class ProxyService {
#Inject #Named("vProxyImpl")
private VProxy proxy;
public VProxy getProxy() {
return proxy;
}
}
public abstract class AbstractService{
#Inject
private ProxyService proxyService;
}
Alternatively You can consider making VProxy singleton - I seems that what You want to obtain is just one instance of Proxy in a whole application. You need to decide yourself what is that best approach here.
I have a method (in a separated class library) which is called by a WebRole and a WorkerRole. This method contains the path of a file, which is returned using Environment.GetEnvironmentVariable("RoleRoot"), as follows:
private string FooPath()
{
string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
return Path.Combine(appRoot + #"\", #"approot\file.foo");
}
When I call this method from a WorkerRole the path is returned normally. But when I call it from a WebRole I get null.
Any ideas?
EDIT: I am using APNS-Sharp to send push messages to iOS and it requires a .p12 certificate in order to work. Currently I have the .p12 in the root of my class library (which is called by both WebRole and WorkerRole). But the point is: Why RoleRoot returns null when I call it from a WebRole but returns the path when I call from a WorkerRole?
RoleRoot returns false for WebRole because the WebRole uses IIS, just like a normal website. That's why it's difficult to get Environment Variables from a WebRole.
In order to get the path properly I had to use the classic Server.MapPath and reference the bin folder, instead of approot:
private string FooPathWebRole()
{
string appRoot = HttpContext.Current.Server.MapPath(#"~\");
return Path.Combine(appRoot + #"\", #"bin\file.foo");
}
For the WorkerRole nothing has changed:
private string FooPathWorkerRole()
{
string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
return Path.Combine(appRoot + #"\", #"approot\file.foo");
}
In addition, I found out that Azure doesn't import p12 certificates. I would have to transform it into another format, which I don't believe would work for me. So, the best option is to place them on the root of the application and mark its Build Action to Content.
I tried from webrole and it works for me. I place it at the OnStart() code of the web role, which is called by WaIISHost
If you want to load a certificate, you could try the advice in http://blogs.msdn.com/b/jnak/archive/2010/01/29/installing-certificates-in-windows-azure-vms.aspx
Linked from How do I import a public certificate to Windows Azure?