ebay OAuth 2.0 library Cannot Resolve method initialize() - java

i wanted to write a bit for Android ebay client.
but im struggeling with the first probleme.
first i start a new Java Android Project with IntelliJ
I want to use this Library ebay-oauth-android-client
like described on Git:
Obtaining Library
This library is distributed via maven central repository. To use this
library, include the below as dependency in your project
dependencies {
compile 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
}
i put this snippet in my Gradle.build and replace compile with implementation since compile is depricated.
so far so good. gradle import this library.
but the next step not working for me:
Application Setup
Before performing OAuth, the library should be initialized with details about your application from eBay developer portal. The library uses
Client ID. For details see Getting your OAuth credentials
Redirect Uri. for details see Getting your Redirect_Uri
Url encoded list of scopes. for details see Specifying OAuth scopes
Use these details in ApiSessionConfiguration.initialize() as shown below:
ApiSessionConfiguration.initialize(
apiEnvironment = ApiEnvironment.PRODUCTION,
apiConfiguration = ApiConfiguration(
<Client ID>,
<Redirect Uri>,
<space separated scopes>
)
)
So i try to call initialze:
my Code with error
But when i try that the Compiler tells me that:
cannot find symbol method initialize(<null>)
When i Jump to the Class Declaration of ApiSessionConfiguration is written that:
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package com.ebay.api.client.auth.oauth2.model
public final class ApiSessionConfiguration private constructor() {
public companion object {
private final val instance: com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration /* compiled code */
public final fun getInstance(): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }
public final fun initialize(apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment, apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }
}
public final var apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration? /* compiled code */
public final var apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment? /* compiled code */
}
i dont really understand what im doing wrong. in the sample file on Git ApiSessionConfiguration.initalize() is called without any errors.
i already tried to Invalidate Cache, Clean Build, and start over again.
when i try to import the library from Project Structure Librarys New from Maven repo it says:
no files were downloaded...

Doesn't it can resolve initialize method with single argument?
Did you tried initialize method with two arguments?
Their sample app takes 2 arguments:
https://github.com/eBay/ebay-oauth-android-client/blob/master/sample/src/main/java/com/ebay/api/client/auth/MainActivity.kt#L37-L44
Updated:
But to access to Kotlin companion object function from java you need to call ApiSessionConfiguration.Companion.initialize method

Related

How to import/load classes into a jenkinsfile from another file

I need to import custom classes defined outside of my jenkinsfile. These classes have constructors which require parameters. I've already tried using load() for each of the class files, but it seems this only works for script files that just define static methods. When I tried using this to load my class files, it threw an error that it could not find an <init> method.
I currently have a way of importing these classes that works, but it requires re-cloning the repository as a library (code below). I'd like to move away from this since it's inefficient and seems like it should be unnecessary.
current working (but not great) implementation:
Jenkinsfile:
lib = library(identifier: "<libraryName>#${env.currentBranch}",
retriever: modernSCM([$class: 'GitSCMSource',
credentialsId: <credentialsId>,
id: '<id>',
remote: env.projectRemote,
traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]])).com.company.jenkins.sdk
def git = lib.Git.new(this, currentStage, currentStep)
...
src/com/company/jenkins/sdk/Git.groovy:
package com.company.jenkins.sdk.Git
class Git implements Serializable {
def script
def stage
def step
Git(script, stage, step){
...
}
}
I'd like to get rid of that library command and replace it with a simpler way of importing these classes.

Using jar from scala project from python via Py4j

