+ Start a Discussion
iceberg4uiceberg4u 

Problems with running applets in Visual Force

The applet starts successfully.Its purpose is to upload a pdf file.I have used the Salesforce APIs.And have included them in the JAR that I have prepared.The whole process works fine in HTML locally.The error that I am getting on Visual Force is :->

Exception in thread "AWT-EventQueue-4" java.lang.ClassFormatError: Incompatible magic value 168430090 in class file javax/servlet/ServletConfig
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getDeclaredMethod(Unknown Source)
    at org.apache.commons.discovery.tools.ClassUtils.findPublicStaticMethod(ClassUtils.java:116)
    at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:178)
    at org.apache.axis.configuration.EngineConfigurationFactoryFinder.access$200(EngineConfigurationFactoryFinder.java:46)
    at org.apache.axis.configuration.EngineConfigurationFactoryFinder$1.run(EngineConfigurationFactoryFinder.java:128)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:113)
    at org.apache.axis.configuration.EngineConfigurationFactoryFinder.newFactory(EngineConfigurationFactoryFinder.java:160)
    at org.apache.axis.client.Service.getEngineConfiguration(Service.java:813)
    at org.apache.axis.client.Service.getAxisClient(Service.java:104)
    at org.apache.axis.client.Service.<init>(Service.java:113)
    at SforceServiceLocator.<init>(SforceServiceLocator.java:8)
    at UploadingPDF.login(UploadingPDF.java:78)
    at UploadingPDF.actionPerformed(UploadingPDF.java:224)
    at javax.swing.JTextField.fireActionPerformed(Unknown Source)
    at javax.swing.JTextField.postActionEvent(Unknown Source)
    at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


What can I do??Do i need to do the login and other such commands in this java file heres the whole java fileI have used this function as well.The error starts immediately after printing"Creating the binding to the web service":->

public boolean login() {
        un = ****;
        if (un.length() == 0) {
            return false;
        }
        pw = ******;
        if (pw.length() == 0) {
            return false;
        }

        // Provide feed back while we create the web service binding
        System.out.println("Creating the binding to the web service...");

    
        /*
         * There are 2 ways to get the binding, one by passing a url to the
         * getSoap() method of the SforceServiceLocator, the other by not
         * passing a url. In the second case the binding will use the url
         * contained in the wsdl file when the proxy was generated.
         */
        try {
            binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
            System.out
                    .println("The login url is: "
                            + binding
                                    ._getProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY));
        } catch (ServiceException ex) {
            System.out
                    .println("ERROR: creating binding to soap service, error was: \n"
                            + ex.getMessage());
            System.out.print("Hit return to continue...");
            return false;
        }
       

        // Time out after a minute
        binding.setTimeout(60000);

        // Attempt the login giving the user feedback
        System.out.println("LOGGING IN NOW....");
        try {
            loginResult = binding.login(un, pw);
        } catch (LoginFault lf) {
            System.out.println(lf.getExceptionMessage());
            // lf.printStackTrace();
          //  getUserInput("\nHit return to continue...");
            return false;
        } catch (UnexpectedErrorFault uef) {
            System.out.println(uef.getExceptionMessage());
            uef.printStackTrace();
           // getUserInput("\nHit return to continue...");
            return false;
        } catch (RemoteException re) {
            System.out.println(re.getMessage());
            re.printStackTrace();
           // getUserInput("\nHit return to continue...");
            return false;
        }

        System.out
                .println("\nThe session id is: " + loginResult.getSessionId());
        System.out.println("\nThe new server url is: "
                + loginResult.getServerUrl());

        // set the session header for subsequent call authentication
        binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,
                loginResult.getServerUrl());

        // Create a new session header object and set the session id to that
        // returned by the login
        SessionHeader sh = new SessionHeader();
        sh.setSessionId(loginResult.getSessionId());
        binding.setHeader(new SforceServiceLocator().getServiceName()
                .getNamespaceURI(), "SessionHeader", sh);

        loggedIn = true;

        // call the getServerTimestamp method
        getServerTimestampSample();

        // call the getUserInfo method
        getUserInfoSample();

        return true;

    }


