Skip to content

Commit

Permalink
Changes to the HQApi and subclasses to appropriately add the Response…
Browse files Browse the repository at this point in the history
…Handler interface to the HQConnection and a couple of impls
  • Loading branch information
bsnyder authored and Ryan Morgan committed Mar 4, 2010
1 parent d45df23 commit 37917b4
Show file tree
Hide file tree
Showing 25 changed files with 231 additions and 168 deletions.
3 changes: 0 additions & 3 deletions resources/META-INF/spring/hqapi-context.xml
Expand Up @@ -21,9 +21,6 @@
<constructor-arg index="2" value="#{ systemProperties['scripting.client.secure'] }" />
<constructor-arg index="3" value="#{ systemProperties['scripting.client.user'] }" />
<constructor-arg index="4" value="#{ systemProperties['scripting.client.password'] }" />
<constructor-arg index="5">
<bean class="org.hyperic.hq.hqapi1.XmlResponseHandler"/>
</constructor-arg>
</bean>

<context:annotation-config />
Expand Down
19 changes: 11 additions & 8 deletions src/org/hyperic/hq/hqapi1/AgentApi.java
Expand Up @@ -27,15 +27,15 @@

package org.hyperic.hq.hqapi1;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.hyperic.hq.hqapi1.types.Agent;
import org.hyperic.hq.hqapi1.types.AgentResponse;
import org.hyperic.hq.hqapi1.types.AgentsResponse;
import org.hyperic.hq.hqapi1.types.PingAgentResponse;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* The Hyperic HQ Agent API.
* <br><br>
Expand Down Expand Up @@ -68,7 +68,8 @@ public AgentResponse getAgent(int id)
{
Map<String,String[]> params = new HashMap<String,String[]>();
params.put("id", new String[] { String.valueOf(id) });
return doGet("agent/get.hqu", params, AgentResponse.class);
return doGet("agent/get.hqu", params,
new XmlResponseHandler<AgentResponse>(AgentResponse.class));
}

