GCM Server Side Run-time Error (NoClassDefFoundError : Message$Builder ) - java

This is the server side code for GCM notification, i have build this successfully on ubuntu using command line by adding gcm-server.jar, but at run time it crashes with exception. I have added the jar in the classpath.
Exception at run time :
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/android /gcm/server/Message$Builder
at geo.sendNotification.sendNow(sendNotification.java:30)
at geo.geosense.main(geosense.java:27)
Caused by: java.lang.ClassNotFoundException: com.google.android.gcm.server.Message$Builder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
..
.
import org.json.simple.*;
import java.util.*;
import com.google.android.gcm.server.Message.Builder;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Sender;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.MulticastResult;
public class sendNotification {
Sender sender = null;
public void sendNotification () // function to send message
{
Sender sender = new Sender("XYZ"); // api key
}
public void sendNow(String deviceID, String msg, String param)
{
Message message = new Message.Builder()
.addData("message", msg)
.addData("parameter one", param)
.build();
try{
Result result = sender.send(message, deviceID, 1);
}
catch ( Exception e )
{
e.printStackTrace();
}
}}
____________________________________________________________________________

NoClassDefFoundError means that the application is unable to find the location of the file inside the Application's folder. It is advised to keep all the library files and jar files in libs folder of the project.
Make sure that you have put the gcm.jar file inside the libs folder and not lib folder.
To do that go to project properties > java build path > order and export then give a tick on the jar file that you have added.
Here's a related SO ticket which discuss about NoClassDefFoundError: java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging

Related

JVM falls after parsing images via Tesseract