I have built a jar from my Scala project.
I have the following structure for what I want to use from this jar
package aaa.bbb.ccc
case class FooResult(...)
trait Foo(...) {
def bar(): FooResult
}
object Foo {
private class FooImpl(...) extends Foo {
...
}
def apply(...): Foo
}
First question: Maybe I have misunderstood something in what Py4J offers,
but do I have to write a java/scala class to start the Py4J gateway if I want to use my own classes? Or is it enough to add it to the gateway's jvm's classpath?
Second question (which I guess doesn't apply depending on the answer to above): How do I add my jar when starting the java gateway in order to make it available? To solve this temporarily, I just started the jvm manually with my jar along with the Py4J jar with this command
java -classpath "path/to/py4j.jar:path/to/my.jar" py4j.GatewayServer 0
and then connected to it manually from the Python code. Then I tried to import my classes via
java_import(gateway.jvm, "aaa.bbb.ccc.*")
which didn't throw any error but I'm not sure it worked because it doesn't throw any error if I input some fake classpath.
Third question (which applies if the answer to the first is that I have to write the entry point to access my classes): How does this work when using scala?
object Main extends App {
val gw = new GatewayServer(// TODO: how to expose my classes here?
}

How to keep a jar file external but still use its classes in my Android project?

I need to have a jar file located in a main/assets directory within an Android project. It is important the jar file is located there.
With my main Android project is there a way to reference this jar file in my code and to use its classes?
To be clear I don't want to add the jar to the main project once compiled.
EDIT: I have tried the link below and it seems to load the Class file I've stated. But I'm strugging how to define constructor arguments for the dynamically loaded Class.
android-custom-class-loading-sample
EDIT2
Nearly there. I've confirmed the class is loaded from my classes.jar. I'm stuck instantiating it though.
On the licenseValidatorClazz.getConstructor line I get the error below. I'm guessing I'm missing something from my Interface file?
java.lang.NoSuchMethodException: [interface com.google.android.vending.licensing.Policy, interface com.google.android.vending.licensing.DeviceLimiter, interface com.google.android.vending.licensing.LicenseCheckerCallback, int, class java.lang.String, class java.lang.String]
public Class licenseValidatorClazz = null;
public LicenseValidator validator;
...
// Initialize the class loader with the secondary dex file.
DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(),
null,
mContext.getClassLoader());
try {
// Load the library class from the class loader.
licenseValidatorClazz = cl.loadClass("com.google.android.vending.licensing.LicenseValidator");
validator = (LicenseValidator) licenseValidatorClazz.getConstructor(Policy.class,DeviceLimiter.class,LicenseCheckerCallback.class,int.class,String.class,String.class).newInstance(ddd, new NullDeviceLimiter(),
callback, generateNonce(), mPackageName, mVersionCode);
} catch (Exception exception) {
// Handle exception gracefully here.
exception.printStackTrace();
}
I have an Interface which contains the functions to pass to the loaded class.
public interface LicenseValidator
{
public LicenseCheckerCallback getCallback();
public int getNonce();
public String getPackageName();
public void verify(PublicKey publicKey, int responseCode, String signedData, String signature);
public void handleResponse(int response, ResponseData rawData);
public void handleApplicationError(int code);
public void handleInvalidResponse();
}
TO use an external jar to be associated with your application and use it during runtime, it needs to be in dalvik format since normal jars cannot work under dalvikVM.
Convert your files using the dx tool
using aapt cmd , add those classes.dex to your jar file.
Now this jar which contains files in dalvik format can be loaded into our project.
Here is a post which explains the procedure to accomplish it.
There are steps to accomplish this.
You have to make a copy of your JAR file into the private internal storage of your aplication.
Using the dx tool inside the android folder, you have to generate a classes.dex file associated with the JAR file. The dx tool will be at the location /android-sdks/build-tools/19.0.1 (this file is needed by the Dalvik VM, simply jar can not be read by the dalvik VM))
Using the aapt tool command which is also inside the same location, you have to add the classes.dex to the JAR file.
This JAR file could be loaded dynamically using DexClassLoader.
If you are making a JAR from any one your own library, you have to do this steps (1-4) every time when there is a change in your library source code. So you can automate this steps by creating a shell script(in Mac/Linux/Ubuntu) or batch scripts(in Windows). You can refere this link to understand how to write shell scripts.
Note : One situation for implementing this method is, when it is impossible to add the JAR files directly to the build path of core project and need to be loaded dynamically at run time. In normal cases the JAR files could be added to the build path.
please check this link for the detailed code and implementation.
How to load a jar file at runtime
Android: How to dynamically load classes from a JAR file?
Hope this helps!!
You should try out the Services API - java.util.ServiceLoader
You define a service interface and its implementations in your jar.
package com.my.project;
public interface MyService { ... }
public class MyServiceBarImpl implements MyService { ... }
public class MyServiceFooImpl implements MyService { ... }
Then you define the services contained within the jar file in the META-INF/services/ directory. For instance, in the file 'META-INF/services/com.my.project.MyService', you list the provider classes.
# Known MyService providers.
com.my.project.MyServiceBarImpl # The original implementation for handling "bar"s.
com.my.project.MyServiceFooImpl # A later implementation for "foo"s.
Then, in your main codebase, you can instantiate a MyService instance with the ServiceLoader:
for (MyService service : ServiceLoader.load(MyService.class)) {
//Perform some test to determine which is the right MyServiceImpl
//and then do something with the MyService instance
}
These examples are taken more-or-less straight from the API, although I've changed the package names to make them slightly less annoying to read.

Call a wowza server from android app?

