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
Related
Please read the note below.
I am having a problem in my chatbot program. I already did all the instructions they said on the tutorials of different website about how to create a chatbot in java using aiml. I create a maven project. Add the Ab.jar file in the dependency, even in local repository but still I am having this error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/alicebot/ab/MagicBooleans
at com.Chatbot.main(Chatbot.java:21)
Caused by: java.lang.ClassNotFoundException: org.alicebot.ab.MagicBooleans
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
This is the half of the code in Chatbot.java
import java.io.File;
import org.alicebot.ab.Bot;
import org.alicebot.ab.Chat;
import org.alicebot.ab.History;
import org.alicebot.ab.MagicBooleans;
import org.alicebot.ab.MagicStrings;
import org.alicebot.ab.utils.IOUtils;
public class Chatbot {
private static final boolean TRACE_MODE = false;
static String botName = "super";
public static void main(String[] args) {
try {
String resourcesPath = getResourcesPath();
System.out.println(resourcesPath);
MagicBooleans.trace_mode = TRACE_MODE;
Bot bot = new Bot("super", resourcesPath);
Chat chatSession = new Chat(bot);
bot.brain.nodeStats();
String textLine = "";
It seems that my jar file is not recognized or what. Im actually new to this. Response is a great help.
Note: I have already read some of the NoClassDefError question here in stackoverflow and do what they suggest but still the problem exist.
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.
I'm attempting to follow this AWS tutorial. But I'm having trouble at "You can run GreeterWorker successfully at this point." as I'm getting an UnknownResourceException.
Exception in thread "main" com.amazonaws.services.simpleworkflow.model.UnknownResourceException: Unknown domain: helloWorldWalkthrough (Service: AmazonSimpleWorkflow; Status Code: 400; Error Code: UnknownResourceFault; Request ID: xxxxx)
Steps taken
Resolved permission exception by attaching the SimpleWorkflowFullAccess IAM Policy to my AWS user.
Verified that the helloWorldWalkthrough is registered on the SWF dashboard
registered new helloWorldWalkthrough2 domain, same error occured
The tutorial didn't cover the step about attaching the SimpleWorkflowFullAccess policy to the AWS user, so I'm wondering if there is a similar undocumented step to allow my user to find this domain.
My code is copy/pasted from the GreeterWorker class in the tutorial.
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflow;
import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflowClient;
import com.amazonaws.services.simpleworkflow.flow.ActivityWorker;
import com.amazonaws.services.simpleworkflow.flow.WorkflowWorker;
public class GreeterWorker {
public static void main(String[] args) throws Exception {
ClientConfiguration config = new ClientConfiguration().withSocketTimeout(70*1000);
String swfAccessId = System.getenv("AWS_ACCESS_KEY_ID");
String swfSecretKey = System.getenv("AWS_SECRET_KEY");
AWSCredentials awsCredentials = new BasicAWSCredentials(swfAccessId, swfSecretKey);
AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(awsCredentials, config);
service.setEndpoint("https://swf.us-east-1.amazonaws.com");
String domain = "helloWorldWalkthrough";
String taskListToPoll = "HelloWorldList";
ActivityWorker aw = new ActivityWorker(service, domain, taskListToPoll);
aw.addActivitiesImplementation(new GreeterActivitiesImpl());
aw.start();
WorkflowWorker wfw = new WorkflowWorker(service, domain, taskListToPoll);
wfw.addWorkflowImplementationType(GreeterWorkflowImpl.class);
wfw.start();
}
}
You need to create the domain using the console or through an api call. Domain is not created automatically.
I was also facing the same issue and then I found that the region is hard coded in the main method inside GreeterWorker class as shown below:
service.setEndpoint("https://swf.us-east-1.amazonaws.com");
However my SWF account was in west-2 region.
I was also faving same problem. region is hard coded in tutorial.
I changed code as flllows
service.setEndpoint("https://swf.us-west-2.amazonaws.com");
I am getting this error:
Class not found com.apache.camel.example.tests.ReportIncidentRoutesTest
java.lang.ClassNotFoundException: com.apache.camel.example.tests.ReportIncidentRoutesTest
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
This is the updated stack trace for the new error that I am receiving. In the run configuration I do have it pointing to this class so I am not sure why I am still getting this error.
EDIT: -----------------------------------------------------------------------------------
Copy of my Test Class:
package com.apache.camel.example.tests;
import org.apache.camel.CamelContext;
import org.apache.camel.example.reportincident.InputReportIncident;
import org.apache.camel.example.reportincident.OutputReportIncident;
import org.apache.camel.example.reportincident.ReportIncidentEndpoint;
import org.apache.camel.example.reportincident.ReportIncidentRoutes;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.jvnet.mock_javamail.Mailbox;
import junit.framework.Test;
import junit.framework.TestCase;
/**
* Unit test of our routes
*/
public class ReportIncidentRoutesTest extends TestCase {
private CamelContext camel;
// should be the same address as we have in our route
private static String ADDRESS = "http://localhost:8080/part-five/webservices/incident";
protected void startCamel() throws Exception {
camel = new DefaultCamelContext();
camel.addRoutes(new ReportIncidentRoutes());
camel.start();
}
protected static ReportIncidentEndpoint createCXFClient() {
// we use CXF to create a client for us as its easier than JAXWS and works
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ReportIncidentEndpoint.class);
factory.setAddress(ADDRESS);
return (ReportIncidentEndpoint) factory.create();
}
public void testRendportIncident() throws Exception {
// start camel
startCamel();
// assert mailbox is empty before starting
Mailbox inbox = Mailbox.get("blah#blah.com");
assertEquals("Should not have mails", 0, inbox.size());
// create input parameter
InputReportIncident input = new InputReportIncident();
input.setIncidentId("123");
input.setIncidentDate("2008-08-18");
input.setGivenName("Patrick");
input.setFamilyName("joe");
input.setSummary("Blah");
input.setDetails("Blah blah");
input.setEmail("blah#blah.com");
input.setPhone("845 2962 7576");
// create the webservice client and send the request
ReportIncidentEndpoint client = createCXFClient();
OutputReportIncident out = client.reportIncident(input);
// assert we got a OK back
assertEquals("0", out.getCode());
// let some time pass to allow Camel to pickup the file and send it as an email
Thread.sleep(3000);
// assert mail box
assertEquals("Should have got 1 mail", 1, inbox.size());
// stop camel
camel.stop();
}
}
It seems junit 3 is in the classpath when compiling (assuming you don't get compile errors for any use of junit api) but not when running, so there is some classpath mismatch involved.
It seems you run the test through the eclipse test runner, is that configured to the same junit version as the tests are written for?
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