use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class ServiceProcessor method processOperation.
private void processOperation(JavaModel model, BindingOperationInfo bop, BindingInfo binding) throws ToolException {
boolean enableOpMime = false;
JAXWSBinding bind = binding.getExtensor(JAXWSBinding.class);
if (bind != null && bind.isEnableMime()) {
enableOpMime = true;
}
JAXWSBinding bopBinding = bop.getExtensor(JAXWSBinding.class);
if (bopBinding != null && bopBinding.isEnableMime()) {
enableOpMime = true;
if (bopBinding.getJaxwsParas() != null) {
jaxwsBinding.setJaxwsParas(bopBinding.getJaxwsParas());
}
}
JavaInterface jf = null;
for (JavaInterface jf2 : model.getInterfaces().values()) {
if (binding.getInterface().getName().getLocalPart().equals(jf2.getWebServiceName())) {
jf = jf2;
}
}
if (jf == null) {
throw new ToolException("No Java Interface available");
}
if (isSoapBinding()) {
SoapBinding soapBinding = (SoapBinding) bindingObj;
if (SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()) == null) {
jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
} else {
jf.setSOAPStyle(SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()));
}
} else {
// REVISIT: fix for xml binding
jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
}
Object[] methods = jf.getMethods().toArray();
for (int i = 0; i < methods.length; i++) {
JavaMethod jm = (JavaMethod) methods[i];
if (jm.getOperationName() != null && jm.getOperationName().equals(bop.getName().getLocalPart())) {
if (isSoapBinding()) {
// TODO: add customize here
// doCustomizeOperation(jf, jm, bop);
Map<String, Object> prop = getSoapOperationProp(bop);
String soapAction = prop.get(soapOPAction) == null ? "" : (String) prop.get(soapOPAction);
String soapStyle = prop.get(soapOPStyle) == null ? "" : (String) prop.get(soapOPStyle);
jm.setSoapAction(soapAction);
if (SOAPBindingUtil.getSoapStyle(soapStyle) == null && this.bindingObj == null) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_STYLE_NOT_DEFINED", LOG);
throw new ToolException(msg);
}
if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
jm.setSoapStyle(jf.getSOAPStyle());
} else {
jm.setSoapStyle(SOAPBindingUtil.getSoapStyle(soapStyle));
}
} else {
// REVISIT: fix for xml binding
jm.setSoapStyle(jf.getSOAPStyle());
}
if (jm.getSoapStyle().equals(javax.jws.soap.SOAPBinding.Style.RPC)) {
jm.getAnnotationMap().remove("SOAPBinding");
}
OperationProcessor processor = new OperationProcessor(context);
int headerType = isNonWrappable(bop);
OperationInfo opinfo = bop.getOperationInfo();
JAXWSBinding opBinding = opinfo.getExtensor(JAXWSBinding.class);
JAXWSBinding infBinding = opinfo.getInterface().getExtensor(JAXWSBinding.class);
boolean enableMime = enableOpMime;
boolean enableWrapperStyle = true;
if (infBinding != null && infBinding.isSetEnableWrapperStyle()) {
enableWrapperStyle = infBinding.isEnableWrapperStyle();
}
if (infBinding != null && infBinding.isSetEnableMime()) {
enableMime = infBinding.isEnableMime();
}
if (opBinding != null && opBinding.isSetEnableWrapperStyle()) {
enableWrapperStyle = opBinding.isEnableWrapperStyle();
}
if (opBinding != null && opBinding.isSetEnableMime()) {
enableMime = opBinding.isEnableMime();
}
if (jaxwsBinding.isEnableMime() || enableMime) {
jm.setMimeEnable(true);
}
if ((jm.isWrapperStyle() && headerType > this.noHEADER) || !jaxwsBinding.isEnableWrapperStyle() || (jm.enableMime() && jm.isWrapperStyle()) || !enableWrapperStyle) {
// changed wrapper style
jm.setWrapperStyle(false);
processor.processMethod(jm, bop.getOperationInfo());
jm.getAnnotationMap().remove("ResponseWrapper");
jm.getAnnotationMap().remove("RequestWrapper");
} else {
processor.processMethod(jm, bop.getOperationInfo());
}
if (headerType == this.resultHeader) {
JAnnotation resultAnno = jm.getAnnotationMap().get("WebResult");
if (resultAnno != null) {
resultAnno.addElement(new JAnnotationElement("header", true, true));
}
}
processParameter(jm, bop);
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class ServiceProcessor method processBindings.
private void processBindings(JavaModel model) {
for (BindingInfo binding : service.getBindings()) {
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);
}
Collection<BindingOperationInfo> operations = binding.getOperations();
for (BindingOperationInfo bop : operations) {
processOperation(model, bop, binding);
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class SchemaResourceResolver method validate.
public boolean validate(String wsdlsource, String[] schemas) throws ToolException {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
docFactory.setNamespaceAware(true);
docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
docBuilder = docFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new ToolException(e);
}
String systemId = null;
systemId = URIParserUtil.getAbsoluteURI(wsdlsource);
InputSource is = new InputSource(systemId);
return validate(is, schemas);
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class SchemaResourceResolver method validate.
public boolean validate(InputSource wsdlsource, String[] schemas) throws ToolException {
boolean isValid = false;
Schema schema;
try {
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setFeature("http://xml.org/sax/features/namespaces", true);
saxFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
saxParser = saxFactory.newSAXParser();
if (defaultSchemas != null) {
schemas = addSchemas(defaultSchemas, schemas);
schema = createSchema(schemas);
} else {
schema = createSchema(schemaFromJar, schemas);
}
Validator validator = schema.newValidator();
NewStackTraceErrorHandler errHandler = new NewStackTraceErrorHandler();
validator.setErrorHandler(errHandler);
SAXSource saxSource = new SAXSource(saxParser.getXMLReader(), wsdlsource);
validator.validate(saxSource);
if (!errHandler.isValid()) {
throw new ToolException(errHandler.getErrorMessages());
}
isValid = true;
} catch (IOException ioe) {
throw new ToolException("Cannot get the wsdl " + wsdlsource.getSystemId(), ioe);
} catch (SAXException saxEx) {
throw new ToolException(saxEx);
} catch (ParserConfigurationException e) {
throw new ToolException(e);
}
return isValid;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class SchemaResourceResolver method getDefaultSchemas.
private String[] getDefaultSchemas() throws ToolException {
String loc = schemaLocation;
if (loc == null || "".equals(loc.trim())) {
loc = "./";
}
File f = new File(loc);
if (f.exists() && f.isDirectory()) {
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.toLowerCase().endsWith(".xsd") && !new File(dir.getPath() + File.separator + name).isDirectory()) {
return true;
}
return false;
}
};
File[] files = f.listFiles(filter);
if (files != null) {
List<String> xsdUrls = new ArrayList<>(files.length);
for (File file : files) {
try {
String s = file.toURI().toURL().toString();
xsdUrls.add(s);
if (s.contains("http-conf")) {
xsdUrls.add(0, s);
}
} catch (MalformedURLException e) {
throw new ToolException(e);
}
}
return xsdUrls.toArray(new String[xsdUrls.size()]);
}
}
return null;
}
Aggregations