use of com.sun.enterprise.deployment.EjbSessionDescriptor in project Payara by payara.
the class RemoteInterfaceSuperInterface method check.
/**
* Remote interface/business methods test.
* Verify the following:
*
* The remote interface is allowed to have superinterfaces. Use of interface
* inheritance is subject to the RMI-IIOP rules for the definition of remote
* interfaces.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
return result;
}
if (descriptor.getRemoteClassName() == null || "".equals(descriptor.getRemoteClassName())) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable", "Not Applicable because, EJB [ {0} ] does not have {1} Interface.", new Object[] { descriptor.getEjbClassName(), "Remote" }));
return result;
}
boolean oneFailed = false;
try {
ClassLoader jcl = getVerifierContext().getClassLoader();
Class c = Class.forName(descriptor.getRemoteClassName(), false, jcl);
Class remote = c;
boolean validRemoteInterface = false;
boolean ok = false;
// walk up the class tree
do {
Class[] interfaces = c.getInterfaces();
if (interfaces.length == 0) {
ok = true;
}
for (Class intf : interfaces) {
logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { intf.getName() });
// requirement is met if one superinterface complies.
if (!ok) {
ok = RmiIIOPUtils.isValidRmiIIOPInterface(intf);
}
// check the methods now.
if (RmiIIOPUtils.isValidRmiIIOPInterfaceMethods(intf)) {
// this interface is valid, continue
if (intf.getName().equals("javax.ejb.EJBObject")) {
validRemoteInterface = true;
break;
}
} else {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to " + "rules of RMI-IIOP for superinterfaces. All " + "enterprise beans remote interfaces are allowed " + "to have superinterfaces that conform to the " + "rules of RMI-IIOP for superinterfaces . [ {1} ]" + " is not a valid remote interface.", new Object[] { intf.getName(), descriptor.getRemoteClassName() }));
}
}
} while ((((c = c.getSuperclass()) != null) && (!validRemoteInterface)));
if (!ok) {
// check that one superinterface met rmiiiop requirement
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to rules of " + "RMI-IIOP for superinterfaces. All enterprise beans " + "remote interfaces are allowed to have superinterfaces " + "that conform to the rules of RMI-IIOP for superinterfaces. " + " [ {1} ] is not a valid remote interface.", new Object[] { remote.getName(), descriptor.getRemoteClassName() }));
}
if (validRemoteInterface) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly conforms to rules of RMI-IIOP for superinterfaces.", new Object[] { descriptor.getRemoteClassName() }));
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
addGoodDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Remote interface [ {0} ] does not exist or is not " + "loadable within bean [ {1} ]", new Object[] { descriptor.getRemoteClassName(), descriptor.getName() }));
oneFailed = true;
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
return result;
}
use of com.sun.enterprise.deployment.EjbSessionDescriptor in project Payara by payara.
the class EjbNode method writeDescriptor.
/**
* write the descriptor class to a DOM tree and return it
*
* @param parent node for the DOM tree
* @param node name for the descriptor
* @param the descriptor to write
* @return the DOM tree top node
*/
@Override
public Node writeDescriptor(Node parent, String nodeName, EjbDescriptor ejbDescriptor) {
Element ejbNode = (Element) super.writeDescriptor(parent, nodeName, ejbDescriptor);
appendTextChild(ejbNode, RuntimeTagNames.EJB_NAME, ejbDescriptor.getName());
appendTextChild(ejbNode, RuntimeTagNames.JNDI_NAME, ejbDescriptor.getJndiName());
RuntimeDescriptorNode.writeCommonComponentInfo(ejbNode, ejbDescriptor);
appendTextChild(ejbNode, RuntimeTagNames.PASS_BY_REFERENCE, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getPassByReference()));
if (ejbDescriptor instanceof IASEjbCMPEntityDescriptor) {
CmpNode cmpNode = new CmpNode();
cmpNode.writeDescriptor(ejbNode, RuntimeTagNames.CMP, (IASEjbCMPEntityDescriptor) ejbDescriptor);
}
// principal
if (Boolean.FALSE.equals(ejbDescriptor.getUsesCallerIdentity())) {
RunAsIdentityDescriptor raid = ejbDescriptor.getRunAsIdentity();
if (raid != null && raid.getPrincipal() != null) {
Node principalNode = appendChild(ejbNode, RuntimeTagNames.PRINCIPAL);
appendTextChild(principalNode, RuntimeTagNames.NAME, raid.getPrincipal());
}
}
if (ejbDescriptor instanceof EjbMessageBeanDescriptor) {
EjbMessageBeanDescriptor msgBeanDesc = (EjbMessageBeanDescriptor) ejbDescriptor;
// mdb-connection-factory?
if (ejbDescriptor.getIASEjbExtraDescriptors().getMdbConnectionFactory() != null) {
MDBConnectionFactoryNode mcfNode = new MDBConnectionFactoryNode();
mcfNode.writeDescriptor(ejbNode, RuntimeTagNames.MDB_CONNECTION_FACTORY, ejbDescriptor.getIASEjbExtraDescriptors().getMdbConnectionFactory());
}
// jms-durable-subscription-name
if (msgBeanDesc.hasDurableSubscription()) {
appendTextChild(ejbNode, RuntimeTagNames.DURABLE_SUBSCRIPTION, msgBeanDesc.getDurableSubscriptionName());
}
appendTextChild(ejbNode, RuntimeTagNames.JMS_MAX_MESSAGES_LOAD, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getJmsMaxMessagesLoad()));
}
// ior-configuration
IORConfigurationNode iorNode = new IORConfigurationNode();
for (EjbIORConfigurationDescriptor iorConf : ejbDescriptor.getIORConfigurationDescriptors()) {
iorNode.writeDescriptor(ejbNode, RuntimeTagNames.IOR_CONFIG, iorConf);
}
appendTextChild(ejbNode, RuntimeTagNames.IS_READ_ONLY_BEAN, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().isIsReadOnlyBean()));
appendTextChild(ejbNode, RuntimeTagNames.REFRESH_PERIOD_IN_SECONDS, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getRefreshPeriodInSeconds()));
appendTextChild(ejbNode, RuntimeTagNames.COMMIT_OPTION, ejbDescriptor.getIASEjbExtraDescriptors().getCommitOption());
appendTextChild(ejbNode, RuntimeTagNames.CMT_TIMEOUT_IN_SECONDS, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getCmtTimeoutInSeconds()));
appendTextChild(ejbNode, RuntimeTagNames.USE_THREAD_POOL_ID, ejbDescriptor.getIASEjbExtraDescriptors().getUseThreadPoolId());
// gen-classes
writeGenClasses(ejbNode, ejbDescriptor);
// bean-pool
BeanPoolDescriptor beanPoolDesc = ejbDescriptor.getIASEjbExtraDescriptors().getBeanPool();
if (beanPoolDesc != null) {
BeanPoolNode bpNode = new BeanPoolNode();
bpNode.writeDescriptor(ejbNode, RuntimeTagNames.BEAN_POOL, beanPoolDesc);
}
// bean-cache
BeanCacheDescriptor beanCacheDesc = ejbDescriptor.getIASEjbExtraDescriptors().getBeanCache();
if (beanCacheDesc != null) {
BeanCacheNode bcNode = new BeanCacheNode();
bcNode.writeDescriptor(ejbNode, RuntimeTagNames.BEAN_CACHE, beanCacheDesc);
}
if (ejbDescriptor instanceof EjbMessageBeanDescriptor) {
EjbMessageBeanDescriptor msgBeanDesc = (EjbMessageBeanDescriptor) ejbDescriptor;
if (msgBeanDesc.hasResourceAdapterMid()) {
MDBResourceAdapterNode mdb = new MDBResourceAdapterNode();
mdb.writeDescriptor(ejbNode, RuntimeTagNames.MDB_RESOURCE_ADAPTER, msgBeanDesc);
}
} else if (ejbDescriptor instanceof EjbSessionDescriptor) {
// web-services
WebServiceEndpointRuntimeNode wsRuntime = new WebServiceEndpointRuntimeNode();
wsRuntime.writeWebServiceEndpointInfo(ejbNode, ejbDescriptor);
}
// flush-at-end-of-method
FlushAtEndOfMethodDescriptor flushMethodDesc = ejbDescriptor.getIASEjbExtraDescriptors().getFlushAtEndOfMethodDescriptor();
if (flushMethodDesc != null) {
FlushAtEndOfMethodNode flushNode = new FlushAtEndOfMethodNode();
flushNode.writeDescriptor(ejbNode, RuntimeTagNames.FLUSH_AT_END_OF_METHOD, flushMethodDesc);
}
// checkpointed-methods
// checkpoint-at-end-of-method
CheckpointAtEndOfMethodDescriptor checkpointMethodDesc = ejbDescriptor.getIASEjbExtraDescriptors().getCheckpointAtEndOfMethodDescriptor();
if (checkpointMethodDesc != null) {
CheckpointAtEndOfMethodNode checkpointNode = new CheckpointAtEndOfMethodNode();
checkpointNode.writeDescriptor(ejbNode, RuntimeTagNames.CHECKPOINT_AT_END_OF_METHOD, checkpointMethodDesc);
}
if (ejbDescriptor.getIASEjbExtraDescriptors().getPerRequestLoadBalancing() != null) {
appendTextChild(ejbNode, RuntimeTagNames.PER_REQUEST_LOAD_BALANCING, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getPerRequestLoadBalancing()));
}
// availability-enabled
setAttribute(ejbNode, RuntimeTagNames.AVAILABILITY_ENABLED, ejbDescriptor.getIASEjbExtraDescriptors().getAttributeValue(IASEjbExtraDescriptors.AVAILABILITY_ENABLED));
return ejbNode;
}
use of com.sun.enterprise.deployment.EjbSessionDescriptor in project Payara by payara.
the class EjbDescriptorImpl method getRemoveMethods.
/**
* Get the remove methods of the EJB
*
* @return An iterator over the remove methods
*/
@Override
public Collection<Method> getRemoveMethods() {
Set<Method> removeMethods = new HashSet<Method>();
if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
if (sessionDesc.isStateful() && sessionDesc.hasRemoveMethods()) {
for (MethodDescriptor mDesc : sessionDesc.getRemoveMethodDescriptors()) {
Method m = mDesc.getMethod(ejbDesc);
if (m == null) {
throw new IllegalStateException("Can't resolve remove method " + mDesc + " For EJB " + sessionDesc.getName());
}
removeMethods.add(m);
}
}
}
return removeMethods;
}
use of com.sun.enterprise.deployment.EjbSessionDescriptor in project Payara by payara.
the class EjbServicesImpl method getDefaultGlobalJndiName.
private String getDefaultGlobalJndiName(EjbDescriptor<?> ejbDesc) {
EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ((EjbDescriptorImpl<?>) ejbDesc).getEjbDescriptor();
String clientView = null;
if (sessionDesc.isLocalBean()) {
clientView = sessionDesc.getEjbClassName();
} else if (sessionDesc.getLocalBusinessClassNames().size() >= 1) {
clientView = sessionDesc.getLocalBusinessClassNames().iterator().next();
} else if (sessionDesc.getRemoteBusinessClassNames().size() >= 1) {
clientView = sessionDesc.getRemoteBusinessClassNames().iterator().next();
}
return clientView != null ? sessionDesc.getPortableJndiName(clientView) : null;
}
use of com.sun.enterprise.deployment.EjbSessionDescriptor in project Payara by payara.
the class EjbCreateMethodStatic method check.
/**
* Session Bean's ejbCreate(...) methods static test.
* Each session Bean class must define one or more ejbCreate(...) methods.
* The number and signatures of a session Bean's create methods are specific
* to each EJB class. The method signatures must follow these rules:
*
* The method name must be ejbCreate.
*
* The method must not be declared as static.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor instanceof EjbSessionDescriptor) {
boolean oneFailed = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
Class[] ejbCreateMethodParameterTypes;
int foundAtLeastOne = 0;
boolean ejbCreateFound = false;
boolean isStatic = false;
// start do while loop here....
do {
Method[] methods = c.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
// reset flags from last time thru loop
ejbCreateFound = false;
isStatic = false;
// The method name must be ejbCreate.
if (methods[i].getName().startsWith("ejbCreate")) {
foundAtLeastOne++;
ejbCreateFound = true;
// The method must not be declared as static.
int modifiers = methods[i].getModifiers();
if (Modifier.isStatic(modifiers)) {
isStatic = true;
}
// method
if (ejbCreateFound && (!isStatic)) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares non-static [ {1} ] method.", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
} else if (ejbCreateFound && isStatic) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", new Object[] { methods[i].getName(), methods[i].getName() }));
}
}
}
} while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
if (foundAtLeastOne == 0) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: [ {0} ] does not properly declare at least one ejbCreate(...) method. [ {1} ] is not a valid bean.", new Object[] { descriptor.getEjbClassName(), descriptor.getEjbClassName() }));
oneFailed = true;
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
oneFailed = true;
}
if (oneFailed) {
result.setStatus(result.FAILED);
} else {
result.setStatus(result.PASSED);
}
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Session", "Entity" }));
return result;
}
}
Aggregations