Java EJB Client connection via SSL port - java

My requirement is to connect an application deployed in weblogic server, i will use a shell script to invoke a java EJB client residing in the same server but i need to use via SSL port.
When i try connecting with non-ssl port the connection is established but when SSL port is used im getting the below error:
"javax.namin.CommunicationException: Failed to initialize JNDI context, tried 2 time or times, the interval of each time is 0ms.
[Login failed for an unknown reason:P] [Root exception is weblogic.socket.UnrecoverableConnectException: [Login faile dfor an unknown reason:P]
Current java client arguments doesnot include SSL parameters, please help on this how do i achieve this.

Related

Access ActiveMQ with reverse proxy enabled

The goal is to publish/send message into ActiveMQ through Java code inside a secured company network.
I have configured ActiveMQ in an AWS Cloud EC2 machine (console access: IPAddress:8161). Also I can publish the messages using the AWS IPAddress and port number 61616 (IPAddress:61616) through Java code.
But now I need to publish messages from inside a company network. It is secured and can't access the AWS IPAddress directly.
So we create reverse proxy for
IPAddress:8161 to activemq-ui.testdemo.com
IPAddress:61616 to activemq-api.testdemo.com
Now I can access ActiveMQ console from our company network using activemq-ui.testdemo.com. But couldn't access activemq-api.testdemo.com through Java code.
Getting Below Error:
SEVERE: Error Message: javax.jms.JMSException: Could not connect to broker URL: tcp://activemq-api.demo.com. Reason:
java.lang.IllegalArgumentException: port out of range:-1
Error looks like expecting port number in the URL. But not sure what to pass for this.
Can anyone help me on how to access ActiveMQ API inside corporate network?
You need to provide the port that the client should attempt to connect to on the connection URI as the error is telling you, something like:
tcp://activemq-api.demo.com:80
The client does not attempt to guess or deduce what the port is you want it to use and so that field is mandatory.

Java Lwm2m Bootstrap Server

I would like to connect one LwM2M client to multiple servers LwM2M by bootstrap server. I'm using Leshan (LwM2M implementation in Java).
So I'm using Lwm2m demo from github.com/Eclipse/Leshan. I run the server demo, the bootstrap server demo, and the client demo. I want to register the client in the server User Interface by using bootstrap server (I entered the client endpoint, the server URI, no security mode).
When I run them both, the client is not registered and I have this message in the terminal matching the client :
[bootstrap=Bootstrap Server [uri=coap://192.168.1.100:5683],
deviceMangements={123=DM Server
[uri=coap://192.168.1.85:8081,lifetime=20, binding=U]}].
[2016-07-05 12:48:17,684 INFO RegistrationEngine] Trying to register to
coap://192.168.1.85:8081 ...
[2016-07-05 12:49:39,113 ERROR RegistrationEngine] Registration failed: Timeout.
[2016-07-05 12:49:39,116 INFO RegistrationEngine] Unable to connect to any server,
next retry in 600s ...
How can I fix this?
coap://192.168.1.85:8081 doesn't sound like a standard CoAP port which is more like 5683 (or 5684 for DTLS)
First you better check your configuration such as IP Address and Port.
Client should point to bootstrap server IP and port. Bootstrap server configure client to correct server.
According to your terminal message, lifetime is only 20s. You can try to extend the life time to 180s (3mins) in Bootstrap.
[bootstrap=Bootstrap Server [uri=coap://192.168.1.100:5683],
deviceMangements={123=DM Server
[uri=coap://192.168.1.85:8081,lifetime=20, binding=U]}].
[2016-07-05 12:48:17,684 INFO RegistrationEngine] Trying to register
to coap://192.168.1.85:8081 ... [2016-07-05 12:49:39,113 ERROR
RegistrationEngine] Registration failed: Timeout. [2016-07-05
12:49:39,116 INFO RegistrationEngine] Unable to connect to any server,
next retry in 600s ...

Why does java rmi keep connecting to 127.0.1.1. When ip is 192.168.X.X?

I have a java rmi application i simply do:
Client:
Registry registry = LocateRegistry.getRegistry("localhost");
costApi = (CostApi) registry.lookup("server.CostApi");
Everything works fine when I host the server at localhost. When I start the same program at another machine withing the local network, at 192.168.x.x and change to:
Client:
Registry registry = LocateRegistry.getRegistry("192.168.x.x");
costApi = (CostApi) registry.lookup("server.CostApi");
it does not work anymore and it fails with a very strange error:
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy0.dataCost(Unknown Source)
at billing.data.DataBiller.performBilling(DataBiller.java:57)
at billing.data.DataBiller.consumeMessage(DataBiller.java:46)
at general.templates.RabbitWorker.run(RabbitWorker.java:124)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
I'm not even trying to connect to 127.0.1.1 but to 192.168.x.x, how do I solve this? I prefer to use java code only and not modify my machine with config files. I'm using linux
This is usually caused by a misconfiguration. Check your /etc/hosts file to ensure that:
localhost maps to 127.0.0.1
your real hostname maps to your real host address
Some Linux distributions are known to have this back to front.
If the problem persists, try setting java.rmi.server.hostname at the server to the IP address the client should use when executing remote method calls. It needs to be set before you export any remote objects, including the Registry.
The problem is caused by the IP address embedded in the stub, which ultimately comes from something like InetAddress.getLocalAddress(), which is fallible as above. It is overridden by java.rmi.server.hostname.
This is item A.1 in the FMI FAQ, but note that the item is mistitled. It doesn't happen during lookup(), it happens when you call a remote method on the resulting stub.
I just ran into the same issue. I'm doing something very similar to what you are doing. What I noticed was that the first time I ran the client program, and it failed ( by design of the firewall test ) - that it failed with an error message showing the actual ip address of the host that I originally specified ( the 192.168.x.x address ), but all subsequent failures show that it is failing to make a connection to 127.0.0.1. Currently I'm suspecting some kind of caching on the client - has the JVM marked that ip address as never accessible again and it's refusing to ever try to connect to it again?
UPDATE: In my case, the JVM on the RMI Server side was not able to properly set the java.rmi.server.hostname property at JVM startup. This property was being left as null. When clients connect to a specific RMI Registry and ask for a stub to a particular named object, they receive a stub containing the ip address of the remote machine where the actual object can be found. The RMI server copies the contents of the java.rmi.server.hostname property into the stubs it returns to clients, so if the java.rmi.server.hostname property is "" and it copies that to each stub it creates, each stub contains a reference to remote server with an IP address of "". By default the client jvm reacts to this by attempting to connect to the server object on the localhost, 127.0.0.1. To work around the problem, try this line of code before exporting any remote objects on the server side:
System.setProperty( "java.rmi.server.hostname", "192.168.RMIServer.IP" ) ;
This property will be automatically copied to all remote stubs exported on that server, and clients who receive that stub should then be able to reach the remote server ( assuming any firewalls are configured correctly ).

How to connect my web application to SQL Server / SQL Server Express

I am working with a web application that connects to a SQL Server database with this:
jdbc.url=jdbc:jtds:sqlserver://127.0.0.1/MyDatabase
jdbc.username=sa
jdbc.password=password
I am relatively new to SQL Server, however I have successfully accessed a SQLEXPRESS instance through the SQL Server Management Studio.
I can see from the Security->Login folder there is a "sa" entry
However when I run the web application I am getting this error:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property
'dataSource' threw exception; nested exception is
org.apache.commons.dbcp.SQLNestedException: Cannot create
PoolableConnectionFactory (Network error IOException: Connection
refused: connect)
I seems that the user: "sa" is not authenticated to access the database?
If so, how can I use the SQL Server management studio to fix this?
Make sure authentication mode is set to Mixed. It's set to Windows authentication mode as default which disables sa account. See here: http://msdn.microsoft.com/en-us/library/ms143705%28v=sql.90%29.aspx
Edit: as Jacob suggested, make sure you can connect via TCP/IP (I assume it's used by the driver). To do so launch SQL Management Studio and in connection preferences set: Authentication - SQL Server authentication, login - sa, password - your password. Then click Options, connection properties and select tcp/ip as protocol. Check if you can login.
Also check these things:
http://msdn.microsoft.com/en-us/library/bb909712(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/bb909725(v=vs.90).aspx
To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". Until telnet doesn't connect, jTDS won't either.
e.g, c:>telnet servername 1433
to enable telnet client on windows
http://social.technet.microsoft.com/wiki/contents/articles/910.how-to-enable-telnet-client-in-windows-7.aspx

post message to a remote JMS provider

I want to be able to send messages to a remote JBoss server (JBoss MQ).
I can do it for a local one but i'm stuck when trying with a remote one.
can anyone explain to me how to do it ?
are there any specific steps to take ?
[what i've tried so far]
I need to send a message to a remote server's queue (running "JBoss MQ") so that it can process the message and act on it.
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://192.168.131.129:1299");
InitialContext jndiContext = new InitialContext(properties);
//[2] Look up connection factory and queue.
ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext.lookup("UIL2XAConnectionFactory");
Queue queue = (Queue)jndiContext.lookup("Queue/DataTransferQueue");
but I get an exception when running the above code :
(even though, I can ping the remote server).
javax.naming.CommunicationException: Could not obtain connection to any of these urls: 192.168.1.131.129:1299 and
discovery failed with error: javax.naming.CommunicationException:
Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
[Root exception is javax.naming.CommunicationException: Failed to connect to server 192.168.1.131.129:1299
Is there anything special to do to connect to a remote queue ?
Have you verified that you can connect to that remote host and port, i.e. telnet 192.168.131.129 1299? You might have a firewall that's blocking some traffic but allowing pings.
OK, so after trying a lot, I finally found out what the problem was :
I didn't start JBoss on the remote server in a way it could accept remote connections. by default, JBoss starts allowing only local connections.
so, I restarted it with this argument : -b 0.0.0.0 and it works fine now.
Thanks for your help and support.

Categories