Search in sources :

Example 26 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class IiopSslConfigHandler method delete.

@Override
public void delete(DeleteSsl command, ActionReport report) {
    IiopService iiopService = command.config.getExtensionByType(IiopService.class);
    IiopListener iiopListener = null;
    for (IiopListener listener : iiopService.getIiopListener()) {
        if (listener.getId().equals(command.listenerId)) {
            iiopListener = listener;
        }
    }
    if (iiopListener == null) {
        report.setMessage(localStrings.getLocalString("delete.ssl.iiop.listener.notfound", "Iiop Listener named {0} not found", command.listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (iiopListener.getSsl() == null) {
        report.setMessage(localStrings.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", command.listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<IiopListener>() {

            public Object run(IiopListener param) throws PropertyVetoException {
                param.setSsl(null);
                return null;
            }
        }, iiopListener);
    } catch (TransactionFailure e) {
        command.reportError(report, e);
    }
}
Also used : IiopListener(org.glassfish.orb.admin.config.IiopListener) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) IiopService(org.glassfish.orb.admin.config.IiopService)

Example 27 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class CreateHTTPLoadBalancerCommand method addLoadBalancer.

private void addLoadBalancer(final String lbConfigName) {
    LoadBalancers loadBalancers = domain.getExtensionByType(LoadBalancers.class);
    // create load-balancers parent element if it does not exist
    if (loadBalancers == null) {
        Transaction transaction = new Transaction();
        try {
            ConfigBeanProxy domainProxy = transaction.enroll(domain);
            loadBalancers = domainProxy.createChild(LoadBalancers.class);
            ((Domain) domainProxy).getExtensions().add(loadBalancers);
            transaction.commit();
        } catch (TransactionFailure ex) {
            transaction.rollback();
            String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        } catch (RetryableException ex) {
            transaction.rollback();
            String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<LoadBalancers>() {

            @Override
            public Object run(LoadBalancers param) throws PropertyVetoException, TransactionFailure {
                LoadBalancer lb = param.createChild(LoadBalancer.class);
                lb.setDeviceHost(devicehost);
                lb.setDevicePort(deviceport);
                lb.setLbConfigName(lbConfigName);
                lb.setName(load_balancer_name);
                // add properties
                if (properties != null) {
                    for (Object propname : properties.keySet()) {
                        Property newprop = lb.createChild(Property.class);
                        newprop.setName((String) propname);
                        newprop.setValue(properties.getProperty((String) propname));
                        lb.getProperty().add(newprop);
                    }
                }
                if (sslproxyhost != null) {
                    Property newprop = lb.createChild(Property.class);
                    newprop.setName("ssl-proxy-host");
                    newprop.setValue(sslproxyhost);
                    lb.getProperty().add(newprop);
                }
                if (sslproxyport != null) {
                    Property newprop = lb.createChild(Property.class);
                    newprop.setName("ssl-proxy-port");
                    newprop.setValue(sslproxyport);
                    lb.getProperty().add(newprop);
                }
                param.getLoadBalancer().add(lb);
                return Boolean.TRUE;
            }
        }, loadBalancers);
    } catch (TransactionFailure ex) {
        String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) LoadBalancers(org.glassfish.loadbalancer.config.LoadBalancers) LoadBalancer(org.glassfish.loadbalancer.config.LoadBalancer) Property(org.jvnet.hk2.config.types.Property)

Example 28 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class ConfigureJMSCluster method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // Server targetServer = domain.getServerNamed(target);
    // String configRef = targetServer.getConfigRef();
    Cluster cluster = domain.getClusterNamed(clusterName);
    if (cluster == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidClusterName", "No Cluster by this name has been configured"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    List instances = cluster.getInstances();
    String warning = null;
    if (instances.size() > 0) {
        ActionReport listReport = habitat.getService(ActionReport.class);
        ParameterMap parameters = new ParameterMap();
        parameters.set("DEFAULT", clusterName);
        commandRunner.getCommandInvocation("list-instances", listReport, context.getSubject()).parameters(parameters).execute();
        if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
            warning = localStrings.getLocalString("configure.jms.cluster.clusterWithInstances", "Warning: Please make sure running this command with all cluster instances stopped, otherwise it may lead to inconsistent JMS behavior and corruption of configuration and message stores.");
        } else {
            String result = listReport.getMessage();
            String fixedResult = result.replaceAll("not running", "stopped");
            if (fixedResult.indexOf("running") > -1) {
                warning = localStrings.getLocalString("configure.jms.cluster.clusterWithInstances", "Warning: Please make sure running this command with all cluster instances stopped, otherwise it may lead to inconsistent JMS behavior and corruption of configuration and message stores.");
                warning = warning + "\r\n" + result + "\r\n";
            }
        }
    }
    Config config = domain.getConfigNamed(cluster.getConfigRef());
    JmsService jmsService = config.getExtensionByType(JmsService.class);
    if (jmsService == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.nojmsservice", "No JMS Service element in config"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (!CONVENTIONAL.equalsIgnoreCase(clusterType) && !ENHANCED.equalsIgnoreCase(clusterType)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongClusterType", "Invalid option sepecified for clustertype. Valid options are conventional and enhanced"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && !MASTER_BROKER.equalsIgnoreCase(configStoreType) && !SHARED_DB.equalsIgnoreCase(configStoreType)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongConfigStoreType", "Invalid option sepecified for configstoretype. Valid options are masterbroker and shareddb"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (ENHANCED.equalsIgnoreCase(clusterType) && configStoreType != null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongStoreType", "configstoretype option is not configurable for Enhanced clusters."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && !MASTER_BROKER.equalsIgnoreCase(configStoreType) && !FILE.equalsIgnoreCase(messageStoreType) && !JDBC.equalsIgnoreCase(messageStoreType)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongMessageStoreType", "Invalid option sepecified for messagestoretype. Valid options are file and jdbc"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (ENHANCED.equalsIgnoreCase(clusterType) && messageStoreType != null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongmsgStoreType", "messagestoretype option is not configurable for Enhanced clusters."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    String integrationMode = jmsService.getType();
    if (REMOTE.equalsIgnoreCase(integrationMode)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.remoteMode", "JMS integration mode should be either EMBEDDED or LOCAL to run this command. Please use the asadmin.set command to change the integration mode"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    String changeIntegrationMode = null;
    if (EMBEDDED.equalsIgnoreCase(integrationMode) && ENHANCED.equalsIgnoreCase(clusterType)) {
        try {
            ConfigSupport.apply(new SingleConfigCode<JmsService>() {

                public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
                    param.setType(LOCAL);
                    return param;
                }
            }, jmsService);
            changeIntegrationMode = localStrings.getLocalString("configure.jms.cluster.integrationModeChanged", "WARNING: JMS integration mode has been changed from EMBEDDED to LOCAL automatically.");
        } catch (TransactionFailure tfe) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.cannotChangeIntegrationMode", "Unable to change the JMS integration mode to LOCAL for Enhanced cluster {0}.", clusterName) + " " + tfe.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(tfe);
            return;
        }
    }
    if (MASTER_BROKER.equalsIgnoreCase(configStoreType) && FILE.equals(messageStoreType)) {
        if (dbvendor != null || dburl != null || dbuser != null) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidDboptions", "Database options should not be specified for this configuration"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (!MASTER_BROKER.equalsIgnoreCase(configStoreType) || ENHANCED.equalsIgnoreCase(clusterType) || JDBC.equalsIgnoreCase(messageStoreType)) {
        if (dbvendor == null) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.nodbvendor", "No DataBase vendor specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else if (dburl == null) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.nojdbcurl", "No JDBC URL specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else if (!isSupportedDbVendor()) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.invaliddbvendor", "Invalid DB Vednor specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && configStoreType == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.noConfigStoreType", "No configstoretype specified. Using the default value - masterbroker"));
        configStoreType = "masterbroker";
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && messageStoreType == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.noMessagetoreType", "No messagestoretype specified. Using the default value - file"));
        messageStoreType = "file";
    }
    config = domain.getConfigNamed(cluster.getConfigRef());
    JmsAvailability jmsAvailability = config.getAvailabilityService().getExtensionByType(JmsAvailability.class);
    final Boolean availabilityEnabled = Boolean.valueOf(ENHANCED.equalsIgnoreCase(clusterType));
    try {
        ConfigSupport.apply(new SingleConfigCode<JmsAvailability>() {

            public Object run(JmsAvailability param) throws PropertyVetoException, TransactionFailure {
                param.setAvailabilityEnabled(availabilityEnabled.toString());
                if (availabilityEnabled.booleanValue()) {
                    param.setMessageStoreType(JDBC);
                } else {
                    param.setConfigStoreType(configStoreType.toLowerCase(Locale.ENGLISH));
                    param.setMessageStoreType(messageStoreType.toLowerCase(Locale.ENGLISH));
                }
                param.setDbVendor(dbvendor);
                param.setDbUsername(dbuser);
                param.setDbPassword(jmsDbPassword);
                param.setDbUrl(dburl);
                if (props != null) {
                    for (Map.Entry e : props.entrySet()) {
                        Property prop = param.createChild(Property.class);
                        prop.setName((String) e.getKey());
                        prop.setValue((String) e.getValue());
                        param.getProperty().add(prop);
                    }
                }
                return param;
            }
        }, jmsAvailability);
    /* //update the useMasterBroker flag on the JmsService only if availabiltyEnabled is false
            if(!availabilityEnabled.booleanValue()){
              ConfigSupport.apply(new SingleConfigCode<JmsService>() {
                public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {

                    param.setUseMasterBroker(useMasterBroker.toString());
                    return param;
                }
            }, jmsservice);
            }*/
    } catch (TransactionFailure tfe) {
        report.setMessage((changeIntegrationMode == null ? "" : changeIntegrationMode + "\n") + localStrings.getLocalString("configure.jms.cluster.fail", "Unable to Configure JMS Cluster for cluster {0}.", clusterName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage((warning == null ? "" : warning + "\n") + (changeIntegrationMode == null ? "" : changeIntegrationMode + "\n") + localStrings.getLocalString("configure.jms.cluster.success", "JMS Cluster Configuration updated for Cluster {0}.", clusterName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) JmsAvailability(com.sun.enterprise.connectors.jms.config.JmsAvailability) List(java.util.List) Property(org.jvnet.hk2.config.types.Property)

Example 29 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class WebContainer method createHttpListener.

protected WebConnector createHttpListener(NetworkListener listener, HttpService httpService, Mapper mapper) {
    if (!Boolean.valueOf(listener.getEnabled())) {
        return null;
    }
    int port = 8080;
    WebConnector connector;
    checkHostnameUniqueness(listener.getName(), httpService);
    try {
        port = Integer.parseInt(listener.getPort());
    } catch (NumberFormatException nfe) {
        String msg = rb.getString(LogFacade.HTTP_LISTENER_INVALID_PORT);
        msg = MessageFormat.format(msg, listener.getPort(), listener.getName());
        throw new IllegalArgumentException(msg);
    }
    if (mapper == null) {
        for (Mapper m : habitat.<Mapper>getAllServices(Mapper.class)) {
            if (m.getPort() == port && m instanceof ContextMapper) {
                ContextMapper cm = (ContextMapper) m;
                if (listener.getName().equals(cm.getId())) {
                    mapper = m;
                    break;
                }
            }
        }
    }
    String defaultVS = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
    if (!defaultVS.equals(org.glassfish.api.web.Constants.ADMIN_VS)) {
        // Before we start a WebConnector, let's makes sure there is
        // not another Container already listening on that port
        DataChunk host = DataChunk.newInstance();
        char[] c = defaultVS.toCharArray();
        host.setChars(c, 0, c.length);
        DataChunk mb = DataChunk.newInstance();
        mb.setChars(new char[] { '/' }, 0, 1);
        MappingData md = new MappingData();
        try {
            mapper.map(host, mb, md);
        } catch (Exception e) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "", e);
            }
        }
        if (md.context != null && md.context instanceof ContextRootInfo) {
            ContextRootInfo r = (ContextRootInfo) md.context;
            if (!(r.getHttpHandler() instanceof ContainerMapper)) {
                new BindException("Port " + port + " is already used by Container: " + r.getHttpHandler() + " and will not get started.").printStackTrace();
                return null;
            }
        }
    }
    /*
         * Create Connector. Connector is SSL-enabled if
         * 'security-enabled' attribute in <http-listener>
         * element is set to TRUE.
         */
    boolean isSecure = Boolean.valueOf(listener.findHttpProtocol().getSecurityEnabled());
    if (isSecure && defaultRedirectPort == -1) {
        defaultRedirectPort = port;
    }
    String address = listener.getAddress();
    if ("any".equals(address) || "ANY".equals(address) || "INADDR_ANY".equals(address)) {
        address = null;
    /*
             * Setting 'address' to NULL will cause Tomcat to pass a
             * NULL InetAddress argument to the java.net.ServerSocket
             * constructor, meaning that the server socket will accept
             * connections on any/all local addresses.
             */
    }
    connector = (WebConnector) _embedded.createConnector(address, port, isSecure);
    connector.setMapper(mapper);
    connector.setJvmRoute(engine.getJvmRoute());
    if (logger.isLoggable(Level.INFO)) {
        logger.log(Level.INFO, LogFacade.HTTP_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), listener.getPort() });
    }
    connector.setDefaultHost(listener.findHttpProtocol().getHttp().getDefaultVirtualServer());
    connector.setName(listener.getName());
    connector.setInstanceName(instanceName);
    connector.configure(listener, isSecure, httpService);
    _embedded.addConnector(connector);
    connectorMap.put(listener.getName(), connector);
    // If we already know the redirect port, then set it now
    // This situation will occurs when dynamic reconfiguration occurs
    String redirectPort = listener.findHttpProtocol().getHttp().getRedirectPort();
    if (redirectPort != null) {
        connector.setRedirectPort(Integer.parseInt(redirectPort));
    } else if (defaultRedirectPort != -1) {
        connector.setRedirectPort(defaultRedirectPort);
    }
    ObservableBean httpListenerBean = (ObservableBean) ConfigSupport.getImpl(listener);
    httpListenerBean.addListener(configListener);
    return connector;
}
Also used : BindException(java.net.BindException) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) ContextRootInfo(org.glassfish.grizzly.config.ContextRootInfo) Mapper(org.glassfish.grizzly.http.server.util.Mapper) ContextMapper(org.glassfish.internal.grizzly.ContextMapper) ContainerMapper(com.sun.enterprise.v3.services.impl.ContainerMapper) MappingData(org.glassfish.grizzly.http.server.util.MappingData) DataChunk(org.glassfish.grizzly.http.util.DataChunk) ObservableBean(org.jvnet.hk2.config.ObservableBean) ContextMapper(org.glassfish.internal.grizzly.ContextMapper) ContainerMapper(com.sun.enterprise.v3.services.impl.ContainerMapper)

