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;
}
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 });
}
}
}
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;
}
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;
}
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;
}
}
Aggregations