use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class CustomizationParser method parse.
public void parse(ToolContext pe) {
this.env = pe;
String[] bindingFiles;
try {
wsdlURL = URIParserUtil.getAbsoluteURI((String) env.get(ToolConstants.CFG_WSDLURL));
if (env.get(ToolConstants.CFG_CATALOG) != null) {
wsdlNode = resolveNodeByCatalog(wsdlURL);
}
if (wsdlNode == null) {
wsdlNode = getTargetNode(this.wsdlURL);
}
if (wsdlNode == null) {
throw new ToolException(new Message("MISSING_WSDL", LOG, wsdlURL));
}
customizedElements.put(wsdlURL, wsdlNode);
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++) {
try {
addBinding(bindingFiles[i]);
} catch (XMLStreamException xse) {
Message msg = new Message("STAX_PARSER_ERROR", LOG);
throw new ToolException(msg, xse);
}
}
for (Map.Entry<Element, Element> entry : jaxwsBindingsMap.entrySet()) {
nodeSelector.addNamespaces(entry.getKey());
Element oldTargetNode = entry.getValue();
Element targetNode = oldTargetNode;
internalizeBinding(entry.getKey(), targetNode, "");
String uri = entry.getKey().getAttribute("wsdlLocation");
customizedElements.put(uri, targetNode);
updateJaxwsBindingMapValue(targetNode);
}
buildHandlerChains();
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class CustomizationParser method resolveByCatalog.
private String resolveByCatalog(String url) {
if (StringUtils.isEmpty(url)) {
return null;
}
Bus bus = env.get(Bus.class);
OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
try {
return new OASISCatalogManagerHelper().resolve(catalogResolver, url, null);
} catch (Exception e1) {
Message msg = new Message("FAILED_RESOLVE_CATALOG", LOG, url);
throw new ToolException(msg, e1);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class CustomizationParser method addBinding.
private void addBinding(String bindingFile) throws XMLStreamException {
Element root = null;
XMLStreamReader xmlReader = null;
try {
URIResolver resolver = new URIResolver(bindingFile);
xmlReader = StaxUtils.createXMLStreamReader(resolver.getURI().toString(), resolver.getInputStream());
root = StaxUtils.read(xmlReader, true).getDocumentElement();
} catch (Exception e1) {
Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { bindingFile });
throw new ToolException(msg, e1);
} finally {
StaxUtils.close(xmlReader);
}
XMLStreamReader reader = StaxUtils.createXMLStreamReader(root);
StaxUtils.toNextTag(reader);
if (isValidJaxwsBindingFile(bindingFile, reader)) {
String wsdlLocation = root.getAttribute("wsdlLocation");
Element targetNode = null;
if (!StringUtils.isEmpty(wsdlLocation)) {
String wsdlURI = getAbsoluteURI(wsdlLocation, bindingFile);
targetNode = getTargetNode(wsdlURI);
String resolvedLoc = wsdlURI;
if (targetNode == null && env.get(ToolConstants.CFG_CATALOG) != null) {
resolvedLoc = resolveByCatalog(wsdlURI);
targetNode = getTargetNode(resolvedLoc);
}
if (targetNode == null) {
Message msg = new Message("POINT_TO_WSDL_DOES_NOT_EXIST", LOG, new Object[] { bindingFile, resolvedLoc });
throw new ToolException(msg);
}
root.setAttributeNS(null, "wsdlLocation", wsdlURI);
} else {
targetNode = wsdlNode;
root.setAttributeNS(null, "wsdlLocation", wsdlURL);
}
jaxwsBindingsMap.put(root, targetNode);
} else if (isValidJaxbBindingFile(reader)) {
String schemaLocation = root.getAttribute("schemaLocation");
String resolvedSchemaLocation = resolveByCatalog(schemaLocation);
if (resolvedSchemaLocation != null) {
InputSource tmpIns = null;
try {
tmpIns = convertToTmpInputSource(root, resolvedSchemaLocation);
} catch (Exception e1) {
Message msg = new Message("FAILED_TO_ADD_SCHEMALOCATION", LOG, bindingFile);
throw new ToolException(msg, e1);
}
jaxbBindings.add(tmpIns);
} else {
jaxbBindings.add(new InputSource(bindingFile));
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class FaultGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
if (passthrough()) {
return;
}
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
for (JavaModel javaModel : map.values()) {
Map<String, JavaExceptionClass> exceptionClasses = javaModel.getExceptionClasses();
for (Entry<String, JavaExceptionClass> entry : exceptionClasses.entrySet()) {
JavaExceptionClass expClz = entry.getValue();
clearAttributes();
if (penv.containsKey(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID)) {
String faultSerialVersionUID = penv.get(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID).toString();
setAttributes("faultSerialVersionUID", faultSerialVersionUID);
if ("FQCN".equalsIgnoreCase(faultSerialVersionUID)) {
setAttributes("suid", generateHashSUID(expClz.getFullClassName()));
} else if ("TIMESTAMP".equalsIgnoreCase(faultSerialVersionUID)) {
setAttributes("suid", generateTimestampSUID());
} else if ("NONE".equalsIgnoreCase(faultSerialVersionUID)) {
// nothing
setAttributes("suid", "");
} else {
// do a quick Parse to make sure it looks like a Long
try {
Long.parseLong(faultSerialVersionUID);
} catch (NumberFormatException nfe) {
throw new ToolException(nfe);
}
setAttributes("suid", faultSerialVersionUID);
}
} else {
setAttributes("suid", "");
}
setAttributes("expClass", expClz);
String exceptionSuperclass;
if (penv.containsKey(ToolConstants.CFG_EXCEPTION_SUPER)) {
exceptionSuperclass = penv.get(ToolConstants.CFG_EXCEPTION_SUPER).toString();
} else {
exceptionSuperclass = "java.lang.Exception";
}
String simpleName = exceptionSuperclass.indexOf('.') == -1 ? exceptionSuperclass : exceptionSuperclass.substring(exceptionSuperclass.lastIndexOf('.') + 1);
String exceptionSuperclassString = simpleName;
for (JavaField jf : expClz.getFields()) {
String jfClassName = jf.getClassName();
if (jfClassName.substring(jfClassName.lastIndexOf(".") + 1).equals(simpleName)) {
exceptionSuperclassString = exceptionSuperclass;
}
setAttributes("paraName", ProcessorUtil.mangleNameToVariableName(jf.getName()));
}
ClassCollector collector = penv.get(ClassCollector.class);
for (String pkg : collector.getTypesPackages()) {
if (collector.containTypesClass(pkg, simpleName)) {
exceptionSuperclassString = exceptionSuperclass;
}
}
if (expClz.getName().equals(exceptionSuperclassString)) {
exceptionSuperclassString = exceptionSuperclass;
}
setAttributes("exceptionSuperclass", exceptionSuperclassString);
if (!exceptionSuperclass.startsWith("java.lang.") && !exceptionSuperclassString.equals(exceptionSuperclass)) {
expClz.addImport(exceptionSuperclass);
}
setCommonAttributes();
doWrite(FAULT_TEMPLATE, parseOutputName(expClz.getPackageName(), expClz.getName()));
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class ParameterProcessor method processWrappedAbstractOutput.
private void processWrappedAbstractOutput(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
if (messagePartsNotUnique(inputMessage) || messagePartsNotUnique(outputMessage)) {
processOutput(method, inputMessage, outputMessage);
return;
}
if (outputMessage.getMessagePartsNumber() == 0) {
addVoidReturn(method);
return;
}
MessagePartInfo inputPart = inputMessage.getMessagePartsNumber() > 0 ? inputMessage.getFirstMessagePart() : null;
MessagePartInfo outputPart = outputMessage.getMessagePartsNumber() > 0 ? outputMessage.getFirstMessagePart() : null;
List<QName> inputWrapElement = null;
List<QName> outputWrapElement = null;
if (inputPart != null) {
inputWrapElement = ProcessorUtil.getWrappedElementQNames(context, inputPart.getElementQName());
}
if (outputPart != null) {
outputWrapElement = ProcessorUtil.getWrappedElementQNames(context, outputPart.getElementQName());
}
if (inputWrapElement == null || outputWrapElement.isEmpty()) {
addVoidReturn(method);
return;
}
method.setReturn(null);
boolean qualified = ProcessorUtil.isSchemaFormQualified(context, outputPart.getElementQName());
if (outputWrapElement.size() == 1) {
QName outElement = outputWrapElement.iterator().next();
boolean sameWrapperChild = false;
for (QName inElement : inputWrapElement) {
if (isSameWrapperChild(inElement, outElement)) {
JavaParameter jpIn = null;
for (JavaParameter j : method.getParameters()) {
if (inElement.equals(j.getQName())) {
jpIn = j;
}
}
JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.INOUT, outputPart);
if (!qualified && !isRefElement(outputPart, outElement)) {
jp.setTargetNamespace("");
}
if (jpIn != null && !jpIn.getClassName().equals(jp.getClassName())) {
jp.setStyle(JavaType.Style.OUT);
}
addParameter(outputPart, method, jp);
sameWrapperChild = true;
if (method.getReturn() == null) {
addVoidReturn(method);
}
break;
}
}
if (!sameWrapperChild) {
JavaReturn jreturn = getReturnFromQName(outElement, outputPart);
if (!qualified && !this.isRefElement(outputPart, outElement)) {
jreturn.setTargetNamespace("");
}
method.setReturn(jreturn);
}
return;
}
for (QName outElement : outputWrapElement) {
if ("return".equals(outElement.getLocalPart())) {
if (method.getReturn() != null) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("WRAPPER_STYLE_TWO_RETURN_TYPES", LOG);
throw new ToolException(msg);
}
JavaReturn jreturn = getReturnFromQName(outElement, outputPart);
if (!qualified) {
jreturn.setTargetNamespace("");
}
method.setReturn(jreturn);
continue;
}
boolean sameWrapperChild = false;
if (inputWrapElement != null) {
for (QName inElement : inputWrapElement) {
if (isSameWrapperChild(inElement, outElement)) {
JavaParameter jpIn = null;
for (JavaParameter j : method.getParameters()) {
if (inElement.equals(j.getQName())) {
jpIn = j;
}
}
JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.INOUT, outputPart);
if (!qualified && !isRefElement(outputPart, outElement)) {
jp.setTargetNamespace("");
}
if (jpIn != null && !jpIn.getClassName().equals(jp.getClassName())) {
jp.setStyle(JavaType.Style.OUT);
checkPartName(outputMessage, outElement, jp);
}
addParameter(outputPart, method, jp);
sameWrapperChild = true;
break;
}
}
}
if (!sameWrapperChild) {
JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.OUT, outputPart);
if (!qualified && !isRefElement(outputPart, outElement)) {
jp.setTargetNamespace("");
}
checkPartName(outputMessage, outElement, jp);
addParameter(outputPart, method, jp);
}
}
if (method.getReturn() == null) {
addVoidReturn(method);
}
}
Aggregations