Need simple code: Get Glassfish InitialContext & lookup ConnectionFactory - glassfish

My glassfish4 server runs on localhost.
My java client is a simple GUI run from Eclipse.
My glassfish4 admin console assures me I have a Resources/JMS Resources/Connection Factories/jms/goConnectionFactory properly configured.
So I though it would be trivial for the client to get an InitialContext from glassfish and use it to lookup "jms/goConnectionFactory. Not true,
And after reading answered questions (all too wrapped up in other special issues to be helpful) I still can't connect.
Can anyone tell me the properties I need to load to make this work?
Properties prop = new Properties:
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.impl.SerialInitContextFactory");
prop.setProperty(Context.URL_PKG_PREFIXES,
"com.sun.enterprise.naming");
prop.setProperty("org.omg.CORBA.ORBInitialPort","3700");
prop.etProperty("org.omg.CORBA.ORBInitialHost","localhost");
System.out.printlin (jndiContext.getClass().getName();
InitialContext jndiContext = new InitialContext (props);
ConnectionFactory =
(ConnectionFactory) jndiContext.lookup("jms/goConnectionFactory");
The 1st printlin() returns this to the console "javax.naming.InitialContext".
But a try/catch block (not shown) around the lookup() catches a NullPointerException
And I don't know how to tell if my InitialContext object is a valid one from my glassfish4 server, or I'm using it incorrectly.
Anyway ... a glassfish server, and a java GUI client (run from Eclipse), both running on the same machine seems a pretty generic arrangement. So I'm sure it would help all newbees to JMS to have just one trivial snipt of code that proves it works -- without having to spend a week hunting to no avail.
Note: I also tried
factory =
(ConnectionFactory)
PortableRemoteObject.narrow(
jndiContext.lookup("jms/goConnectionFactory"),
ConnectionFactory.class
);
But I'm pretty sure I won't need that till I try to get my local client to talk to my glassfish4 running on a virtual server elsewhere.
And I used "localhost:8080", instead of just "localhost", in prop above. Same result. I get some kind of InitialContext Object. But it won't retrieve a ConnectionFactory.
Can anyone offer any help?

...
System.out.printlin (jndiContext.getClass().getName();
InitialContext jndiContext = new InitialContext (props);
...
Isn't the first line the cause of your null pointer? The jndiContext is not yet initialized at that point.

Related

CefSharp.BrowserSubProcess.Core WCF pipe failure

Our application is using CefSharp version 73.1.130. The issue only occurs on a small number of internal workstations within our organization. Worth noting, we are also seeing the same error with CefSharp version 92. Another strange thing is that it the issue is consistent, but only when the web apps are launched through certain navigations. Other navigations work consistently for these users.
We use RegisterJsObject to register a javascript object with browser. If I understand correctly, asynchronous binding is preferred moving forward.
The issue presents as strange/unexpected behavior in the hosted web application due to failure to retrieve context from the host WinForms application. The behavior would suggest a failure to register/bind the js object with the RegisterJsObject method. However, that method is not throwing an exception.
Enabled Cef logging showed the following error:
ERROR:JavascriptRootObjectWrapper.cpp(34)] IBrowserProcess is null, unable to bind object
After looking into the code, it appears the location that the value pointed to by "IBrowserProcess" is set is in WcfEnabledSubProcess::OnBrowserCreated (https://github.com/cefsharp/CefSharp/blob/cefsharp/73/CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.cpp). I was able to build CefSharp and add additional logging to that method.
On my workstation (I'm not affected by the issue), I get through OnBrowserCreated with no exceptions. However, on my coworkers workstation I see the following line is failing:
...
channelFactory->Open();
auto browserProcess = channelFactory->CreateChannel();
auto clientChannel = ((IClientChannel^)browserProcess);
try
{
clientChannel->Open(); <-- FAILS
browser->ChannelFactory = channelFactory;
browser->BrowserProcess = browserProcess;
}
catch (Exception^)
{
}
}
With the error:
There was an error reading from the pipe: The pipe has been ended. (109, 0x6d)
Has anyone seen this issue before? I'm not sure how much this will help, but does anyone know if it's possible to enable WCF tracing with the CefSharp.BrowserSubProcess.exe. I have been trying this, but no luck so far.

LettuceConnectionFactory with SentinelTopologyProvider

I am using lettuce through the spring boot API org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory .
My bean is configured as
#Bean
public LettuceConnectionFactory lettuceSentinelConnectionFactory() {
RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration(mastername, new HashSet<>(sentinelnodes));
return new LettuceConnectionFactory(sentinelConfig);
}
This works fine, except for reconnecting after topology changes, resulting in exceptions.
io.lettuce.core.RedisCommandExecutionException: READONLY You can't write against a read only slave.
Some bugreports seem to confirm this behaviour .
With great interest I read that lettuce implements a dynamic topology discoverer for sentinels SentinelTopologyProvider, which should fix the issue elegantly.
However I am unable to make the LettuceConnectionFactory use this dynamic SentinelTopologyProvider, and googling did not return anything neither.
Can anyone give a hint or some sample code on how to write this code?

How to use Miniprofiler storage to support multiple web instances?

I've hooked up Miniprofiler to my local ASP.NET Core project and it works as expected. Now I need it to work in a hosted environment where there are multiple instances of the same website and there are no sticky sessions. It is my understanding that this should be supported if you just set the storage option when configuring the profiler. However, setting the storage does not seem to do anything. I initialize the storage like this:
var redisConnection = "...";
MiniProfiler.DefaultOptions.Storage = new RedisStorage(redisConnection);
app.UseMiniProfiler();
After doing this, I expected that I could open a profiled page and a result would be added to my redis cache. I would then also expect that a new instance of my website would list the original profiling result. However, nothing is written to the cache when generating new profile results.
To test the connection, I tried manually saving a profiler instance (storage.Save()) and it gets saved to the storage. But again, the saved result is not loaded when showing profiler results (and regardless, none of the examples I've seen requires you to do this). I have a feeling that I've missed some point about how the storage is supposed to work.
It turns out that my assumption that MiniProfiler.DefaultOptions.Storage would be used was wrong. After changing my setup code to the following, it works.
// Startup.cs ConfigureServices
var redisConnection = "...";
services.AddMiniProfiler(o =>
{
o.RouteBasePath = "/profiler";
o.Storage = new RedisStorage(redisConnection); // This is new
});
// Startup.cs Configure
app.UseMiniProfiler();

ServiceLoader issue in WebLogic12c

I have been trying to refactor our Activiti implementation into using CDI but ran into a number of problems. I've spent way too much time trying to resolve this already, but I just can't let it go...I think I've pinned the problem down now, setting up a clean structured war without involving Activiti and have been able to reproduce what I think is the main problem.
Basically I have jar1 and jar2, both CDI enabled by including META-INF/beans.xml. Both jars specify a class in META-INF/services/test.TheTest pointing to implementations local to respective jar. jar1 depends on jar2. Also, both jars point to an implementation of javax.enterprise.inject.spi.Extension, triggering the scenario. In each implementation of Extension, I have a method like:
public void afterDeploymentValidation(
#Observes AfterDeploymentValidation event, BeanManager beanManager) {
System.out.println("In jar1 extension");
ServiceLoader<TheTest> loader = ServiceLoader.load(TheTest.class);
Iterator<TheTest> serviceIterator = loader.iterator();
List<TheTest> discoveredLookups = new ArrayList<TheTest>();
while (serviceIterator.hasNext()) {
TheTest serviceInstance = (TheTest) serviceIterator.next();
discoveredLookups.add(serviceInstance);
System.out.println(serviceInstance.getClass().getName());
}
}
Now, my problem is that the ServiceLoader does not see any implementations in either case when running WebLogic12c. The same code works perfectly fine in both Jboss 7.1.1 and Glassfish , listing both implementations of the test.TheTest interface.
Is it fair to assume that this is indeed a problem in WebLogic 12c or am I doing something wrong? Please bare in mind that I am simply trying to emulate the production setup we use when incorporating Activiti.
Regards,
/Petter
There is a Classloader Analysis Tool provided with WLS, have you seen if this will help with the diagnosis of your issue.
You can access this tool by going to ip:port/wls-cat/index.jsp
Where port will be the port of the managed server where your application is deployed.

Object already exists exception in RSACryptoServiceProvider

First let me start by saying I'm sorry if I posted this question in the wrong place. I saw the entry at Object already exists in RSACryptoServiceProvider. I tried the solutions offered there. But, they did not solve my issue. Also, I didn't see an option to re-ask the question.
I have almost the same issue. I have a class that uses RSACryptoServiceProvider that runs in two projects on the same machine and under the same account. Both projects live in the same solution and share the same encryption code. One project, the server, is a Windows service and the other, the client, is a Windows application. They use the RSACryptoServiceProvider to talk to each other over a named pipe using asymmetric encryption. I started out by just having the server run in another Windows form within the same application as the client. Everything ran fine. Then, I moved the server to a Windows service.
The Windows service starts up fine. It seems to be able to create it's instance of the RSACryptoServiceProvider fine. But, when the client, which runs in the Windows application, starts up it gets a runtime error when it tries to create it. Here is the code that runs in both projects.
rule = New CryptoKeyAccessRule("everyone", CryptoKeyRights.FullControl, AccessControlType.Allow)
csp = New CspParameters
csp.KeyContainerName = _KeyContainerName
csp.Flags = CspProviderFlags.UseMachineKeyStore
csp.CryptoKeySecurity = New CryptoKeySecurity()
csp.CryptoKeySecurity.SetAccessRule(rule)
//Object already exists exception happens here
rsa = New RSACryptoServiceProvider(_KeySize, csp)
As you can see, I have the code that sets the access rule as mentioned in the other post on this subject. Unfortunately, this did not solve my issue. Is there anything else that needs to change?