I want to generate a file in sharepoint online I use this code but I still have an exception java.net.ConnectException: Connection timed out: connect
Any ideas please??
public static CopySoap getPort(String username, String password) {
Copy service = new Copy();
CopySoap port = service.getCopySoap();
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"https://mysite/sites/_vti_bin/Copy.asmx");
return port;
}
public static void createDocument(CopySoap port) throws Exception {
String url = "https://mysite/sites/Documents partages/test.txt";
String sourceUrl = "C:\\TEMP\\test.txt";
File file=new File(sourceUrl);
DestinationUrlCollection urls = new DestinationUrlCollection();
urls.getString().add(url);
byte[] content = readAll(file);
FieldInformation titleInfo = new FieldInformation ();
titleInfo.setDisplayName("Title");
titleInfo.setType(FieldType.TEXT);
titleInfo.setValue("Test Doc");
FieldInformationCollection infos = new FieldInformationCollection ();
infos.getFieldInformation().add(titleInfo);
CopyResultCollection results = new CopyResultCollection ();
Holder<CopyResultCollection> resultHolder = new Holder<CopyResultCollection>(results);
Holder<Long> longHolder = new Holder<Long>(new Long(-1));
port.copyIntoItems(sourceUrl, urls, infos, content, longHolder, resultHolder);
logger.debug("Long holder: " + longHolder.value);
//do something meaningful here
for (CopyResult copyResult : resultHolder.value.getCopyResult()) {
logger.debug("Destination: " + copyResult.getDestinationUrl());
logger.debug("Error Message: " + copyResult.getErrorMessage());
logger.debug("Error Code: " + copyResult.getErrorCode());
if(copyResult.getErrorCode() != CopyErrorCode.SUCCESS)
throw new Exception("Upload failed for: " + copyResult.getDestinationUrl() + " Message: "
+ copyResult.getErrorMessage() + " Code: " + copyResult.getErrorCode() );
}
Related
I am getting java.net.ConnectException:connection refused error while trying to write junit for creating object in gcs using fake-gcs-server image. Please find the below code. Bucket name is test and consider, it is already created.
#TempDir
private static File directory;
private static final GenericContainer<?> GCS_CONTAINER = new GenericContainer<>(DockerImageName.parse("fsouza/fake-gcs-server:1.33.1"))
.withExposedPorts(4443).withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint(
"/bin/fake-gcs-server",
"-scheme", "http"
));
String fakeGcsExternalUrl = "http://" + GCS_CONTAINER.getContainerIpAddress() + ":" + GCS_CONTAINER.getFirstMappedPort();
private static final Storage storage = new Storage.Builder(getTransport(), GsonFactory.getDefaultInstance(), null).setRootUrl(fakeGcsExternalUrl).setApplicationName("test").build();
void test() {
final File localFile1 = new File(directory.getAbsolutePath() + File.separator + "testFile.txt");
localFile1.createNewFile();
try (final FileWriter fileWriter = new FileWriter(localFile1.getPath())) {
fileWriter.write("Test gs file content");
}
final InputStream stream = FileUtils.openInputStream(localFile1);
Path path = localFile1.toPath();
String contentType = Files.probeContentType(path);
uploadFile("test", "/sampleFiles/newFile.txt", contentType, stream, null);
}
public String uploadFile(final Storage storage, final String bucketName, final String filePath,
final String contentType, final InputStream inputStream, final Map<String, String> metadata)
throws IOException {
final InputStreamContent contentStream = new InputStreamContent(contentType, inputStream);
final StorageObject objectMetadata = new StorageObject().setName(filePath);
objectMetadata.setMetadata(GoogleLabels.manageLabels(metadata));
final Storage.Objects.Insert insertRequest = storage.objects().insert(bucketName, objectMetadata,
contentStream);
return insertRequest.execute().getName();
}
This problem might be related to you omitting to set the fake-gcs-server's external URL property to the container's address. Make sure you follow guide in the official repo https://github.com/fsouza/fake-gcs-server/blob/cf3fcb083e19553636419818e29f84825bd1e13c/examples/java/README.md, particularly, that you execute the following code:
private static void updateExternalUrlWithContainerUrl(String fakeGcsExternalUrl) throws Exception {
String modifyExternalUrlRequestUri = fakeGcsExternalUrl + "/_internal/config";
String updateExternalUrlJson = "{"
+ "\"externalUrl\": \"" + fakeGcsExternalUrl + "\""
+ "}";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(modifyExternalUrlRequestUri))
.header("Content-Type", "application/json")
.PUT(BodyPublishers.ofString(updateExternalUrlJson))
.build();
HttpResponse<Void> response = HttpClient.newBuilder().build()
.send(req, BodyHandlers.discarding());
if (response.statusCode() != 200) {
throw new RuntimeException(
"error updating fake-gcs-server with external url, response status code " + response.statusCode() + " != 200");
}
}
before using the container.
I have a java project in Eclipse which was written by some other developer. I am very new to Java and have made some modifications in the source code. Now i want to test the code by executing it in eclipse. How can I create a main class and execute the modified code.
Following is the class file which I want to run
public class Bio_Verify extends AbstractOutboundServiceProvider
{
public static String EndPointURL = null;
public static String ApiKey = null;
public static String Version = null;
public static String EntityId = null;
public static String requestId = null;
public static String EncryptionKey = null;
public static String SignatureKey = null;
public static String SignAlgorithm = null;
public String requestData = null;
public String requestXML = null;
public String response = null;;
public String errorMsg;
public void preprocess(IUsbMessage inputMsg)
{
LogManager.logDebug("Bio_Verify: preprocess():: inside preprocess");
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: START");
}
public IUsbMessage executeOutboundRequest(String inputMsg)
{
int i = 0;
int j = 0;
String resolution = null;
String key = null;
String criteria = null;
String position = null;
String format = null;
String data = null;
String intent = null;
String resBodyXML = null;
String outputXMLMsg = null;
String[] responseMsg = new String[2];
IUsbMessage outMsg = null;
Verify verify = new Verify();
Fingerprint fingerprint = new Fingerprint();
requestData = "CN01473|cif|UNKNOWN_FINGER|508|BMP|Qk12WeoAAAA=|verify";
//Forming requestId for Bio
Date date = Calendar.getInstance().getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
requestId = dateFormat.format(date);
EndPointURL = OutboundConstants.Bio_Endpoint;
ApiKey = OutboundConstants.ApiKey;
Version = OutboundConstants.Version;
EntityId = OutboundConstants.EntityId;
EncryptionKey = OutboundConstants.EncryptionKey;
SignAlgorithm = OutboundConstants.SignAlgorithm;
SignatureKey = OutboundConstants.SignatureKey;
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Bio_Endpoint URL is " + EndPointURL);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Api Key is " + ApiKey);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Version is " + Version);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: EntityId is " + EntityId);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: EncryptionKey is " + EncryptionKey);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: SignatureKey is " + SignatureKey);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: SignAlgorithm is " + SignAlgorithm);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Request Id is " + requestId);
//Extraction data from the request XML
for(i=0;i<7;i++){
int x = requestData.indexOf("|");
int y = requestData.length();
if(i==0){
key = requestData.substring(0, x);
LogManager.logDebug("Key: "+key);
requestData = requestData.substring(x+1,y);
}
if(i==1){
criteria = requestData.substring(0, x);
LogManager.logDebug("Criteria: "+criteria);
requestData = requestData.substring(x+1,y);
}
if(i==2){
position = requestData.substring(0, x);
LogManager.logDebug("Position: "+position);
requestData = requestData.substring(x+1,y);
}
if(i==3){
format = requestData.substring(0, x);
LogManager.logDebug("Format: "+format);
requestData = requestData.substring(x+1,y);
}
if(i==4){
resolution = requestData.substring(0, x);
LogManager.logDebug("Resolution: "+resolution);
requestData = requestData.substring(x+1,y);
}
if(i==5){
data = requestData.substring(0, x);
requestData = requestData.substring(x+1,y);
}
if(i==6){
intent = requestData;
LogManager.logDebug("Intent: "+intent);
}
}
FingerprintImage fingerprintimage = new FingerprintImage(format,resolution,data);
fingerprint.image = fingerprintimage;
fingerprint.position = position;
responseMsg = verify.verify(key, criteria, fingerprint, intent);
this.errorMsg = responseMsg[0];
this.response = responseMsg[1];
LogManager.logDebug("Back in bio verify - array element1"+this.errorMsg);
LogManager.logDebug("Back in bio verify - array element2"+this.response);
outMsg = UsbMessageFactory.createUbusMessage();
outMsg.setMsgType("XML");
outMsg.setMsgSubType("FIXML");
LogManager.logDebug("Bio: executeOutboundRequest():: errorMsg=" + errorMsg);
if (errorMsg.toString().trim().length() > 0)
{
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Inside FAILURE");
outMsg.setBackEndTranStatus("FAILURE");
outMsg.setErrMsgFlg(1);
outMsg.setPayload(new Object[] { new CIFatalException(errorMsg.toString()) });
}
else
{
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: Inside SUCCESS");
outMsg.setBackEndTranStatus("SUCCESS");
outMsg.setErrMsgFlg(0);
resBodyXML = this.response.toString();
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: outputXMLMsg XML:" + outputXMLMsg);
outMsg.setPayload(new Object[] { outputXMLMsg });
}
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: outMsg:" + outMsg);
LogManager.logDebug("Bio_Verify: executeOutboundRequest():: END");
return outMsg;
}
Can you follow the steps , this will help to you
There are 6 steps are below added ( I think you will get idea how to archive your problem )
1.Right click inside package and you can see CLASS then it will pop up this attached window
2. Insight Main method you can crate some object like I have created and pass parameter what you want (You just understand what method you have to call )
You have to write main function into Bio_Verify class.
main function is boot function.
So if you write main function, you can execute this class.
ex)
public class BioVerify extends AbstractOutboundServiceProvider {
public static void main(String[] args) {
// TODO: Write a code....
}
}
write the main function below to the code and create object for BIO_verify class and it's function
Below is the code Snippet.. that must call WSDL in other server dynamically
but in the moment of calling
(int i = webServiceModuleService.notificationRecieved("xyz");)
returned exception :(
note: i haven't any beaInvoke method in my service :|
public static void main(String[] args) {
java.sql.Connection conn = null;
InitialContext context;
try {
context = new InitialContext();
DataSource ds = (DataSource) context.lookup("jdbc/dataSourceDS");
conn = ds.getConnection();
} catch (SQLException e) {
} catch (NamingException e) {
}
QueryRunner run = new QueryRunner();
SampleResultSetHandler h = new SampleResultSetHandler();
Object[] res = null;
try {
res = run.query(conn, "select SERVER_IP,SERVER_PORT from SERVER where UPPER(SERVER_NAME)=? ", h, "test");
} catch (SQLException e) {
}
String ip = res[0].toString();
String port = res[1].toString();
String endpointURL = "http://" + ip + ":" + port + "/context-root/WebServiceModuleService";
try {
URL tmpURL = new URL(endpointURL + "?wsdl");
System.err.println(tmpURL);
WebServiceModuleService_Service webServiceModuleService_Service = new WebServiceModuleService_Service(tmpURL,
new QName("/org/parsisys/test/mina/model/services/common/",
"WebServiceModuleService"));
WebServiceModuleService webServiceModuleService = null;
webServiceModuleService = webServiceModuleService_Service.getWebServiceModuleServiceSoapHttpPort();
BindingProvider bp = (BindingProvider) webServiceModuleService;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
// Configure credential providers
Map<String, Object> requestContext = ((BindingProvider) webServiceModuleService).getRequestContext();
try {
setPortCredentialProviderList(requestContext);
} catch (Exception ex) {
ex.printStackTrace();
}
//Call WebService ... ==> Exception :(
int i = webServiceModuleService.notificationRecieved("xyz");
//logp("successfully call the webservice for [ip&port:" + ip + ":" + port + "] [transid : " +transid + "]");
} catch (Exception e) {
//log
//TODO: Clean This
System.err.println(e.getMessage());
e.printStackTrace();
return;
}
}
#Generated("Oracle JDeveloper")
public static void setPortCredentialProviderList(Map<String, Object> requestContext) throws Exception {
// TODO - Provide the required credential values
String username = "";
String password = "";
String clientKeyStore = "";
String clientKeyStorePassword = "";
String clientKeyAlias = "";
String clientKeyPassword = "";
String serverKeyStore = "";
String serverKeyStorePassword = "";
String serverKeyAlias = "";
List<CredentialProvider> credList = new ArrayList<CredentialProvider>();
// Add the necessary credential providers to the list
// Code commented out due to empty username/password value found in the credential.
// credList.add(getUNTCredentialProvider(username, password));
// Code commented out due to empty server keystore value found in the credential.
// credList.add(getBSTCredentialProvider(clientKeyStore, clientKeyStorePassword, clientKeyAlias, clientKeyPassword, serverKeyStore, serverKeyStorePassword, serverKeyAlias, requestContext));
credList.add(getSAMLTrustCredentialProvider());
requestContext.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credList);
}
#Generated("Oracle JDeveloper")
public static CredentialProvider getSAMLTrustCredentialProvider() {
return new SAMLTrustCredentialProvider();
}
daynamic webservice call is generated with jdeveloper and it's works in clien't tester but in my module when i call webservice return exception :/
StackTrace is: ↓
Method beaInvoke is exposed as WebMethod, but there is no corresponding wsdl operation with name {/org/parsisys/test/mina/model/services/common/}beaInvoke in the wsdl:portType{/org/parsisys/test/mina/model/services/common/}WebServiceModuleService
javax.xml.ws.WebServiceException: Method beaInvoke is exposed as WebMethod, but there is no corresponding wsdl operation with name {/org/parsisys/test/mina/model/services/common/}beaInvoke in the wsdl:portType{/org/parsisys/test/mina/model/services/common/}WebServiceModuleService
at com.sun.xml.ws.model.JavaMethodImpl.freeze(JavaMethodImpl.java:382)
at com.sun.xml.ws.model.AbstractSEIModelImpl.freeze(AbstractSEIModelImpl.java:124)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:336)
at com.sun.xml.ws.db.DatabindingImpl.(DatabindingImpl.java:99)
at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:74)
at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:58)
at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:120)
at com.sun.xml.ws.client.WSServiceDelegate.buildRuntimeModel(WSServiceDelegate.java:882)
at com.sun.xml.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:899)
at com.sun.xml.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:862)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:451)
at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegateImpl.internalGetPort(WLSProvider.java:1698)
at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegateImpl$PortClientInstanceFactory.createClientInstance(WLSProvider.java:1769)
at weblogic.wsee.jaxws.spi.ClientInstancePool.takeSimpleClientInstance(ClientInstancePool.java:389)
at weblogic.wsee.jaxws.spi.ClientInstancePool.take(ClientInstancePool.java:243)
at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegateImpl$3.apply(WLSProvider.java:1555)
at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegateImpl$3.apply(WLSProvider.java:1517)
at weblogic.wsee.jaxws.spi.ClientIdentityRegistry.initClientIdentityFeatureAndCall(ClientIdentityRegistry.java:1456)
at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegateImpl.getPort(WLSProvider.java:1513)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:420)
at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegateImpl.getPort(WLSProvider.java:1477)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:402)
at javax.xml.ws.Service.getPort(Service.java:119)
at org.parsisys.test.mina.model.service.WebServiceModuleService_Service.beaInvokeSuper(WebServiceModuleService_Service.java)
at org.parsisys.test.mina.model.service.WebServiceModuleService_Service$beaVersion0_31.getWebServiceModuleServiceSoapHttpPort(WebServiceModuleService_Service.java:51)
at org.parsisys.test.mina.model.service.WebServiceModuleService_Service.getWebServiceModuleServiceSoapHttpPort(WebServiceModuleService_Service.java)
at org.parsisys.test.mina.files.notification.queue.NotificationQueueRecieved$beaVersion0_11.onMessage(NotificationQueueRecieved.java:330)
at org.parsisys.test.mina.files.notification.queue.NotificationQueueRecieved.onMessage(NotificationQueueRecieved.java)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:5107)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:4775)
at weblogic.jms.client.JMSSession.executeMessage(JMSSession.java:4170)
at weblogic.jms.client.JMSSession.access$000(JMSSession.java:127)
at weblogic.jms.client.JMSSession$UseForRunnable.run(JMSSession.java:5627)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:666)
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)
please help me. tnx
For me this occurs when the WSDL does not agree with the generated classes.
I want to send image files (jpg, png) to NAS server in java using smb
I have added the jcifs-1.3.19.jar. as mentioned here and here
Edit: I have successfully sent jpeg image to a shared folder on server using this code, but the speed is very slow, its sending almost 1kb/second. Any Solution??
static final String USER_NAME = "Waqas";
static final String PASSWORD = "mypass";
static final String NETWORK_FOLDER = "smb://DESKTOP-LAP/Users/Waqas/";
public boolean copyFiles(FileInputStream file, String fileName) {
boolean successful = false;
int cursor;
SmbFileOutputStream sfos;
SmbFile sFile;
String path;
NtlmPasswordAuthentication auth;
try{
String user = USER_NAME + ":" + PASSWORD;
auth = new NtlmPasswordAuthentication(user);
StrictMode.ThreadPolicy tp = StrictMode.ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);
path = NETWORK_FOLDER + fileName;
sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);
while((cursor = file.read())!=-1){
sfos.write(cursor);
}
successful = true;
System.out.println("Successful " + successful);
}
catch (Exception e) {
successful = false;
e.printStackTrace();
}
return successful;
}
Finally here is the solution:
public boolean copyFiles(FileInputStream file, String fileName) {
boolean successful = false;
int cursor;
SmbFileOutputStream sfos;
SmbFile sFile;
String path;
NtlmPasswordAuthentication auth;
try{
String user = USER_NAME + ":" + PASSWORD;
System.out.println("User: " + user);
auth = new NtlmPasswordAuthentication(user);
StrictMode.ThreadPolicy tp = StrictMode.ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);
path = NETWORK_FOLDER + fileName+".jpeg";
System.out.println("Path: " +path);
sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);
long t0 = System.currentTimeMillis();
byte[] b = new byte[8192];
int n, tot = 0;
Log.d("asdf","initiating : total="+tot);
while((n = file.read(b))>0){
sfos.write( b, 0, n );
tot += n;
Log.d("asdf","writing : total="+tot);
}
successful = true;
Log.d("asdf","Successful : total="+tot);
}
catch (Exception e) {
successful = false;
e.printStackTrace();
Log.d("asdf","exxeption ");
}
return successful;
}
I'm trying to send a trap v1 using snmp4j. It doesn't throwns any exception and execute everything, but the trap is not reaching its destiny. Am I missing something? Is there another way to do it? The IP and the ports in the code are corrects. What would be wrong?
Here's the code:
public class SNMPv1 {
public static final String community = "public";
public static final String trapOid = ".1.3.6.1.4.1.2595.1.2";
public static final String ipAddress = "10.200.1.220";
public static final String agentIPAddress = "10.200.1.120";
public static final int port = 164;
private static final int specificTrap = 1;
public static void main(String[] args)
{
SNMPv1 snmp4JTrap = new SNMPv1();
/* Sending V1 Trap */
snmp4JTrap.sendSnmpV1Trap();
}
public void sendSnmpV1Trap()
{
try
{
//Create Transport Mapping
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
//Create Target
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(community));
comtarget.setVersion(SnmpConstants.version1);
comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
comtarget.setRetries(4);
comtarget.setTimeout(10000);
//Create PDU for V1
PDUv1 pdu = new PDUv1();
pdu.setType(PDU.V1TRAP);
pdu.setEnterprise(new OID(trapOid));
pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC); // 6
pdu.setSpecificTrap(specificTrap);
pdu.setAgentAddress(new IpAddress(agentIPAddress));
VariableBinding v = new VariableBinding();
v.setOid(SnmpConstants.sysName);
v.setVariable(new OctetString("Param1"));
pdu.add(v);
VariableBinding v2 = new VariableBinding();
v2.setOid(SnmpConstants.sysName);
v2.setVariable(new OctetString("Param2"));
pdu.add(v2);
VariableBinding v3 = new VariableBinding();
v3.setOid(SnmpConstants.sysName);
v3.setVariable(new OctetString("Param3"));
pdu.add(v3);
VariableBinding v4 = new VariableBinding();
v4.setOid(SnmpConstants.sysName);
v4.setVariable(new OctetString("Param4"));
pdu.add(v4);
VariableBinding v5 = new VariableBinding();
v5.setOid(SnmpConstants.sysName);
v5.setVariable(new OctetString("Param5"));
pdu.add(v5);
VariableBinding v6 = new VariableBinding();
v6.setOid(SnmpConstants.sysName);
v6.setVariable(new OctetString("Param6"));
pdu.add(v6);
//Send the PDU
Snmp snmp = new Snmp(transport);
System.out.println("Sending trap to" + ipAddress + ":" + port);
snmp.send(pdu, comtarget);
snmp.close();
System.out.println("Trap send successfully!!");
}
catch (Exception e)
{
System.err.println("Error sending Trap to " + ipAddress + ":" + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
}