In Weblogic (10), how do I access the node name from Java? - java

I would like to set up some per-node configuration in a weblogic cluster and need to access the node name from Java.

The following might suffice in your case (the startup scripts set the weblogic.Name system property to the server name at server startup):
System.getProperty("weblogic.Name");

you can set system properties using -D option. If you are using a managed weblogic server with nodemanager you can set some propertie you want in the "Server Start" tab, in java options field. something like
-DVARIABLE_NAME=some_id_you_may_use
than in java code:
String sMyPropVariable = System.getProperty("VARIABLE_NAME");
[]s

Related

Proxy settings for Big Query Java client

I am writing a Java application that interacts with the Big Query APIs and which will also run in a docker container. I need help in setting up http and https for my application. I am not sure whether specifying only environment variables for docker container is sufficient or only setting the proxy in java code is required or both and how can I do the same.
Thanks in Advance
There are multiple options to achieve this. The cleanest way is to tell the JVM to use system proxies and define the proxy as environment variables for your Docker container. All options are described below.
Option 1: Setting the proxy directly in Java
You can define the proxy directly in your code using System.setProperty(String, String):
System.setProperty("http.proxyHost", "proxy.example.com");
System.setProperty("http.proxyPort", "8080");
Note that the proxy is hardcoded. This solution only works if the proxy stays the same for all environments (local development, deployment on server / cloud).
Option 2: Sepcifying the proxy when invoking the JVM
You can set the proxy as command line parameters when invoking the VM. You don't need additional configurations in your code.
java -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080 YourApplication
You can also use environment variables here, if you have them set. That way the proxy settings could dynamically change depending on the environment.
Option 3: Using system proxies
The third option is to tell the JVM to use the configured system proxies (which you can do as described below). This is again achieved by setting a command line parameter.
java -Djava.net.useSystemProxies=true YourApplication
Setting the system proxy
To set the system proxies for Docker, you again have two options.
Option a: Use environment variables
You can use environment variables directly in your Dockerfile:
ENV HTTP_PROXY "http://proxy.example.com:8080"
Or you can specify the environment variables in your docker run command:
docker run --env HTTP_PROXY="http://proxy.example.com:8080" your-container
Option b: Configuring the Docker client
On the Docker client, create or edit the file ~/.docker/config.json and set the proxy:
{
"proxies":
{
"default":
{
"httpProxy": "http://proxy.example.com:8080"
}
}
}
This option only configures your local client, you would need to configure other environments accordingly.

Binding CORBA object to Weblogic 11g not working

I have written server side code to bind CORBA object to Weblogic 11g.
Have created context factory and binding ORB reference from servant.
Its getting bound to JNDI tree , but while doing lookup from client its giving error as
"java.rmi.NoSuchObjectException: The object identified by: '257' could not be found"
vaibhav singh has solved the issue by following procedure:
Root Cause Analysis:
The startup options was containing JVM arguments "-Dweblogic.management.server=t3://10.188.103.55:7002". The admin server should not contain this, as it makes the server to run in managed server mode. So the thing was admin server was starting as managed server, and trying to contact itself, creating a deadlock kind scenario.
Usually ${ADMIN_URL} sets up the variable "weblogic.management.server". I tried to find out that who set this varible in this condition, as setDomain.sh script stricts that this variable is null for admin server startup. On little debugging on environment it was clear ${JAVA_OPTS} was exported in the UNIX session, as one can also see in startup the variables are repeated. So the crux of matter was I restarted one managed server which exported JAVA_OPTS variable in the session and when I restarted admin server, it appended its options in already exported JAVA_OPTS but not clearing it.
Solution:
Either manually purge the startup variables from UNIX, Linux session if you are stubborn and don't want to close your session.
Kill the UNIX Linux session. Start a new session, it will automatically purge the exported variables. Now start your admin server.
Resource Link:
Full Details is described here: Caused by: java.rmi.NoSuchObjectException: The object identified by: '31' could not be found. Either it was has not been exported or it has been collected by the distributed garbage collector.

System.getProperty() on a server

I'm using System.getProperty("user.name") to get the name of localuser. It works fine and now my class need to work on server.
Unfortunately, System.getProperty("user.name") try to catch the user name of the server and return "root".
Is it possible using System.getProperty() I get the name of localuser running the class on the server? If not, is there any way?
System.getProperty("user.name") returns user's account name on which the java process is running. As you mentioned on your local computer you are running it on user "Filiipe" however on server you are running it as a root user. Maybe you are using tomcat/jboss started automatically as a system service, that kind of services are running under root user.
You can also easily check it with ps -ef command on linux - the first column is user that started the service.
You can also try override this parameter by adding additional option to your server starting script -Duser.name=Fellipe. I didn't try it but it may work.

WebSphere Issue

