How do I get the WebSphere ConfigService into a servlet?

I have a servlet in an enterprise application on WebSphere Application Server 7.
I want the servlet to read configuration settings from the resource user environment provider.

This particular framework is not WebSphere Portal and I am not using Spring, but I am trying to adapt the code from this page about using resource providers with Spring:
http://blogs.perficient.com/portals/2012/03/28/using- wps-style-resource-environment-providers-with-spring

I have a problem with the first line of my test method:

com.ibm.websphere.management.configservice.ConfigService service
    =com.ibm.websphere.management.configservice.ConfigServiceFactory.getConfigService();
      

The method getConfigService()

on this line always returns null

in my servlet. The method does not throw any exceptions, and no errors are thrown in the server logs; it just returns null

.
(Note: I am showing the package names in the above code for clarity. In real code, I am the import

relevant classes.)

How do I get an object ConfigService

in my servlet?

The class ConfigServiceFactory

also has a method createConfigService(boolean enable, java.util.Properties props)

, but the Javadoc does not say what is expected for its arguments and I cannot find any examples using it.

Edit:

I've tried using ConfigServiceProxy

both http://www-01.ibm.com/support/docview.wss?uid=swg21411254 as suggested by Magic Wand and can't get this to work. Details of the problems. Does anyone know how to make this work?

Point 5 at the bottom of the page about usage ConfigServiceProxy

says:

Change the properties connectProps.setProperty (AdminClient.CONNECTOR_HOST, "localhost"); and connectProps.setProperty (AdminClient.CONNECTOR_PORT, "8880") as needed.

But it doesn't tell you how to determine the correct host and port, and I haven't found this information elsewhere, so I'm just guessing.

To find the hostnames and ports, I went to the WebSphere Integrated Solutions Console, navigated to Servers -> Server Types -> WebSphere Application Servers, clicked the application server running my servlet, and clicked Ports.

Here is a portion of my code that is trying to get ConfigServiceProxy

, in which I only change the hostname and port number depending on which port I am trying:

 Properties connectProps = new Properties();
    connectProps.setProperty(AdminClient.CONNECTOR_TYPE,
        AdminClient.CONNECTOR_TYPE_SOAP);
    connectProps.setProperty(AdminClient.CONNECTOR_HOST,"localhost");
    connectProps.setProperty(AdminClient.CONNECTOR_PORT,"9634");
    AdminClient adminClient=AdminClientFactory.createAdminClient(connectProps);
    ConfigService service=new ConfigServiceProxy(adminClient);
      

I first tried the only port for which the host is "localhost" because that is what the linked example uses. The port name for this is "IPC_CONNECTOR_ADDRESS" and the port number is 9634.
This throws an exception when called AdminClientFactory.createAdminClient

. The stack trace starts at:

com.ibm.websphere.management.exception.ConnectorException: ADMC0016E: The system cannot create a SOAP connector to connect to host localhost at port 9634.
    at com.ibm.websphere.management.AdminClientFactory.createAdminClientPrivileged (AdminClientFactory.java:634)
    at com.ibm.websphere.management.AdminClientFactory.access $ 000 (AdminClientFactory.java:126)
    at com.ibm.websphere.management.AdminClientFactory $ 1.run (AdminClientFactory.java:209)
    at com.ibm.ws.security.util.AccessController.doPrivileged (AccessController.java:63)
    at com.ibm.websphere.management.AdminClientFactory.createAdminClient (AdminClientFactory.java:205)
    at com.isw.ResourceEnvironmentProviderPlaceHolderConfigurer.getConfigService (ResourceEnvironmentProviderPlaceHolderConfigurer.java:113)

And nested reasons:

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:56)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:39)
    at java.lang.reflect.Constructor.newInstance (Constructor.java:527)
    at com.ibm.websphere.management.AdminClientFactory.createAdminClientPrivileged (AdminClientFactory.java:456)
    ... 38 more
