Search in sources :

Example 1 with DeploymentException

use of org.glassfish.deployment.common.DeploymentException in project Payara by payara.

the class EjbDeployer method createAutomaticPersistentTimersForEJB.

/**
 * Start EJB Timer Service and create automatic timers for this EJB in this target
 */
private void createAutomaticPersistentTimersForEJB(EjbDescriptor ejbDescriptor, String target) {
    try {
        // Start EJB Timer Service if it wasn't started yet. On DAS the first start will create the timer table.
        EJBTimerService timerService = EJBTimerService.getEJBTimerService(target);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "EjbDeployer BEAN ID? " + ejbDescriptor.getUniqueId());
            _logger.log(Level.FINE, "EjbDeployer TimerService: " + timerService);
        }
        if (timerService != null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "EjbDeployer - calling timerService.createSchedules for " + ejbDescriptor.getUniqueId());
            }
            timerService.createSchedulesOnServer(ejbDescriptor, getOwnerId(target));
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "EjbDeployer Done With BEAN ID: " + ejbDescriptor.getUniqueId());
            }
        } else {
            throw new RuntimeException("EJB Timer Service is not available");
        }
    } catch (Exception e) {
        throw new DeploymentException("Failed to create automatic timers for " + ejbDescriptor.getName(), e);
    }
}
Also used : DeploymentException(org.glassfish.deployment.common.DeploymentException) EJBTimerService(com.sun.ejb.containers.EJBTimerService) DeploymentException(org.glassfish.deployment.common.DeploymentException) IASSecurityException(com.sun.enterprise.security.util.IASSecurityException)

Example 2 with DeploymentException

use of org.glassfish.deployment.common.DeploymentException in project Payara by payara.

the class WebServicesDeployer method doWebServiceDeployment.

/**
 * Prepares the servlet based web services specified in web.xml for deployment.
 *
 * Swap the application written servlet implementation class for
 * one provided by the container.  The original class is stored
 * as runtime information since it will be used as the servant at
 * dispatch time.
 */
private void doWebServiceDeployment(WebBundleDescriptor webBunDesc) throws DeploymentException, MalformedURLException {
    /**
     * Combining code from <code>com.sun.enterprise.deployment.backend.WebServiceDeployer</code>
     * in v2
     */
    Collection<WebServiceEndpoint> endpoints = webBunDesc.getWebServices().getEndpoints();
    ClassLoader cl = webBunDesc.getClassLoader();
    WsUtil wsutil = new WsUtil();
    for (WebServiceEndpoint nextEndpoint : endpoints) {
        WebComponentDescriptor webComp = nextEndpoint.getWebComponentImpl();
        if (!nextEndpoint.hasServletImplClass()) {
            throw new DeploymentException(format(rb.getString(LogUtils.DEPLOYMENT_BACKEND_CANNOT_FIND_SERVLET), nextEndpoint.getEndpointName()));
        }
        if (nextEndpoint.hasEndpointAddressUri()) {
            webComp.getUrlPatternsSet().clear();
            webComp.addUrlPattern(nextEndpoint.getEndpointAddressUri());
        }
        if (!nextEndpoint.getWebService().hasFilePublishing()) {
            String publishingUri = nextEndpoint.getPublishingUri();
            String publishingUrlPattern = (publishingUri.charAt(0) == '/') ? publishingUri : "/" + publishingUri + "/*";
            webComp.addUrlPattern(publishingUrlPattern);
        }
        String servletImplClass = nextEndpoint.getServletImplClass();
        try {
            Class servletImplClazz = cl.loadClass(servletImplClass);
            String containerServlet;
            if (wsutil.isJAXWSbasedService(nextEndpoint.getWebService())) {
                containerServlet = "org.glassfish.webservices.JAXWSServlet";
                addWSServletContextListener(webBunDesc);
            } else {
                containerServlet = SingleThreadModel.class.isAssignableFrom(servletImplClazz) ? "org.glassfish.webservices.SingleThreadJAXRPCServlet" : "org.glassfish.webservices.JAXRPCServlet";
            }
            webComp.setWebComponentImplementation(containerServlet);
        } catch (ClassNotFoundException cex) {
            throw new DeploymentException(format(rb.getString(LogUtils.DEPLOYMENT_BACKEND_CANNOT_FIND_SERVLET), nextEndpoint.getEndpointName()));
        }
        /**
         * Now trying to figure the address from <code>com.sun.enterprise.webservice.WsUtil.java</code>
         */
        // Get a URL for the root of the webserver, where the host portion
        // is a canonical host name.  Since this will be used to compose the
        // endpoint address that is written into WSDL, it's better to use
        // hostname as opposed to IP address.
        // The protocol and port will be based on whether the endpoint
        // has a transport guarantee of INTEGRAL or CONFIDENTIAL.
        // If yes, https will be used.  Otherwise, http will be used.
        WebServerInfo wsi = new WsUtil().getWebServerInfoForDAS();
        URL rootURL = wsi.getWebServerRootURL(nextEndpoint.isSecure());
        String contextRoot = webBunDesc.getContextRoot();
        URL actualAddress = nextEndpoint.composeEndpointAddress(rootURL, contextRoot);
        if (wsi.getHttpVS() != null && wsi.getHttpVS().getPort() != 0) {
            logger.log(Level.INFO, LogUtils.ENDPOINT_REGISTRATION, new Object[] { nextEndpoint.getEndpointName(), actualAddress });
        }
    }
}
Also used : WebServerInfo(org.glassfish.web.deployment.util.WebServerInfo) DeploymentException(org.glassfish.deployment.common.DeploymentException)