Best Answer chosen by Admin (Salesforce Developers) 
sfdcdev.wordpress.comsfdcdev.wordpress.com

I have had this issue as well. Later I found out that the Magic Number issue is caused when the Jar file is not properly being returned by Server on which it is hosted. 

Make sure that you refered to the jar file correctly before you try something else. 

One more thing it is ok to compile the Jar file in JRE 1.5 and run it on 1.6 this should not cause any issues. 

Make sure the jar is refered in the way shown below. 


<applet code="AppLauncherApplet.class" archive="{!$Resource.SignedAppLauncherAppletLauncher}" width="400" height="400"> 

All Answers

dchasmandchasman
I am not sure what is going on here but I would like to point out that with the new apex:inputFile component I suspect you can accomplish your goals with little to no code, no applet or client side java at all, etc.
iceberg4uiceberg4u
I cannot use this component as I need to use these files again for uploading and scanning.Please is there a way of finding out which JVM is supported in Salesforce.The classfiles that I have is compiled using jre 1.5. I even tried with 1.6 but I still get the same error.Visiting many forums and other sites I was just able to find out that its the error of version compatibility.Or if anything please suggest...


David VPDavid VP
What jvm version salesforce is running has no influence on your applets. These are run by the JVM on the client machines. Salesforce just 'hosts' the jar files, that's all.
Do you have the problem on the same PC that runs it locally without errors ?


-David
iceberg4uiceberg4u
No I do not have any such errors while I perform it in my computer.I have used the applet in my own eclipse's appletviewer version 1.4,1.5 and 1.6.There were no such errors and file got uploaded.

I then tried each of these versions in an HTML file after making a jar file out of my project.It still was working properly and the file was getting uploaded.

Now I have put the jar file as a static resource after zipping it.The application gives the above error when I put it there.

Also after putting in a lots of system.out.prinltn I have found the following things:->

1)My class file that is called ApptoAppl.class is called. in the VF page.
2)When I call a function present in the salesforce class files that i downloaded from wiki I get the error i.e. the class just does not get loaded

This is the call that I have made in main class file.

binding = (SoapBindingStub) new SforceServiceLocator().getSoap();

The call does not occur I do not know for what reason,Here is the class that is written

public class SforceServiceLocator extends org.apache.axis.client.Service implements SforceService {
public Soap getSoap() throws javax.xml.rpc.ServiceException {
       java.net.URL endpoint;
        try {
            System.out.println("Hello");
            endpoint = new java.net.URL(Soap_address);
        }
        catch (java.net.MalformedURLException e) {
            throw new javax.xml.rpc.ServiceException(e);
        }
        return getSoap(endpoint);
    }
}

Is it because of the jar files axis,axis-ant that I have used??But these jar files work properly when I use it in my html environment.
SuperfellSuperfell
does your jar contain all your dependencies rejar'd into the one jar? where are you expecting it to load the axis jars from?
iceberg4uiceberg4u
I have uploaded the salesforce api and my main class file in one jar and the other axis and ant jars i have signed them.Then these jar files i have zipped in one file and loaded in static resource
SuperfellSuperfell
do you have a manifest in the main jar that details the entries to the other jars?
iceberg4uiceberg4u
Yes I have the manifest file in the main jar file.But I do not see any entry made to the other jar files.If that is the mistake could you please help me out as to how do i write it in the manifest file??For example I am using "axis.jar" over here.


sfdcdev.wordpress.comsfdcdev.wordpress.com

I have had this issue as well. Later I found out that the Magic Number issue is caused when the Jar file is not properly being returned by Server on which it is hosted. 

Make sure that you refered to the jar file correctly before you try something else. 

One more thing it is ok to compile the Jar file in JRE 1.5 and run it on 1.6 this should not cause any issues. 

Make sure the jar is refered in the way shown below. 


<applet code="AppLauncherApplet.class" archive="{!$Resource.SignedAppLauncherAppletLauncher}" width="400" height="400"> 

This was selected as the best answer
MiddhaMiddha

I am trying to save the applet in static resource and facing many issues. Can i get a working example of any applet saved in static resource and connecting to salesforce.

 

Can anyone please provide me with that?