Caused by: com.ibm.websphere.management.exception.ConnectorNotAvailableException: [SOAPException: faultCode = SOAP-ENV: Client; msg = Connection reset; targetException = java.net.SocketException: Connection reset]
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient.reconnect (SOAPConnectorClient.java:422)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient. (SOAPConnectorClient.java:222)
    ... 43 more
Caused by: [SOAPException: faultCode = SOAP-ENV: Client; msg = Connection reset; targetException = java.net.SocketException: Connection reset]
    at org.apache.soap.transport.http.SOAPHTTPConnection.send (SOAPHTTPConnection.java:479)
    at org.apache.soap.rpc.Call.WASinvoke (Call.java:451)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient $ 4.run (SOAPConnectorClient.java:372)
    at com.ibm.ws.security.util.AccessController.doPrivileged (AccessController.java:118)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient.reconnect (SOAPConnectorClient.java:365)
    ... 44 more

Next, I tried a port named "SOAP_CONNECTOR_ADDRESS", where host is the FQDN of the server and the port number is 8881, so the host and port lines look like this:

 connectProps.setProperty(AdminClient.CONNECTOR_HOST,"server.company.net.au");
    connectProps.setProperty(AdminClient.CONNECTOR_PORT,"9634");
      

This threw an exception when trying to build ConfigServiceProxy

. The stack trace starts at these lines and has no reason:

javax.management.InstanceNotFoundException: WebSphere: process = InfraCluster_server1, type = ConfigService, *
    at com.ibm.websphere.management.configservice.ConfigServiceProxy. (ConfigServiceProxy.java:67)
    at com.isw.ResourceEnvironmentProviderPlaceHolderConfigurer.getConfigService (ResourceEnvironmentProviderPlaceHolderConfigurer.java:114)
    at com.isw.ResourceEnvironmentProviderPlaceHolderConfigurer.loadEnvironmentProviderProperties (ResourceEnvironmentProviderPlaceHolderConfigurer.java:205)
    at com.isw.insight.client.REPTest.doGet (REPTest.java:50)

Finally, I tried a port named "WC_adminhost" where the host is "*" and the port is 9062. I tried this with both the hostname set to "localhost" and the server FQDN and both failed with the same exception.
Like the IPC_CONNECTOR_ADDRESS port, this throws an exception when called AdminClientFactory.createAdminClient

. The stack trace starts at:

com.ibm.websphere.management.exception.ConnectorException: ADMC0016E: The system cannot create a SOAP connector to connect to host server.company.net.au at port 9062.
    at com.ibm.websphere.management.AdminClientFactory.createAdminClientPrivileged (AdminClientFactory.java:634)
    at com.ibm.websphere.management.AdminClientFactory.access $ 000 (AdminClientFactory.java:126)
    at com.ibm.websphere.management.AdminClientFactory $ 1.run (AdminClientFactory.java:209)
    at com.ibm.ws.security.util.AccessController.doPrivileged (AccessController.java:63)
    at com.ibm.websphere.management.AdminClientFactory.createAdminClient (AdminClientFactory.java:205)
    at com.isw.ResourceEnvironmentProviderPlaceHolderConfigurer.getConfigService (ResourceEnvironmentProviderPlaceHolderConfigurer.java:113)

And nested reasons:

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:56)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:39)
    at java.lang.reflect.Constructor.newInstance (Constructor.java:527)
    at com.ibm.websphere.management.AdminClientFactory.createAdminClientPrivileged (AdminClientFactory.java:456)
    ... 36 more
Caused by: com.ibm.websphere.management.exception.ConnectorNotAvailableException: [SOAPException: faultCode = SOAP-ENV: Client; msg = Error opening socket: java.net.ConnectException: Connection refused; targetException = java.lang.IllegalArgumentException: Error opening socket: java.net.ConnectException: Connection refused]
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient.reconnect (SOAPConnectorClient.java:422)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient. (SOAPConnectorClient.java:222)
    ... 41 more
