IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#TechXchangePresenter
 View Only
  • 1.  Not able to compile Java Service

    Posted Tue June 26, 2007 05:22 PM

    Hello All,
    I wrote a java service which encrypts based on the tripleDES algorithm.

    I imported the following in the shared tab

    javax.crypto.Cipher;
    javax.crypto.BadPaddingException;
    javax.crypto.IllegalBlockSizeException;
    javax.crypto.KeyGenerator;
    java.security.Key;
    java.security.InvalidKeyException;

    I included the following property in the extended field

    watt.server.compile=javac -O -classpath {0} -d {1} {2}

    when i try to compile the java service i am getting the following error

    Java Service Error
    D:\wm61\IntegrationServer\packages\Test\code\source\Test.java:63: unreported exception java.security.NoSuchAlgorithmException; must be caught or declared to be thrown
    key = KeyGenerator.getInstance(algorithm).generateKey();
    ^
    D:\wm61\IntegrationServer\packages\Test\code\source\Test.java:64: unreported exception java.security.NoSuchAlgorithmException; must be caught or declared to be thrown
    cipher = Cipher.getInstance(algorithm);
    ^
    D:\wm61\IntegrationServer\packages\Test\code\source\Test.java:67: unreported exception java.security.InvalidKeyException; must be caught or declared to be thrown
    cipher.init(Cipher.ENCRYPT_MODE, key);
    ^
    D:\wm61\IntegrationServer\packages\Test\code\source\Test.java:69: unreported exception javax.crypto.IllegalBlockSizeException; must be caught or declared to be thrown
    byte recoveredBytes = cipher.doFinal(inputBytes);
    ^
    Note: D:\wm61\IntegrationServer\packages\Test\code\source\Test.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.
    4 errors
    could someone please help how to compile this code sucessfully.
    Please find attached the java service code

    Thanks in Advance
    yarkar
    EncryptionCode.txt (707 Bytes)


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: Not able to compile Java Service

    Posted Tue June 26, 2007 05:32 PM

    Wrap your code in a try-catch block.

    try {
    key = KeyGenerator.getInstance(algorithm).generateKey();
    cipher = Cipher.getInstance(algorithm);
    
    cipher.init(Cipher.ENCRYPT_MODE, key);
    byte[] inputBytes = inputString.getBytes();
    byte[] recoveredBytes = cipher.doFinal(inputBytes);
    encryptedData = new String(recoveredBytes);
    } catch (Exception ex) {
    throw new ServiceException("Error:  something bad happened - " + ex);
    }

    You might need to go through some basic java training and purchase a book or two. A couple of books I’d recommend given your example is “Beginning Cryptography with Java” by David Hook. or “Java Security” by Scott Oakes.

    Mark


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: Not able to compile Java Service

    Posted Tue June 26, 2007 07:11 PM

    Mark,
    Than You for the reply.

    I included the latest code with errorHandling but when i compile the code i get the nullPointer exception.Could you let me know how to fix this problem.

    Please find attached the latest code.

    Thanks in Advance,
    Yarkar
    EncryptionCode.txt (785 Bytes)


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: Not able to compile Java Service

    Posted Tue June 26, 2007 07:13 PM

    Sorry. I am unable to help you debug your code. If you are just learning java, you might want to start with something easier than encryption.

    Mark


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 5.  RE: Not able to compile Java Service

    Posted Mon July 16, 2007 10:57 PM

    Hi Yarkar,

    Can I have the inputString you are supplying for this service? The probable reason could be that your inputString does not meet the blockSize length. The default blockSize length is 8 bytes. And so your inputString should have its length in multiple of 8 bytes. In case it is not in multiple of 8 Bytes you may need to append with the required Bytes . Try running the service with inputString as multiples of 8 Bytes an hope this would help you to try for alternate solutions like as mentioned to append with required number of Bytes.

    • Dinakar.

    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services