I'm able to restart JBoss AS 7.2.0 Final using Jboss CLI with the following command:
jboss-cli.bat --connect --controller=IP:9999 --command=:shutdown(restart=true)
Now i need to do it programmatically from a java class, i've tried using the Jboss cli API, here after my code, but it only performs a shutdonw and doesn't restart!
CommandContext ctx = null;
try {
ctx = org.jboss.as.cli.CommandContextFactory.getInstance().newCommandContext();
ctx.connectController(IP, 9999);
ctx.handle(":shutdown(restart=true)");
} catch (CommandLineException e) {
System.out.println(e.getMessage());
}
Any idea please?
There really is no JBoss AS 7.2.0.Final but I tested the following on WildFly 8 and JBoss EAP 6.x and it worked for me. Note that port 9990 is used in WildFly and port 9999 is used for JBoss EAP 6.x.
public static void main(final String[] args) throws Exception {
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
final ModelNode op = Operations.createOperation("shutdown");
op.get("restart").set(true);
client.execute(op);
}
}
Related
My application (C#, VS2017) previously targeted Python 3.5.1. I have updated the system to Python 3.7.1 and have this is causing PythonEngine.Initialize() to crash the application without throwing an exception.
One internet suggestion was to set the Python env in VS, however this causes VS2017 to close when opening Python/environments. I switched to VS2019 and encountered the same issue with the stripped down code here:
using System.Windows.Forms;
using Python.Runtime;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
try
{
PythonEngine.Initialize();
}
catch (Exception e)
{
string ex = e.ToString();
}
}
}
}
Python.Net was installed successfully using:
pip install pythonnet
UPDATE Dec 2022
There are 2 optional environment strings you can use to locate the python dll.
PYTHONNET_PYDLL explicitly set the dll name
PYTHONNET_PYVER explicitly set just the version string part of the dll name
Compiling with WINDOWS, OSX or LINUX defined is not required anymore
Here's my PythonNet init function.
Note that running "pip install pythonnet" only installs the ability to load & use CLR types & assemblies from Python. To embed PythonNet in a C# app, you actually don't need to install pythonnet on the Python side.
This function uses some globals set at startup.
Program.PythonHome -- points to the Python root folder I'm using
Program.ScriptsDir -- my own app python scripts dir
Program.ApplicationName -- just my own app name
I also call PythonEngine.BeginAllowThreads(); as I'm calling from multiple threads.
public static void InitPython(Microsoft.Extensions.Logging.ILogger logger)
{
string py_home = Program.PythonHome;
string py_path = $"{py_home};";
// will be different on linux/mac
string[] py_paths = {"DLLs", "lib", "lib/site-packages", "lib/site-packages/win32"
, "lib/site-packages/win32/lib", "lib/site-packages/Pythonwin" };
foreach (string p in py_paths)
{
py_path += $"{py_home}/{p};";
}
try
{
PythonEngine.PythonPath = $"{Program.ScriptsDir};{py_path}";
PythonEngine.PythonHome = Program.PythonHome;
PythonEngine.ProgramName = Program.ApplicationName;
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
logger.LogInformation("Python Version: {v}, {dll}", PythonEngine.Version.Trim(), Runtime.PythonDLL);
logger.LogInformation("Python Home: {home}", PythonEngine.PythonHome);
logger.LogInformation("Python Path: {path}", PythonEngine.PythonPath);
}
catch (System.TypeInitializationException e)
{
throw new Exception($"FATAL, Unable to load Python, dll={Runtime.PythonDLL}", e);
}
catch (Exception e)
{
throw new Exception($"Python initialization Exception, {e.Message}", e);
}
}
I am using Microsoft.azure.webjobs (3.0.0-beta1-10941) in a .net core 2 console app. The aim is to create a azure web job,
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
The config.UseTimer() is expected a reference of Microsoft.Azure.WebHost.Host but it needs 2.1.0.0. If i add this by removed beta version 3.0.0-beta1-10941 then host.runandblock() falls over at WindowsAzure.Storage incorrectly deployed install edm, data, or data.services.
I installed the dependencies but still no luck
I have downgraded windowsAzure.Storage to lower than 9 but same issue.
Azure WebJobs NuGet Package Error
Any ideas how to resolved config.UseTimes() in .net core 2.0?
Thanks
Any ideas how to resolved config.UseTimes() in .net core 2.0?
In your case you could use the Microsoft.Azure.WebJobs.Extensions Version 3.0.0-beta4.
I also do a demo for it. The following is detail steps.
1.Create a net core 2.0 console application.
2.Add the following code in the Program.cs file.
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseTimers();
config.DashboardConnectionString ="storage connectionstring";
config.StorageConnectionString = "storage connectionstring";
var host = new JobHost(config);
host.RunAndBlock();
3. Add the Functions.cs file to the project.
public class Functions
{
public static void CronJob([TimerTrigger("0 */1 * * * *")] TimerInfo timer)
{
Console.WriteLine("Cron job fired!");
}
}
4. Test it on my side.
Check documentation. There are solutions for 2.x and 3.x.
For 3.x can be used "b.AddTimers();" Example:
static async Task Main()
{
var builder = new HostBuilder();
builder.UseEnvironment(EnvironmentName.Development);
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
});
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage();
b.AddTimers();
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
The time-triggered method: (need to be in a static class)
public static class TimeTrigger
{
// Runs once every 10 seconds
public static void TimerJob([TimerTrigger("00:00:10")] TimerInfo timer)
{
Console.WriteLine("Timer job fired!");
}
}
I am using apache cxf java client to connect my WS. I am also using NTLM for authentication.
Now problem I am facing due to credential caching. First time i tried user which does not have privileges to access WS method. when I changed the user , it is still using same user to access WS method.
I am running in tomcat, so cannot kill my JVM .. tried all possible combination on httpClientPolicy.
Any help will be appreciated.
This is NTLM specific problem. sun.net.www.protocol.https.HttpsURLConnectionImpl is getting serverAuthorization via java.net.Authenticator. requestPasswordAuthentication(). This authorization info is maintained in sun.net.www.protocol.http.AuthCacheValue.cache.
So if we override sun.net.www.protocol.http.AuthCacheValue means we can fix this issue.
AuthCacheValue.setAuthCache(new AuthCache()
{
#Override
public void remove(String arg0, AuthCacheValue arg1) { }
#Override
public void put(String arg0, AuthCacheValue arg1) { }
#Override
public AuthCacheValue get(String arg0, String arg1)
{
return null;
}
});
Reference :
http://web.archiveorange.com/archive/v/ACbGtycfTs2dqbRNpy6d
http://tigrou.nl/2011/06/11/cached-credentials-in-http-basic-authentication/
I googled and tried a lot of solutions to this problem.. apparently the simplest code that worked is as below using the JCIFS library
//Set the jcifs properties
jcifs.Config.setProperty("jcifs.smb.client.domain", "domainname");
jcifs.Config.setProperty("jcifs.netbios.wins", "xxx.xxx.xxx.xxx");
jcifs.Config.setProperty("jcifs.smb.client.soTimeout", "300000"); // 5 minutes
jcifs.Config.setProperty("jcifs.netbios.cachePolicy", "1200"); // 20 minutes
jcifs.Config.setProperty("jcifs.smb.client.username", "username");
jcifs.Config.setProperty("jcifs.smb.client.password", "password");
//Register the jcifs URL handler to enable NTLM
jcifs.Config.registerSmbURLHandler();
Apparently CXF 3.0 doesnt have a valid way of configuring the HTTP Client (4.3.x) with NTCredentials instance. Please refer to bug https://issues.apache.org/jira/browse/CXF-5671
By the way, if you have a simple message which needs to be transmitted, just use HTTP Client (I worked using 4.3.4.. not sure of the earlier versions) with NTCredentials Instance. That too did the magic for me.. The sample is as below:
final NTCredentials ntCredentials = new NTCredentials("username", "Passworrd","destination", "domain");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, ntCredentials);
CloseableHttpClient httpclient = HttpClientBuilder.create()
.setDefaultCredentialsProvider(credsProvider)
.build();
I am new to google api. I am trying to create a simple web application (Java EE) to read DocumentListFeed from google doc. My code in the servlet is:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
DocsService service = new DocsService("Document List Demo");
service.setUserCredentials(NAME, PASSWORD);
response.getWriter().println("helloooooo");
//URL documentListFeedUrl = new URL("http://docs.google.com/feeds/documents/private/full");
URL documentListFeedUrl = new URL("https://docs.google.com/feeds/default/private/full?v=3");
DocumentListFeed feed = service.getFeed(documentListFeedUrl, DocumentListFeed.class);
for(DocumentListEntry entry : feed.getEntries())
{
response.getWriter().println(entry.getTitle().getPlainText());
}
}
catch (Exception e)
{
response.getWriter().println(e);
}
}
But it is showing me the error: java.lang.NoClassDefFoundError: com/google/gdata/client/docs/DocsService
I am using Glassfish server and Ecllipse. And added external jar file: activation.jar, guava-r07.jar, mail.jar, servlet.jar, gdata-client-1.0.jar, gdata-client-meta-1.0.jar, gdata-core-1.0.jar, gdata-media-1.0.jar, gdata-docs-3.0.jar, gdata-docs-meta-3.0.jar.
I have copied this same code to java standard edition and it is working fine. Could please tell me why this thing is not working in Java EE? Is it a problem in GlassFish server?
It just means that the jars are not present in your Glassfish server classpath.
Add all the jars you listed to yuor glassfish server classpath. Since am not an Glassfish expert i cannot help you in adding the jars to your server.
In case of weblogic, you just need to package all the jars in your project APP-INF directory.
Hope it helps.
I'm using SoapUI 4.0 and i'm starting my mockservices via SoapUI API :
public static void startMockServices(String soapuiProject) throws Exception
{
WsdlProject proj = new WsdlProject(soapuiProject);
List<MockService> mockList = proj.getMockServiceList();
for (MockService mockService : mockList) {
mockService.addMockRunListener(new LogListener());
mockService.start();
}
}
public static void finishMocks() {
SoapUI.getThreadPool().shutdown();
try {
SoapUI.getThreadPool().awaitTermination(5l, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
SoapUI.shutdown();
}
The MockServices start well, but when I try to tear them down, the thread where jetty is running is still hanging up and my process does not finish.
I've tried to stop it via MockRunner.stop() as well but the thread still does not stop as well.
Is there any way I can stop the jetty thread so that my process finishes?
I know, better late than never.
On SoapUi 5.x.x, in the setting file, set the
con:setting id="HttpSettings#leave_mockengine to false!
In java, after, on the runner, you can set the settings file :)