Monday, 30 April 2012

Installing multiple external jars into a local maven repository.

Suppose you have a variety of dependency jars you need to install into your local repository - Note: These arent artefacts produced by your build but external jars. Well, no shortcuts here. From a recent reply I gave on Stackoverflow - You'll have to do it via a script, the long and boring way. This is what we use - modifying the values in each of the `set` statements
    set GROUP_ID=someNamespace
    set ARTIFACT_ID=myartifact
    set VERSION=1
    set COMPONENT=%ARTIFACT_ID%-%VERSION%
    set FILEPATH=D:\my.jar
    
    call mvn install:install-file ^
     -DgroupId=%GROUP_ID% ^
     -DartifactId=%ARTIFACT_ID% ^
     -Dversion=%VERSION% ^
     -Dfile=%FILEPATH% ^
     -Dpackaging=jar ^
     -DgeneratePom=true
    
    set GROUP_ID=someNamespace2
    set ARTIFACT_ID=myartifact2
    set VERSION=1
    set COMPONENT=%ARTIFACT_ID%-%VERSION%
    set FILEPATH=D:\my2.jar
    
    call mvn install:install-file ^
     -DgroupId=%GROUP_ID% ^
     -DartifactId=%ARTIFACT_ID% ^
     -Dversion=%VERSION% ^
     -Dfile=%FILEPATH% ^
     -Dpackaging=jar ^
     -DgeneratePom=true

Tuesday, 10 April 2012

Rooting HTC Wildfire and installing Cyanogenmod

There are many guides out there, this is a diary of events and some errors you might run into and resolutions which worked for me.

Phone Model HTC Wildfire A3333 running on Android 2.2.1 (Froyo)

Began with HBOOT 1.01.0002

Note: To find your HBOOT version -

Switch the phone off, then hold the volume down button and while holding press the power button. At the top of the screen it will show the HBOOT version. To exit this screen, press the power button to select fastboot and then use the volume down to select reboot.

The One-click guide given at http://www.brighthub.com/mobile/htc/articles/100819.aspx did not work initially.

It ran successfully up to step 11 out of 11, when running Revolutionary it gets to a screen on the tool with the message stuck at "Waiting for device"

So I had to do this the older way downgrading to HBOOT 1.01.0001 followed by switching the phone to S-OFF mode

The complete guide which works for me is this one

http://www.aritrasen.com/2011/09/17/how-to-root-htc-wildfire-2-2-1-and-install-cyanogenmod/


Further errors that appear along the way and their solutions:

1. Revolutionary stuck at "Waiting for device"

The solution which worked after consulting various forums, was to install latest version of HTC Sync on the PC and then uninstall it, leaving the HTC Drivers on the PC.

Under Control Panel > Add/Remove Programs you should see the HTC drivers shown in the image below.



2. After this it proceeds to the point where Revolutionary says "Waiting for root"

This takes forever and does nothing.

Of course this is because I thought one of the steps was optional - that of downgrading from Froyo(2.2.1) to Eclair(2.1). Turns out, I do need to do that - once that is done, Revolutionary goes ahead and gives the Success message.


3. After that you can install Cyanogenmod. Ensure you install 7.1.0.1 and not 7.1.0.

7.1.0 is buggy and as soon as the phone reboots, it gives a "Force Close" message with no status / notification bar. It also does not show any incoming phone calls - you can hear the ringtone but there is not way to accept the call.

All of this is fixed in 7.1.0.1 which is downloadable as update-cm-7.1.0.1-buzz-signed.zip

After that, surprise surprise, there's no GMail, Market or Maps. These are not part of Cyanogenmod. These are available as a separate zip from http://wiki.cyanogenmod.com/wiki/Latest_Version/Google_Apps.

I used gapps-gb-20110828-signed.zip for Wildfire but still had to install Google Maps separately from the Market.

After this, I uninstalled some of the apps I didnt want to use in the Cyanogenmod ROM.

A list of what is safe to remove and what is not is given at the

Cyanogenmod wiki at http://wiki.cyanogenmod.com/wiki/Barebones

Follow the instructions and play around with it.

I later upgraded to CM 7.2 using this ROM from here

For those used to HTC's Predictive Dialer, the native CM one kind of sucks. Use the Touchpal Contacts smart dialer app from the Market. http://forum.xda-developers.com/showthread.php?t=817128

With 7.2 I've seen my battery charges quicker than before (with HTC ROM) and the interface is much quicker too.

Dont' forget to add some Lockscreen Gestures

More cool things to do are here

Additional reference links:

http://androidforums.com/wildfire-tips-tricks/348619-easy-ways-improve-htc-wildfire-speed.html

http://androidforums.com/wildfire-all-things-root/459656-what-do-when-rooted.html


http://unrevoked.com/rootwiki/doku.php/public/adb_in_recovery

Wednesday, 4 April 2012

Weblogic - Accessing Server Runtime details using JMX

We had a requirement to access certain runtime info on the Weblogic server to carry out some admin tasks.

One way to do this is via the JMX API, which in Weblogic is available as an extensive set of MBeans

There are plenty of tutorials and examples of using these on the net.

Now within your Weblogic domain, if you run as part of a Cluster then you would access Domain information on the Admin server if you need to identify the running servers in the cluster.

This uses
weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean
object which is bound only on the Admin server.
One full example of this is at http://middlewaremagic.com/weblogic/?p=210

