NoClassDEfFoundError while Using AXis with Lotus notes 6.5 - java

I am trying to use APACHE-AXIS framework in Lotus notes 6.5.
I did:
Created java library in Script library
created the Java files from WSDL and added to the library
added xml-apis.jar to the library.
Now i created an agent an added the created library to it.
See Agent code below:
import lotus.domino.*;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.axis.client.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
URL url = new URL("http://foo.com");
QName qName = new QName("xxxx", "getFooDataUser");
TestWebServiceLocator loc = new TestWebServiceLocator();
System.out.println("Before STUB Calling");
// (Your code goes here)
} catch(Exception e) {
e.printStackTrace();
}
}
}
Now in the agent whenever the code encounters any initialization code (Constructor calls), it is NoClassDefFoundError
See Stack trace below:
java.lang.NoClassDefFoundError: javax/xml/parsers/ParserConfigurationException
at org.apache.axis.configuration.FileProvider.configureEngine(FileProvider.java:179)
at org.apache.axis.AxisEngine.init(AxisEngine.java:172)
at org.apache.axis.AxisEngine.<init>(AxisEngine.java:156)
at org.apache.axis.client.AxisClient.<init>(AxisClient.java:52)
at org.apache.axis.client.Service.getAxisClient(Service.java:103)
at org.apache.axis.client.Service.<init>(Service.java:112)
at JavaAgent.NotesMain(JavaAgent.java:18)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(NotesThread.java:218)

Add xalan-2.0.1.jar to the library.
You can find the details in
http://www.java2s.com/Code/Jar/x/Downloadxalan201jar.htm

Related

Problems with LDAP authentication: java.lang.IncompatibleClassChangeError

I've got a class that allows me to authenticate with LDAP. When i run this code in a project with just one class (for testing reasons) i don't have problems and it returns a boolean value, as is expected, but when i run it in the project i'm working in, i got the following error:
java.lang.IncompatibleClassChangeError: Class org.apache.mina.filter.codec.ProtocolCodecFilter does not implement the requested interface org.apache.mina.core.filterchain.IoFilter
This is the method the allows me to authenticate:
public static void autenticarUsuario(String usuar, String password) throws LdapException, CursorException{
Dn user = Dn.EMPTY_DN;
try{
BasicConfigurator.configure();
LdapConnectionConfig config = new LdapConnectionConfig();
config.setLdapHost(SERVER_IP);
config.setLdapPort(PORT);
config.setName("uid=ldapsearch,ou=System,ou=Users,dc=fiec,dc=espol,dc=edu,dc=ec");
config.setCredentials(CREDENTIALS);
conn = new LdapNetworkConnection(config);
}catch(Exception e){
}
String s1 = usuar;
String s2 = password;
//System.out.println("Nombre: "+s1+" Contra: "+s2);
try {
conn.bind();
System.out.println(conn.isAuthenticated());
// Create the SearchRequest object
SearchRequest req = new SearchRequestImpl();
req.setScope( SearchScope.SUBTREE );
req.addAttributes( "*" );
req.setTimeLimit( 0 );
req.setBase( new Dn( "ou=Users,dc=fiec,dc=espol,dc=edu,dc=ec" ) );
req.setFilter( "(uid="+ s1 +")" );
// Process the request
SearchCursor searchCursor = conn.search( req );
while ( searchCursor.next() )
{
Response r = searchCursor.get();
if(r instanceof SearchResultEntry){
Entry re = ((SearchResultEntry) r).getEntry();
user = re.getDn();
}
}
conn.bind(user, s2);
//return(conn.isAuthenticated());
inLDAP = conn.isAuthenticated();
} catch (InvalidConnectionException ex) {
//System.out.println(ex);
}
catch (LdapException e) {
e.printStackTrace();
} catch (CursorException e) {
e.printStackTrace();
}
inLDAP = false;
}
The project i'm working in is a JAVAFX application, but this method is called in a class that doesn't extend from application (just java code to verify user credentials).
This is the stacktrace:
Exception in thread "pool-1-thread-1" java.lang.IncompatibleClassChangeError: Class org.apache.mina.filter.codec.ProtocolCodecFilter does not implement the requested interface org.apache.mina.core.filterchain.IoFilter
at org.apache.mina.core.filterchain.DefaultIoFilterChain.register(DefaultIoFilterChain.java:267)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.addLast(DefaultIoFilterChain.java:174)
at org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder.buildFilterChain(DefaultIoFilterChainBuilder.java:436)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:528)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:501)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$400(AbstractPollingIoProcessor.java:67)
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1116)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
These are the libraries i'm working:
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.SearchCursor;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.message.Response;
import org.apache.directory.api.ldap.model.message.SearchRequest;
import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
import org.apache.directory.api.ldap.model.message.SearchResultEntry;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.mina.*;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
import org.apache.directory.ldap.client.api.exception.InvalidConnectionException;
import org.apache.log4j.BasicConfigurator;
I don't know why this is happening, i'll appreciate any help in advance
It is a version problem. Between Mina 1.0 and Mina 2.0, they moved the IoFilter interface (among other things) from org.apache.mina.filterchain to org.apache.mina.core.filterchain. I think you are trying to use code compiled for Mina 2.0 with the Mina 1.0 implementation.
Solution: examine your build and runtime classpaths and dependencies to figure out how this happened ... and fix the inconsistency.