Example 3 with DeploymentException

use of org.glassfish.deployment.common.DeploymentException in project Payara by payara.

the class WebServicesDeployer method setupJaxWSServiceForDeployment.

protected void setupJaxWSServiceForDeployment(DeploymentContext dc, WebService ws) throws DeploymentException {
    BundleDescriptor bundle = dc.getModuleMetaData(BundleDescriptor.class);
    // for modules this is domains/<domain-name>/j2ee-modules/<module-name>
    // for apps this is domains/<domain-name>/j2ee-apps/<app-name>/<foo_war> (in case of embedded wars)
    // or domains/<domain-name>/j2ee-apps/<app-name>/<foo_jar> (in case of embedded jars)
    File moduleDir = dc.getSourceDir();
    // For modules this is domains/<domain-name>/generated/xml
    // Check with Hong about j2ee-modules
    File wsdlDir = dc.getScratchDir("xml");
    mkDirs(wsdlDir);
    // For modules this is domains/<domain-name>/generated/xml
    // Check with Hong about j2ee-modules
    File stubsDir = dc.getScratchDir("ejb");
    mkDirs(stubsDir);
    if (!DOLUtils.warType().equals(bundle.getModuleType()) && !DOLUtils.ejbType().equals(bundle.getModuleType())) {
        // unknown module type with @WebService, just ignore...
        return;
    }
    wsdlDir = new File(wsdlDir, bundle.getWsdlDir().replaceAll("/", "\\" + File.separator));
    // Check if catalog file is present, if so get mapped WSDLs
    String wsdlFileUri;
    File wsdlFile;
    try {
        checkCatalog(bundle, ws, moduleDir);
    } catch (DeploymentException e) {
        logger.log(Level.SEVERE, LogUtils.ERROR_RESOLVING_CATALOG);
    }
    if (ws.hasWsdlFile()) {
        // If wsdl file is an http URL, download that WSDL and all embedded relative wsdls, schemas
        if (ws.getWsdlFileUri().startsWith("http")) {
            try {
                wsdlFileUri = downloadWsdlsAndSchemas(new URL(ws.getWsdlFileUri()), wsdlDir);
            } catch (Exception e) {
                throw new DeploymentException(e.toString(), e);
            }
            wsdlFile = new File(wsdlDir, wsdlFileUri);
        } else {
            wsdlFileUri = ws.getWsdlFileUri();
            File wsdlFileAbs = new File(wsdlFileUri);
            wsdlFile = wsdlFileAbs.isAbsolute() ? wsdlFileAbs : new File(moduleDir, wsdlFileUri);
        }
        if (!wsdlFile.exists()) {
            String errorMessage = format(logger.getResourceBundle().getString(LogUtils.WSDL_NOT_FOUND), ws.getWsdlFileUri(), bundle.getModuleDescriptor().getArchiveUri());
            logger.log(Level.SEVERE, errorMessage);
            throw new DeploymentException(errorMessage);
        }
    }
}
Also used : DeploymentException(org.glassfish.deployment.common.DeploymentException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DeploymentException(org.glassfish.deployment.common.DeploymentException) SAXException(org.xml.sax.SAXException)

Example 4 with DeploymentException

use of org.glassfish.deployment.common.DeploymentException in project Payara by payara.

the class WebServicesDeployer method resolveCatalog.

public URL resolveCatalog(File catalogFile, String wsdlFile, WebService ws) throws DeploymentException {
    try {
        URL retVal = null;
        // Get an entity resolver
        org.xml.sax.EntityResolver resolver = XmlUtil.createEntityResolver(catalogFile.toURL());
        org.xml.sax.InputSource source = resolver.resolveEntity(null, wsdlFile);
        if (source != null) {
            String mappedEntry = source.getSystemId();
            // return file://<absolute path
            if (mappedEntry.startsWith("file:")) {
                File f = new File(mappedEntry.substring(mappedEntry.indexOf(":") + 1));
                if (!f.exists()) {
                    throw new DeploymentException(format(rb.getString(LogUtils.CATALOG_RESOLVER_ERROR), mappedEntry));
                }
                retVal = f.toURI().toURL();
                if (ws != null) {
                    ws.setWsdlFileUri(f.getAbsolutePath());
                    ws.setWsdlFileUrl(retVal);
                }
            } else if (mappedEntry.startsWith("http")) {
                retVal = new URL(mappedEntry);
                if (ws != null) {
                    ws.setWsdlFileUrl(retVal);
                }
            }
        }
        return retVal;
    } catch (Throwable t) {
        throw new DeploymentException(format(rb.getString(LogUtils.CATALOG_ERROR), catalogFile.getAbsolutePath(), t.getMessage()));
    }
}
Also used : DeploymentException(org.glassfish.deployment.common.DeploymentException)

Example 5 with DeploymentException

use of org.glassfish.deployment.common.DeploymentException in project Payara by payara.

the class WebServicesDeployer method prepare.

/**
 * Prepares the application bits for running in the application server.
 * For certain cases, this is exploding the jar file to a format the
 * ContractProvider instance is expecting, generating non portable
 * artifacts and other application specific tasks.
 * Failure to prepare should throw an exception which will cause the overall
 * deployment to fail.
 *
 * @param dc deployment context
 * @return true if the prepare phase was successful
 */
@Override
public boolean prepare(DeploymentContext dc) {
    try {
        Application app = dc.getModuleMetaData(Application.class);
        if (app == null) {
            // hopefully the DOL gave a good message of the failure...
            logger.log(Level.SEVERE, LogUtils.FAILED_LOADING_DD);
            return false;
        }
        BundleDescriptor bundle = DOLUtils.getCurrentBundleForContext(dc);
        String moduleCP = getModuleClassPath(dc);
        final List<URL> moduleCPUrls = ASClassLoaderUtil.getURLsFromClasspath(moduleCP, File.pathSeparator, null);
        final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        URLClassLoader newCl = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {

            @Override
            public URLClassLoader run() {
                return new URLClassLoader(ASClassLoaderUtil.convertURLListToArray(moduleCPUrls), oldCl);
            }
        });
        Thread.currentThread().setContextClassLoader(newCl);
        WebServicesDescriptor wsDesc = bundle.getWebServices();
        for (WebService ws : wsDesc.getWebServices()) {
            if ((new WsUtil()).isJAXWSbasedService(ws)) {
                setupJaxWSServiceForDeployment(dc, ws);
            } else {
                JAXRPCCodeGenFacade facade = habitat.getService(JAXRPCCodeGenFacade.class);
                if (facade != null) {
                    facade.run(habitat, dc, moduleCP, false);
                } else {
                    throw new DeploymentException(rb.getString(LogUtils.JAXRPC_CODEGEN_FAIL));
                }
            }
        }
        doWebServicesDeployment(app, dc);
        Thread.currentThread().setContextClassLoader(oldCl);
        WebServicesContainer container = habitat.getService(WebServicesContainer.class);
        WebServicesDeploymentMBean bean = container.getDeploymentBean();
        WebServiceDeploymentNotifier notifier = getDeploymentNotifier();
        bean.deploy(wsDesc, notifier);
        return true;
    } catch (Exception ex) {
        RuntimeException re = new RuntimeException(ex.getMessage());
        re.initCause(ex);
        throw re;
    }
}
Also used : JAXRPCCodeGenFacade(org.glassfish.internal.api.JAXRPCCodeGenFacade) WebServicesDeploymentMBean(org.glassfish.webservices.deployment.WebServicesDeploymentMBean) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DeploymentException(org.glassfish.deployment.common.DeploymentException) SAXException(org.xml.sax.SAXException) DeploymentException(org.glassfish.deployment.common.DeploymentException)

Aggregations

DeploymentException (org.glassfish.deployment.common.DeploymentException)30 IASSecurityException (com.sun.enterprise.security.util.IASSecurityException)8 IOException (java.io.IOException)6 Application (com.sun.enterprise.deployment.Application)4 File (java.io.File)4 ResourceException (javax.resource.ResourceException)4 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)4 Iterator (java.util.Iterator)3 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)3 Resource (com.sun.enterprise.config.serverbeans.Resource)2 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 ArrayList (java.util.ArrayList)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 OpsParams (org.glassfish.api.deployment.OpsParams)2 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)2 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 ServiceInterfaceGenerator (com.sun.ejb.codegen.ServiceInterfaceGenerator)1