/**
Expand All @@ -90,7 +91,8 @@ public AgentResponse getAgent(String address, int port)
Map<String,String[]> params = new HashMap<String,String[]>();
params.put("address", new String[] { address });
params.put("port", new String[] { String.valueOf(port) });
return doGet("agent/get.hqu", params, AgentResponse.class);
return doGet("agent/get.hqu", params,
new XmlResponseHandler<AgentResponse>(AgentResponse.class));
}

/**
Expand All @@ -106,7 +108,7 @@ public AgentsResponse getAgents()
throws IOException
{
return doGet("agent/list.hqu", new HashMap<String,String[]>(),
AgentsResponse.class);
new XmlResponseHandler<AgentsResponse>(AgentsResponse.class));
}

/**
Expand All @@ -125,6 +127,7 @@ public PingAgentResponse pingAgent(Agent agent)
{
Map <String,String[]> params = new HashMap<String,String[]>();
params.put("id", new String[] { String.valueOf(agent.getId()) });
return doGet("agent/ping.hqu", params, PingAgentResponse.class);
return doGet("agent/ping.hqu", params,
new XmlResponseHandler<PingAgentResponse>(PingAgentResponse.class));
}
}
16 changes: 11 additions & 5 deletions src/org/hyperic/hq/hqapi1/AlertApi.java
Expand Up @@ -27,6 +27,7 @@

package org.hyperic.hq.hqapi1;

import org.hyperic.hq.hqapi1.types.AgentResponse;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.AlertsResponse;
Expand Down Expand Up @@ -106,7 +107,8 @@ public AlertsResponse findAlerts(long begin, long end, int count,
params.put("notFixed", new String[] { Boolean.toString(notFixed)});
}

return doGet("alert/find.hqu", params, AlertsResponse.class);
return doGet("alert/find.hqu", params,
new XmlResponseHandler<AlertsResponse>(AlertsResponse.class));
}

/**
Expand Down Expand Up @@ -146,7 +148,8 @@ public AlertsResponse findAlerts(Resource r, long begin, long end,
params.put("notFixed", new String[] { Boolean.toString(notFixed)});
}

return doGet("alert/findByResource.hqu", params, AlertsResponse.class);
return doGet("alert/findByResource.hqu", params,
new XmlResponseHandler<AlertsResponse>(AlertsResponse.class));
}

/**
Expand Down Expand Up @@ -229,7 +232,8 @@ public AlertsResponse fixAlerts(Integer[] alertIds, String reason)
params.put("id", ids);
params.put("reason", new String[] { reason });

return doGet("alert/fix.hqu", params, AlertsResponse.class);
return doGet("alert/fix.hqu", params,
new XmlResponseHandler<AlertsResponse>(AlertsResponse.class));
}

/**
Expand Down Expand Up @@ -284,7 +288,8 @@ public AlertsResponse ackAlerts(Integer[] alertIds, String reason, Long pause)
params.put("reason", new String[] { reason });
params.put("pause", new String[] { Long.toString(pause)});

return doGet("alert/ack.hqu", params, AlertsResponse.class);
return doGet("alert/ack.hqu", params,
new XmlResponseHandler<AlertsResponse>(AlertsResponse.class));
}

/**
Expand Down Expand Up @@ -323,6 +328,7 @@ public StatusResponse delete(Integer[] alertIds)
}
params.put("id", ids);

return doGet("alert/delete.hqu", params, StatusResponse.class);
return doGet("alert/delete.hqu", params,
new XmlResponseHandler<StatusResponse>(StatusResponse.class));
}
}
12 changes: 7 additions & 5 deletions src/org/hyperic/hq/hqapi1/AlertDefinitionApi.java
Expand Up @@ -28,6 +28,7 @@
package org.hyperic.hq.hqapi1;

import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
import org.hyperic.hq.hqapi1.types.AlertsResponse;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.AlertDefinition;
import org.hyperic.hq.hqapi1.types.AlertDefinitionResponse;
Expand Down Expand Up @@ -119,7 +120,7 @@ public AlertDefinitionsResponse getAlertDefinitions(boolean excludeTypeBased,
}

return doGet("alertdefinition/listDefinitions.hqu", params,
AlertDefinitionsResponse.class);
new XmlResponseHandler<AlertDefinitionsResponse>(AlertDefinitionsResponse.class));
}

/**
Expand Down Expand Up @@ -158,7 +159,7 @@ public AlertDefinitionsResponse getAlertDefinitions(AlertDefinition parent)
params.put("parentId", new String[] { Integer.toString(parent.getId()) });

return doGet("alertdefinition/listDefinitions.hqu", params,
AlertDefinitionsResponse.class);
new XmlResponseHandler<AlertDefinitionsResponse>(AlertDefinitionsResponse.class));
}

/**
Expand All @@ -178,7 +179,7 @@ public AlertDefinitionsResponse getTypeAlertDefinitions(boolean excludeIds)
params.put("excludeIds", new String[] { Boolean.toString(excludeIds)});

return doGet("alertdefinition/listTypeDefinitions.hqu", params,
AlertDefinitionsResponse.class);
new XmlResponseHandler<AlertDefinitionsResponse>(AlertDefinitionsResponse.class));
}

/**
Expand All @@ -198,7 +199,8 @@ public StatusResponse deleteAlertDefinition(int id)

params.put("id", new String[] { Integer.toString(id) });

return doGet("alertdefinition/delete.hqu", params, StatusResponse.class);
return doGet("alertdefinition/delete.hqu", params,
new XmlResponseHandler<StatusResponse>(StatusResponse.class));
}

/**
Expand All @@ -218,6 +220,6 @@ public AlertDefinitionsResponse syncAlertDefinitions(List<AlertDefinition> defin
request.getAlertDefinition().addAll(definitions);

return doPost("alertdefinition/sync.hqu", request,
AlertDefinitionsResponse.class);
new XmlResponseHandler<AlertDefinitionsResponse>(AlertDefinitionsResponse.class));
}
}
13 changes: 8 additions & 5 deletions src/org/hyperic/hq/hqapi1/ApplicationApi.java
Expand Up @@ -35,7 +35,8 @@ public ApplicationsResponse listApplications()
throws IOException
{
Map<String, String[]> params = new HashMap<String, String[]>();
return doGet("application/list.hqu", params, ApplicationsResponse.class);
return doGet("application/list.hqu", params,
new XmlResponseHandler<ApplicationsResponse>(ApplicationsResponse.class));
}

/**
Expand All @@ -55,7 +56,7 @@ public ApplicationResponse createApplication(Application app)
ApplicationRequest appRequest = new ApplicationRequest();
appRequest.setApplication(app);
return doPost("application/create.hqu", appRequest,
ApplicationResponse.class);
new XmlResponseHandler<ApplicationResponse>(ApplicationResponse.class));
}

/**
Expand All @@ -75,7 +76,7 @@ public ApplicationResponse updateApplication(Application app)
ApplicationRequest appRequest = new ApplicationRequest();
appRequest.setApplication(app);
return doPost("application/update.hqu", appRequest,
ApplicationResponse.class);
new XmlResponseHandler<ApplicationResponse>(ApplicationResponse.class));
}

/**
Expand All @@ -93,7 +94,8 @@ public StatusResponse deleteApplication(int id)
{
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("id", new String[] { Integer.toString(id)});
return doGet("application/delete.hqu", params, StatusResponse.class);
return doGet("application/delete.hqu", params,
new XmlResponseHandler<StatusResponse>(StatusResponse.class));
}

/**
Expand All @@ -112,6 +114,7 @@ public ApplicationsResponse syncApplications(List<Application> applications)

ApplicationsRequest applicationsRequest = new ApplicationsRequest();
applicationsRequest.getApplication().addAll(applications);
return doPost("application/sync.hqu", applicationsRequest, ApplicationsResponse.class);
return doPost("application/sync.hqu", applicationsRequest,
new XmlResponseHandler<ApplicationsResponse>(ApplicationsResponse.class));
}
}
6 changes: 4 additions & 2 deletions src/org/hyperic/hq/hqapi1/AutodiscoveryApi.java
Expand Up @@ -27,6 +27,7 @@

package org.hyperic.hq.hqapi1;

import org.hyperic.hq.hqapi1.types.ApplicationsResponse;
import org.hyperic.hq.hqapi1.types.QueueResponse;
import org.hyperic.hq.hqapi1.types.StatusResponse;

Expand Down Expand Up @@ -63,7 +64,7 @@ public QueueResponse getQueue()
throws IOException
{
return doGet("autodiscovery/getQueue.hqu", new HashMap<String,String[]>(),
QueueResponse.class);
new XmlResponseHandler<QueueResponse>(QueueResponse.class));
}

/**
Expand All @@ -84,6 +85,7 @@ public StatusResponse approve(int id)

params.put("id", new String[] { String.valueOf(id) });

return doGet("autodiscovery/approve.hqu", params, StatusResponse.class);
return doGet("autodiscovery/approve.hqu", params,
new XmlResponseHandler<StatusResponse>(StatusResponse.class));
}
}
8 changes: 4 additions & 4 deletions src/org/hyperic/hq/hqapi1/BaseApi.java
Expand Up @@ -49,10 +49,10 @@ abstract class BaseApi {
* parameter may have multiple values.
*/
<T> T doGet(String action, Map<String, String[]> params,
Class<T> resultClass)
ResponseHandler<T> responseHandler)
throws IOException
{
return _conn.doGet(BASE_URI + action, params, resultClass);
return _conn.doGet(BASE_URI + action, params, responseHandler);
}