I have an app that works on backend it uses maven dependency: tess4j 5.4.0
Trained data was installed and connected through env variable.
I have endpoint where I can create entity by adding an image and it works correctly when I use Postman(image added -> text recognized and added to entity -> entity created -> I can create next component), but if I invoke this endpoint via frontend - JVM crashed after 4-5 minutes. If I turn off this function I can create entities and backend works correctly
Also it works when I try to run in locally, but when I deploy it on the server everything breaks(via frontend).
Example of entity Service:
public String storeFileAndGetContentText(MultipartFile file) {
String fileName;
Path targetLocation = this.fileStorageLocation.resolve(fileName);
Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
File targetFile = targetLocation.toFile();
String contentText = new RecognitionService().parseImage(targetFile);
return contentText;
}
Example of recognition service:
public class RecognitionService {
private static ITesseract tesseract;
static {
try {
tesseract = new Tesseract();
} catch (Exception e) {
log.warn("Failure during Tesseract initialization", e);
}
}
public String parseImage(File file) {
try {
return tesseract.doOCR(file).replaceAll("\n", " ").trim();
} catch (TesseractException e) {
log.warn("Tesseract can't read file {}", file.getName(), e);
return "";
}
}
Logs:
java.lang.IllegalStateException: failed to obtain node locks, tried [/usr/share/elasticsearch/data]; maybe these locations are not writable or multiple nodes were started on the same data path?
at org.elasticsearch.server#8.4.2/org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:285)
at org.elasticsearch.server#8.4.2/org.elasticsearch.node.Node.<init>(Node.java:456)
at org.elasticsearch.server#8.4.2/org.elasticsearch.node.Node.<init>(Node.java:311)
at org.elasticsearch.server#8.4.2/org.elasticsearch.bootstrap.Elasticsearch$2.<init>(Elasticsearch.java:214)
at org.elasticsearch.server#8.4.2/org.elasticsearch.bootstrap.Elasticsearch.initPhase3(Elasticsearch.java:214)
at org.elasticsearch.server#8.4.2/org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:67)
Caused by: java.io.IOException: failed to obtain lock on /usr/share/elasticsearch/data
at org.elasticsearch.server#8.4.2/org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:230)
at org.elasticsearch.server#8.4.2/org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:198)
at org.elasticsearch.server#8.4.2/org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:277)
... 5 more
Caused by: java.nio.file.NoSuchFileException: /usr/share/elasticsearch/data/node.lock
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixPath.toRealPath(UnixPath.java:825)
at org.apache.lucene.core#9.3.0/org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:94)
at org.apache.lucene.core#9.3.0/org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:43)
at org.apache.lucene.core#9.3.0/org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:44)
at org.elasticsearch.server#8.4.2/org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:223)
... 7 more
Suppressed: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/node.lock
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
at java.base/java.nio.file.Files.newByteChannel(Files.java:380)
at java.base/java.nio.file.Files.createFile(Files.java:658)
at org.apache.lucene.core#9.3.0/org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:84)
Actually, I see that something wrong with ElasticSearch, but I don’t see how it’s connected
I installed tesseract-ocr on target machine - to make test recognition work
I tried to install next libraries: imagemagic, ghostscript - I thought that tesseract-ocr expect something from these libraries(found in Intenet)

How can I overcome Error in oracle.odi.core.OdiInstance.createInstance

I am trying my first ODI (Oracle Data Integrator) SDK java program. (below). It just tries to connect.
package docOdi;
import oracle.odi.core.OdiInstance;
import oracle.odi.core.config.MasterRepositoryDbInfo;
import oracle.odi.core.config.OdiInstanceConfig;
import oracle.odi.core.config.PoolingAttributes;
import oracle.odi.core.config.WorkRepositoryDbInfo;
public class Test {
public static void main(String[] args) {
System.out.println("Creating Master and Work Repo objects...");
MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(
OdiBean.Url, OdiBean.Driver,
OdiBean.Master_User, OdiBean.Master_Pass.toCharArray(),
new PoolingAttributes());
WorkRepositoryDbInfo workInfo = new WorkRepositoryDbInfo(
OdiBean.WorkRepoName, new PoolingAttributes());
System.out.println("Creating Odi Config...");
OdiInstanceConfig odiCfg = new OdiInstanceConfig(masterInfo,workInfo);
System.out.println("Connecting");
OdiInstance odiInstance=OdiInstance.createInstance(odiCfg); // <<< this line error: java.lang.NoClassDefFoundError: org/eclipse/persistence/sessions/Session
}
}
However, I get this error:
java.lang.NoClassDefFoundError: org/eclipse/persistence/sessions/Session
here are the jars I am using
I am not sure why this small/test program is trying to use org/eclipse/persisence/session
I did not see that class in ANY of my odi jars in this folder
C:\Oracle\Middleware\ODI\odi\sdk\lib
I welcome feedback.
so it seems the way to create java programs using the oracle.odi.* packages is to simply add all the jar's in the following folder to your classpath
[your_ODI_HOME]\odi\sdk\lib
As there are many layers of dependencies in the odi java classes
fyi:
Below is a listing of the jars for my v12 ODI install
activation.jar,
aopalliance.jar,
bsf.jar,
bsh-2.0b4.jar,
commons-beanutils-1.7.0.jar,
commons-codec-1.3.jar,
commons-collections-3.2.2.jar,
commons-discovery-0.4.jar,
commons-httpclient-3.1.jar,
commons-io-2.2.jar,
commons-lang-2.2.jar,
commons-logging-1.1.1.jar,
commons-net-3.3.jar,
commons-vfs-1.0.jar,
commons-vfs2-2.0.jar,
connector.jar,
cpld.jar,
enterprise_data_quality.jar,
gson-2.6.2.jar,
hsqldb.jar,
jakarta-oro-2.0.8.jar,
javolution.jar,
jms.jar,
jsch-0.1.53.jar,
json-path-2.2.0.jar,
jython.jar,
jzlib-1.07.jar,
log4j-1.2.16.jar,
odi-core.jar,
odi-sap.jar,
odi-wls-template-gen.jar,
odihapp_common.jar,
odihapp_essbase.jar,
odihapp_planning.jar,
ogg_jmx_interface.jar,
oracle.odi-jaxrsri.jar,
oracle.odi-sdk-jse.jar,
org.eclipse.jgit_3.6.2.201501210735-r.jar,
pop3.jar,
sapjco.jar,
sapjco3.jar,
slf4j-api-1.7.5.jar,
spring-aop.jar,
spring-beans.jar,
spring-context-support.jar,
spring-context.jar,
spring-core.jar,
spring-expression.jar,
spring-instrument-tomcat.jar,
spring-instrument.jar,
spring-jdbc.jar,
spring-jms.jar,
spring-orm.jar,
spring-oxm.jar,
spring-struts.jar,
spring-test.jar,
spring-tx.jar,
spring-web.jar,
spring-webmvc-portlet.jar,
spring-webmvc.jar,
svnkit-1.8.3.jar,
trilead-ssh2-1.0.0-build217.jar,
trove.jar,
woodstox.jar,
XmlSchema-1.4.2.jar,

Why can't java find my class?

I have a class that compiles without error. The class has a main method. But when I try to run it on ubuntu linux from the classes' directory I get a class not found error. I am pretty sure I am missing something dead obvious but I don't see it.
Here is my ls operation:
zookeeper#zookeeper-virtual-machine:~/zookeeper-3.4.5/programs$ ls
CreateGroup.java LsGroup.class LsGroup.java zookeeper-3.4.5.jar
Here is what happens when I to run LsGroup
zookeeper#zookeeper-virtual-machine:~/zookeeper-3.4.5/programs$ java -cp "zookeeper-3.4.5.jar" LsGroup
Exception in thread "main" java.lang.NoClassDefFoundError: LsGroup
Caused by: java.lang.ClassNotFoundException: LsGroup
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: LsGroup. Program will exit.
Here is the code for LsGroup
package org.zookeeper;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.Watcher.Event.KeeperState;
public class LsGroup implements Watcher {
private static final int SESSION_TIMEOUT = 5000;
private ZooKeeper zk;
private CountDownLatch connectedSignal = new CountDownLatch(1);
public void connect(String hosts) throws IOException, InterruptedException {
zk = new ZooKeeper(hosts, SESSION_TIMEOUT, this);
connectedSignal.await();
}
#Override
public void process(WatchedEvent event) { // Watcher interface
if (event.getState() == KeeperState.SyncConnected) {
connectedSignal.countDown();
}
}
public void ls(String groupName) throws KeeperException, InterruptedException {
String path = "/" + groupName;
try {
List<String> children = zk.getChildren(path, false);
for (String child : children) {
System.out.println(path+"/"+child);
System.out.println(zk.getChildren(path +"/"+ child, false));
}
} catch (KeeperException.NoNodeException e) {
System.out.printf("Group %s does not exist\n", groupName);
System.exit(1);
}
}
public void close() throws InterruptedException {
zk.close();
}
public static void main(String[] args) throws Exception {
LsGroup lsGroup = new LsGroup();
lsGroup.connect(args[0]);
lsGroup.ls(args[1]);
lsGroup.close();
}
}
The original problem was that your class was in a package, but you were trying to load it as if it weren't in a package. You'd normally organize your source code to match your package hierarchy, then from the root of the hierarchy, you'd run something like:
java -cp .:zookeeper-3.4.5.jar org.zookeeper.LsGroup
Now that you've temporarily worked around the package issue by moving the code out of a package, the next problem is that the current directory isn't in the classpath. So instead of this:
java -cp "zookeeper-3.4.5.jar" LsGroup
You want:
java -cp .:zookeeper-3.4.5.jar LsGroup
Once you've got that working, you should move the classes back into packages, as per normal Java best practice.
You could remove the package declaration:
package org.zookeeper;
...or just place your LsGroup class in org/zookeeper directory.
The class file is supposed to live in a path like:
org/zookeeper/LsGroup.class
The -cp must include the directory that contains the org/ directory. Then you can
java -cp parent-of-org org.zookeeper.LsGroup
The message "wrong name: org/zookeeper/LsGroup" means, you have to respect the package structure of Java. Use the following directory structure:
./org/zookeeper/LsGroup.class
Then launch java org.zookeeper.LsGroup from within the current directory. The package separator "." will be translated to corresponding directory.
Your files are not under package org.zookeeper
You should be running your class from ~/zookeeper-3.4.5/org/zookeeper
Otherwise JVM won't find the classes to load.
Your class is part of the org.zookeeper package but you keep it in the root folder of your project (/zookeeper-3.4.5/programs).
The qualified name of the package member and the path name to the file are parallel (see Managing Source and Class Files), so if your package is org.zookeeper the class file should be kept in /zookeeper-3.4.5/programs/org/zookeeper
You made two mistakes:
1) You tried to run java LsGroup but you have to use the complete name including packages java org.zookeeper.LsGroup
2) your directory structure is not correct: the package org.zookeeper corresponds with the directory structure ./org/zookeeper/
If you change the directory structure and then run java from the top of this directory structure it should work

