All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.enunciate.modules.xfire.XFireDeploymentModule Maven / Gradle / Ivy

Go to download

The Enunciate XML module generates the artifacts required to deploy XFire-supported SOAP endpoints.

There is a newer version: 1.20
Show newest version
/*
 * Copyright 2006-2008 Web Cohesion
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.codehaus.enunciate.modules.xfire;

import freemarker.template.TemplateException;
import org.codehaus.enunciate.EnunciateException;
import org.codehaus.enunciate.apt.EnunciateFreemarkerModel;
import org.codehaus.enunciate.config.EnunciateConfiguration;
import org.codehaus.enunciate.config.WsdlInfo;
import org.codehaus.enunciate.contract.jaxws.*;
import org.codehaus.enunciate.contract.validation.Validator;
import org.codehaus.enunciate.main.Enunciate;
import org.codehaus.enunciate.main.FileArtifact;
import org.codehaus.enunciate.main.webapp.BaseWebAppFragment;
import org.codehaus.enunciate.main.webapp.WebAppComponent;
import org.codehaus.enunciate.modules.FreemarkerDeploymentModule;
import org.codehaus.enunciate.modules.spring_app.ServiceEndpointBeanIdMethod;
import org.springframework.web.servlet.DispatcherServlet;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.TreeSet;

/**
 * 

XFire Module

* *

The XFire deployment module is a simple module that generates the request/response beans * for rpc/lit SOAP operations.

* *

The XFire module used to be the primary module for assembing the app. As of release 1.5, * this functionality has been separated into the spring-app module. However, the XFire module still * depends on the spring-app module to function, as it assumes that the endpoint beans are defined * in the Spring root application context. * *

* *

Steps

* *

generate

* *

The "generate" step generates the source beans and the spring configuration file. And the spring * servlet file for the XFire soap servlet.

* *

Configuration

* *

There are no additional configuration elements for the XFire module.

* *

Artifacts

* *

The XFire deployment module exports the following artifacts:

* *
    *
  • The "xfire-server.src.dir" artifact is the directory where the beans are generated.
  • *
* * @author Ryan Heaton * @docFileName module_xfire.html */ public class XFireDeploymentModule extends FreemarkerDeploymentModule { /** * @return "xfire" */ @Override public String getName() { return "xfire"; } /** * @return The URL to "rpc-request-bean.fmt" */ protected URL getRPCRequestBeanTemplateURL() { return XFireDeploymentModule.class.getResource("rpc-request-bean.fmt"); } /** * @return The URL to "rpc-response-bean.fmt" */ protected URL getRPCResponseBeanTemplateURL() { return XFireDeploymentModule.class.getResource("rpc-response-bean.fmt"); } /** * @return The URL to "xfire-servlet.xml.fmt" */ protected URL getXfireServletTemplateURL() { return XFireDeploymentModule.class.getResource("xfire-servlet.xml.fmt"); } /** * @return The URL to "xfire-servlet.xml.fmt" */ protected URL getParameterNamesTemplateURL() { return XFireDeploymentModule.class.getResource("enunciate-soap-parameter-names.properties.fmt"); } @Override public void init(Enunciate enunciate) throws EnunciateException { super.init(enunciate); if (!isDisabled() && !enunciate.isModuleEnabled("jaxws")) { throw new EnunciateException("The XFire module requires an enabled JAXWS module."); } } // Inherited. @Override public void initModel(EnunciateFreemarkerModel model) { super.initModel(model); EnunciateConfiguration config = model.getEnunciateConfig(); for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) { for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) { String path = "/soap/" + ei.getServiceName(); if (config != null) { path = config.getDefaultSoapSubcontext() + '/' + ei.getServiceName(); if (config.getSoapServices2Paths().containsKey(ei.getServiceName())) { path = config.getSoapServices2Paths().get(ei.getServiceName()); } } ei.putMetaData("soapPath", path); } } } @Override public void doFreemarkerGenerate() throws IOException, TemplateException { if (!isUpToDate()) { EnunciateFreemarkerModel model = getModel(); //generate the rpc request/response beans. for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) { for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) { for (WebMethod webMethod : ei.getWebMethods()) { for (WebMessage webMessage : webMethod.getMessages()) { if (webMessage instanceof RPCInputMessage) { model.put("message", webMessage); processTemplate(getRPCRequestBeanTemplateURL(), model); } else if (webMessage instanceof RPCOutputMessage) { model.put("message", webMessage); processTemplate(getRPCResponseBeanTemplateURL(), model); } } } } } model.put("endpointBeanId", new ServiceEndpointBeanIdMethod()); model.put("docsDir", enunciate.getProperty("docs.webapp.dir")); processTemplate(getXfireServletTemplateURL(), model); processTemplate(getParameterNamesTemplateURL(), model); } else { info("Skipping generation of XFire support classes as everything appears up-to-date...."); } getEnunciate().addArtifact(new FileArtifact(getName(), "xfire-server.src.dir", getGenerateDir())); getEnunciate().addAdditionalSourceRoot(getGenerateDir()); } @Override protected void doBuild() throws EnunciateException, IOException { super.doBuild(); File webappDir = getBuildDir(); webappDir.mkdirs(); File webinf = new File(webappDir, "WEB-INF"); getEnunciate().copyFile(new File(getGenerateDir(), "xfire-servlet.xml"), new File(webinf, "xfire-servlet.xml")); getEnunciate().copyFile(new File(getGenerateDir(), "enunciate-soap-parameter-names.properties"), new File(new File(webinf, "classes"), "enunciate-soap-parameter-names.properties")); BaseWebAppFragment webappFragment = new BaseWebAppFragment(getName()); webappFragment.setBaseDir(webappDir); WebAppComponent servletComponent = new WebAppComponent(); servletComponent.setName("xfire"); servletComponent.setClassname(DispatcherServlet.class.getName()); TreeSet urlMappings = new TreeSet(); for (WsdlInfo wsdlInfo : getModel().getNamespacesToWSDLs().values()) { for (EndpointInterface endpointInterface : wsdlInfo.getEndpointInterfaces()) { urlMappings.add(String.valueOf(endpointInterface.getMetaData().get("soapPath"))); } } servletComponent.setUrlMappings(urlMappings); webappFragment.setServlets(Arrays.asList(servletComponent)); getEnunciate().addWebAppFragment(webappFragment); } /** * Whether the generated sources are up-to-date. * * @return Whether the generated sources are up-to-date. */ protected boolean isUpToDate() { return enunciate.isUpToDateWithSources(getGenerateDir()); } @Override public Validator getValidator() { return new XFireValidator(); } // Inherited. @Override public boolean isDisabled() { if (super.isDisabled()) { return true; } else if (getModelInternal() != null && getModelInternal().getNamespacesToWSDLs().isEmpty()) { debug("XFire module is disabled because there are no endpoint interfaces."); return true; } return false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy