Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, October 7, 2014

Json very nice tool

Given by Greg

Very nice tool !

http://www.jsonschema2pojo.org/

Enable to visualize how will look the generated java POJO code by giving its json schema representation.

For ex:

Assuming the following  Json schema:

{
  "type":"object",
  "properties": {
    "foo": {
      "type": "string"
    },
    "bar": {
      "type": "integer"
    },
    "baz": {
      "type": "boolean"
    }
  }
}

You'll obtain the following JAVA POJO class:
-----------------------------------com.example.Example.java-----------------------------------

package com.example;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"foo",
"bar",
"baz"
})
public class Example {

@JsonProperty("foo")
private String foo;
@JsonProperty("bar")
private Integer bar;
@JsonProperty("baz")
private Boolean baz;
@JsonIgnore
private Map<StringObject> additionalProperties = new HashMap<StringObject>();

@JsonProperty("foo")
public String getFoo() {
return foo;
}

@JsonProperty("foo")
public void setFoo(String foo) {
this.foo = foo;
}

@JsonProperty("bar")
public Integer getBar() {
return bar;
}

@JsonProperty("bar")
public void setBar(Integer bar) {
this.bar = bar;
}

@JsonProperty("baz")
public Boolean getBaz() {
return baz;
}

@JsonProperty("baz")
public void setBaz(Boolean baz) {
this.baz = baz;
}

@JsonAnyGetter
public Map<StringObject> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String nameObject value) {
this.additionalProperties.put(namevalue);
}

}

Monday, April 28, 2014

RegEx tool

A RegEx online tool , highly recommended by Grigory R.

http://www.regexr.com/


As well, here's a quite good video tutorialto watch before using the tool : 



http://www.youtube.com/watch?v=fOH62XXGdLs#t=124



Sunday, January 5, 2014

Call jmx using simple script instead of jconsole

There’s option to call for jmx bean (attribute/operations) using the console only , without opening any jconsole.
Download the jmxterm open source
Then, type something like:

java -jar jmxterm-1.0-alpha-4-uber.jar java --url localhost:10099 -i script/getServiceStatus.txt

where the scripts/getServiceStatus.txt file is something like:

domain LpTag
bean LpTag:name=ServiceStatusManage
get ServiceStatus



My original post in nation (@liveperson )




jmxterm - a JMX tool using command line

Posted by Michael Zamir in R&D Tech forum on Jan 13, 2014 8:37:00 AM
Hello all

I've discovered recently an helpful jar that enables to query/execute a remote jmx server from command line.
This utility is an open-source , called jmxterm .

It enables you to access directly a JMX server , to query it or to execute operations on it, without having to open a jconsole.
It can be useful for automation and for the keyboard lover, like me or simply to check whether your server (local server or remote QA/CI server is up and healthy)
I'm using it for quickly checking the service status of my server (here in the example) or to run some trivial operation (clear cache etc ...)

Jar can be found here: \\tlvfs\Files\jmx  (most of you have it mapped under your drive T:\jmx )
I've also create a very simple batch and shell script file for easing your first steps, if any ... 

