Access objects through JNDI from an external JVM in Atg Dyanmo Application Server - jndi

I am trying to access some objects using JNDI from an external JVM in Atg Dyanmo Application Server. I am using the following code -
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
public class URLTest {
public static Object getNamedObject() {
Object o = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "atg.jndi.url.dynamoejb.RemoteEJBContext");
env.put(Context.URL_PKG_PREFIXES, "atg.jndi.url.dynamoejb ");
env.put(Context.PROVIDER_URL, "rmi://10.112.83.203:8860");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
try
{
Context ctx = new InitialContext(env);
System.out.println("Got Context - " + ctx);
o = ctx.lookup("dynamo:/pearsonpoc/beans/UserInformation");
System.out.println("Lookup success - " + o);
}
catch (Exception e) {
System.out.println("ERR - " + e);
}
return o;
}
}
When I am running this code at the same jvm, it works fine, but when I am trying this from other jvm it does not work. Rmi server is running on the port 8860. Is there any setting on server which basically stop requests from clients?
This is the exception i am getting -
09:46:25,963 INFO [STDOUT] Got Context - javax.naming.InitialContext#e3a921
09:46:26,010 INFO [STDOUT] ERR - javax.naming.NameNotFoundException: dynamo:/pearsonpoc/beans/UserInformation
09:46:26,010 INFO [STDOUT] Result - null
Please help. Thanks

You need to export the service on the server.
make this change to.
/atg/dynamo/server/RmiServer.properties
exportedServices+=/pearsonpoc/beans/UserInformation

Related

Connecting to Neo4j Aura with .NET Core 2.2 web api

I am trying to connect a to Neo4j Aura instance from a .NET core 2.2 web api. I understand I need the Neo4j .Net Driver v4.0.0-alpha01, but I do not seem to be able to connect. There aren't very many examples out there as this driver is new and so is Aura.
I keep getting:
Failed after retried for 6 times in 30000 ms. Make sure that your database is online and retry again.
I configure the driver as such
public void ConfigureServices(IServiceCollection services)
{
string uri = "neo4j://1234567.databases.neo4j.io:7687";//not actual subdomain
string username = "neo4j";
string password = "seeeeeeecret";//not actual password
services.AddCors();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSingleton(GraphDatabase.Driver(uri, AuthTokens.Basic(username, password)));
}
and in my test controller i run this
private async Task<string> Neo4JTestAsync()
{
string db = "MyDb";
string message = "TESTMESSAGE";
IAsyncSession session = _driver.AsyncSession(o => o.WithDatabase(db));
try
{
var greeting = session.WriteTransactionAsync(async tx =>
{
var result = tx.RunAsync("CREATE (a:Greeting) " +
"SET a.message = $message " +
"RETURN a.message + ', from node ' + id(a)",
new { message });
var res = await result;
return "return something eventually";
});
return await greeting;
}
catch (Exception e)
{
return e.Message; // throws "Failed after retried for 6 times in 30000 ms. Make sure that your database is online and retry again"
}
finally
{
await session.CloseAsync();
}
}
I can't get the exact error message you do - but I'm pretty sure this is due to encryption - one of the big differences between the 1.x and 4.x drivers is the default position on Encryption - which is now off by default.
So you'll want to change your initialisation to:
services.AddSingleton(GraphDatabase.Driver(uri, AuthTokens.Basic(username, password), config => config.WithEncryptionLevel(EncryptionLevel.Encrypted)));
That should get you going. Also - make sure you stick with the neo4j:// protocol, as that'll route you properly.
Have you tried bolt:// in the connection string?
string uri = "bolt://1234567.databases.neo4j.io:7687";//not actual subdomain

JNLP application returns NULL for all System.getenv()