I working in an Java application. I am using Struts2 and Hibernate. The application was working fine in Tomcat7 , But when I deployed that On IBM"S Websphere I am getting the following error for the following URL
http://localhost:8080/MYAPPS
Error 404: There is no Action mapped for action name .
http://localhost:8080/MYAPPS/
Error 404: There is no Action mapped for namespace [/] and action name [] associated with context path
The default port is 9080. Change the port in url as others suggested.
Check the following:
Login to the console , click on servers -> serverName -> ports -> WC_defaulthost (webcontainer port )
For example if it shows as 9080
Click on Environment -> Virtual Host -> default host (or the host the application is mapped to)- > Click on Host Aliases . Make sure the port is defined, if not add the port and the restart the server.
access the application as follow.
http://localhost:9080/MYAPPS/
http://hostname:9080/MYAPPS/
If the problem persists, open the systemout.log file and look for more details.
Try this, it may help to find the port number for web host or secure web host,
Go for the following path,
/opt/IBM/WebSphere/AppServer/profiles/Dmgr01_demo/config/cells/localhostCell01/nodes/Dmgr_node,
try find this file serverindex.xml,
there you can find the "WC_adminhost" port number.
Hope this help !
thanks!.
I don't think this is the virtual host issue. You obviously have configured it right as there's no virtualhost error.
What's your WAS's version? WAS V6.1.X has the notorious reputation not to support whatever is popular. Try adding this as a customized web container property:
com.ibm.ws.webcontainer.invokefilterscompatibility
set its value to true

How can I make "jconsole" work with Websphere 6.1?

I've deployed some Managed Beans on WebSphere 6.1 and I've managed to invoke them through a standalone client, but when I try to use the application "jconsole" distributed with the standard JDK can can't make it works.
Has anyone achieved to connect the jconsole with WAS 6.1?
IBM WebSphere 6.1 it's supossed to support JSR 160 JavaTM Management Extensions (JMX) Remote API. Furthermore, it uses the MX4J implementation (http://mx4j.sourceforge.net). But I can't make it works with neither "jconsole" nor "MC4J".
I have the Classpath and the JAVA_HOME correctly setted, so the issue it's not there.
WebSphere's support for JMX is crap. Particularly, if you need to connect to any secured JMX beans. Here's an interesting tidbit, their own implementation of jConsole will not connect to their own JVM. I have had a PMR open with IBM for over a year to fix this issue, and have gotten nothing but the runaround. They clearly don't want to fix this issue.
The only way I have been able to invoke remote secured JMX beans hosted on WebSphere has been to implement a client using the "WebSphere application client". This is basically a stripped down app server used for stuff like this.
Open a PMR with IBM. Perhaps if more people report this issue, they will actually fix it.
Update: You can run your application as a WebSphere Application Client in RAD. Open the run menu, then choose "Run...". In the dialog that opens, towards the bottom on the left hand side, you will see "WebSphere v6.1 Application Client". I'm not sure how to start and Application Client outside of RAD.
IT WORKS !
http://issues.apache.org/jira/browse/GERONIMO-4534;jsessionid=FB20DD5973F01DD2D470FB9A1B45D209?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
1) Change the config.xml and start the server.
-see here how to change config.xml: http://publib.boulder.ibm.com/wasce/V2.1.0/en/working-with-jconsole.html
2) start the jconsole with : jconsole -J-Djavax.net.ssl.keyStore=%GERONIMO_HOME%\var\security\keystores\geronimo-default -J-Djavax.net.ssl.keyStorePassword=secret -J-Djavax.net.ssl.trustStore=%GERONIMO_HOME%\var\security\keystores\geronimo-default -J-Djavax.net.ssl.trustStorePassword=secret -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;%JAVA_HOME%\lib\tools.jar;%GERONIMO_HOME%\repository\org\apache\geronimo\framework\geronimo-kernel\2.1.4\geronimo-kernel-2.1.4.jar
[or your version of geronimo-kernel jar]
3) in the jconsole interface->advanced, input:
JMX URL: service:jmx:rmi:///jndi/rmi://localhost:1099/JMXSecureConnector
user name: system
password: manager
4) click the connect button.
If you want the WebSphere MBeans this one works for me:
The key is to configure the classpath and the security properly.
in one line:
jconsole -J-Dwas.install.root=C:/was61 -J-Djava.ext.dirs=C:/was61/plugins;C:/was61/plugins/com.ibm.ws.security.crypto_6.1.0;C:/was61/lib;C:/was61/java/jre/lib/ext -J-Dcom.ibm.SSL.ConfigURL="file:../../properties/ssl.client.props" -J-Dcom.ibm.CORBA.ConfigURL="file:../../properties/sas.client.props" service:jmx:iiop://host:port/jndi/JMXConnector
where port = bootstrap port ex: (2809)
Be careful when setting the sas and the ssl props.
Robert
I have successfully connected to ActiveMQ and ServiceMix using the JConsole. Does WAS 6.1 use Java Management Extension (JMX) technology? JMX is required for JConsole.
If your path is set correctly it should work fine. On windows you go to System Properties -> Advanced Tab -> Environment Variables. Have your JAVA_HOME System variable set to the path of your JDK or JRE and your Path variable with %JAVA_HOME%/bin added somewhere in there. Then all you need to do is go to Start->Run->JConsole. Select the correct Process Name and your done.
Where are you having problems at? I hope this helps.
Edit:
Here is the Java Doc's on JConsole.
Hmm... I know that WebSphere is kind of hard to configure. Thats part of the reason we used ServiceMix for our ESB. Maybe its not enabled by default in WebSphere and you would have to turn it on in the config somewhere.
Websphere 6.1 does not support the JConsole for some reason even though it fully implements the JMS specs. Seems to be a week area at the moment. Your best bet is to look at the Admin client to implement you own console.
You all seem to be incorrect. I am running Websphere 6.1.041 , using JDK 1.5 , and I just started up Jconsole and used the "simple connect" tab to connect to localhost with port=0 and without a username and password and it works fine.

Categories

Resources