WSO2 Governance Registry - Adding Notification for Service

I am following the example listed in this link to add custom email notifications.
In my maven project 'RegistryService': I created the EmailTransformHandler and used maven to create the RegistryService-0.1.jar. I also modified the GREG_HOME/repository/conf/axis2/axis2.xml by adding the handler:
<handler name="EmailTransformHandler"
class="com.registration.example.service.EmailTransformHandler"/>
and dropped the RegistryService-0.1.jar in GREG_HOME/repository/components/dropins
package com.registration.example.service;
import java.util.ArrayList;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.handlers.AbstractHandler;
public class EmailTransformHandler extends AbstractHandler implements Handler {
private String name;
public String getName() {
return name;
}
#Override
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
if (msgContext.getTo() != null && msgContext.getTo().getAddress().startsWith("mailto:")) {
try {
SOAPEnvelope env = msgContext.getEnvelope();
AXIOMXPath xPath = new AXIOMXPath("//ns:text");
xPath.addNamespace("ns", "registry_example");
OMElement element = (OMElement) ((ArrayList) xPath.evaluate(env)).get(0);
element.setText(element.getText().replace("--", "This message intercepted by Terminator"));
} catch (Exception e) {
e.printStackTrace();
}
}
return InvocationResponse.CONTINUE;
}
}
When I go to the GREG_HOME/bin and start the server I get following exception:
2013-02-08 12:05:00,952] FATAL {org.wso2.carbon.core.init.CarbonServerManager} - WSO2 Carbon initialization Failed
org.apache.axis2.AxisFault: Exception occured while loading the Axis configuration from GREG_HOME/wso2/wso2greg-4.5.3/repository/conf/axis2/axis2.xml
at org.wso2.carbon.core.CarbonAxisConfigurator.getAxisConfiguration(CarbonAxisConfigurator.java:190)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
at org.wso2.carbon.core.CarbonConfigurationContextFactory.createNewConfigurationContext(CarbonConfigurationContextFactory.java:65)
at org.wso2.carbon.core.init.CarbonServerManager.initializeCarbon(CarbonServerManager.java:398)
at org.wso2.carbon.core.init.CarbonServerManager.removePendingItem(CarbonServerManager.java:290)
at org.wso2.carbon.core.init.PreAxis2ConfigItemListener.bundleChanged(PreAxis2ConfigItemListener.java:118)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:847)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: org.apache.axis2.deployment.DeploymentException: com.registration.example.service.EmailTransformHandler
at org.apache.axis2.deployment.util.Utils.loadHandler(Utils.java:149)
at org.apache.axis2.deployment.AxisConfigBuilder.processPhaseList(AxisConfigBuilder.java:549)
at org.apache.axis2.deployment.AxisConfigBuilder.processPhaseOrders(AxisConfigBuilder.java:584)
at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:150)
at org.wso2.carbon.core.CarbonAxisConfigurator.populateAxisConfiguration(CarbonAxisConfigurator.java:308)
at org.wso2.carbon.core.CarbonAxisConfigurator.getAxisConfiguration(CarbonAxisConfigurator.java:188)
... 8 more
Caused by: java.lang.ClassNotFoundException: com.registration.example.service.EmailTransformHandler
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.axis2.util.Loader.loadClass(Loader.java:261)
at org.apache.axis2.util.Loader.loadClass(Loader.java:229)
at org.apache.axis2.deployment.util.Utils.loadHandler(Utils.java:116)
... 13 more
What configuration am I missing? Googling about this error does not yield any relevant results( except some Russian forums which do not help me much). I even tried adding the jar via WSO2 Management Console as an extension, but I still get this exception.
According to the error, your RegistryService-0.1.jar is not set properly to the class path.
If the jar file is not an OSGI bundle that jar file should be drop in to the "GREG_HOME/repository/components/lib" directory.
-Ajith

