Skip to content

Commit

Permalink
Refactor weblogic app lifecycle listener quickfix for code readabilit…
Browse files Browse the repository at this point in the history
…y. Cleaned up imports. Added test files for weblogic lazy DB transactions.
  • Loading branch information
John Steele committed Apr 11, 2017
1 parent 8167e04 commit 6360da3
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 32 deletions.
Expand Up @@ -75,12 +75,8 @@ private String refactor(QuickfixLocationDTO locationDTO) throws Exception
{
if (method.getName().toString().equals("lookupService"))
{
for (Iterator<Object> iter = method.getBody().statements().iterator(); iter.hasNext();)
{
iter.next();
iter.remove();
}

method.getBody().statements().clear();

// Context context = new InitialContext();
ClassInstanceCreation creation = ast.newClassInstanceCreation();
creation.setType(ast.newSimpleType(ast.newSimpleName("InitialContext")));
Expand Down
Expand Up @@ -2,38 +2,25 @@

import java.util.logging.Logger;

import org.apache.commons.validator.routines.InetAddressValidator;
import org.jboss.windup.ast.java.data.TypeReferenceLocation;
import org.jboss.windup.config.AbstractRuleProvider;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.loader.RuleLoaderContext;
import org.jboss.windup.config.metadata.RuleMetadata;
import org.jboss.windup.config.operation.Iteration;
import org.jboss.windup.config.operation.iteration.AbstractIterationOperation;
import org.jboss.windup.config.phase.MigrationRulesPhase;
import org.jboss.windup.config.query.Query;
import org.jboss.windup.config.query.QueryPropertyComparisonType;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.graph.model.resource.SourceFileModel;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.reporting.category.IssueCategoryModel;
import org.jboss.windup.reporting.category.IssueCategoryRegistry;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.reporting.model.QuickfixModel;
import org.jboss.windup.reporting.model.QuickfixType;
import org.jboss.windup.reporting.quickfix.Quickfix;
import org.jboss.windup.rules.apps.java.condition.JavaClass;
import org.jboss.windup.rules.apps.java.ip.HardcodedIPLocationModel;
import org.jboss.windup.rules.apps.java.model.JavaClassModel;
import org.jboss.windup.rules.apps.java.model.JavaSourceFileModel;
import org.jboss.windup.rules.apps.java.scan.ast.JavaTypeReferenceModel;
import org.jboss.windup.rules.apps.xml.model.XmlFileModel;
import org.jboss.windup.rules.files.condition.FileContent;
import org.jboss.windup.rules.files.model.FileLocationModel;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.config.Rule;
import org.ocpsoft.rewrite.context.EvaluationContext;

/**
Expand All @@ -47,7 +34,6 @@ public class NonPortableJNDInamespaceRuleProvider extends AbstractRuleProvider
private static final String RULE_ID = "non-portable-JNDI-namespace";
private static final String HINT_TITLE = "Non-portable JNDI namepsace reference.";
private static final String HINT = "InitialContext should be instantiated with no arguments. Once an instance is constructed, look up the service using portable JNDI lookup syntax. Ensure also that in case system properties for InitialContext are provided, they do not need to be changed for the JBoss.";
// "Non-portable JNDI namepsace must be refactored to use standardized portable JNDI namespaces.";
private static final String QUICKFIX_NAME = "InitialContext should be instantiated with no arguments. Once an instance is constructed, look up the service using portable JNDI lookup syntax";

@Override
Expand All @@ -56,8 +42,6 @@ public Configuration getConfiguration(RuleLoaderContext context)
return ConfigurationBuilder
.begin()
.addRule()
// for all files ending in java, properties, and xml,
// query for the regular expression {ip}
.when(FileContent.matches("Service service = (Service)context.lookup("))
.perform(new AbstractIterationOperation<FileLocationModel>()
{
Expand Down
Expand Up @@ -136,23 +136,15 @@ private void refactorLifecycleMethods(AST ast, TypeDeclaration typeDecl)
postStartAnnotation.setTypeName(ast.newName("PostConstruct"));
method.modifiers().add(0, postStartAnnotation);
method.setName(ast.newSimpleName("startup"));
for (Iterator<Object> iter = method.parameters().iterator(); iter.hasNext();)
{
iter.next();
iter.remove();
}
method.parameters().clear();
}
else if (method.getName().toString().equals("preStop"))
{
MarkerAnnotation preStopAnnotation = ast.newMarkerAnnotation();
preStopAnnotation.setTypeName(ast.newName("PreDestroy"));
method.modifiers().add(0, preStopAnnotation);
method.setName(ast.newSimpleName("shutdown"));
for (Iterator<Object> iter = method.parameters().iterator(); iter.hasNext();)
{
iter.next();
iter.remove();
}
method.parameters().clear();
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions test-files/summit-demo-test/solution/weblogic-ejb-jar.xml
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<stateful-session-descriptor>
<allow-concurrent-calls>true</allow-concurrent-calls>
</stateful-session-descriptor>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ItemLookupBean</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<transaction-descriptor>
<trans-timeout-seconds>180</trans-timeout-seconds>
</transaction-descriptor>
<enable-call-by-reference>true</enable-call-by-reference>
<run-as-principal-name>Admin</run-as-principal-name>
<jndi-name>ejb/ItemLookupBean</jndi-name>
<entity-descriptor>
<persistence>
<delay-updates-until-end-of-tx>True</delay-updates-until-end-of-tx>
</persistence>
</entity-descriptor>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ProductCatalogBean</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<transaction-descriptor>
<trans-timeout-seconds>180</trans-timeout-seconds>
</transaction-descriptor>
<enable-call-by-reference>true</enable-call-by-reference>
<run-as-principal-name>Admin</run-as-principal-name>
<jndi-name>ejb/ProductCatalogBean</jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>LogEventSubscriber</ejb-name>
<message-driven-descriptor>
<destination-jndi-name>jms/LogEventQueue</destination-jndi-name>
</message-driven-descriptor>
<run-as-principal-name>admin_user</run-as-principal-name>
</weblogic-enterprise-bean>
<security-role-assignment>
<role-name>acme_user</role-name>
<principal-name>AnvilUser</principal-name>
<principal-name>Admin</principal-name>
</security-role-assignment>
<!-- http://docs.oracle.com/cd/E15051_01/wls/docs103/ejb/DDreference-ejb-jar.html#wp1114299 -->
<idempotent-methods>
<method>
<ejb-name>ItemLookupBean</ejb-name>
<method-name>lookupItem</method-name>
<method-params>
<method-param>java.lang.Long</method-param>
</method-params>
</method>
<method>
<ejb-name>ProductCatalogBean</ejb-name>
<method-name>populateCatalog</method-name>
</method>
</idempotent-methods>
</weblogic-ejb-jar>
62 changes: 62 additions & 0 deletions test-files/summit-demo-test/test/transactions/weblogic-ejb-jar.xml
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<stateful-session-descriptor>
<allow-concurrent-calls>true</allow-concurrent-calls>
</stateful-session-descriptor>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ItemLookupBean</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<transaction-descriptor>
<trans-timeout-seconds>180</trans-timeout-seconds>
</transaction-descriptor>
<enable-call-by-reference>true</enable-call-by-reference>
<run-as-principal-name>Admin</run-as-principal-name>
<jndi-name>ejb/ItemLookupBean</jndi-name>
<entity-descriptor>
<persistence>
<delay-updates-until-end-of-tx>True</delay-updates-until-end-of-tx>
</persistence>
</entity-descriptor>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ProductCatalogBean</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<transaction-descriptor>
<trans-timeout-seconds>180</trans-timeout-seconds>
</transaction-descriptor>
<enable-call-by-reference>true</enable-call-by-reference>
<run-as-principal-name>Admin</run-as-principal-name>
<jndi-name>ejb/ProductCatalogBean</jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>LogEventSubscriber</ejb-name>
<message-driven-descriptor>
<destination-jndi-name>jms/LogEventQueue</destination-jndi-name>
</message-driven-descriptor>
<run-as-principal-name>admin_user</run-as-principal-name>
</weblogic-enterprise-bean>
<security-role-assignment>
<role-name>acme_user</role-name>
<principal-name>AnvilUser</principal-name>
<principal-name>Admin</principal-name>
</security-role-assignment>
<!-- http://docs.oracle.com/cd/E15051_01/wls/docs103/ejb/DDreference-ejb-jar.html#wp1114299 -->
<idempotent-methods>
<method>
<ejb-name>ItemLookupBean</ejb-name>
<method-name>lookupItem</method-name>
<method-params>
<method-param>java.lang.Long</method-param>
</method-params>
</method>
<method>
<ejb-name>ProductCatalogBean</ejb-name>
<method-name>populateCatalog</method-name>
</method>
</idempotent-methods>
</weblogic-ejb-jar>

0 comments on commit 6360da3

Please sign in to comment.