use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class ServiceProcessor method processPort.
private JavaPort processPort(JavaModel model, ServiceInfo si, EndpointInfo port) throws ToolException {
BindingInfo binding = port.getBinding();
String portType = binding.getInterface().getName().getLocalPart();
JavaInterface intf = PortTypeProcessor.getInterface(context, si, binding.getInterface());
JavaPort jport = new JavaPort(NameUtil.mangleNameToClassName(port.getName().getLocalPart()));
jport.setPackageName(intf.getPackageName());
jport.setPortName(port.getName().getLocalPart());
jport.setBindingAdress(port.getAddress());
jport.setBindingName(binding.getName().getLocalPart());
jport.setPortType(portType);
jport.setInterfaceClass(intf.getName());
bindingType = getBindingType(binding);
if (bindingType == null) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_SPECIFY_ONE_PROTOCOL", LOG, binding.getName());
throw new ToolException(msg);
}
if (isSoapBinding()) {
SoapBinding spbd = SOAPBindingUtil.getProxy(SoapBinding.class, this.bindingObj);
jport.setStyle(SOAPBindingUtil.getSoapStyle(spbd.getStyle()));
jport.setTransURI(spbd.getTransportURI());
}
Collection<BindingOperationInfo> operations = binding.getOperations();
for (BindingOperationInfo bop : operations) {
processOperation(model, bop, binding);
}
jport.setJavaDoc(port.getDocumentation());
JAXWSBinding bind = port.getExtensor(JAXWSBinding.class);
if (bind != null) {
jport.setMethodName(bind.getMethodName());
jport.setJavaDoc(bind.getMethodJavaDoc());
}
return jport;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class ServiceProcessor method processMultipart.
public void processMultipart(JavaMethod jm, BindingOperationInfo operation, MIMEMultipartRelated ext, JavaType.Style style) throws ToolException {
List<MIMEPart> mimeParts = CastUtils.cast(ext.getMIMEParts());
for (MIMEPart mPart : mimeParts) {
List<ExtensibilityElement> extns = CastUtils.cast(mPart.getExtensibilityElements());
for (ExtensibilityElement extElement : extns) {
if (extElement instanceof MIMEContent) {
MIMEContent mimeContent = (MIMEContent) extElement;
String mimeJavaType = getJavaTypeForMimeType(mPart);
if (JavaType.Style.IN.equals(style)) {
String paramName = ProcessorUtil.mangleNameToVariableName(mimeContent.getPart());
JavaParameter jp = jm.getParameter(paramName);
if (jp == null) {
Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
throw new ToolException(message);
}
if (!jp.getClassName().equals(mimeJavaType)) {
// jp.setType(mimeJavaType);
jp.setClassName(mimeJavaType);
}
} else if (JavaType.Style.OUT.equals(style)) {
JavaType jp = null;
if (!"void".equals(jm.getReturn().getType()) && mimeContent.getPart().equals(jm.getReturn().getName())) {
jp = jm.getReturn();
jp.setClassName(mimeJavaType);
}
if (jp == null) {
for (JavaParameter para : jm.getParameters()) {
if (mimeContent.getPart().equals(para.getPartName())) {
jp = para;
}
}
if (jp != null) {
((JavaParameter) jp).setClassName(mimeJavaType);
}
}
if (jp == null) {
Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
throw new ToolException(message);
}
}
} else if (extElement instanceof SOAPHeader) {
processSoapHeader(jm, operation, extElement);
}
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToJavaContainer method processWsdl.
private void processWsdl() {
validate(context);
FrontEndProfile frontend = context.get(FrontEndProfile.class);
if (frontend == null) {
throw new ToolException(new Message("FOUND_NO_FRONTEND", LOG));
}
WSDLConstants.WSDLVersion version = getWSDLVersion();
String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
@SuppressWarnings("unchecked") List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
if (serviceList == null) {
serviceList = new ArrayList<>();
// Build the ServiceModel from the WSDLModel
if (version == WSDLConstants.WSDLVersion.WSDL11) {
AbstractWSDLBuilder builder = frontend.getWSDLBuilder();
builder.setContext(context);
builder.setBus(getBus());
context.put(Bus.class, getBus());
wsdlURL = URIParserUtil.getAbsoluteURI(wsdlURL);
builder.build(wsdlURL);
builder.customize();
Definition definition = builder.getWSDLModel();
context.put(Definition.class, definition);
builder.validate(definition);
WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
if (context.isVerbose()) {
serviceBuilder.setUnwrapLogLevel(Level.INFO);
}
serviceBuilder.setIgnoreUnknownBindings(true);
String allowRefs = (String) context.get(ToolConstants.CFG_ALLOW_ELEMENT_REFS);
if (!StringUtils.isEmpty(allowRefs) || context.optionSet(ToolConstants.CFG_ALLOW_ELEMENT_REFS)) {
if (allowRefs.length() > 0 && allowRefs.charAt(0) == '=') {
allowRefs = allowRefs.substring(1);
}
if (StringUtils.isEmpty(allowRefs)) {
allowRefs = "true";
}
serviceBuilder.setAllowElementRefs(Boolean.valueOf(allowRefs));
}
String serviceName = (String) context.get(ToolConstants.CFG_SERVICENAME);
if (serviceName != null) {
List<ServiceInfo> services = serviceBuilder.buildServices(definition, getServiceQName(definition));
serviceList.addAll(services);
} else if (definition.getServices().size() > 0) {
serviceList = serviceBuilder.buildServices(definition);
} else {
serviceList = serviceBuilder.buildMockServices(definition);
}
// remove definition from cache so that won't fail when encounter same wsdl file
// name but different wsdl content(CXF-3340)
getBus().getExtension(WSDLManager.class).removeDefinition(definition);
} else {
// TODO: wsdl2.0 support
}
}
context.put(ToolConstants.SERVICE_LIST, serviceList);
Map<String, InterfaceInfo> interfaces = new LinkedHashMap<String, InterfaceInfo>();
ServiceInfo service0 = serviceList.get(0);
SchemaCollection schemaCollection = service0.getXmlSchemaCollection();
context.put(ToolConstants.XML_SCHEMA_COLLECTION, schemaCollection);
context.put(ToolConstants.PORTTYPE_MAP, interfaces);
context.put(ClassCollector.class, createClassCollector());
Processor processor = frontend.getProcessor();
if (processor instanceof ClassNameProcessor) {
processor.setEnvironment(context);
for (ServiceInfo service : serviceList) {
context.put(ServiceInfo.class, service);
((ClassNameProcessor) processor).processClassNames();
context.put(ServiceInfo.class, null);
}
}
if (context.optionSet(ToolConstants.CFG_NO_TYPES)) {
context.remove(ToolConstants.CFG_TYPES);
context.remove(ToolConstants.CFG_ALL);
context.remove(ToolConstants.CFG_COMPILE);
}
generateTypes();
if (context.getErrorListener().getErrorCount() > 0) {
return;
}
for (ServiceInfo service : serviceList) {
context.put(ServiceInfo.class, service);
if (context.basicValidateWSDL()) {
validate(service);
}
if (context.getErrorListener().getErrorCount() == 0) {
// Build the JavaModel from the ServiceModel
processor.setEnvironment(context);
processor.process();
}
}
if (context.getErrorListener().getErrorCount() > 0) {
return;
}
if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
enforceWSDLLocation(context);
}
if (!isSuppressCodeGen()) {
// Generate artifacts
for (FrontEndGenerator generator : frontend.getGenerators()) {
generator.generate(context);
}
}
context.remove(ToolConstants.SERVICE_LIST);
// Build projects: compile classes and copy resources etc.
if (context.optionSet(ToolConstants.CFG_COMPILE)) {
new ClassUtils().compile(context);
}
if (context.isExcludeNamespaceEnabled()) {
try {
removeExcludeFiles();
} catch (IOException e) {
throw new ToolException(e);
}
}
if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
processClientJar(context);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToJavaContainer method getServiceQName.
@SuppressWarnings("unchecked")
public QName getServiceQName(Definition def) {
List<Definition> defs = new ArrayList<>();
defs.add(def);
Iterator<?> ite1 = def.getImports().values().iterator();
while (ite1.hasNext()) {
List<javax.wsdl.Import> defList = CastUtils.cast((List<?>) ite1.next());
for (javax.wsdl.Import importDef : defList) {
defs.add(importDef.getDefinition());
}
}
String serviceName = (String) context.get(ToolConstants.CFG_SERVICENAME);
for (Definition definition : defs) {
if (serviceName != null) {
for (Iterator<QName> ite = definition.getServices().keySet().iterator(); ite.hasNext(); ) {
QName qn = ite.next();
if (qn.getLocalPart().equalsIgnoreCase(serviceName.toLowerCase())) {
return qn;
}
}
}
}
Message msg = new Message("SERVICE_NOT_FOUND", LOG, new Object[] { serviceName });
throw new ToolException(msg);
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToJavaContainer method validate.
public void validate(ToolContext env) throws ToolException {
String outdir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
if (!isSuppressCodeGen()) {
if (outdir != null) {
File dir = new File(outdir);
if (!dir.exists() && !dir.mkdirs()) {
Message msg = new Message("DIRECTORY_COULD_NOT_BE_CREATED", LOG, outdir);
throw new ToolException(msg);
}
if (!dir.isDirectory()) {
Message msg = new Message("NOT_A_DIRECTORY", LOG, outdir);
throw new ToolException(msg);
}
}
if (env.optionSet(ToolConstants.CFG_COMPILE)) {
String clsdir = (String) env.get(ToolConstants.CFG_CLASSDIR);
if (clsdir != null) {
File dir = new File(clsdir);
if (!dir.exists() && !dir.mkdirs()) {
Message msg = new Message("DIRECTORY_COULD_NOT_BE_CREATED", LOG, clsdir);
throw new ToolException(msg);
}
}
}
}
String wsdl = (String) env.get(ToolConstants.CFG_WSDLURL);
if (StringUtils.isEmpty(wsdl)) {
Message msg = new Message("NO_WSDL_URL", LOG);
throw new ToolException(msg);
}
env.put(ToolConstants.CFG_WSDLURL, URIParserUtil.getAbsoluteURI(wsdl));
if (!env.containsKey(ToolConstants.CFG_WSDLLOCATION)) {
// make sure the "raw" form is used for the wsdlLocation
// instead of the absolute URI that normalize may return
boolean assumeFileURI = false;
try {
URI uri = new URI(wsdl);
String uriScheme = uri.getScheme();
if (uriScheme == null) {
assumeFileURI = true;
}
wsdl = uri.toString();
} catch (Exception e) {
// not a URL, assume file
assumeFileURI = true;
}
if (assumeFileURI) {
if (wsdl.indexOf(":") != -1 && !wsdl.startsWith("/")) {
wsdl = "file:/" + wsdl;
} else {
wsdl = "file:" + wsdl;
}
try {
URI uri = new URI(wsdl);
wsdl = uri.toString();
} catch (Exception e1) {
// ignore...
}
}
wsdl = wsdl.replace("\\", "/");
env.put(ToolConstants.CFG_WSDLLOCATION, wsdl);
}
String[] bindingFiles;
try {
bindingFiles = (String[]) env.get(ToolConstants.CFG_BINDING);
if (bindingFiles == null) {
return;
}
} catch (ClassCastException e) {
bindingFiles = new String[1];
bindingFiles[0] = (String) env.get(ToolConstants.CFG_BINDING);
}
for (int i = 0; i < bindingFiles.length; i++) {
bindingFiles[i] = URIParserUtil.getAbsoluteURI(bindingFiles[i]);
}
env.put(ToolConstants.CFG_BINDING, bindingFiles);
}
Aggregations