TWL's Algorithms

We tried to update a nested jar file inside a jar file and we see the following exception when we execute our java program residing in the jar file:

Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spin-sdk-0-SNAPSHOT.jar
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:109)
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:87)
	at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:72)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/spin-sdk-0-SNAPSHOT.jar'
	at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:252)
	at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:237)
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:104)
	... 4 more

Turns out that we cannot update the nested jar file using the linux’s zip program. We must extract all files in the jar, then put in the nested jar file together with the extracted files in the same directory, and finally create the jar again with the jar application.

Example execution (replace yourjar.jar with the name of your container jar file that will contain the nested jar file)

jar -xvf yourjar.jar
# put your nested jar here
jar -cfM0 yourjar.jar ./

update
    salesCodes s
set description = 
    ((select
        description
      from
        tempSalesCodes tmp
      where
        tmp.code = s.code
    ))
where s.code in (select code from tempSalesCodes);
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
private LocalDateTime messageTimestamp;

We use the above pattern for a field called messageTimestamp containing dates such as 2022-08-03T11:11:14+08:00

To know all the possible characters that we can use in the pattern field, please refer to the SimpleDateFormat class in javadoc. Example link: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

Say you have a haproxy front end listening on HTTPS 443 and have two different processes that will process the request depending on what hostname was used in reaching your haproxy server. How do you do that?

Example haproxy.cfg snippet:

frontend  banks *:443
    mode tcp
    use_backend first if { req.ssl_sni -i first.example.com }
    use_backend second if { req.ssl_sni -i second.example.com }
    default_backend             first

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend first
    mode         tcp
    balance      roundrobin
    server  app1 127.0.0.1:8080 check

backend second
    mode         tcp
    balance      roundrobin
    server  app2 127.0.0.1:8081 check

By default, Chrome’s developer console comes with a selector $ also. However, it is different from jQuery’s $ selector. If we want to test our jQuery rapidly, we will need to use jQuery’s $ selector instead. How?

Run these command in the developer console to overwrite $ with jQuery’s selector:

(function(e, s) {
e.src = s;
e.onload = function() {
jQuery.noConflict();
console.log('jQuery injected');
};
document.head.appendChild(e);
})(document.createElement('script'), 'https://code.jquery.com/jquery-latest.min.js');

Wait for the console to show:

jQuery loaded

Then run the following command:

var $ = jQuery;

After you run the above code, the $ will become jQuery’s selector.

@Bean
public static CustomEditorConfigurer customEditorConfigurer () {
    CustomEditorConfigurer cec = new CustomEditorConfigurer();
    cec.setPropertyEditorRegistrars(
                        new PropertyEditorRegistrar[]{
                                            new MyCustomBeanRegistrar()});
    return cec;
}

static class MyCustomBeanRegistrar implements PropertyEditorRegistrar {
    @Override
    public void registerCustomEditors (PropertyEditorRegistry registry) {
        registry.registerCustomEditor(Proxy.Type.class,
                                      new ProxyTypeEditor());
    }
}

static class ProxyTypeEditor extends PropertyEditorSupport {
    @Override
    public String getAsText() {
        Proxy.Type proxyType = (Proxy.Type)getValue();
        return proxyType.name();
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        Proxy.Type proxyType = Proxy.Type.valueOf(text);
        setValue(proxyType);
    }
}

The code above is an example of converting a string into a enum – Proxy.Type while loading it from a property file. You just have to add those methods in the code above to your class annotated with @Configuration. I know enums will be converted automatically by Spring, but this is just for the purpose of providing an example.

Per SSL/TLS specifications, cipher suites have the form:
SSL_KeyExchangeAlg_WITH_CipherAlg_MacAlg
or
TLS_KeyExchangeAlg_WITH_CipherAlg_MacAlg

For example, the cipher suite TLS_RSA_WITH_AES_128_CBC_SHA uses RSA as the
key exchange algorithm, AES_128_CBC (128 bits AES cipher algorithm in CBC
mode) as the cipher (encryption) algorithm, and SHA-1 as the message digest
algorithm for HMAC.

The algorithm can be one of the following standard algorithm names:
1. JSSE cipher suite name, e.g., TLS_RSA_WITH_AES_128_CBC_SHA
2. JSSE key exchange algorithm name, e.g., RSA
3. JSSE cipher (encryption) algorithm name, e.g., AES_128_CBC
4. JSSE message digest algorithm name, e.g., SHA

Hence you can add to the jdk.tls.disabledAlgorithms according to the formats listed above.

git diff -w > gitdiffw
git stash  # or git reset --hard if you feel confident
git apply --ignore-space-change gitdiffw

Use the above commands to remove whitespace changes in your commit.

How?

Go to this folder via file explorer or command line:

~/.local/share/applications

Then create a file named your_application.desktop and put the following contents

[Desktop Entry]
Type=Application
Name=Eclipse
Comment=Eclipse Integrated Development Environment
Icon=/opt/eclipse/icon.xpm
Exec=/opt/eclipse/eclipse
Terminal=false
Categories=Development;IDE;Java;
StartupWMClass=Eclipse

Replace the file’s contents with information relevant to your application.

Then save it.

When you click the “Show Applications” link, type your application’s name in the search box and you should see the link appearing.

First, you have to enable the eclipse plugin.

In the project/ folder in your project, create a file called plugins.sbt if it does not exist. Then append this line to that file.

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")

Next, run this command in the project’s root directory.

activator compile eclipse

Then in the same directory, run this command, placing 9999 with the debugging port you wish to listen on and 9002 with the port you wish the application to listen on.

activator -jvm-debug 9999 ~"run 9002"

  • Open Eclipse and import the project as existing project into the workspace.
  • Right-click your project, then choose Debug As -> Debug Configurations...
  • Right-click Remote Java Application, then click New.
  • The host should already be set to localhost. Set the port to 9999 (the default port used by the activator -jvm-debug command).
  • Click Apply to save, then Debug to connect to your running Play instance.

Go to your website through the browser and start debugging.

Create your own website, free on WordPress.com.Create your own website.
Start free