/**
Expand All @@ -63,9 +63,9 @@ <T> T doGet(String action, Map<String, String[]> params,
* like: '/hqu/hqapi1/user/syncUsers.hqu'
* ex: 'resource/syncResources.hqu'
*/
<T> T doPost(String action, Object o, Class<T> resultClass)
<T> T doPost(String action, Object o, ResponseHandler<T> responseHandler)
throws IOException
{
return _conn.doPost(BASE_URI + action, o, resultClass);
return _conn.doPost(BASE_URI + action, o, responseHandler);
}
}
10 changes: 5 additions & 5 deletions src/org/hyperic/hq/hqapi1/Connection.java
Expand Up @@ -6,7 +6,7 @@

public interface Connection {

<T> T doGet(String path, Map<String, String[]> params, File targetFile, Class<T> resultClass)
<T> T doGet(String path, Map<String, String[]> params, File targetFile, ResponseHandler<T> responseHandler)
throws IOException;

/**
Expand All @@ -24,7 +24,7 @@ <T> T doGet(String path, Map<String, String[]> params, File targetFile, Class<T>
* @throws IOException
* If a network error occurs during the request.
*/
<T> T doGet(String path, Map<String, String[]> params, Class<T> resultClass)
<T> T doGet(String path, Map<String, String[]> params, ResponseHandler<T> responseHandler)
throws IOException;

/**
Expand All @@ -45,7 +45,7 @@ <T> T doGet(String path, Map<String, String[]> params, Class<T> resultClass)
* @throws IOException
* If a network error occurs during the request.
*/
<T> T doPost(String path, Map<String, String[]> params, Class<T> resultClass)
<T> T doPost(String path, Map<String, String[]> params, ResponseHandler<T> responseHandler)
throws IOException;

/**
Expand All @@ -65,7 +65,7 @@ <T> T doPost(String path, Map<String, String[]> params, Class<T> resultClass)
* If a network error occurs during the request.
*/
<T> T doPost(String path, Map<String, String> params, File file,
Class<T> resultClass) throws IOException;
ResponseHandler<T> responseHandler) throws IOException;

