OutOfMemory Issue - java

I tried to run the software tests already created in ellipse and now this error appears, any solution?
Logger logger = Logger.getLogger("");
logger.setLevel(Level.OFF);
//Remove as mensagens do chromedriver na consola (e no output)
System.out.println(String.format("%n%n", char.class));
SimpleDateFormat dateTimeInGMT = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
System.out.println("--> Teste executado no dia --> " + dateTimeInGMT.format(new Date()));
StringBuilder sb = new StringBuilder();
String str = "";
try {
String filename = "C:\\Eclipse\\eclipse\\fs.txt";
FileWriter fw = new FileWriter(filename, true);
// fw.write(dateTimeInGMT.format(new Date()));
fw.close();
BufferedReader br = new BufferedReader(new FileReader("C:\\Eclipse\\eclipse\\fs.txt"));
// read the file content
while (str != null) {
sb.append(str);
sb.append(System.lineSeparator());
str = br.readLine();
System.out.println(str);
}
br.close();
} catch (IOException ioe) {
System.out.println(ioe);
}
// TODO Auto-generated method stub
System.out.println("starting");
int tests = 0;
int success = 0;
int failed = 0;
List<Pair<String, String>> faileds = new ArrayList<>();
List<String> testsNames = new ArrayList<String>();
testsNames.add("UC2Login");
// testsNames.add("UC5consultarPerfil");
// testsNames.add("UC16CriarPaciente");
for (String classi : testsNames) {
try {
System.out.println("runnnig " + classi);
Class<?> c = Class.forName("casosUso." + classi);
Method method = c.getDeclaredMethod("start");
Object d = c.newInstance();
tests++;
#SuppressWarnings("unchecked")
Pair<Boolean, String> result = (Pair<Boolean, String>) method.invoke(d);
if (result.getKey()) {
success++;
} else {
failed++;
faileds.add(new Pair<String, String>(classi, result.getValue()));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("\n\n\n\n ==== REPORT ====");
System.out.println(String.format("resume -> tests:%d success:%d failed:%d", tests, success, failed));
for (Pair<String, String> pair : faileds) {
System.out.println(String.format("%s - %s : %n%n", pair.getKey(), pair.getValue()));
}
}
--> Teste executado no dia --> 27-mai-2019 11:36:20
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source)
at java.lang.AbstractStringBuilder.append(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at casosUso.Main1.main(Main1.java:44)

Related

Calling as400 system from Java

I am calling as400 system from Java. I am able to connect to a program of as400 system but not able to get the output data. It is giving me empty message.
AS400 as400 = new AS400("as242g.na.sysco.net", "dprint", "dprint");
System.out.println(as400);
ProgramParameter[] parameters=new ProgramParameter[4];
AS400Text opcoText=new AS400Text(3,as400);
AS400Text emoptyText=new AS400Text(1,as400);
AS400Text indicatorText=new AS400Text(1,as400);
parameters[0]=new ProgramParameter(opcoText.toBytes("056"));
parameters[1]=new ProgramParameter(emoptyText.toBytes(" "));
parameters[2]=new ProgramParameter(indicatorText.toBytes("Y"));
parameters[3] = new ProgramParameter(10);
String fullProgramName = "/QSYS.LIB/SCSUINT.LIB/DPIM10CL.PGM";
System.out.println(fullProgramName);
ProgramCall programCall=new ProgramCall(as400);
try {
programCall.setProgram(fullProgramName,parameters);
if (programCall.run()) {
System.out.println("run");
AS400Text text1 = new AS400Text(10,as400);
String message=(String) text1.toObject(parameters[3].getOutputData());
System.out.println(message);
}
else {
System.out.println("false");
}
} catch (PropertyVetoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AS400SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ErrorCompletingRequestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ObjectDoesNotExistException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Could someone please help what changes need to be done to get the desired output result

opencv java Error loading class org/bytedeco/javacpp/Loader. snapshot from video

i am trying to generate a snapshot from a video using the following code. and it is working fine running as a java application on sts.
public class VideoThumbTaker {
public static void main(String[] args)
{
FFmpegFrameGrabber g = new FFmpegFrameGrabber("/home/anupam/Downloads/jk.mp4");
g.setFormat("mp4");
try {
g.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0 ; i < 1 ; i++) {
try {
ImageIO.write(g.grab().getBufferedImage(), "png", new File("/home/anupam/Downloads/" + System.currentTimeMillis() + ".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
g.stop();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
using maven dependency
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>0.8</version>
</dependency>
after deploying a war file.the following code gives Error loading class org/bytedeco/javacpp/Loader
#RequestMapping(value = "menu9data", method = RequestMethod.POST)
public JSONObject view(#RequestPart(name = "file", required = false) MultipartFile image,#Valid MenuData model, BindingResult results) {
String name1;
FFmpegFrameGrabber g = new FFmpegFrameGrabber("/home/anupam/Downloads/"+name1); //Error
g.setFormat("mp4");
try {
System.out.println("enterss");
g.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0 ; i < 1 ; i++) {
/* try {
// ImageIO.write(((Object) g.grab()).getBufferedImage(), "png", new File("/home/anupam/Downloads/"+name1+"snap"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
try {
g.stop();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Error accessing Cassandra MBeans from Java

I'm trying to access the messaging metrics provided by Cassandra from Java using JMX. I get the correct results when I use the following query with swiss java knife
java -jar sjk-plus-0.4.2.jar mx -s localhost:7100 -mg -all -b org.apache.cassandra.metrics:type=Messaging,name=* -f Mean
org.apache.cassandra.metrics:type=Messaging,name=CrossNodeLatency
1331.0469921040174
org.apache.cassandra.metrics:type=Messaging,name=datacenter1-Latency
1331.1071897694487
However, with the following Java code I get a javax.management.InstanceNotFoundException: org.apache.cassandra.metrics:type=Messaging exception.
JMXServiceURL url = null;
try {
url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:7100/jmxrmi");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JMXConnector mConnector = null;
try {
mConnector = JMXConnectorFactory.connect(url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MBeanServerConnection mMBSC = null;
try {
mMBSC = mConnector.getMBeanServerConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ObjectName mObjectName = null;
try {
mObjectName = new ObjectName("org.apache.cassandra.metrics:type=Messaging");
} catch (MalformedObjectNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Set<ObjectName> myMbean = null;
try {
myMbean = mMBSC.queryNames(mObjectName, null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
System.out.println((mMBSC.getAttribute(mObjectName, "*")).toString());
} catch (AttributeNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstanceNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MBeanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ReflectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Could someone please explain where am I making a mistake?
Swiss Java Knife seems to accept an ObjectName wildcard (or pattern) as:
org.apache.cassandra.metrics:type=Messaging,name=*
but your code is simply looking up a non-pattern MBean as:
org.apache.cassandra.metrics:type=Messaging
Change your code to:
Use the pattern
queryNames will return a Set of matching ObjectNames, so iterate through the set and query each one.
You need to specify a string array of actual MBean attribute names, not "*" as in your code. (It would be nice if that was supported)
Something like:
mObjectName = new ObjectName("org.apache.cassandra.metrics:type=Messaging,name=*");
Set<ObjectName> names = mMBSC.queryNames(mObjectName, null);
for(ObjectName on: names) {
System.out.println(on + "\n" + mMBSC.getAttribute(on, "Mean").toString());
}

How to resolve error of certificate while accessing vcenter using java?

I am using vmware API. By using this API I am able to get information of ESX devices. Now I want to get information about vcenter using this API, but get exception "Java.rmi.remoteException: VI SDK Invoke exception : javax.net.ssl.SSLHandShakeException: java.security."
Here is a code:
public void realesx(){
System.out.println("Running ESX Realtime for host ..."+host);
JSONObject esxcmdout = new JSONObject();
String url = "https://" + host + "/sdk/vimService";
try {
ServiceInstance si = new ServiceInstance(new URL(url), user, pass,true);
System.out.println("host :"+host+"---"+si.getAboutInfo().getFullName());
System.out.println(" Version is .. " +si.getAboutInfo().version);
System.out.println(" os type is .. " +si.getAboutInfo().osType);
System.out.println("Vendor is .. " + si.getAboutInfo().vendor);
System.out.println("name is" + si.getAboutInfo().name);
try{
esxcmdout.put("vmWayerVersion", si.getAboutInfo().version);
esxcmdout.put("vmWayerOSType", si.getAboutInfo().osType);
esxcmdout.put("vmWayerVendor", si.getAboutInfo().vendor);
esxcmdout.put("vmWayerName", si.getpublic void realesx(){
System.out.println("Running ESX Realtime for host ..."+host);
JSONObject esxcmdout = new JSONObject();
String url = "https://" + host + "/sdk/vimService";
try {
ServiceInstance si = new ServiceInstance(new URL(url), user, pass,true);
System.out.println("host :"+host+"---"+si.getAboutInfo().getFullName());
System.out.println(" Version is .. " +si.getAboutInfo().version);
System.out.println(" os type is .. " +si.getAboutInfo().osType);
System.out.println("Vendor is .. " + si.getAboutInfo().vendor);
System.out.println("name is" + si.getAboutInfo().name);
try{
esxcmdout.put("vmWayerVersion", si.getAboutInfo().version);
esxcmdout.put("vmWayerOSType", si.getAboutInfo().osType);
esxcmdout.put("vmWayerVendor", si.getAboutInfo().vendor);
esxcmdout.put("vmWayerName", si.getAboutInfo().name);
}
catch (Exception e){
e.printStackTrace();
}
ManagedEntity[] managedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("VirtualMachine");
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("HostSystem");
for (ManagedEntity hostmanagedEntity : hostmanagedEntities) {
HostSystem hostsys = (HostSystem) hostmanagedEntity;
String ESXhostname = hostsys.getName();
//System.out.println("main system version is .. " + hostsys.getConfig());
HostListSummary hls = hostsys.getSummary();
HostHardwareSummary hosthwi = hls.getHardware();
HostListSummaryQuickStats hqs = hls.getQuickStats();
Datastore[] HDS = hostsys.getDatastores();
StringBuilder DS = new StringBuilder();
for (int i=0;i <HDS.length;i++){
DatastoreSummary dsm =HDS[i].getSummary();
DS.append(dsm.name+":"+dsm.capacity+":"+dsm.freeSpace+"-");
}
int MEM=hqs.overallMemoryUsage;
int UPT=hqs.getUptime();
Integer CPU=hqs.getOverallCpuUsage();
String esxkey = "ESXRealInfo";
String esxvalue = "ESXhostname-" + ESXhostname
+ ";CPU Usage-" + CPU + ";MEM Usage-"
+ MEM + ";UPTIME-" + UPT+"; Datastores -"+DS;
try {
esxcmdout.put(esxkey, esxvalue);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for (int i = 0; i < managedEntities.length; i++) {
VirtualMachine vm = (VirtualMachine) managedEntities[i];
String vmName = vm.getName();
String vmIP = vm.getGuest().getIpAddress();
VirtualMachineConfigInfo config = vm.getConfig();
VirtualHardware hw = config.getHardware();
String vmVersion = config.version;
System.out.println("######### vm version is ###### ... "+ vmVersion);
int vmCPU = hw.getNumCPU();
int vmMem = hw.getMemoryMB();
String vmkey = "vm" + i;
String vmvalues = "Name-" + vmName + ";IP-" + vmIP + ";vmCPU-"
+ vmCPU + ";vmMem-" + vmMem + ";vmVersion-" + vmVersion;
System.out.println("string to write is... "+vmvalues);
try {
esxcmdout.put(vmkey, vmvalues);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
si.getServerConnection().logout();
}
catch (InvalidProperty e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RuntimeFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
runMT.httpput(runtype, host, vmwtype, esxcmdout);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}AboutInfo().name);
}
catch (Exception e){
e.printStackTrace();
}
ManagedEntity[] managedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("VirtualMachine");
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("HostSystem");
for (ManagedEntity hostmanagedEntity : hostmanagedEntities) {
HostSystem hostsys = (HostSystem) hostmanagedEntity;
String ESXhostname = hostsys.getName();
//System.out.println("main system version is .. " + hostsys.getConfig());
HostListSummary hls = hostsys.getSummary();
HostHardwareSummary hosthwi = hls.getHardware();
HostListSummaryQuickStats hqs = hls.getQuickStats();
Datastore[] HDS = hostsys.getDatastores();
StringBuilder DS = new StringBuilder();
for (int i=0;i <HDS.length;i++){
DatastoreSummary dsm =HDS[i].getSummary();
DS.append(dsm.name+":"+dsm.capacity+":"+dsm.freeSpace+"-");
}
int MEM=hqs.overallMemoryUsage;
int UPT=hqs.getUptime();
Integer CPU=hqs.getOverallCpuUsage();
String esxkey = "ESXRealInfo";
String esxvalue = "ESXhostname-" + ESXhostname
+ ";CPU Usage-" + CPU + ";MEM Usage-"
+ MEM + ";UPTIME-" + UPT+"; Datastores -"+DS;
try {
esxcmdout.put(esxkey, esxvalue);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for (int i = 0; i < managedEntities.length; i++) {
VirtualMachine vm = (VirtualMachine) managedEntities[i];
String vmName = vm.getName();
String vmIP = vm.getGuest().getIpAddress();
VirtualMachineConfigInfo config = vm.getConfig();
VirtualHardware hw = config.getHardware();
String vmVersion = config.version;
System.out.println("######### vm version is ###### ... "+ vmVersion);
int vmCPU = hw.getNumCPU();
int vmMem = hw.getMemoryMB();
//sasSystem.out.println(vmName + vmIP + vmCPU + vmMem);
String vmkey = "vm" + i;
String vmvalues = "Name-" + vmName + ";IP-" + vmIP + ";vmCPU-"
+ vmCPU + ";vmMem-" + vmMem + ";vmVersion-" + vmVersion;
System.out.println("string to write is... "+vmvalues);
try {
esxcmdout.put(vmkey, vmvalues);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
si.getServerConnection().logout();
}
catch (InvalidProperty e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RuntimeFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
runMT.httpput(runtype, host, vmwtype, esxcmdout);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This code works fine for collecting information of ESX devices.
How do I resolve error of certificate for vcenter?
Is there any alternative way to do this?
You have to import the certificate so go through this vSphere_Documentation page to know import certificates.
edit:
try the given below code and have a look at this answer
KeyStore keyStore = KeyStore.getInstance("JKS");
String fileName = "D:\\certs_path\\cacerts"; // cerrtification file path
System.setProperty("javax.net.ssl.trustStore", fileName);
try changing the last argument on the ServiceInstance to false like this: ServiceInstance si = new ServiceInstance(new URL(url), user, pass,false);

passive ftp in java - why is the stream not ready

yet another java problem ...
got a client which should connect to a server via passive mode.
it seems to work fine, i get the ip adress and the port and the passivesocket says that it's ready.
but the passivesocket.getInputStream isn't ready at all - so i can't read from it and don't get the response to LIST.
can't figure out why, any suggestions?
public synchronized void getPasvCon() throws IOException, InterruptedException {
// Commands abholen
// IP Adresse holen
Thread.sleep(200);
String pasv = commands.lastElement();
String ipAndPort = pasv.substring(pasv.indexOf("(") + 1,
pasv.indexOf(")"));
StringTokenizer getIp = new StringTokenizer(ipAndPort);
// holt die IP
String ipNew = ""; // IP für den neuen Socket
for (int i = 0; i < 4; i++) {
if (i < 3) {
ipNew += (getIp.nextToken(",") + ".");
} else {
ipNew += (getIp.nextToken(","));
}
}
Integer portTemp1 = new Integer( getIp.nextToken(","));
Integer portTemp2 = new Integer (getIp.nextToken(","));
portNew = (portTemp1 << 8 )+ portTemp2;
System.out.println(">>>>> " + ipNew + ":" + portNew);
try {
pasvSocket = new Socket(ipNew, portNew);
System.out.println("Socket verbunden: "+ pasvSocket.isConnected());
} catch (UnknownHostException e) {
System.out.println("Host unbekannt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fromPasvServer = new BufferedReader(new InputStreamReader(
pasvSocket.getInputStream()));
Thread.sleep(2000);
System.out.println("Streams bereit: " + fromPasvServer.ready() + " | " );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
writePasvCommands = new PrintWriter(pasvSocket.getOutputStream(),
true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread.sleep(3000);
Thread pasvKonsole = new Thread(new PasvKonsole(this));
pasvKonsole.start();
}
public void LIST() throws IOException {
writeCommands.print("LIST\n");
writeCommands.flush();
}
public void run() {
try {
connect();
// getStatus();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
USER();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PASS();
try {
Thread.sleep(2000);
PASV();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
import java.io.IOException;
public class PasvKonsole extends Thread {
Client client;
public PasvKonsole(Client client) {
this.client = client;
}
public void run() {
System.out.println("========= PasvKonsole started");
while(true) {
try {
String lineP = client.fromPasvServer.readLine();
System.out.println("***" + lineP);
System.out.println("Ich bin da und tue auch was");
} catch (IOException e) {}
}
}
}
Added a Thread.Sleep and it works.

Categories

Resources