Example 30 with Element

use of org.jvnet.hk2.config.Element 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);
}
Also used : HashMap(java.util.HashMap) AnnotatedElement(java.lang.reflect.AnnotatedElement) ServiceReferenceContainer(com.sun.enterprise.deployment.types.ServiceReferenceContainer) Addressing(javax.xml.ws.soap.Addressing) AppClientContext(com.sun.enterprise.deployment.annotation.context.AppClientContext) Field(java.lang.reflect.Field) ServiceReferenceContainerContext(com.sun.enterprise.deployment.annotation.context.ServiceReferenceContainerContext) com.sun.enterprise.deployment(com.sun.enterprise.deployment) MTOM(javax.xml.ws.soap.MTOM) Service(org.jvnet.hk2.annotations.Service) RespectBinding(javax.xml.ws.RespectBinding) Method(java.lang.reflect.Method) WebServiceFeatureAnnotation(javax.xml.ws.spi.WebServiceFeatureAnnotation) Annotation(java.lang.annotation.Annotation) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Property (org.jvnet.hk2.config.types.Property)14 PropertyVetoException (java.beans.PropertyVetoException)13 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)13 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 List (java.util.List)4 TreeMap (java.util.TreeMap)4 ActionReport (org.glassfish.api.ActionReport)4 MultiException (org.glassfish.hk2.api.MultiException)4 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)4 ConfigModel (org.jvnet.hk2.config.ConfigModel)4 Dom (org.jvnet.hk2.config.Dom)4 Application (com.sun.enterprise.config.serverbeans.Application)3 Domain (com.sun.enterprise.config.serverbeans.Domain)3 Server (com.sun.enterprise.config.serverbeans.Server)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)3 File (java.io.File)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3