JavaAgent in Lotus Notes 6.5 using axis api gives Exception "No implementation defined for org.apache.commons.logging.LogFactory"

I needed to write a JavaAgent in a Lotus Notes 6.5 DB to access a web service. I used Axis Apache API for this purpose. I created A Java agent and added the jar files of axis in the agent by using Edit Project button.
Below is the agent code:
import lotus.domino.*;
import javax.xml.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.net.URL;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
String endpoint = "http://ws.apache.org:5049/axis/services/echo";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint) );
call.setOperationName(new QName("http://soapinterop.org/", "echoString"));
String ret = (String) call.invoke( new Object[] { "Hello!" } );
System.out.println("Sent 'Hello!', got '" + ret + "'");
} catch(Exception e) {
e.printStackTrace();
}
}
}
And below is the exception thrown:
java.lang.ExceptionInInitializerError: org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory
at org.apache.commons.discovery.tools.SPInterface.newInstance(SPInterface.java:197)
at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:378)
at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:84)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:80)
at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:72)
at org.apache.axis.configuration.EngineConfigurationFactoryFinder.<clinit>(EngineConfigurationFactoryFinder.java:94)
at org.apache.axis.client.Service.<init>(Service.java:111)
at JavaAgent.NotesMain(JavaAgent.java:17)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(NotesThread.java:218)
I thried to follow some links on the internet like, But i was not able to get exactly what it was asking to do. eg: http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/40d033fba3897f4d85256cd30034026a?OpenDocument
Any help will be great. All i wanted to do is write an agent so that i can access a web service, say temperature conversion web service on w3schools. http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius
I googled with your error message and this is the first hit:
http://croarkin.blogspot.fi/2010/08/commons-logging-headaches-with-axis.html
It suggests using a commons-logging.properties file with:
org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger
org.apache.commons.logging.LogFactory = org.apache.commons.logging.impl.LogFactoryImpl
or putting this to your code:
#BeforeClass
public static void beforeClass() {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
}
Probably you've already tried this because it's the first hit with google but just in case...

Categories

Resources