Search in sources :

Example 1 with WebServerInfo

use of org.glassfish.web.deployment.util.WebServerInfo in project Payara by payara.

the class WebServicesApplication method start.

public boolean start(ApplicationContext startupContext) throws Exception {
    cl = startupContext.getClassLoader();
    try {
        app = deploymentCtx.getModuleMetaData(Application.class);
        DeployCommandParameters commandParams = ((DeploymentContext) startupContext).getCommandParameters(DeployCommandParameters.class);
        String virtualServers = commandParams.virtualservers;
        Iterator<EjbEndpoint> iter = ejbendpoints.iterator();
        EjbEndpoint ejbendpoint = null;
        while (iter.hasNext()) {
            ejbendpoint = iter.next();
            String contextRoot = ejbendpoint.contextRoot;
            WebServerInfo wsi = new WsUtil().getWebServerInfoForDAS();
            URL rootURL = wsi.getWebServerRootURL(ejbendpoint.isSecure);
            dispatcher.registerEndpoint(contextRoot, httpHandler, this, virtualServers);
            // Fix for issue 13107490 and 17648
            if (wsi.getHttpVS() != null && wsi.getHttpVS().getPort() != 0) {
                logger.log(Level.INFO, LogUtils.EJB_ENDPOINT_REGISTRATION, new Object[] { app.getAppName(), rootURL + contextRoot });
            }
        }
    } catch (EndpointRegistrationException e) {
        logger.log(Level.SEVERE, LogUtils.ENDPOINT_REGISTRATION_ERROR, e.toString());
    }
    return true;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) WebServerInfo(org.glassfish.web.deployment.util.WebServerInfo) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) URL(java.net.URL)

Example 2 with WebServerInfo

use of org.glassfish.web.deployment.util.WebServerInfo 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 WebServerInfo

use of org.glassfish.web.deployment.util.WebServerInfo in project Payara by payara.

the class WsUtil method handleGet.

/**
 * Serve up the FINAL wsdl associated with this web service.
 * @return true for success, false for failure
 */
