use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class TemplateListOfResource method getPostCommand.
/**
* allows for remote files to be put in a tmp area and we pass the
* local location of this file to the corresponding command instead of the content of the file
* * Yu need to add enctype="multipart/form-data" in the form
* for ex: <form action="http://localhost:4848/management/domain/applications/application" method="post" enctype="multipart/form-data">
* then any param of type="file" will be uploaded, stored locally and the param will use the local location
* on the server side (ie. just the path)
*/
public String getPostCommand() {
ConfigModel.Property p = parent.model.getElement(tagName);
if (p == null) {
// "*"
ConfigModel.Property childElement = parent.model.getElement("*");
if (childElement != null) {
ConfigModel.Node node = (ConfigModel.Node) childElement;
ConfigModel childModel = node.getModel();
List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, parent.document);
for (ConfigModel subChildConfigModel : subChildConfigModels) {
if (subChildConfigModel.getTagName().equals(tagName)) {
return ResourceUtil.getCommand(RestRedirect.OpType.POST, subChildConfigModel);
}
}
}
} else {
ConfigModel.Node n = (ConfigModel.Node) p;
String command = ResourceUtil.getCommand(RestRedirect.OpType.POST, n.getModel());
if (command != null) {
return command;
}
// last possible case...the @Create annotation on a parent method
Class<? extends ConfigBeanProxy> cbp = null;
try {
cbp = (Class<? extends ConfigBeanProxy>) parent.model.classLoaderHolder.loadClass(parent.model.targetTypeName);
} catch (MultiException e) {
//
return null;
}
Create create = null;
for (Method m : cbp.getMethods()) {
ConfigModel.Property pp = parent.model.toProperty(m);
if ((pp != null) && (pp.xmlName.equals(tagName)) && (m.isAnnotationPresent(Create.class))) {
create = m.getAnnotation(Create.class);
break;
}
}
if (create != null) {
return create.value();
}
}
return null;
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class CombinedJavaConfigSystemPropertyListener method changed.
/* force serial behavior; don't allow more than one thread to make a mess here */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
// ignore a REMOVE and an ADD of the same value
final UnprocessedChangeEvents unp = ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tc, T t) {
NotProcessed result = null;
if (tc == Profiler.class) {
result = new NotProcessed("Creation or changes to a profiler require restart");
} else if (tc == Property.class && t.getParent().getClass() == JavaConfig.class) {
result = new NotProcessed("Addition of properties to JavaConfig requires restart");
} else if (tc == JavaConfig.class && t instanceof JavaConfig) {
final JavaConfig njc = (JavaConfig) t;
logFine(type, njc);
// we must *always* check the jvm options, no way to know except by comparing,
// plus we should send an appropriate message back for each removed/added item
final List<String> curProps = new ArrayList<String>(njc.getJvmOptions());
final boolean jvmOptionsWereChanged = !oldProps.equals(curProps);
final List<String> reasons = handle(oldProps, curProps);
oldProps = curProps;
// something in the JavaConfig itself changed
// to do this well, we ought to keep a list of attributes, so we can make a good message
// saying exactly which attribute what changed
final Map<String, String> curAttrs = collectAttrs(njc);
reasons.addAll(handleAttrs(oldAttrs, curAttrs));
oldAttrs = curAttrs;
result = reasons.isEmpty() ? null : new NotProcessed(CombinedJavaConfigSystemPropertyListener.toString(reasons));
} else if (tc == SystemProperty.class && t instanceof SystemProperty) {
final SystemProperty sp = (SystemProperty) t;
// check to see if this system property is for this instance
ConfigBeanProxy proxy = sp.getParent();
ConfigView p = ConfigSupport.getImpl(proxy);
if (p == ConfigSupport.getImpl(server) || p == ConfigSupport.getImpl(config) || (cluster != null && p == ConfigSupport.getImpl(cluster)) || p == ConfigSupport.getImpl(domain)) {
// check to see if this system property is referenced by any of the options
String pname = sp.getName();
if (referencesProperty(pname, oldProps) || referencesProperty(pname, oldAttrs.values())) {
result = new NotProcessed("The system-property, " + pname + ", that is referenced by the Java configuration, was modified");
}
}
if (type == TYPE.ADD || type == TYPE.CHANGE) {
// create-system-properties
if (proxy instanceof Domain) {
return addToDomain(sp);
} else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
return addToConfig(sp);
} else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
return addToCluster(sp);
} else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
return addToServer(sp);
}
} else if (type == TYPE.REMOVE) {
if (proxy instanceof Domain) {
return removeFromDomain(sp);
} else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
return removeFromConfig(sp);
} else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
return removeFromCluster(sp);
} else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
return removeFromServer(sp);
}
}
} else {
// ignore other changes that are reported
}
return result;
}
}, logger);
return unp;
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class SetCommand method setLeafElement.
public static void setLeafElement(final ConfigBean node, final String elementName, final String values) throws TransactionFailure {
ConfigBeanProxy readableView = node.getProxy(node.getProxyType());
ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {
/**
* Runs the following command passing the configuration object. The
* code will be run within a transaction, returning true will commit
* the transaction, false will abort it.
*
* @param param is the configuration object protected by the
* transaction
* @return any object that should be returned from within the
* transaction code
* @throws java.beans.PropertyVetoException if the changes cannot be
* applied to the configuration
*/
@Override
public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
WriteableView writeableParent = (WriteableView) Proxy.getInvocationHandler(param);
StringTokenizer st = new StringTokenizer(values, ",");
List<String> valList = new ArrayList<>();
while (st.hasMoreTokens()) {
valList.add(st.nextToken());
}
ConfigBean bean = writeableParent.getMasterView();
for (Method m : writeableParent.getProxyType().getMethods()) {
// Check to see if the method is a setter for the element
// An element setter has to have the right name, take a single
// collection parameter that parameterized with the right type
Class[] argClasses = m.getParameterTypes();
Type[] argTypes = m.getGenericParameterTypes();
ConfigModel.Property prop = bean.model.toProperty(m);
if (prop == null || !prop.xmlName().equals(elementName) || argClasses.length != 1 || !Collection.class.isAssignableFrom(argClasses[0]) || argTypes.length != 1 || !(argTypes[0] instanceof ParameterizedType) || !Types.erasure(Types.getTypeArgument(argTypes[0], 0)).isAssignableFrom(values.getClass())) {
continue;
}
// we have the right method. Now call it
try {
m.invoke(writeableParent.getProxy(writeableParent.<ConfigBeanProxy>getProxyType()), valList);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new TransactionFailure("Exception while setting element", e);
}
return node;
}
throw new TransactionFailure("No method found for setting element");
}
}, readableView);
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class BasePersistenceStrategyBuilder method readInstanceLevelParams.
public void readInstanceLevelParams(ServerConfigLookup serverConfigLookup) {
org.glassfish.web.config.serverbeans.SessionManager smBean = serverConfigLookup.getInstanceSessionManager();
if (smBean != null) {
// The persistence-type controls what properties of the
// session manager can be configured
org.glassfish.web.config.serverbeans.ManagerProperties mgrBean = smBean.getManagerProperties();
if (mgrBean != null) {
// manager reap-interval-in-seconds
String reapIntervalInSecondsString = mgrBean.getReapIntervalInSeconds();
if (reapIntervalInSecondsString != null) {
try {
reapInterval = Integer.parseInt(reapIntervalInSecondsString);
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.MANAGER_REAP_INTERVAL_SET, reapInterval);
}
} catch (NumberFormatException e) {
// XXX need error message
}
} else {
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.NO_INSTANCE_LEVEL_VALUE_SET_MGR_REAP_INTERVAL);
}
}
// max-sessions
String maxSessionsString = mgrBean.getMaxSessions();
if (maxSessionsString != null) {
try {
maxSessions = Integer.parseInt(maxSessionsString);
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.MAX_SESSIONS_SET, maxSessions);
}
} catch (NumberFormatException e) {
// XXX need error message
}
} else {
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.NO_INSTANCE_LEVEL_VALUE_SET_MAX_SESSIONS);
}
}
// session-file-name
String sessionFilenameString = mgrBean.getSessionFileName();
if (sessionFilenameString != null) {
sessionFilename = sessionFilenameString;
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.SESSION_FILENAME_SET, sessionFilename);
}
}
// START CR 6275709
sessionIdGeneratorClassname = mgrBean.getSessionIdGeneratorClassname();
if (sessionIdGeneratorClassname != null && _logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.SESSION_ID_GENERATOR_CLASSNAME_SET, sessionIdGeneratorClassname);
}
// END CR 6275709
// Now do properties under <manager-properties> element
List<Property> props = mgrBean.getProperty();
if (props != null) {
for (Property prop : props) {
String name = prop.getName();
String value = prop.getValue();
// maxIdleBackupSeconds
if (name.equalsIgnoreCase("maxIdleBackupSeconds")) {
try {
maxIdleBackup = Integer.parseInt(value);
} catch (NumberFormatException e) {
// XXX need error message
}
} else if (name.equalsIgnoreCase(MIN_IDLE_SWAP_PROPERTY)) {
try {
minIdleSwap = Integer.parseInt(value);
} catch (NumberFormatException e) {
// XXX need error message
}
} else if (name.equalsIgnoreCase(MAX_IDLE_SWAP_PROPERTY)) {
try {
maxIdleSwap = Integer.parseInt(value);
} catch (NumberFormatException e) {
// XXX need error message
}
}
}
}
}
org.glassfish.web.config.serverbeans.StoreProperties storeBean = smBean.getStoreProperties();
if (storeBean != null) {
// Store reap-interval-in-seconds
String reapIntervalInSecondsString = storeBean.getReapIntervalInSeconds();
if (reapIntervalInSecondsString != null) {
try {
storeReapInterval = Integer.parseInt(reapIntervalInSecondsString);
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.STORE_REAP_INTERVAL_SET, storeReapInterval);
}
} catch (NumberFormatException e) {
// XXX need error message
}
}
// Directory
String directoryString = storeBean.getDirectory();
if (directoryString != null) {
directory = directoryString;
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.DIRECTORY_SET, directoryString);
}
}
}
}
SessionProperties spBean = serverConfigLookup.getInstanceSessionProperties();
if (spBean != null) {
// session timeout-in-seconds
String timeoutSecondsString = spBean.getTimeoutInSeconds();
if (timeoutSecondsString != null) {
try {
sessionMaxInactiveInterval = Integer.parseInt(timeoutSecondsString);
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.SESSION_MAX_INACTIVE_INTERVAL_SET, sessionMaxInactiveInterval);
}
} catch (NumberFormatException e) {
// XXX need error message
}
} else {
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.NO_INSTANCE_LEVEL_VALUE_SET_SESSION_MAX_INACTIVE_INTERVAL);
}
}
}
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class WebServiceRefHandler method processAWsRef.
protected HandlerProcessingResult processAWsRef(AnnotationInfo annInfo, WebServiceRef annotation) throws AnnotationProcessorException {
AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler();
AnnotatedElement annElem = annInfo.getAnnotatedElement();
Class annotatedType = null;
Class declaringClass = null;
InjectionTarget target = null;
String defaultServiceRefName = null;
if (annInfo.getElementType().equals(ElementType.FIELD)) {
// this is a field injection
Field annotatedField = (Field) annElem;
// check this is a valid field
if (annCtx instanceof AppClientContext) {
if (!Modifier.isStatic(annotatedField.getModifiers())) {
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.injectionfieldnotstatic", "Injection fields for application clients must be declared STATIC"), annInfo);
}
}
annotatedType = annotatedField.getType();
declaringClass = annotatedField.getDeclaringClass();
defaultServiceRefName = declaringClass.getName() + "/" + annotatedField.getName();
target = new InjectionTarget();
target.setFieldName(annotatedField.getName());
target.setClassName(annotatedField.getDeclaringClass().getName());
} else if (annInfo.getElementType().equals(ElementType.METHOD)) {
// this is a method injection
Method annotatedMethod = (Method) annElem;
validateInjectionMethod(annotatedMethod, annInfo);
if (annCtx instanceof AppClientContext) {
if (!Modifier.isStatic(annotatedMethod.getModifiers())) {
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.injectionmethodnotstatic", "Injection methods for application clients must be declared STATIC"), annInfo);
}
}
annotatedType = annotatedMethod.getParameterTypes()[0];
declaringClass = annotatedMethod.getDeclaringClass();
// Derive javabean property name.
String propertyName = getInjectionMethodPropertyName(annotatedMethod, annInfo);
// prefixing with fully qualified type name
defaultServiceRefName = declaringClass.getName() + "/" + propertyName;
target = new InjectionTarget();
target.setMethodName(annotatedMethod.getName());
target.setClassName(annotatedMethod.getDeclaringClass().getName());
} else if (annInfo.getElementType().equals(ElementType.TYPE)) {
// name must be specified.
if (!ok(annotation.name())) {
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.nonametypelevel", "TYPE-Level annotation must specify name member."), annInfo);
}
// this is a dependency declaration, we need the service interface
// to be specified
annotatedType = annotation.type();
if (annotatedType == null || annotatedType == Object.class) {
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.typenotfound", "TYPE-level annotation symbol must specify type member."), annInfo);
}
declaringClass = (Class) annElem;
} else {
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidtype", "annotation not allowed on this element."), annInfo);
}
MTOM mtom = null;
Addressing addressing = null;
RespectBinding respectBinding = null;
// Other annotations like SchemaValidation etc to be passed on to
// ServiceReferenceDescriptor
Map<Class<? extends Annotation>, Annotation> otherAnnotations = new HashMap<Class<? extends Annotation>, Annotation>();
for (Annotation a : annElem.getAnnotations()) {
if (!(a.annotationType().isAnnotationPresent(WebServiceFeatureAnnotation.class)))
continue;
if (a instanceof MTOM) {
mtom = (MTOM) a;
} else if (a instanceof Addressing) {
addressing = (Addressing) a;
} else if (a instanceof RespectBinding) {
respectBinding = (RespectBinding) a;
} else {
if (!otherAnnotations.containsKey(a.getClass())) {
otherAnnotations.put(a.getClass(), a);
}
}
}
String serviceRefName = !ok(annotation.name()) ? defaultServiceRefName : annotation.name();
ServiceReferenceContainer[] containers = null;
if (annCtx instanceof ServiceReferenceContainerContext) {
containers = ((ServiceReferenceContainerContext) annCtx).getServiceRefContainers();
}
if (containers == null || containers.length == 0) {
annInfo.getProcessingContext().getErrorHandler().fine(new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidannotationforthisclass", "Illegal annotation symbol for this class will be ignored"), annInfo));
return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
}
// now process the annotation for all the containers.
for (ServiceReferenceContainer container : containers) {
ServiceReferenceDescriptor aRef = null;
try {
aRef = container.getServiceReferenceByName(serviceRefName);
}// ignore
catch (Throwable t) {
}
if (aRef == null) {
// time to create it...
aRef = new ServiceReferenceDescriptor();
aRef.setName(serviceRefName);
container.addServiceReferenceDescriptor(aRef);
}
// merge other annotations
Map<Class<? extends Annotation>, Annotation> oa = aRef.getOtherAnnotations();
if (oa == null)
aRef.setOtherAnnotations(otherAnnotations);
else {
for (Map.Entry<Class<? extends Annotation>, Annotation> entry : otherAnnotations.entrySet()) {
if (!oa.containsKey(entry.getKey()))
oa.put(entry.getKey(), entry.getValue());
}
}
// merge wsdlLocation
if (!ok(aRef.getWsdlFileUri()) && ok(annotation.wsdlLocation()))
aRef.setWsdlFileUri(annotation.wsdlLocation());
if (!aRef.hasMtomEnabled() && mtom != null) {
aRef.setMtomEnabled(mtom.enabled());
aRef.setMtomThreshold(mtom.threshold());
}
// check Addressing annotation
if (aRef.getAddressing() == null && addressing != null) {
aRef.setAddressing(new com.sun.enterprise.deployment.Addressing(addressing.enabled(), addressing.required(), addressing.responses().toString()));
}
// check RespectBinding annotation
if (aRef.getRespectBinding() == null && respectBinding != null) {
aRef.setRespectBinding(new com.sun.enterprise.deployment.RespectBinding(respectBinding.enabled()));
}
// Store mapped name that is specified
if (!ok(aRef.getMappedName()) && ok(annotation.mappedName()))
aRef.setMappedName(annotation.mappedName());
// Store lookup name that is specified
if (!aRef.hasLookupName() && ok(getLookupValue(annotation, annInfo)))
aRef.setLookupName(getLookupValue(annotation, annInfo));
aRef.setInjectResourceType("javax.jws.WebServiceRef");
if (target != null)
aRef.addInjectionTarget(target);
// Read the WebServiceClient annotation for the service name space
// uri and wsdl (if required)
WebServiceClient wsclientAnn;
// of these default values.
if (!Object.class.equals(annotation.value()) && (!javax.xml.ws.Service.class.equals(annotation.value()))) {
// port.
if (aRef.getServiceInterface() == null) {
aRef.setServiceInterface(annotation.value().getName());
}
if (aRef.getPortInfoBySEI(annotatedType.getName()) == null) {
ServiceRefPortInfo portInfo = new ServiceRefPortInfo();
portInfo.setServiceEndpointInterface(annotatedType.getName());
aRef.addPortInfo(portInfo);
}
// set the port type requested for injection
if (aRef.getInjectionTargetType() == null) {
aRef.setInjectionTargetType(annotatedType.getName());
}
wsclientAnn = (WebServiceClient) annotation.value().getAnnotation(WebServiceClient.class);
} else {
// no value provided in the annotation
wsclientAnn = (WebServiceClient) annotatedType.getAnnotation(WebServiceClient.class);
}
if (wsclientAnn == null) {
throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.classnotannotated", "Class must be annotated with a {1} annotation\n symbol : {1}\n location: {0}", new Object[] { annotatedType.toString(), WebServiceClient.class.toString() }));
}
// annotation, get it from WebServiceClient annotation
if (aRef.getWsdlFileUri() == null) {
aRef.setWsdlFileUri(wsclientAnn.wsdlLocation());
}
// Set service name space URI and service local part
if (aRef.getServiceName() == null) {
aRef.setServiceNamespaceUri(wsclientAnn.targetNamespace());
aRef.setServiceLocalPart(wsclientAnn.name());
}
if (aRef.getServiceInterface() == null) {
aRef.setServiceInterface(annotatedType.getName());
}
}
// have @HandlerChain but the SEI has one specified through JAXWS customization
if (annElem.getAnnotation(javax.jws.HandlerChain.class) == null) {
return (new HandlerChainHandler()).processHandlerChainAnnotation(annInfo, annCtx, annotatedType, declaringClass, false);
}
return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
}
Aggregations