use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JAXWSBindingParser method queryXPathNode.
private Node queryXPathNode(Node target, String expression) {
NodeList nlst;
try {
ContextImpl contextImpl = new ContextImpl(target);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(contextImpl);
nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
Message msg = new Message("XPATH_ERROR", LOG, new Object[] { expression });
throw new ToolException(msg, e);
}
if (nlst.getLength() != 1) {
Message msg = new Message("ERROR_TARGETNODE_WITH_XPATH", LOG, new Object[] { expression });
throw new ToolException(msg);
}
Node rnode = nlst.item(0);
if (!(rnode instanceof Element)) {
return null;
}
return rnode;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class HandlerConfigGenerator method generateHandlerChainFile.
private void generateHandlerChainFile(Element hChains, Writer writer) throws ToolException {
try {
StaxUtils.writeTo(hChains, writer, 2);
writer.close();
} catch (Exception ex) {
throw new ToolException(ex);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class OperationProcessor method processMethod.
void processMethod(JavaMethod method, OperationInfo operation) throws ToolException {
if (isAsyncMethod(method)) {
return;
}
MessageInfo inputMessage = operation.getInput();
MessageInfo outputMessage = operation.getOutput();
if (inputMessage == null) {
LOG.log(Level.WARNING, "NO_INPUT_MESSAGE", new Object[] { operation.getName() });
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("INVALID_MEP", LOG, new Object[] { operation.getName() });
throw new ToolException(msg);
}
ParameterProcessor paramProcessor = new ParameterProcessor(context);
method.clear();
JAXWSBinding opBinding = operation.getExtensor(JAXWSBinding.class);
JAXWSBinding ptBinding = operation.getInterface().getExtensor(JAXWSBinding.class);
JAXWSBinding defBinding = operation.getInterface().getService().getDescription().getExtensor(JAXWSBinding.class);
boolean enableAsync = false;
boolean enableMime = false;
boolean enableWrapper = method.isWrapperStyle();
if (defBinding != null) {
if (defBinding.isSetEnableMime()) {
enableMime = defBinding.isEnableMime();
}
if (defBinding.isSetEnableAsyncMapping()) {
enableAsync = defBinding.isEnableAsyncMapping();
}
if (defBinding.isSetEnableWrapperStyle()) {
enableWrapper = defBinding.isEnableWrapperStyle();
}
}
if (ptBinding != null) {
if (ptBinding.isSetEnableMime()) {
enableMime = ptBinding.isEnableMime();
}
if (ptBinding.isSetEnableAsyncMapping()) {
enableAsync = ptBinding.isEnableAsyncMapping();
}
if (ptBinding.isSetEnableWrapperStyle()) {
enableWrapper = ptBinding.isEnableWrapperStyle();
}
}
if (opBinding != null) {
if (opBinding.isSetEnableMime()) {
enableMime = opBinding.isEnableMime();
}
if (opBinding.isSetEnableAsyncMapping()) {
enableAsync = opBinding.isEnableAsyncMapping();
}
if (opBinding.isSetEnableWrapperStyle()) {
enableWrapper = opBinding.isEnableWrapperStyle();
}
}
enableWrapper = checkEnableWrapper(enableWrapper, method);
enableAsync = checkEnableAsync(enableAsync, method);
enableMime = checkEnableMime(enableMime, method);
method.setWrapperStyle(enableWrapper && method.isWrapperStyle());
paramProcessor.process(method, inputMessage, outputMessage, operation.getParameterOrdering());
if (method.isWrapperStyle()) {
setWrapper(operation);
method.annotate(new WrapperAnnotator(wrapperRequest, wrapperResponse));
}
method.annotate(new WebMethodAnnotator());
method.annotate(new WebResultAnnotator());
if (!method.isOneWay() && enableAsync && !isAddedAsycMethod(method)) {
addAsyncMethod(method);
}
if (enableMime) {
method.setMimeEnable(true);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class ParameterProcessor method processInput.
private void processInput(JavaMethod method, MessageInfo inputMessage) throws ToolException {
if (requireOutOfBandHeader()) {
try {
Class.forName("org.apache.cxf.binding.soap.SoapBindingFactory");
} catch (Exception e) {
LOG.log(Level.WARNING, new Message("SOAP_MISSING", LOG).toString());
}
}
JAXWSBinding mBinding = inputMessage.getOperation().getExtensor(JAXWSBinding.class);
for (MessagePartInfo part : inputMessage.getMessageParts()) {
if (isOutOfBandHeader(part) && !requireOutOfBandHeader()) {
continue;
}
JavaParameter param = getParameterFromPart(method, part, JavaType.Style.IN);
if (mBinding != null && mBinding.getJaxwsParas() != null) {
for (JAXWSParameter jwp : mBinding.getJaxwsParas()) {
if (part.getName().getLocalPart().equals(jwp.getPart())) {
param.setName(jwp.getName());
}
}
}
addParameter(part, method, param);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class PortTypeProcessor method getInterface.
public static JavaInterface getInterface(ToolContext context, ServiceInfo serviceInfo, InterfaceInfo interfaceInfo) throws ToolException {
JavaInterface intf = interfaceInfo.getProperty("JavaInterface", JavaInterface.class);
if (intf == null) {
intf = new InterfaceMapper(context).map(interfaceInfo);
JAXWSBinding jaxwsBinding = null;
if (serviceInfo.getDescription() != null) {
jaxwsBinding = serviceInfo.getDescription().getExtensor(JAXWSBinding.class);
}
JAXWSBinding infBinding = interfaceInfo.getExtensor(JAXWSBinding.class);
if (infBinding != null && infBinding.getPackage() != null) {
intf.setPackageName(infBinding.getPackage());
} else if (jaxwsBinding != null && jaxwsBinding.getPackage() != null) {
intf.setPackageName(jaxwsBinding.getPackage());
}
if (infBinding != null && !infBinding.getPackageJavaDoc().equals("")) {
intf.setPackageJavaDoc(infBinding.getPackageJavaDoc());
} else if (jaxwsBinding != null && !jaxwsBinding.getPackageJavaDoc().equals("")) {
intf.setPackageJavaDoc(jaxwsBinding.getPackageJavaDoc());
}
String name = intf.getName();
if (infBinding != null && infBinding.getJaxwsClass() != null && infBinding.getJaxwsClass().getClassName() != null) {
name = infBinding.getJaxwsClass().getClassName();
if (name.contains(".")) {
intf.setPackageName(name.substring(0, name.lastIndexOf('.')));
name = name.substring(name.lastIndexOf('.') + 1);
}
intf.setClassJavaDoc(infBinding.getJaxwsClass().getComments());
}
if (StringUtils.isEmpty(intf.getClassJavaDoc())) {
intf.setClassJavaDoc(interfaceInfo.getDocumentation());
}
ClassCollector collector = context.get(ClassCollector.class);
if (context.optionSet(ToolConstants.CFG_AUTORESOLVE)) {
int count = 0;
String checkName = name;
while (collector.isReserved(intf.getPackageName(), checkName)) {
checkName = name + "_" + (++count);
}
name = checkName;
} else if (collector.isReserved(intf.getPackageName(), name)) {
throw new ToolException("RESERVED_SEI_NAME", LOG, name);
}
interfaceInfo.setProperty("InterfaceName", name);
intf.setName(name);
collector.addSeiClassName(intf.getPackageName(), intf.getName(), intf.getPackageName() + "." + intf.getName());
interfaceInfo.setProperty("JavaInterface", intf);
if (context.containsKey(ToolConstants.CFG_SEI_SUPER)) {
String[] supers = context.getArray(ToolConstants.CFG_SEI_SUPER);
for (String s : supers) {
intf.addSuperInterface(s);
}
}
}
return intf;
}
Aggregations