I have a servlet in an enterprise application on WebSphere Application Server 7.
I want the servlet to read configuration parameters from a custom resource environment provider.
This particular environment is not WebSphere Portal, and I'm not using Spring, but I'm trying to adapt the code from this page about using resource envirnment providers with Spring:
http://blogs.perficient.com/portals/2012/03/28/using-wps-style-resource-environment-providers-with-spring
I'm having 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 getConfigService() method in this line always returns null in my servlet. The method doesn't throw any exceptions, and no errors appear in the server logs; it just returns null.
(Note I show package names in the above code for clarity. In the real code, I import the relevant classes.)
How do I get a ConfigService object in my servlet?
The ConfigServiceFactory class also has a createConfigService(boolean enable, java.util.Properties props) method, but the Javadoc doesn't say what's expected for its arguments, and I can't find any examples using it.
Edit:
I've tried using a ConfigServiceProxy as per http://www-01.ibm.com/support/docview.wss?uid=swg21411254, as suggested by Magic Wand, and can't get that to work either.
Details of the problems follow. Does anyone know how to make this work?
Point 5 near the bottom of the page about using ConfigServiceProxy says:
Modify the properties connectProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost"); and connectProps.setProperty(AdminClient.CONNECTOR_PORT, "8880") if needed.
But it doesn't say how to determine the correct host and port, and I haven't found that information elsewhere, so I'm just guessing.
To find host names and ports, I've logged into the WebSphere Integrated Solutions Console, gone to Servers -> Server Types -> WebSphere application servers, clicked the app server my servlet runs on, and clicked "Ports".
Here's the part of my code that tries to get a ConfigServiceProxy, in which I change only the host name and port number depending on which port I'm 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);
First, I tried the only port for which the host is "localhost", because that's what the linked example uses. The port name for that is "IPC_CONNECTOR_ADDRESS", and the port number is 9634.
This produces an exception on calling AdminClientFactory.createAdminClient. The stack trace starts with:
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 the nested causes are:
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 the host is the server's fully qualified domain name, and the port number is 8881, so the lines setting host and port look like:
connectProps.setProperty(AdminClient.CONNECTOR_HOST,"server.company.net.au");
connectProps.setProperty(AdminClient.CONNECTOR_PORT,"9634");
This produced an exception on trying to construct the ConfigServiceProxy. The stack trace starts with these lines, and has no cause:
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've tried this both with the host name set to "localhost" and the server's fully qualified domain name, and both fail with the same exception.
Like the IPC_CONNECTOR_ADDRESS port, this produces an exception on calling AdminClientFactory.createAdminClient. The stack trace starts with:
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 the nested causes are:
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
I couldn't determine why ConfigServiceFactory.getConfigService() always returns null, but I have managed to obtain a working ConfigService instance using AdminClient and ConfigServiceProxy based on the code from http://www-01.ibm.com/support/docview.wss?uid=swg21411254.
The basic code is this, with the host name and port number possibly changing 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 doesn't say how to determine the correct host and port. Here is some detail about that:
Host name "localhost" and port number 8880 are the defaults when WebSphere Application Server is configured as a single server with no 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 checked the ports listed for each application server in the WebSphere Integrated Solutions Console (ISC). None of those were correct.
I subsequently found (via Google searching) that each server has several files controlling the actual ports used.
These files are found on each application server's file system in ${USER_INSTALL_ROOT}/properties.
The value of ${USER_INSTALL_ROOT} can be found in "Environment -> Websphere variables" in the ISC.
The complete directory path on Linux is typically /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/properties.
In that directory, the correct host name and port can be found in the file "wsadmin.properties".
As well as using the correct host and port, my environment also required username/password authentication for the SOAP connection. This can be done in two ways.
The credentials can be set in code, with these two lines added to the above code before calling AdminClientFactory.createAdminClient:
connectProps.setProperty(AdminClient.USERNAME,"username");
connectProps.setProperty(AdminClient.PASSWORD,"password");
This requires the 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 every application server on which the code runs, these properties must be set:
com.ibm.SOAP.securityEnabled=true
com.ibm.SOAP.loginUserid=username
com.ibm.SOAP.loginPassword=password
Note the com.ibm.SOAP.securityEnabled property 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 an operating-system console to encode the password.
I used the following documentation for this command:
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 on my application server was:
/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 doesn't use SSL for SOAP.
After all this, my code works.
I did not have to restart any servers at any point in the above process.
Related
I'm building CRUD interface for ArangoDB as Java service.
My ArangoDB service has dynamic IP, but static URL. Thus I want to specify URL instead of IP and port.
But when I set it in arangodb.properties file I get the following exception:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netcracker.unm.activeinventory.services.ArangoService]: Constructor threw exception; nested exception is com.arangodb.ArangoDBException: Could not load property-value arangodb.hosts=127.0.0.1:8538,127.0.0.1:8529,http://arangodb-nms-infra.sdnoshm05.com:443. Expected format ip:port,ip:port,...
How can I do it?
Update
I have figured out that I have to connect to https server. How can I specify it in my arangodb.properties file?
I have tried to connect to the servers endpoint using unix wget command. It doesn't connect if I dont specify https protocol. And so my ArangoDB client doesn't, if there is plain ip:port. I just get java.net.ConnectException: Connection refused exception.
I don't believe you can do that since the service needs to bind to an IP address. Usually, when dealing with dynamic IP addresses your ISP is changing the IP but internally you can configure your IP address statically. Bind to your internal static IP and configure your router to port forward to that internal IP address. Many routers support dynamic DNS through various providers that will map the domain to your changing IP address. I hope that helps.
Update: Setting up HTTPS should be pretty easily done, just follow the docs here: https://docs.arangodb.com/3.2/Manual/Administration/Configuration/SSL.html
I have a working Spring Boot app (1.2) that uses Postgres. Today I am trying to switch it to Oracle, but when I try to connect I get an exception that says:
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
And below that,
Caused by: java.net.ConnectException: Connection refused
So of course that looks like bad credentials, but I know they are good, and they are working in Oracle SQL Developer just fine. I'm baffled. Here are my properties file entries:
# Properties for Hibernate and Oracle
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:#//earth-db-11:5121/stardev
spring.datasource.username=ops$abcdefg
spring.datasource.password=mypassword
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
The only idea I have is that there is a $ in the user name, and I have tried escaping it and putting double quotes around it.
Any ideas?
Thanks...
UPDATE:
Many thanks to BonanzaOne, I did have the port number wrong. Correcting that results in a new error:
java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
I looked it up of course, but I don't follow what its telling me:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Cause: The listener received a request to establish a connection to a database
or other service. The connect descriptor received by the listener specified a
service name for a service (usually a database service) that either has not yet
dynamically registered with the listener or has not been statically configured
for the listener. This may be a temporary condition such as after the listener
has started, but before the database instance has registered with the listener.
Still, SQL Explorer connects fine.
That exception means that the Oracle listener is not up, or you are trying to connect to a listener that don't exist/not accessible.
My guess is that you trying the wrong port "5121". Oracle default port is 1521.
Can you try with that and see what happens?
From the FAQ there are basically two ways of composing your JDBC string URL:
Old syntax
jdbc:oracle:thin:#[HOST][:PORT]:SID
New syntax
jdbc:oracle:thin:#//[HOST][:PORT]/SERVICE
My guess is that you are using the wrong syntax-SID/Service name combination, in other words, you are using the new syntax that requires the SERVICE name, but you are using the SID name to do it.
Try this: jdbc:oracle:thin:#earth-db-11:1521:stardev
Or maybe find out the Service name and apply it to the new syntax that you are using, instead of the SID name.
When I print the I.P. address of the system using InetAddress.getLocalHost(), I get user-VAIO/192.168.1.3 . Now, when I connect to derby using jdbc:derby://localhost:1527/mydatabase;create=true, it connects without any errors but when I connect the same using jdbc:derby://192.168.1.3:1527/mydatabase;create=true, it fails giving me the following exception:-
java.net.ConnectException : Error connecting to server 192.168.1.3 on port 1527 with message Connection refused: connect.
Any help will be appreciated.
When you start your Derby Network Server, you provide a value for the '-h' argument. You might not realize you are doing this, if you are using the packaged StartNetworkServer.bat file, but look inside the batch file, and you will see the -h argument there.
The batch file comes provided with the syntax '-h default' when you download Derby from the Apache website.
But you can change that, to say, for example, '-h 192.168.1.3', and then your Derby Network Server will accept connections that specify 'jdbc:derby://192.168.1.3/my/database'.
Note that if you want to accept such connections from other computers on the network, you will also have to adjust your Windows Firewall rules, as by default it will prevent such connections.
I am running a Java web application using tomcat to send generated reports via emails to the users.
I am able to send the emails but after few hours the server stops sending emails, with the following error.
javax.mail.MessagingException: Unknown SMTP host: mail.mydomain.co.uk;
nested exception is:
java.net.UnknownHostException: mail.mydomain.co.uk
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1970)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at com.turnkey.email.SendEmail.sendMail(SendEmail.java:119)
at com.turnkey.thread.CommunicationThread.run(CommunicationThread.java:399)
Caused by: java.net.UnknownHostException: mail.mydomain.co.uk
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
... 8 more
After some time the server starts sending emails again.
Can anyone tell me what could be the problem.
And how do I solve this problem?
Thanks
This looks like a failure in your name service. The JDK isn't able to look up the host name to find its internet address. Since this works sometimes and not others, it looks like an intermittent failure of the name service. The name service failure could be due to some failure in your local operating system, or it could be due to some network failure communicating with your DNS server or other name service server, or it could be a failure in that DNS server or name service server itself. Determining the exact cause of the failure will require some debugging. Note that the JDK caches the results of name server lookups for some time so you'll need to factor that into your debugging.
Also make sure there is no space at the end of smtp hostname eg. mail.google.comSPACEHERE . Surprisingly this happened to me and finally after removing this space there was no complain about smtp host . Email was successfully sent
Set for host the ip address of the domain name instead of the domain name.
use nslookup mail.mydomain.co.uk on cmd to find the ip address.
It worked for me.
Specially for AIX or Linux OS environment,
We need to add the hostname in the etc/hosts file.. to sole this.
Windows operating system , this may work on Windows system as there is no strict security check however AIX or Linux must add host name to etc/hosts file in order for ping the SMTP server.
avoid doing this may lead Unknown host issue
I downloaded Tomcat Deployer
so i could deploy remotely to my tomcat server, when insert all the correct details it ask for such as:
Manager URL
Username/Password
URL of sync App
when i try to deploy i keep getting this error:
Failed to deploy: com.caucho.hessian.client.HessianRuntimeException: java.net.ConnectException: Connection refused: connect
Projecct [HFJSe] deploy completed.
And nothing is deployed.
If there anything i need to do on my Tomcat server?
The error states that the target machine is refusing the connection, so you'll need to check the following information:
The URL is correct (I know you've stated it, but the URL should be in the format of http://{host}:{port}/TomcatHelper (from what I understand in the documentation)
That if there is a configuation file, that the port is configured appropriately
The target server has that port open to accepting connections
Your username and password is correct
If your "remote" server is on the same local machine, use your loopback address (i.e. localhost