Caused by: [SOAPException: faultCode = SOAP-ENV: Client; msg = Error opening socket: java.net.ConnectException: Connection refused; targetException = java.lang.IllegalArgumentException: Error opening socket: java.net.ConnectException: Connection refused]
    at org.apache.soap.transport.http.SOAPHTTPConnection.send (SOAPHTTPConnection.java:475)
    at org.apache.soap.rpc.Call.WASinvoke (Call.java:451)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient $ 4.run (SOAPConnectorClient.java:372)
    at com.ibm.ws.security.util.AccessController.doPrivileged (AccessController.java:118)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient.reconnect (SOAPConnectorClient.java:365)
    ... 42 more
+3


source to share


1 answer


I couldn't figure out why it ConfigServiceFactory.getConfigService()

always returns null, but I was able to get a working instance ConfigService

using AdminClient

and ConfigServiceProxy

based on the code from http://www-01.ibm.com/support/docview.wss?uid=swg21411254 .

The main code is this: the hostname and port number may change depending on the server configuration:

Properties connectProps = new Properties();
connectProps.setProperty(AdminClient.CONNECTOR_TYPE,
    AdminClient.CONNECTOR_TYPE_SOAP);
connectProps.setProperty(AdminClient.CONNECTOR_HOST,"localhost");
connectProps.setProperty(AdminClient.CONNECTOR_PORT,"8880");
AdminClient adminClient=AdminClientFactory.createAdminClient(connectProps);
ConfigService service=new ConfigServiceProxy(adminClient);
      

The IBM support document does not indicate how to determine the correct host and port. Here are some details on this:

The hostname "localhost" and port number 8880 are the default values ​​when WebSphere Application Server is configured as a single server without a deployment manager. In a clustered environment, at least the port number will be different for each application server.

In my clustered test environment, I first tested the ports listed for each application server in the WebSphere Integrated Solutions Console (ISC). None of them were right.

I subsequently discovered (via google search) that there are several files on each server that control the actual ports used.
These files are located on each application server file system in the $ {USER_INSTALL_ROOT} / properties.
The value of $ {USER_INSTALL_ROOT} can be found under Environment β†’ Websphere Variables in ISC.
The full path to the directory on Linux is usually / opt / IBM / WebSphere / AppServer / profiles / AppSrv 01 / properties.
In this directory, the correct hostname and port can be found in the "wsadmin.properties" file.

Also, using the correct host and port, my environment also required username and password authentication for the SOAP connection. This can be done in two ways.

Credentials can be set in code, with these two lines appended to the above code before the call AdminClientFactory.createAdminClient

:



connectProps.setProperty(AdminClient.USERNAME,"username");
connectProps.setProperty(AdminClient.PASSWORD,"password");
      

This requires a password in plain text, which is not recommended.

Alternatively, credentials can be set in the "soap.client.props" file in the same directory as the "wsadmin.properties" file.
In "soap.client.props" on each application server that runs the code, these properties must be set:

com.ibm.SOAP.securityEnabled = true
com.ibm.SOAP.loginUserid = username
com.ibm.SOAP.loginPassword = password

Note the property com.ibm.SOAP.securityEnabled

in particular: its value must be true

for the username and password to be used.

After setting these properties and saving the file on each server, use the PropFilePasswordEncoder command in the operating system console to encode the password.
For this command I used the following documentation:
http://publib.boulder.ibm.com/infocenter/wsdoc400/v6r0/index.jsp?topic=/com.ibm.websphere.iseries.doc/info/ae/ae/qshpropenc .htm

The actual command used in my application server is /opt/IBM/WebSphere/AppServer/bin/PropFilePasswordEncoder.sh/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/properties/soap.client.props com.ibm.SOAP.loginPassword
This only encodes the password for basic authentication as my configuration does not use SSL for SOAP.

In the end, my code works.
I didn't need to restart any servers at any point in the above process.

+2


source







All Articles