method not found in java # jboss4.0 and linux environment - java

In Linux Method not found in jar file
Environment 1: [Working fine with JBoss 4.0 & Windows ]
Environment 2: [Issue in with JBoss 4.0 & Linux]
ERROR MESSAGE:
SEVERE: >> {==================STACK TRACE IS==========================
Sep 4, 2012 5:12:13 PM com.bct.platform.logger.BPMSLogger logString
SEVERE: >> com.bpms.core.exception.BPMSRuntimeException: BEACP015: No
method available like
this->uploadDocument(org.apache.commons.fileupload.FileItem,java.lang.String,java.lang.String)com.bpms.engine.workflowprocessor.actions.ActionCallProgram.executeAction(ActionCallProgram.java:571)
com.bpms.engine.CommonInterface.executeActions(CommonInterface.java:188)
we are call this reflection
Below is the code sample ,Am trying to call the saveALDocument when cant find the Java in Linux environment . In windows its working fine
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.activation.MimetypesFileTypeMap;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
public class FileUpdation
{
public String saveALDocument(FileItem filebuff,String fileName,String fileUuid) throws Exception
{
String uuidURLMap = "Retry...";
System.out.println("***************SaveDOCUment Entered *************");
try {
byte[] content = filebuff.get();
String filename = filebuff.getName();
if (filename != null) {
filename = FilenameUtils.getName(filename);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return uuidURLMap;
}
public String _getDocURL(String uuid)
{
String strUrl = null;
try {
.........
}
catch (Exception e) {
e.printStackTrace();
}
return strUrl;
}
public String _getName(String strUUID) {
return fileName;
}
}

commons-fileupload-1.2.jar and commons-io-1.1.jar , put them in lib

Related

Error Calling my testImage() Method from inside an imported .jar file from Eclipe in Wavemaker

I am simply trying to call my testImage() method in Wavemaker. I imported the .jar file after running the application perfectly in Eclipse. However when I call the same method in the .jar file in Wavemaker it gives my this error:
Error
Compile failed with output: [{"filename" : "master/services/MyJavaService1/src/com/demo_jquery/myjavaservice1/MyJavaService1.java","type" : "ERROR","lineNumber" : 134,"columnNumber" : 22,"startPosition" : 4743,"endPosition" : 4751,"message" : "The method testImage() in the type pictures.TestUrl is not applicable for the arguments (java.lang.String)"}]
I will now show you the TestUrl class which I call to invoke my two methods testImage() and getImage():
package pictures;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.imageio.ImageIO;
/*
* By: Victor Foning
*
* This program will consist of two Methods:
*
* The First will Test the Validity and reachability of an validity
* of an image URL.
*
* The second methods will log4j
*
*
*
*
*
*/
public class TestUrl {
public Boolean testImage (String l) {
// String urlString = "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";
System.out.println("Using " + l);
// Open connection
URL u = null;
try {
u = new URL( l);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
URLConnection connection = null;
try {
connection = u.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Check if response code is HTTP_OK (200)
HttpURLConnection httpConnection
= (HttpURLConnection) connection;
int code = 0;
try {
code = httpConnection.getResponseCode();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String message = null;
try {
message = httpConnection.getResponseMessage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(code + " " + message);
if (code == HttpURLConnection.HTTP_OK) {
return true;
} else {
return false;
}
}
public void getImage (String u) {
BufferedImage image =null;
try{
URL url =new URL(u);
// read the url
image = ImageIO.read(url);
ImageIO.write(image, "jpg",new File("C://Users//Foning//Desktop//GeoDataLab//mash7.jpg"));
}catch(IOException e){
e.printStackTrace();
}
}
}
The Picture is downloaded locally and the Console out is this:
Using http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png
200 OK
true
Here is my TestDownload main Class through which I call my two Methods:
package pictures;
import java.io.IOException;
/*
* By: Victor Foning 17/Septembre/2019
*
* From this Main Methods we will call:
*
* TestUrl.java and the GetImage.java Methods
*
*
*
*/
public class TestDownload {
public static void main(String[] args) {
String path = "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";
// We Begin encapsulating the TestUrl Methods
TestUrl im = new TestUrl();
boolean image = im.testImage(path);
if(image){
im.getImage(path);
System.out.print("true");
}
else{
System.out.print(" victor_WakeUP_false");
}
}
}
Here I then export the .jar file (in Bold) into Wavemaker and Make the same method invocation through my JavaService Class:
package com.demo_jquery.myjavaservice1;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pictures.TestUrl;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.springframework.beans.factory.annotation.Autowired;
import com.wavemaker.runtime.security.SecurityService;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import com.wavemaker.runtime.service.annotations.HideFromClient;
Here you will find the class getImageFromWaveMaker()I create inside my javaService1 class to invoke my two methods:
package com.demo_jquery.myjavaservice1;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pictures.TestUrl;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.springframework.beans.factory.annotation.Autowired;
import com.wavemaker.runtime.security.SecurityService;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import com.wavemaker.runtime.service.annotations.HideFromClient;
import com.demo_jquery.myjavaservice1.model.*;
#ExposeToClient
public class MyJavaService1 {
private static final Logger logger = LoggerFactory.getLogger(MyJavaService1.class);
#Autowired
private SecurityService securityService;
public void getImageFromWavemaker( String p) {
String path =
"http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";
// We Begin encapsulating the TestUrl Methods
TestUrl im = new TestUrl();
boolean image = im.testImage(path);
if(image){
//im.getImage(url);
logger.info("true");
}
else{
logger.info("victor_WakeUP_false");
}
}
}
Please help me figure out why I get and Error when I run this code?
Thanks to a bit of meditation and positive re-orientation from some good friends I was able to solve this issue.
I came to realize that even though camelcase is accepted when declaring method. I re-declared both methods in my TestUrl Class by starting them with a Capital Letter.
With reference to the Error Code:
Aslo, understanding that all classes in java are derived from the object class and that the String class is one of the most important class in Java. I made that java.lang.String class the Super Class when I created all my Classes in Eclipse.
I did a maven Compile, which generated a .jar file. I proceeded to upload the .jar file in my resource lib file on Wavemaker, Binded my variables accordingly with my JavaService class and the results were good.
Please feel free to express any further perspective on this issue, I would be glad to hear it. Thank you!

Execute jar file using PLSQL

I have a a standalone java program and it read the data from REST end point and insert data into table in Server.
package com.test.main;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.test.connectdb.ConDataBase;
import com.test.entity.User;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://jsonplaceholder.typicode.com/todos/");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
System.out.println("DONE2");
int responsecode = conn.getResponseCode();
String inline = "";
if(responsecode == 200){
Scanner sc = new Scanner(url.openStream());
while(sc.hasNext())
{
inline+=sc.nextLine();
}
System.out.println("JSON data in string format");
System.out.println(inline);
sc.close();
}else{
throw new RuntimeException("HttpResponseCode:" +responsecode);
}
//-----------------------------------------------------------------------
Connection con = new ConDataBase().buildConnection();
User[] userList = new Gson().fromJson(inline, User[].class);
System.out.println(userList.length);
for (User user : userList) {
//System.out.println(user.getCompleted());
String insert_date = "insert into XX_USER "
+ "(USER_ID)"
+ "VALUES"
+"('"+user.getCompleted()+"')";
try {
PreparedStatement ps_data = con.prepareStatement(insert_date);
ps_data.executeUpdate();
con.commit();
System.out.println("Successfully Inserted");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e.getMessage());
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I need to run this jar file using PLSQL. That means I have transferred this jar file into Linux server path (/home/rest). Oracle database is installed in server. I need to run this jar using PLSQL. Is it possible?
Use the LOADJAVA utility to load the jar file and all other jar dependencies into Oracle's internal classpath (this is different from the operating system's class path).
You will probably also want to change your code to a static method without arguments (rather than main with a string array argument) as it will make invoking the method much simpler.
// package and imports
public class Main {
public static void yourMethodName() {
// your code
}
}
Then you need to use something like:
CREATE PROCEDURE get_todos_from_rest_service AS
LANGUAGE JAVA NAME 'com.test.main.Main.yourMethodName()';
To create a procedure wrapper around the java method which you can then invoke in PL/SQL.
A more detailed example can be found here: Database Java Developer's Guide - Java Stored Procedures Application Example

Could not find or load main class onjava

I have the following code and I am trying to create a connection to a database.
I get an error "Could not find or load main class onjava" when I run the command: java -cp . onjava
I am able to run the javac -classpath "C:\CATALINA_HOME\lib*" onjava.java command
Both of my .class and .java files are in the same directory WEB-INF\classes\com\onjava
onjava.java
package com.onjava;
import java.sql.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.*;
import javax.naming.Context;
public class onjava extends HttpServlet {
private DataSource datasource;
public void init(ServletConfig config) throws ServletException {
try {
// Look up the JNDI data source only once at init time
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
datasource = (DataSource) ((InitialContext) envCtx).lookup("jdbc/testdb");
}
catch (NamingException e) {
e.printStackTrace();
}
}
private Connection getConnection() throws SQLException {
return datasource.getConnection();
}
public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException {
Connection connection=null;
try {
connection = getConnection();
//..<do JDBC work>..
if (connection != null) {
String message = "You are connected!";
System.out.println(message);
} else {
System.out.println("Failed to make connection!");
}
}
catch (SQLException sqlException) {
sqlException.printStackTrace();
}
finally {
if (connection != null)
try {connection.close();} catch (SQLException e) {}
}
}
}
EDIT:
I changed my code and I added the public class. But I am facing the same error when I run it!
package src;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Wrapper;
import java.util.Hashtable;
import java.util.Properties;
import java.io.*;
import javax.activation.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jdbc.pool.OracleDataSource;
public class onjava {
public static void main(String[] argv) throws SQLException, NamingException {
Properties prop = new Properties();
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.naming.java.javaURLContextFactory");
Context initialContext = new InitialContext(prop);
if ( initialContext == null){
System.out.print("JNDI problem. Cannot get InitialContext.");
} else {System.out.print("NO JNDI problemb ");}
// Get DataSource
Context envContext = (Context)initialContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/testdb");
System.out.println("\n -------- Oracle JDBC Connection Testing ------");
try {
Connection jdbcConnection = ((Statement) ds).getConnection();
OracleDataSource ods = ((Wrapper) ds).unwrap(OracleDataSource.class);
jdbcConnection.close();
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
String message = "You are connected!";
System.out.println(message);
}
}
When running java like this, you need to explicitly state the main class. Your command should look something more like java -cp . com.onjava.onjava. However, I don't see the main method in this class either. You need to point to the main method (ie, signature public static void main()).
By the way, it is proper convention to give your classes names that start with a capital letter (Onjava).
Ok so from what you told me, you need to have a main class attached to your project. This means going back to your compiler and creating the main method. To add your code, you will need to do something like this in the main class, which I will call onjavaMain:
public class onjavaMain{
//Main method is this
public static void main(String[] args)
{
//create variable of your onjava class
onjava onJavaConnectToDatabase = new onjava();
onJavaConnectToDatabase.doGet(argument1,argument2);
}
}
Now this is not the complete answer, but this will give you an idea of what you need to do in order to run your project in command line.

How to read two XML files using XMLUnit

I am new to XML.After a lot of search i found XMLUnit to do that but the problem am getting is :
whenever i change the contents of xml file to simple string text and try to execute the code ,it still shows green in junit test which it should not do although it is throwing an exception but my requirement is the signal should be red even the files are not in proper xml format.Enclosing my work for so far.
package mypack;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Test;
import org.xml.sax.SAXException;
public class MyXMLTestCase extends XMLTestCase {
enter code here
#Test
public void testMyXmlTestCase() {
FileReader expected = null;
FileReader output = null;
try {
expected = new FileReader("D:/vivek.xml");
output = new FileReader("D:/rahul.xml");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
XMLUnit.setNormalizeWhitespace(Boolean.TRUE);
try {
Diff diff = new Diff(expected,output);
// assertTrue("XMLSimilar"+diff.toString(),diff.similar());
//assertTrue("XMLIdentical"+diff.toString(),diff.identical());
DetailedDiff mydiff = new DetailedDiff(diff);
List allDifferences = mydiff.getAllDifferences();
assertEquals(mydiff.toString(), 0, allDifferences.size());
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Using Java classes to upload a file to a server

I want to create a Java application ( and then make it and applet to work on the web) that allows to upload a file to a remote server. The file has already been downloaded previously from the server. I have already have the code for the download part, but for the uploading I have the following code shown below..
The import libraries are fine but the issue is on the Uploader class that does throw me an error.. I think my BufferReader class is missing something but I need your help to debugging it...
UploadApplet.java
import com.leo.upload.BufferReader;
import com.leo.upload.Uploader;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Properties;
import java.util.Random;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.LoggingPermission;
import java.util.logging.SimpleFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JApplet;
import javax.swing.JPanel;
import netscape.javascript.JSObject;
public class UploadApplet extends JApplet {
public void start()
{
super.start();
uploadFile("/Users/XXXXX/Desktop/Tesing123.indd","http://xx.xx.xxx.xxx/");
}
public String uploadFile(String paramString1, String paramString2)
{
String str = "0";
try {
// I call the Uploader class to make the upload to the server
str = (String)AccessController.doPrivileged(new Uploader(paramString1, paramString2));
System.out.println(str);
}
catch (Exception e) {
e.printStackTrace();
}
return str;
}
Uploader.java
import com.leo.upload.BufferReader;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.security.PrivilegedAction;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Uploader
implements PrivilegedAction<String>
{
private static final String a = Uploader.class.getName();
private Logger b = Logger.getLogger(a);
private String c;
private String d;
public Uploader(String paramString1, String paramString2)
{
this.c = paramString1;
this.d = paramString2;
}
public String run()
{
FileInputStream localFileInputStream = null;
BufferedInputStream localBufferedInputStream = null;
Writer localWriter = null;
InputStream localInputStream = null;
LineNumberReader localLineNumberReader = null;
Object localObject1 = "0";
try
{
File localFile = new File(this.c);
localFileInputStream = new FileInputStream(localFile);
localBufferedInputStream = new BufferedInputStream(localFileInputStream);
Object localObject2 = new URL(this.d);
URLConnection localURLConnection = ((URL)localObject2).openConnection();
localURLConnection.addRequestProperty("Filename", localFile.getName());
localURLConnection.setRequestProperty("Content-type", "application/binary");
long l = localFile.length();
Object localObject3;
if (l <= 2147483647L) {
if ((localURLConnection instanceof HttpURLConnection)) {
localObject3 = (HttpURLConnection)localURLConnection;
((HttpURLConnection)localObject3).setFixedLengthStreamingMode((int)localFile.length());
}
localURLConnection.setDoOutput(true);
**// I call the BufferReader class, and the a method to perform the writing**
BufferReader.a(localBufferedInputStream, localURLConnection.getOutputStream());
localInputStream = localURLConnection.getInputStream();
localLineNumberReader = new LineNumberReader(new InputStreamReader(localInputStream, "UTF8"));
localObject1 = localLineNumberReader.readLine();
}
else {
localObject3 = "An error occurred during file upload: Cannot upload a file larger than 2GB.";
JOptionPane.showMessageDialog(null, localObject3, "Error during file upload", 0);
this.b.severe((String)localObject3);
localObject1 = localObject3;
}
}
catch (Throwable localIOException4) {
localIOException4.printStackTrace();
Object localObject2 = "An error occurred during file upload: " + localIOException4.toString();
localObject1 = localObject2;
} finally {
BufferReader.a(localFileInputStream, localBufferedInputStream, localWriter);
if (localLineNumberReader != null) {
try {
localLineNumberReader.close();
} catch (IOException localIOException5) {
localIOException5.printStackTrace();
}
}
if (localInputStream != null) {
try {
localInputStream.close();
} catch (IOException localIOException6) {
localIOException6.printStackTrace();
}
}
}
return (String)(String)(String)localObject1;
}
}
BufferReader.java
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Writer;
import java.util.logging.Logger;
public final class BufferReader
{
private static Logger logthis = Logger.getLogger(BufferReader.class.getName());
public static void a(InputStream paramInputStream, OutputStream paramOutputStream)
throws IOException
{
byte[] arrayOfByte = new byte[4096];
int i = 0;
int j;
while ((j = paramInputStream.read(arrayOfByte)) != -1) {
paramOutputStream.write(arrayOfByte, 0, j);
i += j;
}
logthis.fine("CopyBytes : " + i);
}
public static void a(InputStream paramInputStream, FileOutputStream paramFileOutputStream, BufferedOutputStream paramBufferedOutputStream)
{
if (paramInputStream != null) {
try {
paramInputStream.close();
} catch (IOException localIOException1) {
localIOException1.printStackTrace();
}
}
if (paramFileOutputStream != null) {
try {
paramFileOutputStream.flush();
} catch (IOException localIOException2) {
localIOException2.printStackTrace();
}
}
if (paramBufferedOutputStream != null) {
try {
paramBufferedOutputStream.flush();
} catch (IOException localIOException3) {
localIOException3.printStackTrace();
}
}
if (paramFileOutputStream != null) {
try {
paramFileOutputStream.close();
} catch (IOException localIOException4) {
localIOException4.printStackTrace();
}
}
if (paramBufferedOutputStream != null)
try {
paramBufferedOutputStream.close();
} catch (IOException localIOException5) {
localIOException5.printStackTrace();
}
}
public static void a(InputStream paramInputStream, BufferedInputStream paramBufferedInputStream, Writer paramWriter)
{
if (paramBufferedInputStream != null)
try {
paramBufferedInputStream.close();
}
catch (IOException localIOException1)
{
}
if (paramInputStream != null)
try {
paramInputStream.close();
}
catch (IOException localIOException2)
{
}
if (paramWriter != null)
try {
paramWriter.close();
}
catch (IOException localIOException3)
{
}
}
public static String a(InputStream paramInputStream)
throws IOException
{
BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(paramInputStream, "UTF-8"));
StringBuilder localStringBuilder = new StringBuilder();
String str = null;
while ((str = localBufferedReader.readLine()) != null) {
localStringBuilder.append(str);
}
localBufferedReader.close();
return localStringBuilder.toString();
}
}
Bear in mind that unsigned applets aren't usually allowed to open connections to addresses that aren't their originating web server...unless you specify that applets can do whatever they want in the client's java control panel

Categories