Topic
  • 9 replies
  • Latest Post - ‏2014-10-07T01:01:07Z by some_cs_student
imrantariq
imrantariq
6 Posts

Pinned topic Create WebSphere administrative client program for java

‏2013-03-20T12:24:25Z |
I am using IBM WebSphere server. I need to Create WebSphere administrative client program for java using WebSphere Administrative API's. I am using this code for creating admin client

...
adminClient = AdminClientFactory.createAdminClient(connectProps);
...


but it gives exception.

The system cannot create a SOAP connector to connect to host localhost at port 8881.


After creating client I want to configure WASADMIN through this API. Am I on right track?
Updated on 2014-03-25T23:49:49Z at 2014-03-25T23:49:49Z by iron-man
  • UniqueScreenName
    UniqueScreenName
    33 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-20T15:46:05Z  
    Having had similar problems connecting, there are a couple of things you should check:

    1) Are you using the same hostname as the on defined in the server?
    2) Is the SOAP port correct for that server (you can see the SOAP port listed in the server log and/or in the Ports section of the console for the server). I believe 8881 might be the default, but it may not be the one in use depending on how the server was set up.
    3) Are you setting the location of your client soap.client.props file as a JVM system property?
    -Dcom.ibm.SOAP.ConfigURL=file:http://path.to.file/soap.client.props
    4) Is Administrative Security turned on?
  • imrantariq
    imrantariq
    6 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-21T07:19:42Z  
    Having had similar problems connecting, there are a couple of things you should check:

    1) Are you using the same hostname as the on defined in the server?
    2) Is the SOAP port correct for that server (you can see the SOAP port listed in the server log and/or in the Ports section of the console for the server). I believe 8881 might be the default, but it may not be the one in use depending on how the server was set up.
    3) Are you setting the location of your client soap.client.props file as a JVM system property?
    -Dcom.ibm.SOAP.ConfigURL=file:http://path.to.file/soap.client.props
    4) Is Administrative Security turned on?
    1) Are you using the same hostname as the on defined in the server?
    • YES

    2) Is the SOAP port correct for that server (you can see the SOAP port listed in the server log and/or in the Ports section of the console for the server). I believe 8881 might be the default, but it may not be the one in use depending on how the server was set up.
    • 8880 is default and Mine port is 881
    3) Are you setting the location of your client soap.client.props file as a JVM system property?
    • YES. Its system file path where my server installed.
    -Dcom.ibm.SOAP.ConfigURL=file:http://path.to.file/soap.client.props
    4) Is Administrative Security turned on?
    • YES
  • UniqueScreenName
    UniqueScreenName
    33 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-21T13:37:15Z  
    1) Are you using the same hostname as the on defined in the server?
    • YES

    2) Is the SOAP port correct for that server (you can see the SOAP port listed in the server log and/or in the Ports section of the console for the server). I believe 8881 might be the default, but it may not be the one in use depending on how the server was set up.
    • 8880 is default and Mine port is 881
    3) Are you setting the location of your client soap.client.props file as a JVM system property?
    • YES. Its system file path where my server installed.
    -Dcom.ibm.SOAP.ConfigURL=file:http://path.to.file/soap.client.props
    4) Is Administrative Security turned on?
    • YES
    Ok. Given that, here is how I am setup and am able to connect to my servers.

    I will add the caveat that I'm just a guy who has worked this out via the docs and trial and error. I'm not a expert and there may be better ways to do this.
    For the client, I have created a directory structure on the file system (the +user.root+) that looks like this:

    {user.root}/
    {user.root}/etc/
    {user.root}/lib/
    {user.root}/messages/
    {user.root}/properties/

    Where:

    The etc/ directory contains the key.p12 and trust.p12 keystores copied from $WAS_INSTALL_ROOT/AppServer/profiles/{profile}/etc/ directory for the server (needed for SSL with Admin Security on).
    The lib/ directory contains the com.ibm.ws.admin.client.{version}.jar and com.ibm.ws.security.crypto.jar. Copied from $WAS_INSTALL_ROOT/AppServer/runtimes and $WAS_INSTALL_ROOT/AppServer/plugins respectively
    The messages/ directory is a copy of the localized messages to display to the user. Copy from $WAS_INSTALL_ROOT/AppServer/properties/messages
    The properties/ directory contains a client side copy of the soap.client.props file and the ssl.client.props files. Copied from $WAS_INSTALL_ROOT/AppServer/profiles/{profile}/properties/ These files are configured as below.
    In the properties/soap.client.props file most of the properties just use the defaults (I am not using Kerebos), but just confirm:

    com.ibm.SOAP.securityEnabled=true
    com.ibm.SOAP.authenticationTarget=BasicAuth
    com.ibm.SOAP.loginSource=prompt
    com.ibm.ssl.alias=DefaultSSLSettings

    If you want to define your credentials for the SOAP connection in this file, you can do so here (you won't need to provide them in the code or command line):

    com.ibm.SOAP.loginUserid={userid}
    com.ibm.SOAP.loginPassword={xor encoded password} To encode, put the cleartext password here and run the $WAS_INSTALL_ROOT/AppServer/bin/PropFilePasswordEncoder.bat tool on the file

    In the properties/ssl.client.props file all of the properties are the defaults, but you need to set the user.root (client install directory) so that it can find the keystores:
    user.root={path to the root of the directory structure created above}

    Assuming you are using the DefaultSSLSettings (as defined in the ssl.client.props file and references in the soap.client.props), that should be the only thing to change in the ssl.client.props file
    When you run the client, set the two following system properties to point your local property files:

    -Dcom.ibm.SSL.ConfigURL=file:{path to user root}/properties/ssl.client.props
    -Dcom.ibm.SOAP.ConfigURL=file:{path to user root}/soap.client.props

    With all those settings, I am able to connect, login, and use the AdminClient to get info out of the server
  • imrantariq
    imrantariq
    6 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-26T06:42:43Z  
    Ok. Given that, here is how I am setup and am able to connect to my servers.

    I will add the caveat that I'm just a guy who has worked this out via the docs and trial and error. I'm not a expert and there may be better ways to do this.
    For the client, I have created a directory structure on the file system (the +user.root+) that looks like this:

    {user.root}/
    {user.root}/etc/
    {user.root}/lib/
    {user.root}/messages/
    {user.root}/properties/

    Where:

    The etc/ directory contains the key.p12 and trust.p12 keystores copied from $WAS_INSTALL_ROOT/AppServer/profiles/{profile}/etc/ directory for the server (needed for SSL with Admin Security on).
    The lib/ directory contains the com.ibm.ws.admin.client.{version}.jar and com.ibm.ws.security.crypto.jar. Copied from $WAS_INSTALL_ROOT/AppServer/runtimes and $WAS_INSTALL_ROOT/AppServer/plugins respectively
    The messages/ directory is a copy of the localized messages to display to the user. Copy from $WAS_INSTALL_ROOT/AppServer/properties/messages
    The properties/ directory contains a client side copy of the soap.client.props file and the ssl.client.props files. Copied from $WAS_INSTALL_ROOT/AppServer/profiles/{profile}/properties/ These files are configured as below.
    In the properties/soap.client.props file most of the properties just use the defaults (I am not using Kerebos), but just confirm:

    com.ibm.SOAP.securityEnabled=true
    com.ibm.SOAP.authenticationTarget=BasicAuth
    com.ibm.SOAP.loginSource=prompt
    com.ibm.ssl.alias=DefaultSSLSettings

    If you want to define your credentials for the SOAP connection in this file, you can do so here (you won't need to provide them in the code or command line):

    com.ibm.SOAP.loginUserid={userid}
    com.ibm.SOAP.loginPassword={xor encoded password} To encode, put the cleartext password here and run the $WAS_INSTALL_ROOT/AppServer/bin/PropFilePasswordEncoder.bat tool on the file

    In the properties/ssl.client.props file all of the properties are the defaults, but you need to set the user.root (client install directory) so that it can find the keystores:
    user.root={path to the root of the directory structure created above}

    Assuming you are using the DefaultSSLSettings (as defined in the ssl.client.props file and references in the soap.client.props), that should be the only thing to change in the ssl.client.props file
    When you run the client, set the two following system properties to point your local property files:

    -Dcom.ibm.SSL.ConfigURL=file:{path to user root}/properties/ssl.client.props
    -Dcom.ibm.SOAP.ConfigURL=file:{path to user root}/soap.client.props

    With all those settings, I am able to connect, login, and use the AdminClient to get info out of the server
    Many thanks for your response. You said that:"use the AdminClient to get info out of the server". Can you tell me few things.

    Can I manage (create/update) shared libraries through this adminClient after connection?
    Can I get JVM properties through it?
    What information you are getting from your server?
    Can you share your code with me. If yes then please send.

    Regards
  • imrantariq
    imrantariq
    6 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-26T07:16:56Z  
    Ok. Given that, here is how I am setup and am able to connect to my servers.

    I will add the caveat that I'm just a guy who has worked this out via the docs and trial and error. I'm not a expert and there may be better ways to do this.
    For the client, I have created a directory structure on the file system (the +user.root+) that looks like this:

    {user.root}/
    {user.root}/etc/
    {user.root}/lib/
    {user.root}/messages/
    {user.root}/properties/

    Where:

    The etc/ directory contains the key.p12 and trust.p12 keystores copied from $WAS_INSTALL_ROOT/AppServer/profiles/{profile}/etc/ directory for the server (needed for SSL with Admin Security on).
    The lib/ directory contains the com.ibm.ws.admin.client.{version}.jar and com.ibm.ws.security.crypto.jar. Copied from $WAS_INSTALL_ROOT/AppServer/runtimes and $WAS_INSTALL_ROOT/AppServer/plugins respectively
    The messages/ directory is a copy of the localized messages to display to the user. Copy from $WAS_INSTALL_ROOT/AppServer/properties/messages
    The properties/ directory contains a client side copy of the soap.client.props file and the ssl.client.props files. Copied from $WAS_INSTALL_ROOT/AppServer/profiles/{profile}/properties/ These files are configured as below.
    In the properties/soap.client.props file most of the properties just use the defaults (I am not using Kerebos), but just confirm:

    com.ibm.SOAP.securityEnabled=true
    com.ibm.SOAP.authenticationTarget=BasicAuth
    com.ibm.SOAP.loginSource=prompt
    com.ibm.ssl.alias=DefaultSSLSettings

    If you want to define your credentials for the SOAP connection in this file, you can do so here (you won't need to provide them in the code or command line):

    com.ibm.SOAP.loginUserid={userid}
    com.ibm.SOAP.loginPassword={xor encoded password} To encode, put the cleartext password here and run the $WAS_INSTALL_ROOT/AppServer/bin/PropFilePasswordEncoder.bat tool on the file

    In the properties/ssl.client.props file all of the properties are the defaults, but you need to set the user.root (client install directory) so that it can find the keystores:
    user.root={path to the root of the directory structure created above}

    Assuming you are using the DefaultSSLSettings (as defined in the ssl.client.props file and references in the soap.client.props), that should be the only thing to change in the ssl.client.props file
    When you run the client, set the two following system properties to point your local property files:

    -Dcom.ibm.SSL.ConfigURL=file:{path to user root}/properties/ssl.client.props
    -Dcom.ibm.SOAP.ConfigURL=file:{path to user root}/soap.client.props

    With all those settings, I am able to connect, login, and use the AdminClient to get info out of the server
    I tried your way to connect but could not. My code is:

    
    ... Properties connectProps = 
    
    new Properties(); connectProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);   connectProps.setProperty(AdminClient.CONNECTOR_HOST, 
    "localhost"); connectProps.setProperty(AdminClient.CONNECTOR_PORT, 
    "8882"); connectProps.setProperty(
    "-Dcom.ibm.SOAP.ConfigURL", 
    "file//D:\\SOAPClient\\properties\\soap.client.props"); connectProps.setProperty(
    "-Dcom.ibm.SSL.ConfigURL", 
    "file//D:\\SOAPClient\\properties\\ssl.client.props");   AdminClient adminClient = 
    
    null; 
    
    try 
    { adminClient = AdminClientFactory.createAdminClient(connectProps); System.out.println(adminClient.toString()); 
    } ...
    


    Getting this exception

    
    ... WARNING: Could not find tmx4jTransform.jar in null/etc/tmx4jTransform.jar - Interoperability to older versions of WebSphere is disabled Mar 26, 2013 12:11:48 PM 
    
    null 
    
    null INFO: ssl.disable.url.hostname.verification.CWPKI0027I Mar 26, 2013 12:11:48 PM 
    
    null 
    
    null INFO: Client code attempting to load security configuration Exception creating admin client: com.ibm.websphere.management.exception.ConnectorException: ADMC0016E: The system cannot create a SOAP connector to connect to host localhost at port 8882.
    


    My SOAP port is 8882 and default is 8880. I use both but no success.
  • SJC
    SJC
    156 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-26T14:34:18Z  
    I tried your way to connect but could not. My code is:

    <pre class="jive-pre"> ... Properties connectProps = new Properties(); connectProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP); connectProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost"); connectProps.setProperty(AdminClient.CONNECTOR_PORT, "8882"); connectProps.setProperty( "-Dcom.ibm.SOAP.ConfigURL", "file//D:\\SOAPClient\\properties\\soap.client.props"); connectProps.setProperty( "-Dcom.ibm.SSL.ConfigURL", "file//D:\\SOAPClient\\properties\\ssl.client.props"); AdminClient adminClient = null; try { adminClient = AdminClientFactory.createAdminClient(connectProps); System.out.println(adminClient.toString()); } ... </pre>

    Getting this exception

    <pre class="jive-pre"> ... WARNING: Could not find tmx4jTransform.jar in null/etc/tmx4jTransform.jar - Interoperability to older versions of WebSphere is disabled Mar 26, 2013 12:11:48 PM null null INFO: ssl.disable.url.hostname.verification.CWPKI0027I Mar 26, 2013 12:11:48 PM null null INFO: Client code attempting to load security configuration Exception creating admin client: com.ibm.websphere.management.exception.ConnectorException: ADMC0016E: The system cannot create a SOAP connector to connect to host localhost at port 8882. </pre>

    My SOAP port is 8882 and default is 8880. I use both but no success.
    A couple of things look unusual to me...

    com.ibm.SOAP.ConfigURL and com.ibm.SSL.ConfigURL are normally handled as System Properties. So you might use System.setProperty() or more usually add them to your command line invocation of "java ..... -Dcom.ibm.SOAP.ConfigURL=xxxx .... myclass". The "-D" is part of the command line syntax and not the property name.

    You can use AdminClient.CONNECTOR_SOAP_CONFIG as an alternative to the literal "com.ibm.SOAP.ConfigURL" if you want to set that property via the connectProps.

    From your post it also looks like your file URLs are missing the colon after 'file'? file:///D:/SOAPClient/properties/soap.client.properties

    This may or may not be the (only) cause of the exception but may be contributing.
    /Stephen
  • UniqueScreenName
    UniqueScreenName
    33 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-26T15:32:58Z  
    • SJC
    • ‏2013-03-26T14:34:18Z
    A couple of things look unusual to me...

    com.ibm.SOAP.ConfigURL and com.ibm.SSL.ConfigURL are normally handled as System Properties. So you might use System.setProperty() or more usually add them to your command line invocation of "java ..... -Dcom.ibm.SOAP.ConfigURL=xxxx .... myclass". The "-D" is part of the command line syntax and not the property name.

    You can use AdminClient.CONNECTOR_SOAP_CONFIG as an alternative to the literal "com.ibm.SOAP.ConfigURL" if you want to set that property via the connectProps.

    From your post it also looks like your file URLs are missing the colon after 'file'? file:///D:/SOAPClient/properties/soap.client.properties

    This may or may not be the (only) cause of the exception but may be contributing.
    /Stephen
    As SJC correctly mentions, the -D indicates a system property on the command line, and it shouldn't be include if you set it in the code.

    The syntax is specific for the file locations, it should be as listed above with the file: protocol. On Windows, this is how I set it as a system property:

    -Dcom.ibm.SSL.ConfigURL=file:C:/Temp/properties/ssl.client.props
    -Dcom.ibm.SOAP.ConfigURL=file:C:/Temp/properties/host.soap.client.props

    Also, turning on tracing will help. Here are the instructions:

    http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.zseries.doc/info/zseries/ae/ttrb_entrstandal.html?resultof=%22%54%72%61%63%65%53%65%74%74%69%6e%67%73%2e%70%72%6f%70%65%72%74%69%65%73%22%20

    The trace string follows the same format as the tracing in the WAS, so to trace everything in the client, in the TraceSettings.properties file you can define the trace string as:

    com.ibm.*=all=enabled

    If you wanted just the SSLConfig, you could have a trace string of:

    SSLConfig=all=enabled

    That should tell you what is going on with the connection. Start with everything enabled and lower the tracing when you want to narrow down into the problem.
  • UniqueScreenName
    UniqueScreenName
    33 Posts

    Re: Create WebSphere administrative client program for java

    ‏2013-03-27T18:57:50Z  
    Many thanks for your response. You said that:"use the AdminClient to get info out of the server". Can you tell me few things.

    Can I manage (create/update) shared libraries through this adminClient after connection?
    Can I get JVM properties through it?
    What information you are getting from your server?
    Can you share your code with me. If yes then please send.

    Regards
    Can I manage (create/update) shared libraries through this adminClient after connection?
    presumably, yes. There are many types you can change via the ConfigService or CommandMgr APIs. I haven't not done so for a shared library, but there is an example of how to change the JVM arguments in the attached class. If you do get it working, it would be good if you posted the solution!

    Can I get JVM properties through it?
    Yes, in a couple of different ways. See the attached class. You can use the AdminClient to get the runtime Mbean for its running state and the ConfigService or CommandMgr API to get the configuration state. There are examples in the attached class as well

    What information you are getting from your server?
    I have just been learning and testing this out recently myself, so I have not built anything as yet. I hope to use it to get information on a variety of types in the config (DataSources, Queue Connection Factories, Container properties, JVM, etc.). I'm looking at doing so using the ConfigService, CommandMgr APIs and the property based configuration mechanism

    Can you share your code with me. If yes then please send.
    I have attached a sample class that I was playing around with. It is not pretty, but it shows how to do some basic stuff and also has references in the comments to where the API documention is. In no way would this class be representative of something that should be used in any kind of production code :)

    To use the class, follow the instructions above for defining the client structure and passing in the system parameters to locate the SSL and SOAP config files

    Hope that helps!
  • some_cs_student
    some_cs_student
    4 Posts

    Re: Create WebSphere administrative client program for java

    ‏2014-10-07T01:01:07Z  
    As SJC correctly mentions, the -D indicates a system property on the command line, and it shouldn't be include if you set it in the code.

    The syntax is specific for the file locations, it should be as listed above with the file: protocol. On Windows, this is how I set it as a system property:

    -Dcom.ibm.SSL.ConfigURL=file:C:/Temp/properties/ssl.client.props
    -Dcom.ibm.SOAP.ConfigURL=file:C:/Temp/properties/host.soap.client.props

    Also, turning on tracing will help. Here are the instructions:

    http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.zseries.doc/info/zseries/ae/ttrb_entrstandal.html?resultof=%22%54%72%61%63%65%53%65%74%74%69%6e%67%73%2e%70%72%6f%70%65%72%74%69%65%73%22%20

    The trace string follows the same format as the tracing in the WAS, so to trace everything in the client, in the TraceSettings.properties file you can define the trace string as:

    com.ibm.*=all=enabled

    If you wanted just the SSLConfig, you could have a trace string of:

    SSLConfig=all=enabled

    That should tell you what is going on with the connection. Start with everything enabled and lower the tracing when you want to narrow down into the problem.

    The above solutions appear to work just fine *if* you are using java and not the wsadmin.sh script itself.

    At a current client site previously, in WAS7 and WAS855 / 8 we were doing something similar to:

    ${wasprofile}/bin/wsadmin.sh -Dcom.ibm.SOAP.ConfigURL=file:/path/to/file.jy -lang jython -f /path/to/scriptFile.jy

    However this consistently failed in all of my testing, in fact the only working version I found was to copy the wsadmin.properties within the profile file and append this line to it:

    com.ibm.SOAP.ConfigURL=/path/to/new_soap_props_file

     

    One this was done I can do:

    ${wasprofile}/bin/wsadmin.sh -p copyOfTheWsAdmin.properties -lang jython -f /path/to/script.jy

    The above works when the loginUserid and the loginPassword are overridden in a copy of the soap.props file but *not* in the original soap.props file within the WebSphere profile directory.
     

    I have tested on WAS855, WAS8 and WAS7 (various versions) and I did confirm that I had a version where this fix was implemented:

    http://www-01.ibm.com/support/docview.wss?uid=swg1PM51621

     

    In my testing I also tried calling my file soap.client.props and placing it in /tmp/, and I also used the -Dcom.ibm.SOAP.ConfigURL=/tmp/file

    And I tested:

    -Dcom.ibm.SOAP.ConfigURL=file:/tmp/file

    Among a few other variations, all variations except the -p option with a full copy of the wsadmn.properties file resulted in a password prompt which does not work well in a script.

    I believe you can use the -D option if you are *not* using the wsadmin.sh script, as per this example:
    http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.0.0/com.ibm.websphere.nd.doc/info/ae/ae/txml_j2se.html

    I'm posting here because this is the first result that appears in google, hopefully this saves someone else some troubleshooting time.