You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by lh...@apache.org on 2008/10/17 17:34:50 UTC
svn commit: r705644 - in
/servicemix/components/bindings/servicemix-snmp/trunk/src:
main/java/org/apache/servicemix/snmp/
main/java/org/apache/servicemix/snmp/util/
test/java/org/apache/servicemix/snmp/ test/resources/
Author: lhein
Date: Fri Oct 17 08:34:49 2008
New Revision: 705644
URL: http://svn.apache.org/viewvc?rev=705644&view=rev
Log:
- implemented some improvements for the oid handling
Added:
servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/
servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDList.java (with props)
servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDListEditor.java (with props)
Modified:
servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/SnmpPollingEndpoint.java
servicemix/components/bindings/servicemix-snmp/trunk/src/test/java/org/apache/servicemix/snmp/SnmpPollingEndpointTest.java
servicemix/components/bindings/servicemix-snmp/trunk/src/test/resources/spring-polling.xml
Modified: servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/SnmpPollingEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/SnmpPollingEndpoint.java?rev=705644&r1=705643&r2=705644&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/SnmpPollingEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/SnmpPollingEndpoint.java Fri Oct 17 08:34:49 2008
@@ -16,12 +16,6 @@
*/
package org.apache.servicemix.snmp;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.List;
-import java.util.Vector;
-
import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.MessageExchange;
@@ -33,6 +27,7 @@
import org.apache.servicemix.common.endpoints.PollingEndpoint;
import org.apache.servicemix.snmp.marshaler.DefaultSnmpMarshaler;
import org.apache.servicemix.snmp.marshaler.SnmpMarshalerSupport;
+import org.apache.servicemix.snmp.util.OIDList;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
@@ -50,7 +45,6 @@
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;
-import org.springframework.core.io.Resource;
/**
* This is the polling endpoint for the snmp component.
@@ -66,7 +60,6 @@
public static final int DEFAULT_SNMP_RETRIES = 2;
public static final int DEFAULT_SNMP_TIMEOUT = 1500;
- private List<OID> objectsOfInterest = new Vector<OID>();
private Address targetAddress;
private TransportMapping transport;
private Snmp snmp;
@@ -74,12 +67,12 @@
private CommunityTarget target;
private PDU pdu;
+ private OIDList oids = new OIDList();
private String address;
private int retries = DEFAULT_SNMP_RETRIES;
private int timeout = DEFAULT_SNMP_TIMEOUT;
private int snmpVersion = DEFAULT_SNMP_VERSION;
private String snmpCommunity = DEFAULT_COMMUNITY;
- private Resource file;
private SnmpMarshalerSupport marshaler = new DefaultSnmpMarshaler();
@@ -157,42 +150,10 @@
throw new DeploymentException("The specified address " + address + " is not valid!");
}
- // check if the oid file is valid
- if (this.file != null) {
- if (this.file.exists()) {
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(this.file.getFile()));
- String line = null;
- while ((line = br.readLine()) != null) {
- this.objectsOfInterest.add(new OID(line.trim()));
- LOG.debug(getEndpoint() + ": Added new OID : " + line.trim());
- }
- } catch (IOException ex) {
- LOG.error("Error reading contents of file " + file.getFilename(), ex);
- throw new DeploymentException("The specified file " + file.getFilename() + " can't be read!");
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (IOException ex) {
- LOG.error("Error closing file " + file.getFilename(), ex);
- }
- }
- }
- } else {
- // the specified resource file is not existing
- throw new DeploymentException("The specified file " + file.getFilename() + " does not exists!");
- }
- } else {
- // no file defined - poller would have nothing to do
- throw new DeploymentException("The file attribute has to be specified!");
- }
-
// finally check if the oid vector contains values
- if (this.objectsOfInterest == null || this.objectsOfInterest.size()<=0) {
+ if (this.oids == null || this.oids.size()<=0) {
// the poller would be unemployed
- throw new DeploymentException("There are no OIDs defined to be polled. Check your OID file.");
+ throw new DeploymentException("There are no OIDs defined to be polled. Check your oids attribute.");
}
}
@@ -206,7 +167,7 @@
this.pdu.setType(PDU.GET);
// prepare the request items
- for (OID oid : objectsOfInterest) {
+ for (OID oid : oids) {
this.pdu.add(new VariableBinding(oid));
}
@@ -366,16 +327,16 @@
this.marshaler = marshaler;
}
- /** * @return Returns the file.
+ /** * @return Returns the oids.
*/
- public Resource getFile() {
- return this.file;
+ public OIDList getOids() {
+ return this.oids;
}
/**
- * @param file The file to set.
+ * @param oids The oids to set.
*/
- public void setFile(Resource file) {
- this.file = file;
+ public void setOids(OIDList oids) {
+ this.oids = oids;
}
}
Added: servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDList.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDList.java?rev=705644&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDList.java (added)
+++ servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDList.java Fri Oct 17 08:34:49 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.snmp.util;
+
+import java.util.LinkedList;
+
+import org.snmp4j.smi.OID;
+
+/**
+ * @author lhein
+ */
+public class OIDList extends LinkedList<OID>{
+ private static final long serialVersionUID = -1553501343342083407L;
+}
Propchange: servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDList.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDListEditor.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDListEditor.java?rev=705644&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDListEditor.java (added)
+++ servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDListEditor.java Fri Oct 17 08:34:49 2008
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.snmp.util;
+
+import java.beans.PropertyEditorSupport;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.StringTokenizer;
+
+import org.snmp4j.smi.OID;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+
+/**
+ * @author lhein
+ */
+public class OIDListEditor extends PropertyEditorSupport {
+
+ /* (non-Javadoc)
+ * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
+ */
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ OIDList list = new OIDList();
+ if (text.indexOf(",") != -1) {
+ // seems to be a comma separated oid list
+ StringTokenizer strTok = new StringTokenizer(text, ",");
+ while (strTok.hasMoreTokens()) {
+ String tok = strTok.nextToken();
+ if (tok != null && tok.trim().length()>0) {
+ list.add(new OID(tok.trim()));
+ } else {
+ // empty token - skip
+ }
+ }
+ } else {
+ // seems to be a file resource
+ try {
+ DefaultResourceLoader loader = new DefaultResourceLoader();
+ Resource file = loader.getResource(text);
+
+ if (file.exists()) {
+ BufferedReader br = null;
+ try {
+ br = new BufferedReader(new FileReader(file.getFile()));
+ String line = null;
+ while ((line = br.readLine()) != null) {
+ list.add(new OID(line.trim()));
+ }
+ } catch (IOException ex) {
+ throw new IllegalArgumentException(text + " is not a valid argument.", ex);
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException ex) {
+ // ignore
+ }
+ }
+ }
+ } else {
+ // the specified resource file is not existing
+ throw new IllegalArgumentException(text + " is not a valid argument.");
+ }
+ } catch (Exception ex) {
+ throw new IllegalArgumentException(text + " is not a valid argument.", ex);
+ }
+ }
+ setValue(list);
+ }
+}
Propchange: servicemix/components/bindings/servicemix-snmp/trunk/src/main/java/org/apache/servicemix/snmp/util/OIDListEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: servicemix/components/bindings/servicemix-snmp/trunk/src/test/java/org/apache/servicemix/snmp/SnmpPollingEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-snmp/trunk/src/test/java/org/apache/servicemix/snmp/SnmpPollingEndpointTest.java?rev=705644&r1=705643&r2=705644&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-snmp/trunk/src/test/java/org/apache/servicemix/snmp/SnmpPollingEndpointTest.java (original)
+++ servicemix/components/bindings/servicemix-snmp/trunk/src/test/java/org/apache/servicemix/snmp/SnmpPollingEndpointTest.java Fri Oct 17 08:34:49 2008
@@ -39,7 +39,7 @@
* sets up an endpoint and waits 30 seconds for a incoming snmp message
* @throws Exception
*/
- public void xtestPolling() throws Exception {
+ public void testPolling() throws Exception {
long waitTime = System.currentTimeMillis();
Receiver receiver = (Receiver) getBean("receiver");
Modified: servicemix/components/bindings/servicemix-snmp/trunk/src/test/resources/spring-polling.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-snmp/trunk/src/test/resources/spring-polling.xml?rev=705644&r1=705643&r2=705644&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-snmp/trunk/src/test/resources/spring-polling.xml (original)
+++ servicemix/components/bindings/servicemix-snmp/trunk/src/test/resources/spring-polling.xml Fri Oct 17 08:34:49 2008
@@ -32,8 +32,8 @@
<snmp:poller service="test:poller"
endpoint="poller"
targetService="test:receiver"
- address="udp:127.0.0.1/161"
- file="classpath:oids.txt"
+ address="udp:172.20.16.62/161"
+ oids="classpath:oids.txt"
period="1000" />
</snmp:endpoints>
</snmp:component>