How to read Weblogic Server details using Restful Java Client

In this post, I will explain how can you read informations from you web logic server using java client.

Use Case – This is small extract from a big use case where we are trying to build a dashboard we can keep seeing status of our deployed applications.

Solution – Only how to get all server and their status,

– Start JDeveloper
– Open localhost:7101/console
– select domain from left pane = “Default”
1
– expand Advanced from right pane -> Check Restart may be required. Enable RESTful Management Services

2

– Create a Java Client like below,

package view;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;

public class JerseyClientGet {

public static void main(String[] args) {
try {
Client client = Client.create();
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(“weblogic”, “welcome1”);
client.addFilter(authFilter);
WebResource webResource = client
.resource(“http://localhost:7101/management/tenant-monitoring/datasources”);

/*http://localhost:7101/management/tenant-monitoring/servers
* http://localhost:7001/management/tenant-monitoring/clusters
http://localhost:7001/management/tenant-monitoring/clusters/{cluster name}
http://localhost:7001/management/tenant-monitoring/applications
http://localhost:7001/management/tenant-monitoring/applications/{application name}
http://localhost:7001/management/tenant-monitoring/datasources
http://localhost:7001/management/tenant-monitoring/datasources/{datasource name}*/

ClientResponse response = webResource.accept(“text/html”)
.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException(“Failed : HTTP error code : “
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println(“Output from Server …. \n”);
System.out.println(output);
} catch (Exception e) {

e.printStackTrace();
}
}
}

– Run client
– Output as below, (I have copied out from console and pasted in html to show in this manner.)

3

 

Happy Coding!

Advertisements

एक उत्तर दें

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / बदले )

Twitter picture

You are commenting using your Twitter account. Log Out / बदले )

Facebook photo

You are commenting using your Facebook account. Log Out / बदले )

Google+ photo

You are commenting using your Google+ account. Log Out / बदले )

Connecting to %s