Dramaturgie

Spring vs. Weblogic

open source vs. commercial JEE

Moskito vs. Elephant

Gunter Winkler, München, 2017-12-18

Gunter Winkler

Weblogic

Oracle WebLogic Server 12c R2 is the industry's best application server for building and deploying enterprise Java EE applications with support for new features for lowering cost of operations, improving performance, enhancing scalability and supporting the Oracle Applications portfolio.
Oracle WebLogic Server 12c, the world’s first cloud-native, enterprise Java platform enables you to fully realize the benefits of cloud computing. Unique multitenancy capability drives massive consolidation. Lightweight microcontainer architecture drives application isolation and 100 percent portability between your private and public cloud. Multi data center high availability architecture protects against application disruption.

Stand: 2017-12-08

Spring & Co.

the source for modern java
The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform.
Spring Boot is designed to get you up and running as quickly as possible, with minimal upfront configuration of Spring.

Weblogic "modules"

    

reference http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html

Open Source

Disziplinen

developers love open source

OSWLS
examples ++++
Maven archetypes++-
documentation + +
community ++o
source code ++--

integration testing is hard

OSWLS
unit ++++
component ++++
integration++o

junit, Mockito, spring-test, jmeter

built-in integration

@RunWith(SpringJUnit4ClassRunner.class)
^1^@SpringApplicationConfiguration^^(classes = SampleJettyApplication.class)
@WebAppConfiguration @DirtiesContext @IntegrationTest("server.port:0")
public class SampleJettyApplicationTests {

  @Value("${local.server.port}") private int port;

  @Test public void testHome() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate()
      .^2^getForEntity("http://localhost:" + this.port, String.class)^^;
    ^3^assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK)^^;
    ^4^assertThat(entity.getBody()).contains("<p>Hello</p>")^^;
  }

}

packaging is easy

OSWLS
Maven +++

maven-war-plugin, maven-ear-plugin, spring-boot-maven-plugin

deploy and run

OSWLS
manually ++o (+)
automatic ++o (-)

bash, WLST

An elephant is light ...

... compared to a whale

"Lightweight microcontainer"

$ docker images
REPOSITORY               TAG    IMAGE ID     CREATED       SIZE
guwi17/java-spring-boot1 latest d81c07d2b0d6 19 hours ago  498 MB
guwi17/weblogic-demo     latest 186690bc821c 2 weeks ago   2.19 GB
guwi17/weblogic-base     latest 9c824e0ed467 2 weeks ago   2.19 GB
guwi17/java-base         latest abdf162be4ff 3 weeks ago   485 MB
debian                   latest 6d83de432e98 6 weeks ago   100 MB 

runtime size

Classic WebApps

OSWLS
Servlet+JSP + ++
JSF o +
thymeleaf +++

Responsive WebApps

Modular WebApps

OSWLS
JAX-RS o o
Spring HATEOAS ++o (+)

Storing Data

OSWLS
WLS JPA/JTA (--)+
hibernate (JPA) + o (+)
Atomikos (JTA) + (--)
Spring Data ++ (+)

Atomikos UserTransaction

public class WrapDataSourceWithAtomikosBpp implements DestructionAwareBeanPostProcessor, Ordered {
  @Override public int getOrder() { return Integer.MIN_VALUE; } // we want to be first

  @Override
  public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
  {
    if (bean instanceof XADataSource) {
      if (bean instanceof OracleDataSource) {
        try { disableCache(bean); } catch (SQLException e) { ... }
      }
      AtomikosDataSourceBean wrapped = new AtomikosDataSourceBean();
      wrapped.setXaDataSource((XADataSource) bean);
      wrapped.setMinPoolSize(minXaPoolSize);
      wrapped.setMaxPoolSize(maxXaPoolSize);
      wrapped.setUniqueResourceName(beanName);
      try { wrapped.setLoginTimeout(60); } catch (SQLException e) { ... }
      return wrapped;
    } else {
      return bean;
    }
  }
}

environment discovery

example: hierarchical properties

@Configuration
@PropertySource(name = "myprops", ignoreResourceNotFound = true,
    value = {
        "^1^file:${user.dir}/config/override.properties^^",
        "^2^file:${user.dir}/config/${stage}/override.properties^^",
        "^3^file:${user.dir}/config/${componentName}/override.properties^^",
        "^4^classpath:/config/${stage}/${componentName}.properties^^",
        "^5^classpath:application-default.properties^^"})
public class DiscoveryConfig {

  @Bean
  public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
  }

}

alternative: TNG Property Loader

Spring inside WLS

weblogic-application.xml

<weblogic-application
	xmlns="http://xmlns.oracle.com/weblogic/weblogic-application"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application 
	    http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
	<prefer-application-packages>
		<package-name>org.slf4j.*</package-name>
		<package-name>^1^org.springframework.*^^</package-name>
		<package-name>^2^org.hibernate.*^^</package-name>
		<package-name>com.fasterxml.jackson.*</package-name>
		<package-name>org.apache.log4j.*</package-name>
		<package-name>org.apache.commons.*</package-name>
		<package-name>com.google.*</package-name>
		<package-name>org.joda.time.*</package-name>
		<package-name>antlr.*</package-name>
		<package-name>javax.persistence.*</package-name>
		<package-name>org.javassist.*</package-name>
		<package-name>javassist.*</package-name>
		<package-name>org.apache.xerces.*</package-name>
	</prefer-application-packages>
	<prefer-application-resources>
		<resource-name>^3^org/slf4j/impl/StaticLoggerBinder.class^^</resource-name>
		<resource-name>^4^META-INF/services/*^^</resource-name>
	</prefer-application-resources>
</weblogic-application>

build with Spring and run in WLS

(if you have to)

Vielen Dank!

Fragen?

guwi17@gmx.de
gunter.winkler@tngtech.com
https://github.com/guwi17