/**
* Issue a POST against the API.
Expand All @@ -82,6 +82,6 @@ <T> T doPost(String path, Map<String, String> params, File file,
* @throws IOException
* If a network error occurs during the request.
*/
<T> T doPost(String path, Object o, Class<T> resultClass)
<T> T doPost(String path, Object o, ResponseHandler<T> responseHandler)
throws IOException;
}
10 changes: 7 additions & 3 deletions src/org/hyperic/hq/hqapi1/ControlApi.java
Expand Up @@ -29,6 +29,7 @@

import org.hyperic.hq.hqapi1.types.ControlHistoryResponse;
import org.hyperic.hq.hqapi1.types.Group;
import org.hyperic.hq.hqapi1.types.QueueResponse;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.ControlActionResponse;
import org.hyperic.hq.hqapi1.types.StatusResponse;
Expand Down Expand Up @@ -92,7 +93,8 @@ private ControlHistoryResponse getHistory(Integer resourceId)
Map<String,String[]> params = new HashMap<String,String[]>();
params.put("resourceId", new String[] { Integer.toString(resourceId)});

return doGet("control/history.hqu", params, ControlHistoryResponse.class);
return doGet("control/history.hqu", params,
new XmlResponseHandler<ControlHistoryResponse>(ControlHistoryResponse.class));
}

/**
Expand Down Expand Up @@ -135,7 +137,8 @@ private ControlActionResponse getActions(Integer resourceId)
Map<String,String[]> params = new HashMap<String,String[]>();
params.put("resourceId", new String[] { Integer.toString(resourceId)});

return doGet("control/actions.hqu", params, ControlActionResponse.class);
return doGet("control/actions.hqu", params,
new XmlResponseHandler<ControlActionResponse>(ControlActionResponse.class));
}

/**
Expand Down Expand Up @@ -185,6 +188,7 @@ private StatusResponse executeAction(Integer resourceId, String action,
params.put("action", new String[] { action });
params.put("arguments", arguments);

return doGet("control/execute.hqu", params, StatusResponse.class);
return doGet("control/execute.hqu", params,
new XmlResponseHandler<StatusResponse>(StatusResponse.class));
}
}

0 comments on commit 37917b4

Please sign in to comment.