I'm trying to make some app that will play the stream from wowza. That part is ok. But next i need to have some option in app, that will comunicate with wowza server. For example how to call a wowza server some method, how to call onConnect method ... How to connect from wowza from a app and stay connected until i call a onDisconnect method??? If somebody have some info i will be very grateful... Thanks in advance...
VideoView.setVideoPath("some path")
does the trick for playing...
You call call a method in a Wowza module using a HTTPProvider (http://www.wowza.com/forums/content.php?30-httpproviders). This gives you a url in your Wowza module which your app will be able to call over HTTP.
So for example you have your Wowza module running under the default of:
http://localhost:1935.
You can add a HTTPProvider to your VHost.xml, such as:
<HTTPProvider>
<BaseClass>com.mycompany.wms.module.SomeModule</BaseClass>
<RequestFilters>logout*</RequestFilters>
<AuthenticationMethod>none</AuthenticationMethod>
</HTTPProvider>
This would let you call a url such as:
http://localhost:1935/logout?id=123456789
In the Java code for your module, you need implement HTTProvider2Base from which you create a onHTTPRequest method. The variables in the query string (so in this example: ?id=123456789) can be used in the method. You can also call methods in your module from here.
An example Java class that would use this call is as follows:
package com.mycompany.wms.module;
import com.wowza.wms.http.HTTProvider2Base;
import com.wowza.wms.http.IHTTPRequest;
import com.wowza.wms.http.IHTTPResponse;
import com.wowza.wms.logging.WMSLogger;
import com.wowza.wms.logging.WMSLoggerFactory;
import com.wowza.wms.vhost.IVHost;
public class SomeModule extends HTTProvider2Base {
public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
//Get the user
String userId = req.getParameter("id");
getLogger().info("Logging out user: " + userId );
logoutUser(userId);
}
private void logoutUser(String userId){
//Do stuff here...
}
private WMSLogger getLogger(){
return WMSLoggerFactory.getLogger(SomeModule.class);
}
}
Some gotchas:
Scoping in onHTTPRequest seems to be outside of your instance so be careful of accessing properties in an instance of the module.
I had to comment out the HTTPProvider node with HTTPServerVersion in it to get my one to work. It seemed to override all other HTTPProviders in my version of Wowza.
I also had trouble with the Wowza running from the IDE not picking up calls to the url via Visual Studio. Once I put my changes into the service version, the calls worked fine.
The app I built which did this was largely based on the conversation in this article: http://www.wowza.com/forums/content.php?182-HTTPProvider-that-returns-detail-server-info

Scala+Android+Roboguice: ClassNotFoundException in loader

I'm evaluating Scala on Android by starting with the NotesList demo. I was able to replace the NotesLiveFolder.java file with its Scala equivalent without problem.
Next, I introduced Roboguice, creating a simple NotesListApplication.java that sets up the Guice modules, and successfully injected a resource into the NoteEditor.java activity.
Finally, I when I tried to replace NotesListApplication.java with its Scala equivalent, I get the following runtime error before the application finishes booting:
java.lang.ClassNotFoundException: com.example.android.notepad.NotesListApplication in loader dalvik.system.PathClassLoader[/data/app/com.example.android.notepad-1.apk]
I created a Google Code project containing the complete Eclipse project and source. The original functioning NotesListApplication.java is:
package com.example.android.notepad;
import java.util.List;
import roboguice.application.RoboApplication;
import com.google.inject.Module;
public class NotesListApplication extends RoboApplication {
private Module module = new BindEverything();
public void setModule(Module module) {
this.module = module;
}
#Override
protected void addApplicationModules(List<Module> modules) {
modules.add(module);
}
}
and the Scala equivalent that causes the error is:
package com.example.android.notepad
import roboguice.application.RoboApplication
class NotesListApplication extends RoboApplication {
val module : Module = new BindEverything()
override protected def addApplicationModules(modules:java.util.List[Module] ) {
modules.add(module)
}
}
I'm building in Eclipse with the ScalaIDE plugin. I'm not running any treeshaker/proguard/etc.
The disassembly shows the Scala classes as expected:
Class descriptor : 'Lcom/example/android/notepad/NotesLiveFolder;'
...
Class descriptor : 'Lcom/example/android/notepad/NotesListApplication;'
Any ideas what could cause this?
Upgrade to 2.0-SNAPSHOT of RoboGuice and then you dont have to use RoboApplication and it all binds automatically. For more how to bind check out the slides from Mike Burtons presentations about RoboGuice at AnDevCon 2 and check out the 2.0 section on the wiki.
Like I posted on the mailing list maybe check out the apk with dedexer and see if the class was actually removed e.g. by Proguard or renamed so it cant be found as a next step.

Categories

Resources