Application with embedded Jetty showing "page not found" if launched as jar

I have an application that uses embedded jetty. When I run this application in Netbeans IDE then I can browse my site # localhost:8080/
When I launch the jar file of my application from command line: java -jar app.jar then browsing localhost:8080/ jetty server says "page not found"
What am I missing here? Can't figure out the problem.
EDIT:
Netbeans project is uploaded to Github
Everything works fine if I run this project in Netbeans.
But when I take the jar file with lib folder and run it in cmd like this: java -jar EmbeddedJettyJspJstl.jar
Then navigating to http://localhost:8080/test I get errors:
org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.jstl_jsp
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
My JSP page uses JSTL and looks like it is not locating the jstl libraries?
And this is the code that starts the server:
package server;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* #author lkallas
*/
public class JettyServer {
// Resource path pointing to where the WEBROOT is
private static final String WEBROOT = "/webapp/";
private static final Logger logger = LoggerFactory.getLogger(JettyServer.class);
public void start() throws IOException, InterruptedException, URISyntaxException {
Server server = new Server();
// HTTP connector
ServerConnector connector = new ServerConnector(server);
connector.setHost("localhost");
connector.setPort(8080);
connector.setIdleTimeout(30000);
// Set the connector
server.addConnector(connector);
// Setup JMX for web applications
MBeanContainer mbContainer = new MBeanContainer(
ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
//Setting up web application
WebAppContext webapp = new WebAppContext();
webapp.setAttribute("javax.servlet.context.tempdir", getScratchDir());
webapp.setDescriptor(WEBROOT + "WEB-INF/web.xml");
webapp.setResourceBase(getWebRootResourceUri().toASCIIString());
webapp.setContextPath("/");
webapp.setWar(getWebRootResourceUri().toASCIIString());
webapp.addAliasCheck(new AllowSymLinkAliasChecker());
//For debugging
logger.info("Descriptor file: {}", webapp.getDescriptor());
logger.info("Resource base: {}", getWebRootResourceUri().toASCIIString());
logger.info("WAR location: {}", webapp.getWar());
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[]{webapp, new DefaultHandler()});
// This webapp will use jsps and jstl. We need to enable the
// AnnotationConfiguration in order to correctly
// set up the jsp container
Configuration.ClassList classlist = Configuration.ClassList
.setServerDefault(server);
classlist.addBefore(
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration");
// Set the ContainerIncludeJarPattern so that jetty examines these
// container-path jars for tlds, web-fragments etc.
// If you omit the jar that contains the jstl .tlds, the jsp engine will
// scan for them instead.
webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*taglibs.*\\.jar$");
// A WebAppContext is a ContextHandler as well so it needs to be set to
// the server so it is aware of where to send the appropriate requests.
server.setHandler(handlerList);
try {
server.start();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
server.dumpStdErr();
}
/**
* Establish Scratch directory for the servlet context (used by JSP
* compilation)
*/
private File getScratchDir() throws IOException {
File tempDir = new File(System.getProperty("java.io.tmpdir"));
File scratchDir = new File(tempDir.toString(), "embedded-jetty");
if (!scratchDir.exists()) {
if (!scratchDir.mkdirs()) {
throw new IOException("Unable to create scratch directory: " + scratchDir);
}
}
return scratchDir;
}
/**
* Get webroot URI.
*
* #return
* #throws FileNotFoundException
* #throws URISyntaxException
*/
private URI getWebRootResourceUri() throws FileNotFoundException, URISyntaxException {
URL indexUri = this.getClass().getResource(WEBROOT);
if (indexUri == null) {
throw new FileNotFoundException("Unable to find resource " + WEBROOT);
}
logger.debug("WEBROOT: {}", indexUri.toURI().toASCIIString());
return indexUri.toURI();
}
}
I have already looked # http://www.eclipse.org/jetty/documentation/current/advanced-embedding.html
There's a number of reasons and causes that could be affecting you.
However you haven't posted any code to help us identify what the specific cause is.
The Jetty Project maintains an example for this setup, btw.
https://github.com/jetty-project/embedded-jetty-uber-jar
Pay attention to your context.setContextPath() (like #Haider-Ali pointed out), and also your context.setBaseResource()
For JSPs in Embedded Jetty you can look at the other example project
https://github.com/jetty-project/embedded-jetty-jsp
Note prior answer about Embedded Jetty and JSP.

External library not available when deploy with fat-jar

I'm using in my program the bluecove library.
While running the program via eclipse, all works smooth. I'm now trying to deploy my program, and following this post i'm using fat-jar.
When i run the jar file (created by fat-jar), the library can't be located, and i'm getting the exception BlueCove libraries not available as result of this line local = LocalDevice.getLocalDevice();.
In the fat-jar window i tried also to add bluecove-2.1.0.jar to the Class-Path place, and also with the path \src\JoJoServer\bluecove-2.1.0.jar.
I tried also to place the bluecove's jar file in different folders, such as the src, or an external folder.
Although i know it's not recommended, i tried the option of One-Jar, nevertheless it didn't help.
To run the jar (the one created by fat jar) i simply double click the file.
What i'm missing?
This is the entire code:
import java.io.IOException;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
#Override
public void run() {
// retrieve the local Bluetooth device object
LocalDevice local = null;
StreamConnectionNotifier notifier;
StreamConnection connection = null;
// setup the server to listen for connection
try {
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
UUID uuid = new UUID("0000110100001000800000805F9B34FB", false);
System.out.println(uuid.toString());
String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
notifier = (StreamConnectionNotifier)Connector.open(url);
} catch (BluetoothStateException e) {
System.out.println("Bluetooth is not turned on.");
e.printStackTrace();
return;
}
// ...
}
I have no clue what could be your problem, but I've tried the process and everything works, so just a summary of what I've did. Maybe you will figure it out by following it...
I don't understand how the posted code could be the entire, I see no class definition. :)
So I've modified it to the main method and it works both from the Eclipse and also by running the JAR generated by the FatJar.
The modified code of the BTTest class:
package test;
import java.io.IOException;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
public class BTTest {
public static void main(String[] args) throws Exception{
// retrieve the local Bluetooth device object
LocalDevice local = null;
StreamConnectionNotifier notifier;
StreamConnection connection = null;
// setup the server to listen for connection
try {
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
UUID uuid = new UUID("0000110100001000800000805F9B34FB", false);
System.out.println(uuid.toString());
String url = "btspp://localhost:" + uuid.toString()
+ ";name=RemoteBluetooth";
notifier = (StreamConnectionNotifier) Connector.open(url);
} catch (BluetoothStateException e) {
System.out.println("Bluetooth is not turned on.");
e.printStackTrace();
return;
}
// ...
}
}
To run or produce it, I have just put the bluecove library in the build path and created the fat jar with a simple way:
http://oi60.tinypic.com/vg1jpt.jpg
Starting the generated jar from command line:
D:\testProjects\bttest>java -jar bttest_fat.jar
BlueCove version 2.1.0 on winsock
0000110100001000800000805f9b34fb
BlueCove stack shutdown completed
Can you post a difference to your process?

Having Issues with the E*Trade OAuth API (Java)

I'm trying to code a program that will trade stocks in a sandbox environment with the E*Trade API. I am using their sample code as a guideline and currently am getting an issue with the .getAuthorizeURL() method. It says that it is undefined for type String however, after decompiling the OAuth jar I am stuck in a rut about how to solve this issue.
import com.etrade.etws.account.Account;
import com.etrade.etws.account.AccountListResponse;
import com.etrade.etws.oauth.sdk.client.IOAuthClient;
import com.etrade.etws.oauth.sdk.client.OAuthClientImpl;
import com.etrade.etws.oauth.sdk.common.Token;
import com.etrade.etws.sdk.client.ClientRequest;
import com.etrade.etws.sdk.client.Environment;
import com.etrade.etws.sdk.common.ETWSException;
import com.etrade.*;
import java.awt.Desktop;
import java.net.URI;
import java.*;
import java.io.IOException;
public class OAuth
{
public static void main(String[] args) throws IOException, ETWSException
{
//Variables
IOAuthClient client = null;
ClientRequest request = null;
Token token = null;
String oauth_consumer_key = null; // Your consumer key
String oauth_consumer_secret = null; // Your consumer secret
String oauth_request_token = null; // Request token
String oauth_request_token_secret = null; // Request token secret
client = OAuthClientImpl.getInstance(); // Instantiate IOAUthClient
request = new ClientRequest(); // Instantiate ClientRequest
request.setEnv(Environment.SANDBOX); // Use sandbox environment
request.setConsumerKey(oauth_consumer_key); //Set consumer key
request.setConsumerSecret(oauth_consumer_secret);
token = client.getRequestToken(request); // Get request-token object
oauth_request_token = token.getToken(); // Get token string
oauth_request_token_secret = token.getSecret(); // Get token secret
}
public String Verification(String client, ClientRequest request)
{
String authorizeURL = null;
authorizeURL = client.getAuthorizeUrl(request); // E*TRADE authorization URL
URI uri = new java.net.URI(authorizeURL);
Desktop desktop = Desktop.getDesktop();
desktop.browse(uri);
return authorizeURL;
}
}
Stack Trace
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.etrade.etws.oauth.sdk.client.OAuthClientImpl.<init>(OAuthClientImpl.java:22)
at com.etrade.etws.oauth.sdk.client.OAuthClientImpl.<clinit>(OAuthClientImpl.java:24)
at OAuth.main(OAuth.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
You need to configure your build path to include the Apache log4j logger (org/apache/log4j/Logger) in your external JARs. It's use is buried down in the ETRADE code.
What are you editing your code in? It should be easy to find instructions for your development environment. APACHE is free and you can download the JAR here: http://logging.apache.org/log4j/2.x/
Note the requirement from ETRADE (https://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-Tutorialhttps://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-Tutorial):
Java SDK
To proceed with this tutorial, you must first have completed the installation of the E*TRADE Java SDK, including:
•Java 1.6 or later installed
•3rd-party jars installed
•E*TRADE Java SDK libraries in your CLASSPATH
You can get instructions for all of the jars here https://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-SDKGuides-Java
If you were using Eclipse IDE, for example, you can follow these instructions How to import a jar in Eclipse

NoSuchMethodError showing for Jira when Java running as Web application, But gets output when running in main

I am creating a Java web application. I added Jira API jars for connecting to Jira to get Issues created in Jira.
And this is my Java program to get the issues
import java.net.URI;
import java.net.URISyntaxException;
import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.NullProgressMonitor;
import com.atlassian.jira.rest.client.domain.Issue;
import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
public class AppJIRADataCollector {
final static JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
public static void main(String args[])
{
AppJIRADataCollector appJira=new AppJIRADataCollector();
appJira.getIssues("http://localhost:8080/", "AP-1", "admin", "admin");
}
public void getIssues(String issueURI,String issueKey,String username, String password) {
try {
final URI jiraServerUri = new URI(issueURI);
final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri,username, password);
System.out.println(restClient);
final NullProgressMonitor pm = new NullProgressMonitor();
final Issue issue = restClient.getIssueClient()
.getIssue(issueKey, pm);
System.out.println(issue);
} catch (URISyntaxException e) {
System.out.println("URI not found");
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
When I run this program, I am getting the output correctly as it prints the issues.
But when I run this as web application, and calling the getIssues() method from servlet, tomcat showing NoSuchMethodError
Here is the stack trace
java.lang.NoSuchMethodError: com.google.common.collect.Iterables.contains(Ljava/lang/Iterable;Ljava/lang/Object;)Z
com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:216)
com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:59)
com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient$1.call(AbstractJerseyRestClient.java:85)
com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:54)
com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.getAndParse(AbstractJerseyRestClient.java:80)
com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.getIssue(JerseyIssueRestClient.java:131)
com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.getIssue(JerseyIssueRestClient.java:123)
com.domain.jirademo.adapters.AppJIRADataCollector.getIssues(AppJIRADataCollector.java:22)
com.domain.jirademo.controllers.ProjectDefectsServlet.doPost(ProjectDefectsServlet.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
Why this is happening? Any problem with JARs? I am using maven. If want I will post the pom also.
EDIT
I added the main method later only. So in the stack trace, line 22 refers to
final Issue issue = restClient.getIssueClient()
.getIssue(issueKey, pm);
NoSuchMethodError it's caused by a version mismatch, you should check your version of guava library.

Categories

Resources