public boolean handleGet(HttpServletRequest request, HttpServletResponse response, WebServiceEndpoint endpoint) throws IOException {
    MimeHeaders headers = getHeaders(request);
    if (hasSomeTextXmlContent(headers)) {
        String message = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.GET_RECEIVED), endpoint.getEndpointName(), endpoint.getEndpointAddressUri());
        writeInvalidMethodType(response, message);
        logger.info(message);
        return false;
    }
    URL wsdlUrl = null;
    String requestUriRaw = request.getRequestURI();
    String requestUri = (requestUriRaw.charAt(0) == '/') ? requestUriRaw.substring(1) : requestUriRaw;
    String queryString = request.getQueryString();
    WebService webService = endpoint.getWebService();
    if (queryString == null) {
        // Get portion of request uri representing location within a module
        String wsdlPath = endpoint.getWsdlContentPath(requestUri);
        if (wsdlPath != null) {
            ModuleDescriptor module = webService.getBundleDescriptor().getModuleDescriptor();
            if (wsdlPath.equals(webService.getWsdlFileUri())) {
                // If the request is for the main wsdl document, return
                // the final wsdl instead of the wsdl from the module.
                wsdlUrl = webService.getWsdlFileUrl();
            } else if (isWsdlContent(wsdlPath, webService.getBundleDescriptor())) {
                // For relative document imports. These documents do not
                // require modification during deployment, so serve them
                // up directly from the packaged module.  isWsdlContent()
                // check ensures we don't serve up arbitrary content from
                // the module.
                URL finalWsdlUrl = webService.getWsdlFileUrl();
                String finalWsdlPath = finalWsdlUrl.getPath();
                // remove the final wsdl uri from the above path
                String wsdlDirPath = finalWsdlPath.substring(0, finalWsdlPath.length() - webService.getWsdlFileUri().length());
                File wsdlDir = new File(wsdlDirPath);
                File wsdlFile = new File(wsdlDir, wsdlPath.replace('/', File.separatorChar));
                try {
                    wsdlUrl = wsdlFile.toURL();
                } catch (MalformedURLException mue) {
                    String msg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.FAILURE_SERVING_WSDL), webService.getName());
                    logger.log(Level.INFO, msg, mue);
                }
            }
        }
    } else if (queryString.equalsIgnoreCase("WSDL")) {
        wsdlUrl = webService.getWsdlFileUrl();
    }
    boolean success = false;
    if (wsdlUrl != null) {
        InputStream is = null;
        try {
            response.setContentType("text/xml");
            response.setStatus(HttpServletResponse.SC_OK);
            // than the one they were deployed on (DAS).
            if (wsdlUrl.toURI().equals(webService.getWsdlFileUrl().toURI())) {
                // get the application module ID
                try {
                    WebServerInfo wsi = getWebServerInfoForDAS();
                    URL url = webService.getWsdlFileUrl();
                    File originalWsdlFile = new File(url.getPath() + "__orig");
                    if (!originalWsdlFile.exists()) {
                        originalWsdlFile = new File(url.getPath());
                    }
                    generateFinalWsdl(originalWsdlFile.toURL(), webService, wsi, response.getOutputStream());
                } catch (Exception e) {
                    // if this fail, we revert to service the untouched
                    // repository item.
                    URLConnection urlCon = wsdlUrl.openConnection();
                    urlCon.setUseCaches(false);
                    is = urlCon.getInputStream();
                    copyIsToOs(is, response.getOutputStream());
                }
            } else {
                // Copy bytes into output. Disable caches to avoid jar URL
                // caching problem.
                URLConnection urlCon = wsdlUrl.openConnection();
                urlCon.setUseCaches(false);
                is = urlCon.getInputStream();
                copyIsToOs(is, response.getOutputStream());
            }
            success = true;
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogUtils.SERVING_FINAL_WSDL, new Object[] { wsdlUrl, request.getRequestURL() + (queryString != null ? ("?" + queryString) : "") });
            }
        } catch (Exception e) {
            String msg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.FAILURE_SERVING_WSDL), webService.getName());
            logger.log(Level.INFO, msg, e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ex) {
                }
            }
        }
    }
    if (!success) {
        String message = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.INVALID_WSDL_REQUEST), request.getRequestURL() + (queryString != null ? ("?" + queryString) : ""), webService.getName());
        logger.info(message);
        writeInvalidMethodType(response, message);
    }
    return success;
}
Also used : WebServerInfo(org.glassfish.web.deployment.util.WebServerInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) PrivilegedActionException(java.security.PrivilegedActionException) SOAPFaultException(javax.xml.rpc.soap.SOAPFaultException) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) SAXParseException(org.xml.sax.SAXParseException) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor)

Example 4 with WebServerInfo

use of org.glassfish.web.deployment.util.WebServerInfo in project Payara by payara.

the class WsUtil method getWebServerInfoForDAS.

