ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Method not found signature problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Method not found signature problem

    Hello,

    Im trying to do authorization in paypal. My constructors and all are being built correctly. Everything seems to be ok up to a point.

    Im trying to get a string access token. that is returned by a method(getAccessToken). I have my procedure set up to receive a string(I think). But it's saying:

    org.apache.commons.codec.binary.Base64" when calling method "getAccessToken"
    with signature "()Ljava.lang.String;" in class
    "com.paypal.core.rest.OAuthTokenCredential".

    The method is defined:

    Code:
    /**
    	 * Access Token that is generated
    	 */
    	private String accessToken;
    
    
    public String getAccessToken() throws PayPalRESTException {
    		if (accessToken == null) {
    	(string object) accessToken = generateAccessToken();
    		}
    		return accessToken;
    	}
    My Procedure is :

    Code:
    D getAccessToken...                                                    
    D                 PR                  like(jString)                    
    D                                     ExtProc(*JAVA                    
    D                                     :'com.paypal.core.rest-          
    D                                     .OAuthTokenCredential'           
    D                                     :'getAccessToken')

  • #2
    Re: Method not found signature problem

    You haven't provided the entire error message -- but from what I can see, it's looking for a class named "org.apache.commons.codec.binary.Base64" and it says that this class is called by the "getAccessToken" method.

    so I think you're misinterpreting the error message. You seem to feel that the signature for getAccessToken is wrong -- but that doesn't seem to be a problem at all. The problem is that getAccessToken calls some base64 routines, and those are nto found in your classpath.

    Comment


    • #3
      Re: Method not found signature problem

      What Scott said.

      If the RNX0301 message says it's a class-not-found message, or a method-not-found message, and the class name or method name are different from the ones in the prototype, it means that RPG called the prototyped method ok, but the called method had some problem finding classes or methods. So not an RPG prototype problem, but a more general Java problem with the classpath or version.

      Comment


      • #4
        Re: Method not found signature problem

        Yall were absolutely correct. I had a typo buried in my classpath. I never would have found that ...

        What is the earliest version that supports generics. I got past the notfound error But I think now i think Im getting a versioning problem.

        My highest jdk is jdk6. Ive got my JVM running sdk 6(I think). Please understand that Im quite the novice at this.

        java -version
        java version "1.6.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0_11-b03)
        Classic VM (build 1.6, build JDK-1.6, native threads, jitc)

        private static final Map<String, KeyStore> storeMap;
        PHP Code:
            static {
                try {
                    
                    
        // Initialize KeyManagerFactory and local KeyStore cache
                    
        kmf KeyManagerFactory.getInstance("SunX509");
                    
        storeMap = new HashMap<StringKeyStore>();
                } catch (
        NoSuchAlgorithmException e) {
                    throw new 
        ExceptionInInitializerError(e);
                }
            } 

        Comment


        • #5
          Re: Method not found signature problem

          Sorry, I don't understand what you mean by "that supports generics." What are "generics" in this context?
          Can you post the error message you're receiving?

          Comment


          • #6
            Re: Method not found signature problem

            This Java tutorial describes generics, full screen mode API, and Java certification related resources


            Im sorry, I found out it's available in 1.5. I forgot to update the post, Sorry. Ive got some other type problem.

            Thank You Scott and Barbara.

            Comment


            • #7
              Re: Method not found signature problem

              Getting initialization error . Do I need to inz my strings before use.

              The program runs from the console. So there are no java errors

              Message . . . . : Java exception received when calling Java method (C G D
              F).
              Cause . . . . . : RPG procedure EDPP02R in program WECTEST/EDPP02R received
              Java exception "java.lang.ExceptionInInitializerError:" when calling method
              "getAccessToken" with signature "()Ljava.lang.String;" in class
              "com.paypal.core.rest.OAuthTokenCredential".
              PHP Code:
                                                                            
              D OAuthTokenCredential
              ...                                     
              D                 S               O   CLASS(*JAVA             
              D                                     
              :'com.paypal.core.rest- 
              D                                     .OAuthTokenCredential'


                                                                                     
              D new_OAuthTokenCredential...                                          
              D                 PR                  like(OAuthTokenCredential)       
              D                                     ExtProc(*JAVA                    
              D                                     
              :'com.paypal.core.rest-          
              D                                     .OAuthTokenCredential'           
              D                                     :*CONSTRUCTOR)                   
              D  clientID                           like(jString)  const             
              D  clientSecret                       like(jString)  const             
                                                                                     
              D getAccessToken...                                                    
              D                 PR                  like(jString)                    
              D                                     ExtProc(*JAVA                    
              D                                     
              :'com.paypal.core.rest-          
              D                                     .OAuthTokenCredential'           
              D                                     :'getAccessToken')               
                                                                                     
                                                                               
              D oauth           s                   like(OAuthTokenCredential
              D clntString      s                   like(jString)              
              D scrtString      s                   like(jString)              
              eval      
              clntString new_String(%trim(ppclnt))  
              eval      
              scrtString new_string(%trim(ppscrt))  
              eval      
              oauth new_OAuthTokenCredential        
                        
              (clntStringscrtString)                
              eval      
              json getAccessToken(oauth

              Comment


              • #8
                Re: Method not found signature problem

                It's java exception. generally this type of error is related to the initialization of a static variables..
                are there any static variables that you using ?
                sorry your information is not enough to find it

                Comment


                • #9
                  Re: Method not found signature problem

                  I do have one static variable. It's a constant. But the program runs in qsh

                  It's got to be related to how I have my prototype defined.

                  Let me ask this.

                  If I get a java exception error and I cancel it, does the java program remain in memory?

                  Because Im getting other strange errors if I try to run it again. I have to sign off/on to clear the job.
                  Last edited by davisty; June 13, 2013, 07:45 AM. Reason: Left something out

                  Comment


                  • #10
                    Re: Method not found signature problem

                    Originally posted by davisty View Post
                    I do have one static variable. It's a constant. But the program runs in qsh
                    do you mind to show the java code which you are running on qsh ?
                    then it is easy to find the issue in rpg intregration

                    Originally posted by davisty View Post
                    Because Im getting other strange errors if I try to run it again. I have to sign off/on to clear the job.
                    you have to restart jvm

                    Comment


                    • #11
                      Re: Method not found signature problem

                      Thank You for your help.

                      There is a property file that it uses. It's getting the end-point from that.

                      package com.paypal.core.rest;


                      import java.io.UnsupportedEncodingException;
                      import java.util.HashMap;
                      import java.util.Map;


                      import org.apache.commons.codec.binary.Base64;


                      import com.google.gson.JsonElement;
                      import com.google.gson.JsonParser;
                      import com.paypal.core.ConfigManager;
                      import com.paypal.core.ConnectionManager;
                      import com.paypal.core.Constants;
                      import com.paypal.core.HttpConfiguration;
                      import com.paypal.core.HttpConnection;
                      import com.paypal.core.SDKUtil;
                      import com.paypal.core.credential.ICredential;


                      public final class OAuthTokenCredential implements ICredential {


                      /**
                      * OAuth URI path parameter
                      */
                      private static final String OAUTH_TOKEN_PATH = "/v1/oauth2/token";


                      /**
                      * Client ID for OAuth
                      */
                      private String clientID;


                      /**
                      * Client Secret for OAuth
                      */
                      private String clientSecret;


                      /**
                      * Access Token that is generated
                      */
                      private String accessToken;


                      /**
                      * Application ID returned by OAuth servers
                      */
                      private transient String appId;


                      /**
                      * Map used for dynamic configuration
                      */
                      private Map<String, String> configurationMap;


                      /**
                      * @param clientID
                      * Client ID for the OAuth
                      * @param clientSecret
                      * Client Secret for OAuth
                      */
                      public OAuthTokenCredential(String clientID, String clientSecret) {
                      super();
                      this.clientID = clientID;
                      this.clientSecret = clientSecret;
                      this.configurationMap = SDKUtil.combineDefaultMap(ConfigManager
                      .getInstance().getConfigurationMap());
                      }


                      /**
                      * @param clientID
                      * Client ID for the OAuth
                      * @param clientSecret
                      * Client Secret for OAuth
                      */
                      public OAuthTokenCredential(String clientID, String clientSecret,
                      Map<String, String> configurationMap) {
                      super();
                      this.clientID = clientID;
                      this.clientSecret = clientSecret;
                      this.configurationMap = SDKUtil.combineDefaultMap(configurationMap);
                      }


                      /**
                      * Computes Access Token by placing a call to OAuth server using ClientID
                      * and ClientSecret. The token is appended to the token type.
                      *
                      * @return the accessToken
                      * @throws PayPalRESTException
                      */
                      public String getAccessToken() throws PayPalRESTException {
                      if (accessToken == null) {
                      // Write Logic for passing in Detail to Identity Api Serv and
                      // computing the token
                      // Set the Value inside the accessToken and result
                      accessToken = generateAccessToken();
                      }
                      return accessToken;
                      }


                      private String generateAccessToken() throws PayPalRESTException {
                      String generatedToken = null;
                      String base64ClientID = generateBase64String(clientID + ":"
                      + clientSecret);
                      generatedToken = generateOAuthToken(base64ClientID);
                      return generatedToken;
                      }


                      /*
                      * Generate a Base64 encoded String from clientID & clientSecret
                      */
                      private String generateBase64String(String clientID)
                      throws PayPalRESTException {
                      String base64ClientID = null;
                      byte[] encoded = null;
                      try {
                      encoded = Base64.encodeBase64(clientID.getBytes("UTF-8"));
                      base64ClientID = new String(encoded, "UTF-8");
                      } catch (UnsupportedEncodingException e) {
                      throw new PayPalRESTException(e.getMessage(), e);
                      }
                      return base64ClientID;
                      }


                      /*
                      * Generate OAuth type token from Base64Client ID
                      */
                      private String generateOAuthToken(String base64ClientID)
                      throws PayPalRESTException {
                      HttpConnection connection = null;
                      HttpConfiguration httpConfiguration = null;
                      String generatedToken = null;
                      try {
                      connection = ConnectionManager.getInstance().getConnection();
                      httpConfiguration = getOAuthHttpConfiguration();
                      connection.createAndconfigureHttpConnection(httpCo nfiguration);
                      Map<String, String> headers = new HashMap<String, String>();
                      headers.put("Authorization", "Basic " + base64ClientID);
                      headers.put(Constants.HTTP_ACCEPT_HEADER, "*/*");
                      headers.put("User-Agent", RESTConfiguration.formUserAgentHeader());
                      String postRequest = "grant_type=client_credentials";
                      String jsonResponse = connection.execute("", postRequest, headers);
                      JsonParser parser = new JsonParser();
                      JsonElement jsonElement = parser.parse(jsonResponse);
                      generatedToken = jsonElement.getAsJsonObject().get("token_type")
                      .getAsString()
                      + " "
                      + jsonElement.getAsJsonObject().get("access_token")
                      .getAsString();
                      appId = jsonElement.getAsJsonObject().get("app_id").getAsS tring();
                      } catch (Exception e) {
                      throw new PayPalRESTException(e.getMessage(), e);
                      }
                      return generatedToken;
                      }


                      /*
                      * Get HttpConfiguration object for OAuth server
                      */
                      private HttpConfiguration getOAuthHttpConfiguration() {
                      HttpConfiguration httpConfiguration = new HttpConfiguration();
                      httpConfiguration
                      .setHttpMethod(Constants.HTTP_CONFIG_DEFAULT_HTTP_ METHOD);
                      String endPointUrl = configurationMap.get(Constants.ENDPOINT);
                      if (endPointUrl == null || endPointUrl.trim().length() <= 0) {
                      String mode = configurationMap.get(Constants.MODE);
                      if (Constants.SANDBOX.equalsIgnoreCase(mode)) {
                      endPointUrl = Constants.REST_SANDBOX_ENDPOINT;
                      } else if (Constants.LIVE.equalsIgnoreCase(mode)) {
                      endPointUrl = Constants.REST_LIVE_ENDPOINT;
                      }
                      }
                      endPointUrl = (endPointUrl.endsWith("/")) ? endPointUrl.substring(0,
                      endPointUrl.length() - 1) : endPointUrl;
                      endPointUrl += OAUTH_TOKEN_PATH;
                      httpConfiguration.setEndPointUrl(endPointUrl);
                      httpConfiguration
                      .setGoogleAppEngine(Boolean.parseBoolean(configura tionMap
                      .get(Constants.GOOGLE_APP_ENGINE)));
                      return httpConfiguration;
                      }


                      }

                      Comment


                      • #12
                        Re: Method not found signature problem

                        not sure but i guess endpointurl is empty..(property file is in classpath ?? ) anyway shall we trace ? set following and give a call to your pgm and check what stdout.log & stderr.log shows
                        Code:
                        ADDENVVAR  ENVVAR(QIBM_USE_DESCRIPTOR_STDIO) VALUE('Y')                
                                                                                                           
                        ADDENVVAR  ENVVAR(QIBM_RPG_JAVA_PROPERTIES) +                          
                                      VALUE('-Djava.version=1.6;-Dos400.run.verbo+              
                                      se=true;-Dos400.stdout=file:/home/mydir/s+              
                                      tdout.log;-Dos400.stderr=file:/home/+                  
                                      /mydir/stderr.log;')    
                                                  
                        ADDENVVAR  ENVVAR(QIBM_RPG_JAVA_EXCP_TRACE) VALUE('Y')
                        Last edited by dhanuxp; June 13, 2013, 09:10 AM.

                        Comment


                        • #13
                          Re: Method not found signature problem

                          Ok, It's going to be a while before I can get to it.

                          But I believe it is getting the properties file. I was getting an error about it not being found, so I included the actual file in the classpath. And Im not getting the error any more. But you may be onto something.

                          Is there any way we can send attachments in this forum?

                          Comment


                          • #14
                            Re: Method not found signature problem

                            So Your program working now ????

                            go advance button , scroll down and under additional options there is a button for attachments

                            Comment


                            • #15
                              Re: Method not found signature problem

                              It's working from the console. But not from the RPG.

                              That's why I was saying that it's got to be in the prototype.

                              I have sent you zip that contains the jar files for source and classes.

                              Let me know if you dont get it.
                              Attached Files

                              Comment

                              Working...
                              X