I've a JNLP Java WebStart application in Which I want to read form the Environment Variables but all of them are NULL.
In my JNLP application I access and print the variables the following way:
Map<String, String> envArgs = System.getenv();
for (String key : envArgs.keySet()) {
System.out.println(key + "=" + arguments.get(key));
}
And Prints just lines like this:
ProgramData=null
ProgramW6432=null
HOMEPATH=null
PROCESSOR_IDENTIFIER=null
ProgramFiles=null
PUBLIC=null
windir=null
MOZ_CRASHREPORTER_PING_DIRECTORY=null
The JNLP application is started form another Java Application using the ProcessBuilder cmd = "C:\JDK\jre\bin\javaws -wait URL2JNLP":
ProcessBuilder pb = new ProcessBuilder(cmd[0], cmd[1], cmd[2]);
pb.environment().put("apple", "isFruite");
try {
return pb.start();
} catch (IOException e) {
LOG.error("Error starting JNLP application", e);
throw new RuntimeException(e);
}
Is there a way to fix this access/passing of the environment variables?

Cannot connect to Solace Cloud

I am following the solace tutorial for Publish/Subscribe (link: https://dev.solace.com/samples/solace-samples-java/publish-subscribe/). Therefore, there shouldn't be anything "wrong" with the code.
I am trying to get my TopicSubscriber to connect to the cloud. After building my jar I run the following command:
java -cp target/SOM_Enrichment-1.0-SNAPSHOT.jar TopicSubscriber <host:port> <client-username#message-vpn> <password>
(with the appropriate fields filled in)
I get the following error:
TopicSubscriber initializing...
Jul 12, 2018 2:27:56 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel call
INFO: Connecting to host 'blocked out' (host 1 of 1, smfclient 2, attempt 1 of 1, this_host_attempt: 1 of 1)
Jul 12, 2018 2:28:17 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel call
INFO: Connection attempt failed to host 'blocked out' ConnectException com.solacesystems.jcsmp.JCSMPTransportException: ('blocked out') - Error communicating with the router. cause: java.net.ConnectException: Connection timed out: no further information ((Client name: 'blocked out' Local port: -1 Remote addr: 'blocked out') - )
Jul 12, 2018 2:28:20 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel close
INFO: Channel Closed (smfclient 2)
Exception in thread "main" com.solacesystems.jcsmp.JCSMPTransportException" (Client name: 'blocked out' Local port: -1 Remote addr: 'blocked out') - Error communicating with the router.
Below is the TopicSubscriber.java file:
import java.util.concurrent.CountDownLatch;
import com.solacesystems.jcsmp.BytesXMLMessage;
import com.solacesystems.jcsmp.JCSMPException;
import com.solacesystems.jcsmp.JCSMPFactory;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.JCSMPSession;
import com.solacesystems.jcsmp.TextMessage;
import com.solacesystems.jcsmp.Topic;
import com.solacesystems.jcsmp.XMLMessageConsumer;
import com.solacesystems.jcsmp.XMLMessageListener;
public class TopicSubscriber {
public static void main(String... args) throws JCSMPException {
// Check command line arguments
if (args.length != 3 || args[1].split("#").length != 2) {
System.out.println("Usage: TopicSubscriber <host:port> <client-username#message-vpn> <client-password>");
System.out.println();
System.exit(-1);
}
if (args[1].split("#")[0].isEmpty()) {
System.out.println("No client-username entered");
System.out.println();
System.exit(-1);
}
if (args[1].split("#")[1].isEmpty()) {
System.out.println("No message-vpn entered");
System.out.println();
System.exit(-1);
}
System.out.println("TopicSubscriber initializing...");
final JCSMPProperties properties = new JCSMPProperties();
properties.setProperty(JCSMPProperties.HOST, args[0]); // host:port
properties.setProperty(JCSMPProperties.USERNAME, args[1].split("#")[0]); // client-username
properties.setProperty(JCSMPProperties.PASSWORD, args[2]); // client-password
properties.setProperty(JCSMPProperties.VPN_NAME, args[1].split("#")[1]); // message-vpn
final Topic topic = JCSMPFactory.onlyInstance().createTopic("tutorial/topic");
final JCSMPSession session = JCSMPFactory.onlyInstance().createSession(properties);
session.connect();
final CountDownLatch latch = new CountDownLatch(1); // used for
// synchronizing b/w threads
/** Anonymous inner-class for MessageListener
* This demonstrates the async threaded message callback */
final XMLMessageConsumer cons = session.getMessageConsumer(new XMLMessageListener() {
#Override
public void onReceive(BytesXMLMessage msg) {
if (msg instanceof TextMessage) {
System.out.printf("TextMessage received: '%s'%n",
((TextMessage) msg).getText());
} else {
System.out.println("Message received.");
}
System.out.printf("Message Dump:%n%s%n", msg.dump());
latch.countDown(); // unblock main thread
}
#Override
public void onException(JCSMPException e) {
System.out.printf("Consumer received exception: %s%n", e);
latch.countDown(); // unblock main thread
}
});
session.addSubscription(topic);
System.out.println("Connected. Awaiting message...");
cons.start();
// Consume-only session is now hooked up and running!
try {
latch.await(); // block here until message received, and latch will flip
} catch (InterruptedException e) {
System.out.println("I was awoken while waiting");
}
// Close consumer
cons.close();
System.out.println("Exiting.");
session.closeSession();
}
}
Any help would be greatly appreciated.
java.net.ConnectException: Connection timed out
The log entry indicates that network connectivity to the specified DNS name/IP address cannot be established.
Next step includes:
Verifying that you are able to resolve the DNS name to an IP
address.
Verifying that the correct DNS name/IP address/Port is in use - You need the "SMF Host" in the Solace Cloud Connection Details.
Verifying that the IP address/Port is not blocked by an intermediate network device.

Invoking Adapter from Java - Worklight 6.2

Below is the java sample code from worklight to invoke adapter.
public static void testAdapterCall(){
try{
DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
String paramArray = "[5, 3,]";
ProcedureQName procedureQname = new ProcedureQName("CalculatorAdapter", "addTwoIntegers");
InvocationResult result = service.invokeProcedure(procedureQname, paramArray);
}
catch(Exception e)
{
e.printStackTrace();
}
}
I'm getting a Null Pointer exception, when it goes to line
DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
Log is as below:
java.lang.NullPointerException
at com.worklight.customcode.Calculator1.testAdapterCall(Calculator1.java:38)
at com.worklight.customcode.Calculator1.main(Calculator1.java:53)
Versions:
Java 1.7
Worklight 6.2
The Adapter is deployed, and the server is also running locally.
I saw this question in other sites also, but it is not answered.
Any help is highly appreciated.
See the documentation in the following PDF document, starting page #13.
public void callProcedure() {
DataAccessService service = worklightBundles.getInstance().getDataAccessService();
String paramArray = "['param1', 'param2', 'param3']";
ProcedureQName procedureQName = new ProcedureQName("adapterName",
"procedureName");
InvocationResult result = service.invokeProcedure(ProcedureQName,
paramArray);
JSONObject jsonObject = result.toJSON();
String value = (String)jsonObject.get("key");
}
Be sure to add any missing includes once you enter the code into a Java IDE, such as Eclipse.

JavaMail store.connect() times out - Can't read gmail Inbox through Java

I am trying to connect to my gmail inbox to read messages through Java Application. I am using..
jdk1.6.0_13
javamail-1.4.3 libs - (mail.jar, mailapi.jar, imap.jar)
Below is my code : MailReader.java
import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
public class MailReader
{
public static void main(String[] args)
{
readMail();
}
public static void readMail()
{
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try
{
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "myEmailId#gmail.com", "myPwd");
System.out.println("Store Connected..");
//inbox = (Folder) store.getFolder("Inbox");
//inbox.open(Folder.READ_WRITE);
//Further processing of inbox....
}
catch (MessagingException e)
{
e.printStackTrace();
}
}
}
I expect to get store connected, but call to store.connect() never returns and I get below output :
javax.mail.MessagingException: Connection timed out;
nested
exception is:
java.net.ConnectException: Connection timed out
at
com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:441)
at
javax.mail.Service.connect(Service.java:233)
at
javax.mail.Service.connect(Service.java:134)
at
ReadMail.readMail(ReadMail.java:21)
at ReadMail.main(ReadMail.java:10)
However I am able to SEND email by Java using SMTP, Transport.send() and same gmail account. But cannot read emails.
What can be the solution ?
IMAP work off a different port (143 for non-secure, 993 for secure) to sendmail (25) and I suspect that's blocked. Can you telnet on that port to that server e.g.
telnet imap.gmail.com {port number}
That'll indicate if you have network connectivity.

Resources