public WebServerInfo getWebServerInfoForDAS() {
    WebServerInfo wsi = new WebServerInfo();
    if (this.networkListeners == null) {
        List<Integer> adminPorts = new ArrayList<Integer>();
        for (org.glassfish.api.container.Adapter subAdapter : WebServiceContractImpl.getInstance().getAdapters()) {
            if (subAdapter instanceof AdminAdapter) {
                AdminAdapter aa = (AdminAdapter) subAdapter;
                adminPorts.add(aa.getListenPort());
            } else if (subAdapter instanceof AdminConsoleAdapter) {
                AdminConsoleAdapter aca = (AdminConsoleAdapter) subAdapter;
                adminPorts.add(aca.getListenPort());
            }
        }
        for (NetworkListener nl : config.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
            if (!adminPorts.contains(Integer.valueOf(nl.getPort()))) {
                // get rid of admin ports
                if (networkListeners == null)
                    networkListeners = new ArrayList<NetworkListener>();
                networkListeners.add(nl);
            }
        }
    }
    // Fix for issue 13107490
    if ((networkListeners != null) && (!networkListeners.isEmpty())) {
        for (NetworkListener listener : networkListeners) {
            String host = listener.getAddress();
            if (listener.getAddress().equals("0.0.0.0"))
                try {
                    host = InetAddress.getLocalHost().getHostName();
                } catch (UnknownHostException e) {
                    // fallback
                    host = "localhost";
                }
            if (listener.findHttpProtocol().getSecurityEnabled().equals("false"))
                wsi.setHttpVS(new VirtualServerInfo("http", host, Integer.parseInt(listener.getPort())));
            else if (listener.findHttpProtocol().getSecurityEnabled().equals("true"))
                wsi.setHttpsVS(new VirtualServerInfo("https", host, Integer.parseInt(listener.getPort())));
        }
    } else {
        wsi.setHttpVS(new VirtualServerInfo("http", "localhost", 0));
        wsi.setHttpsVS(new VirtualServerInfo("https", "localhost", 0));
    }
    return wsi;
}
Also used : VirtualServerInfo(org.glassfish.web.deployment.util.VirtualServerInfo) WebServerInfo(org.glassfish.web.deployment.util.WebServerInfo) AdminConsoleAdapter(com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter) AdminAdapter(com.sun.enterprise.v3.admin.AdminAdapter) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with WebServerInfo

use of org.glassfish.web.deployment.util.WebServerInfo in project Payara by payara.

the class JaxRpcRICodegen method accept.

/**
 * Visits a webs service reference
 */
