2 Replies Latest reply on Dec 2, 2005 3:00 PM by 843833

    NoClassDefFoundError for com.sun.xml.wss.SecurityEnvironment at runtime

    843833
      I am trying to invoke a stored query on a registry. I have followed all directions for configuring the environment to do so using the jwsdp1.6+tomcat download. Everytime time I try to execute a findObjects(...) on the businessquerymanagerimpl I receive the exception below. I've tried both jdk1.4 and 1.5, added the BouncyCastle provider and still receive the exception.


      Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/xml/wss/SecurityEnvironment
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:164)
      at org.freebxml.omar.common.security.SoapSecurityUtil.getInstance(SoapSecurityUtil.java:67)
      at org.freebxml.omar.common.SOAPMessenger.sendSoapRequest(SOAPMessenger.java:189)
      at org.freebxml.omar.common.SOAPMessenger.sendSoapRequest(SOAPMessenger.java:109)
      at org.freebxml.omar.common.QueryManagerSOAPProxy.submitAdhocQueryInternal(QueryManagerSOAPProxy.java:68)
      at org.freebxml.omar.common.QueryManagerSOAPProxy.submitAdhocQuery(QueryManagerSOAPProxy.java:49)
      at org.freebxml.omar.client.xml.registry.DeclarativeQueryManagerImpl.executeQuery(DeclarativeQueryManagerImpl.java:180)
      at org.freebxml.omar.client.xml.registry.DeclarativeQueryManagerImpl.executeQuery(DeclarativeQueryManagerImpl.java:137)
      at org.freebxml.omar.client.xml.registry.DeclarativeQueryManagerImpl.executeQuery(DeclarativeQueryManagerImpl.java:116)
      at org.freebxml.omar.client.xml.registry.BusinessQueryManagerImpl.findObjects(BusinessQueryManagerImpl.java:260)
      at JAXRQueryStored.executeQuery(Unknown Source)
      at JAXRQueryStored.main(Unknown Source)
      Java Result: 1
        • 1. Re: NoClassDefFoundError for com.sun.xml.wss.SecurityEnvironment at runtime
          843833
          Is it SecurityEnvironmentHandler that u r referring to?
          • 2. Re: NoClassDefFoundError for com.sun.xml.wss.SecurityEnvironment at runtime
            843833
            No, it's the SecurityEnvironment class.

            It fails on this line
            BulkResponse response =
                            bqm.findObjects("AdhocQuery", null, namePatterns, 
                                null, null, null, null);
            Entire class
            ----------------------
            /*
             * Copyright (c) 2005 Sun Microsystems, Inc.  All rights reserved.  U.S.
             * Government Rights - Commercial software.  Government users are subject
             * to the Sun Microsystems, Inc. standard license agreement and
             * applicable provisions of the FAR and its supplements.  Use is subject
             * to license terms.
             *
             * This distribution may include materials developed by third parties.
             * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
             * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
             * other countries.
             *
             * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
             *
             * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
             * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
             * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
             * en vigueur de la FAR (Federal Acquisition Regulations) et des
             * supplements a celles-ci.  Distribue par des licences qui en
             * restreignent l'utilisation.
             *
             * Cette distribution peut comprendre des composants developpes par des
             * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
             * sont des marques de fabrique ou des marques deposees de Sun
             * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
             */
            
            import javax.xml.registry.*;
            import javax.xml.registry.infomodel.*;
            import java.net.*;
            import java.util.*;
            import java.io.*;
            import java.security.*;
            import java.security.cert.X509Certificate;
            import javax.security.auth.x500.X500PrivateCredential;
            import org.freebxml.omar.client.xml.registry.BusinessQueryManagerImpl;
            import org.freebxml.omar.client.xml.registry.infomodel.AdhocQueryImpl;
            import org.freebxml.omar.client.xml.registry.util.JAXRUtility;
            
            /**
             * The JAXRQueryStored class consists of a main method, a
             * makeConnection method, an executeQuery method, and some
             * private helper methods. It retrieves a stored query from the
             * registry and invokes it as a declarative query.
             */
            public class JAXRQueryStored {
                Connection connection = null;
            
                public JAXRQueryStored() {
                }
            
                public static void main(String[] args) {
                    
                    //BEH: Note, you had to set the truststore for the client (which also includes the cert and key for the server, saved time
                    //by not having to create truststore
                    System.setProperty("javax.net.ssl.trustStore","d:\\data\\bhizey\\My Documents\\localCert\\keystore.jks");
                    System.setProperty("javax.net.ssl.trustStorePassword", "ebxmlrr");        
                    
                    ResourceBundle registryBundle =
                        ResourceBundle.getBundle("JAXRExamples");
            
                    String queryURL = registryBundle.getString("query.url");
                    String publishURL = registryBundle.getString("publish.url");
            
                    JAXRQueryStored jq = new JAXRQueryStored();
            
                    jq.makeConnection(queryURL, publishURL);
            
                    jq.executeQuery();
                }
            
                /**
                 * Establishes a connection to a registry.
                 *
                 * @param queryUrl        the URL of the query registry
                 * @param publishUrl      the URL of the publish registry
                 */
                public void makeConnection(String queryUrl, String publishUrl) {
                    ResourceBundle bundle = ResourceBundle.getBundle("JAXRExamples");
            
                    /*
                     * Define connection configuration properties.
                     * For simple queries, you need the query URL.
                     */
                    Properties props = new Properties();
                    props.setProperty("javax.xml.registry.queryManagerURL", queryUrl);
            
                    try {
                        ConnectionFactory factory = JAXRUtility.getConnectionFactory();
                        factory.setProperties(props);
                        connection = factory.createConnection();
                        System.out.println("Created connection to registry");
                        // Get authorization from the registry
            
                        String keystorePath = bundle.getString("security.keystorePath");
                        String storepass = bundle.getString("security.storepass");
                        String alias = bundle.getString("security.alias");
                        String keypass = bundle.getString("security.keypass");
            
                        Set credentials = new HashSet();
                        credentials = 
                            getCredentialsFromKeystore(keystorePath, storepass, alias, keypass);
                        System.out.println("BEFORE CREDENTIALS SET");
                        connection.setCredentials(credentials);
                        System.out.println("CREDENTIALS SET");
                        System.out.println("Established security credentials");
                    } catch (Exception e) {
                        e.printStackTrace();
            
                        if (connection != null) {
                            try {
                                connection.close();
                            } catch (JAXRException je) {
                            }
                        }
                    }
                }
            
                /**
                 * Calls the GetCallersUser stored query.
                 *
                 * @param qString        the string argument
                 */
                public void executeQuery() {
                    RegistryService rs = null;
                    DeclarativeQueryManager dqm = null;
                    BusinessQueryManagerImpl bqm = null;
            
                    try {
                        // Get registry service and query manager
                        rs = connection.getRegistryService();
                        dqm = rs.getDeclarativeQueryManager();
                        bqm = (BusinessQueryManagerImpl) rs.getBusinessQueryManager();
                        System.out.println("Got registry service and " + "query managers");
                        
                        // Find the AdhocQuery you want to call
                        // Define name pattern
                        Collection namePatterns = new ArrayList();
                        namePatterns.add("GetCallersUser");
            System.out.println("BEFORE BULK RESPONSE GOTTEN");//FAILS DURING NEXT CALL.
                        // Find objects with name GetCallersUser
                        BulkResponse response =
                            bqm.findObjects("AdhocQuery", null, namePatterns, 
                                null, null, null, null);
            System.out.println("AFTER BULK RESPONSE GOTTEN");
                        Collection queries = response.getCollection();
            System.out.println("QUERIES GOTTEN");
                        // get the first (only) query and invoke it
                        Iterator qIter = queries.iterator();
            System.out.println("ITERATOR GOTTEN");
                        if (!(qIter.hasNext())) {
                            System.out.println("No objects found");
                        } else {
                            AdhocQueryImpl aq = (AdhocQueryImpl) qIter.next();
                            String qName = getName(aq);
                            System.out.println("Query name: " + qName);
                            
                            // Retrieve query type and query string
                            int qType = aq.getType();
                            if (qType == Query.QUERY_TYPE_SQL) {
                                System.out.println("Query type is SQL");
                            } else {
                                System.out.println("Query type is not SQL");
                            }
                            String qString = aq.toString();
                            Query query = dqm.createQuery(qType, qString);
            
                            BulkResponse br = dqm.executeQuery(query);
                            Collection objects = br.getCollection();
            
                            // Display information about the objects found
                            Iterator objIter = objects.iterator();
                            if (!(objIter.hasNext())) {
                                System.out.println("No objects found");
                            } else {
                                while (objIter.hasNext()) {
                                    RegistryObject obj = (RegistryObject) objIter.next();
                                    Concept objType = obj.getObjectType();
                                    System.out.println("Object type is " + 
                                        objType.getValue());
                                    System.out.println("Object name is " + getName(obj));
                                    System.out.println("Object description is " + 
                                        getDescription(obj));
            
                                    // Print spacer between objects
                                    System.out.println(" --- ");
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        // At end, close connection to registry
                        if (connection != null) {
                            try {
                                connection.close();
                            } catch (JAXRException je) {
                            }
                        }
                    }
                }
            
                /**
                 * From test/org/freebxml/omar/client/common/ClientTest.java.
                 *
                 * Obtains a set of credentials using a certificate.
                 *
                 * @param keystorePath   location of client keystore
                 * @param storepass      keystore password
                 * @param alias          user name
                 * @param keypass        user password
                 *
                 * @return   a set of credentials
                 */
                private Set getCredentialsFromKeystore(String keystorePath, 
                        String storepass, String alias, String keypass) throws Exception {
                    HashSet credentials = new HashSet();
                    KeyStore keyStore = KeyStore.getInstance("JKS");
                    System.out.println("KEYSTORE GOTTEN");
                    keyStore.load(new BufferedInputStream(new FileInputStream(keystorePath)), 
                        storepass.toCharArray());
                    System.out.println("KEYSTORE LOADED");
                    X509Certificate cert = (X509Certificate) keyStore.getCertificate(alias);
                    System.out.println("CERT GOTTEN");
                    PrivateKey privateKey = 
                        (PrivateKey) keyStore.getKey(alias, keypass.toCharArray());
                    System.out.println("PRIVATEKEY GOTTEN");
                    if(cert==null)
                        System.out.println("CERT IS NULL");
                    if(privateKey==null)
                        System.out.println("PRIVATEKEY IS NULL");
                    if(alias == null)
                        System.out.println("ALIAS IS NULL");
                    credentials.add(new X500PrivateCredential(cert, privateKey, alias));
                    System.out.println("CREDENTIALS ADDED");
                    return credentials;
                }
            
                /**
                 * Returns the name value for a registry object.
                 *
                 * @param ro        a RegistryObject
                 * @return                the String value
                 */
                private String getName(RegistryObject ro) throws JAXRException {
                    try {
                        return ro.getName()
                                 .getValue();
                    } catch (NullPointerException npe) {
                        return "No Name";
                    }
                }
            
                /**
                 * Returns the description value for a registry object.
                 *
                 * @param ro        a RegistryObject
                 * @return                the String value
                 */
                private String getDescription(RegistryObject ro) throws JAXRException {
                    try {
                        return ro.getDescription()
                                 .getValue();
                    } catch (NullPointerException npe) {
                        return "No Description";
                    }
                }
            
                /**
                 * Returns the key id value for a registry object.
                 *
                 * @param ro        a RegistryObject
                 * @return                the String value
                 */
                private String getKey(RegistryObject ro) throws JAXRException {
                    try {
                        return ro.getKey()
                                 .getId();
                    } catch (NullPointerException npe) {
                        return "No Key";
                    }
                }
            }