If you try this on a managed server directly, you will get this error

java.io.IOException: Unable to resolve 'weblogic.management.mbeanservers.domainruntime'. Resolved 'weblogic.management.mbeanservers'
        at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:195)
        at weblogic.management.remote.common.ClientProviderBase.newJMXConnector(ClientProviderBase.java:83)
        at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:338)
        at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)


So if you do not have the Admin server IP address and port, how can you still identify the other members in the cluster?

A use case for this is if you want to run and access Cluster details from one of the managed servers. But you only have the current running server IP and Port and not that of the Admin server - which is usually the case

There is an MBean for this which is available on the individual managed server as well,
weblogic.management.mbeanservers.runtime.RuntimeServiceMBean

Using this you can get the details of the Admin server and then from there get access to the DomainRuntimeServiceMBean.

A working code example is below

This runs from a JSP where we are able to access the server IP and port via request variables


<%@page import="javax.xml.bind.DatatypeConverter"%>
<%@page import="java.io.IOException"%>
<%@page import="java.net.MalformedURLException"%>
<%@page import="java.util.Hashtable"%>
<%@page import="javax.management.MBeanServerConnection"%>
<%@page import="javax.management.MalformedObjectNameException"%>
<%@page import="javax.management.ObjectName"%>
<%@page import="javax.management.remote.JMXConnector"%>
<%@page import="javax.management.remote.JMXConnectorFactory"%>
<%@page import="javax.management.remote.JMXServiceURL"%>
<%@page import="javax.naming.Context"%>
<%@page import="java.net.URLConnection"%>
<%@page import="java.net.HttpURLConnection"%>
<%@page import="java.net.URL"%>
<%@page import="sun.misc.BASE64Encoder"%>
<%@page import="java.io.InputStream"%>
<%@page import="javax.management.MBeanServer"%>
<%@page import="javax.management.ObjectName"%>
<%@page import="javax.naming.InitialContext"%>

 MBeanServer mBeanServer = null;
 InitialContext ctx = null;
 String administrationURL = null;
 int adminPort = 0;
 try {
  ctx = new InitialContext();
  mBeanServer = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
  
  //Get Admin Server and Port
  ObjectName runtimeService = new ObjectName(
     "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
  String managedServerName = (String) mBeanServer.getAttribute(runtimeService, "ServerName");
  ObjectName msServerRuntime = new ObjectName("com.bea:Name="+ managedServerName + ",Type=ServerRuntime");
  administrationURL = (String) mBeanServer.getAttribute(msServerRuntime, "AdminServerHost");
  adminPort = (Integer) mBeanServer.getAttribute(msServerRuntime, "AdminServerListenPort");
  System.out.println(administrationURL + adminPort);
 } catch (Exception ex) {
  System.out.println("Caught Exception while fetching Admin Server information : "+ ex);
  ex.printStackTrace();
 } finally {
  if (ctx != null) {
   try {
    ctx.close();
   } catch (Exception ex) {
    ex.printStackTrace();
   }
  }
 }

 //Connect via JMX using Admin Server credentials
 String protocol = "t3";
 Integer portInteger = Integer.valueOf(request.getServerPort());
 int port = portInteger.intValue();

 String jndiroot = "/jndi/";
 String mserver = "weblogic.management.mbeanservers.domainruntime";
 JMXServiceURL serviceURL = new JMXServiceURL(protocol, administrationURL, adminPort, jndiroot + mserver);
 Hashtable h = new Hashtable();
 h.put(Context.SECURITY_PRINCIPAL, weblogicuser);
 h.put(Context.SECURITY_CREDENTIALS, weblogicpassword);
 h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");
 JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
 MBeanServerConnection connection = connector.getMBeanServerConnection();

 ObjectName domainRuntimeService = new ObjectName(
 "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
 ObjectName[] serverRT = (ObjectName[]) connection.getAttribute(domainRuntimeService, "ServerRuntimes");
 Hashtable server_states = new Hashtable();
 for (ObjectName ser : serverRT) {
  server_states.put((String) connection.getAttribute(ser,"Name"), (String) connection.getAttribute(ser,"State"));
 }

 ObjectName domain1 = (ObjectName) connection.getAttribute(
    domainRuntimeService, "DomainConfiguration");
 ObjectName[] cluster_list = (ObjectName[]) connection
    .getAttribute(domain1, "Clusters");
 for (ObjectName cl : cluster_list) {

  System.out.println("

 Cluster Name: "
    + (String) connection.getAttribute(cl, "Name"));
  try {
   System.out.println("

");
   ObjectName[] servers = (ObjectName[]) connection.getAttribute(cl, "Servers");
   for (ObjectName ser : servers) {
    String server_name = (String) connection.getAttribute(ser, "Name");
   
    try {
     String server_URL = (String) connection.getAttribute(ser, "ListenAddress");
     Integer server_port = (Integer) connection.getAttribute(ser, "ListenPort");
     System.out.println("Server Name: " + server_name + ", Server State: "
        + server_states.get(server_name)
        + ", :" + server_URL + ":"
        + server_port);

   
    }
   }
  }
  connector.close();
 }


How to connect Raspberry Pi Pico to a external temperature sensor(DHT11 or DHT22)

How to connect Raspberry Pi to DHT 11 / DHT 22   Connect your DHT11 sensor to the Pico accordingly -   Left pin (Signal) - GPIO Pin 22 (or a...