In order to use use it (assuming you're a windows OS user, but same is feasible for linux) , simply run the jmxterm.bat (or jmxterm.sh ) script , which simply calls the jar :


Example : get service status of my service :

./jmxterm.bat --url localhost:10099 -i script/getServiceStatus.txt
Welcome to JMX terminal. Type "help" for available commands.
#domain is set to LpTag
#bean is set to LpTag:name=ServiceStatusManage
#mbean = LpTag:name=ServiceStatusManage:
ServiceStatus = 3 - Service is up;

where the script/getServiceStatus.txt file looks as following:
domain LpTag
bean LpTag:name=ServiceStatusManage
get ServiceStatus
since I wanted to obtain the following bean attribute/operation:






Another example is to enter into the command line itself and to navigate within the tool : for ex, connect your jmx (using open command), then query the domains (domains command) or beans (beans command) and execute different kind of operations ...

cd T:\jmx
jmxterm.bat

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
jmxterm example of direct use:
jmxterm.bat --url localhost:10099 -i script/getServiceStatus.txt
jmxterm.bat -l service:jmx:rmi://Hc1k:9588/jndi/rmi://hc1k:10099/hcserv
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Welcome to JMX terminal. Type "help" for available commands.
$>help
#following commands are available to use:
about    - Display about page
bean     - Display or set current selected MBean.
beans    - List available beans under a domain or all domains
bye      - Terminate console and exit
close    - Close current JMX connection
domain   - Display or set current selected domain.
domains  - List all available domain names
exit     - Terminate console and exit
get      - Get value of MBean attribute(s)
help     - Display available commands or usage of a command
info     - Display detail information about an MBean
jvms     - List all running local JVM processes
open     - Open JMX session or display current connection
option   - Set options for command session
quit     - Terminate console and exit
run      - Invoke an MBean operation
set      - Set value of an MBean attribute


Configure your JVM to expose JMX: 
In order to configure your JVM to expose JMX , add the follow parameters to your JVM arguments:

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.port=10099
-Djava.rmi.server.hostname=myserver.example.com
The final rmi.server.hostname is used for exposing JMX to a specific domain (we can limit it).
Don't know currrently to add more info, but I remember there's another post about it. 
I've copied it from this link 
http://stackoverflow.com/questions/834581/remote-jmx-connection


Enjoy if you can ...

Tuesday, January 1, 2013

Problem during access to JMX bean (attribute / operation)


Once again, I've failed at the exact same place ...
I tried to access a JMX bean programatically ... Everything went well (I'm using this wonderful spring infra for accessing my bean).

BUT ... when you try to access a bean that is not well exposed, according to standard, this won't work:

If you expose an operation (and not as attribute) that looks like
public String getServiceStatus()

since it starts by the prefix get , it doesn't receive argument and it returns a value (not a void).
The standard requires that such method should be at least defined as attribute in the JMX server. If it is not, the javax.management.MBeanServerInvocationHandler   won't be able to access the operation.



You can see that in the invoke() method of this MBeanServerInvocationHandler()


      if (methodName.startsWith("get")
                    && methodName.length() > 3
                    && nargs == 0
                    && !returnType.equals(Void.TYPE)) {
                    return connection.getAttribute(objectName,
                        methodName.substring(3));
                }



So the way I've found for overcoming this obstacle was ... to call another bean :(


Here's an example of Spring usage for accessing JMX bean (it's not mine but it's similar):


<bean id="clientConnector"
      class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
  <property name="serviceUrl" value="service:jmx:rmi://remotehost:9875"/>
</bean>

<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
  <property name="objectName" value="bean:name=testBean"/>
  <property name="proxyInterface" value="org.springframework.jmx.IJmxTestBean"/>
  <property name="server" ref="clientConnector"/>
</bean>

Sunday, July 1, 2012

Connect to jconsole to a remote server

Recently, I've encountered problem for connecting jconsole to my remote server (it was tomcat server). Locally, it did work but remotely, it didn't,
I used JDK 1.7 (it may be linked ... ) and ubuntu (it may be linked also).

So I've added the following property:
-Djava.rmi.server.hostname=michael-ubu 


and it started working ...

Here's the doc that finally helped me:

http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/javarmiproperties.html


java.rmi.server.hostname
The value of this property represents the host name string that should be associated with remote stubs for locally created remote objects, in order to allow clients to invoke methods on the remote object. The default value of this property is the IP address of the local host, in "dotted-quad" format.






This one also helped me:

I had a similar, if not the same, problem. I could connect to the JMX server if I started jconsole locally on the machine.
It appears the RMI server was not listening on the correct ip. So, as was suggested in this related question, I added the following:
-Djava.rmi.server.hostname=<host ip>
to JAVA_OPTS as well, and then it worked.