@Override
public void accept(ServiceReferenceDescriptor serviceRef) {
    if (!processServiceReferences) {
        return;
    }
    boolean codegenRequired = false;
    URL wsdlOverride = null;
    boolean wsdlOverriden = false;
    boolean jaxwsClient = false;
    super.accept(serviceRef);
    try {
        ClassLoader clr = serviceRef.getBundleDescriptor().getClassLoader();
        if (serviceRef.getServiceInterface() != null) {
            Class serviceInterface = clr.loadClass(serviceRef.getServiceInterface());
            if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterface)) {
                jaxwsClient = true;
            }
        }
        // already set.
        for (Iterator ports = serviceRef.getPortsInfo().iterator(); ports.hasNext(); ) {
            ServiceRefPortInfo portInfo = (ServiceRefPortInfo) ports.next();
            if (portInfo.isLinkedToPortComponent()) {
                WebServiceEndpoint linkedPortComponent = portInfo.getPortComponentLink();
                if (linkedPortComponent == null) {
                    throw new Exception(localStrings.getLocalString("enterprise.webservice.componentlinkunresolved", "The port-component-link {0} cannot be resolved", new Object[] { portInfo.getPortComponentLinkName() }));
                }
                WsUtil wsUtil = new WsUtil();
                WebServerInfo wsi = wsUtil.getWebServerInfoForDAS();
                URL rootURL = wsi.getWebServerRootURL(linkedPortComponent.isSecure());
                URL actualAddress = linkedPortComponent.composeEndpointAddress(rootURL);
                if (jaxwsClient) {
                    portInfo.addStubProperty(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, actualAddress.toExternalForm());
                } else {
                    portInfo.addStubProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, actualAddress.toExternalForm());
                }
                if (serviceRef.getBundleDescriptor().getModuleType().equals(DOLUtils.carType())) {
                    wsdlOverride = serviceRef.getWsdlOverride();
                    if (wsdlOverride != null) {
                        wsdlOverriden = true;
                        serviceRef.setWsdlOverride(linkedPortComponent.getWebService().getWsdlFileUrl());
                    }
                }
            }
        }
        // If this is a post JAXRPC-1.1 based web service, then no need for code gen etc etc
        if (jaxwsClient) {
            return;
        }
        if (serviceRef.hasGeneratedServiceInterface()) {
            if (serviceRef.hasWsdlFile() && serviceRef.hasMappingFile()) {
                codegenRequired = true;
            } else {
                throw new Exception("Deployment error for service-ref " + serviceRef.getName() + ".\nService references with generated service " + "interface must include WSDL and mapping information.");
            }
        } else {
            if (serviceRef.hasWsdlFile()) {
                if (serviceRef.hasMappingFile()) {
                    codegenRequired = true;
                } else {
                    throw new Exception("Deployment error for service-ref " + serviceRef.getName() + ".\nService references with wsdl must also have " + "mapping information.");
                }
            }
        }
        if (codegenRequired) {
            ModelInfo modelInfo = createModelInfo(serviceRef);
            /*
                 * If clients exist, force regeneration so that the
                 * ClientArtifactsManager is populated. Issue 10612.
                 */
            String[] args = createJaxrpcCompileArgs(false, hasWebServiceClients);
            CompileTool wscompile = rpcFactory.createCompileTool(System.out, "wscompile");
            wscompileForAccept = wscompile;
            WsCompile delegate = new WsCompile(wscompile, serviceRef);
            delegate.setModelInfo(modelInfo);
            wscompile.setDelegate(delegate);
            jaxrpc(args, delegate, serviceRef, files);
            if (hasWebServiceClients) {
                addArtifactsForAppClient();
            }
        }
        if (wsdlOverriden) {
            serviceRef.setWsdlOverride(wsdlOverride);
        }
    } catch (IllegalStateException e) {
        // do nothing
        logger.info("Attempting to add artifacts for appClient after artifacts were generated" + " " + e.getMessage());
    } catch (Exception e) {
        RuntimeException re = new RuntimeException(e.getMessage());
        re.initCause(e);
        throw re;
    }
}
Also used : CompileTool(com.sun.xml.rpc.spi.tools.CompileTool) ModelFileModelInfo(com.sun.xml.rpc.spi.tools.ModelFileModelInfo) ModelInfo(com.sun.xml.rpc.spi.tools.ModelInfo) J2EEModelInfo(com.sun.xml.rpc.spi.tools.J2EEModelInfo) NoMetadataModelInfo(com.sun.xml.rpc.spi.tools.NoMetadataModelInfo) WebServerInfo(org.glassfish.web.deployment.util.WebServerInfo) WsUtil(org.glassfish.webservices.WsUtil) URL(java.net.URL) IOException(java.io.IOException) Iterator(java.util.Iterator) ASURLClassLoader(com.sun.enterprise.loader.ASURLClassLoader) WsCompile(org.glassfish.webservices.WsCompile)

Aggregations

WebServerInfo (org.glassfish.web.deployment.util.WebServerInfo)5 URL (java.net.URL)2 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)1 ASURLClassLoader (com.sun.enterprise.loader.ASURLClassLoader)1 AdminAdapter (com.sun.enterprise.v3.admin.AdminAdapter)1 AdminConsoleAdapter (com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter)1 CompileTool (com.sun.xml.rpc.spi.tools.CompileTool)1 J2EEModelInfo (com.sun.xml.rpc.spi.tools.J2EEModelInfo)1 ModelFileModelInfo (com.sun.xml.rpc.spi.tools.ModelFileModelInfo)1 ModelInfo (com.sun.xml.rpc.spi.tools.ModelInfo)1 NoMetadataModelInfo (com.sun.xml.rpc.spi.tools.NoMetadataModelInfo)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Iterator (java.util.Iterator)1 SOAPFaultException (javax.xml.rpc.soap.SOAPFaultException)1 EndpointRegistrationException (org.glassfish.api.container.EndpointRegistrationException)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)1 DeploymentException (org.glassfish.deployment.common.DeploymentException)1