use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.
the class SoapBindingFactory method createSoapBinding.
private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
Bus bs = getBus();
WSDLManager m = bs.getExtension(WSDLManager.class);
ExtensionRegistry extensionRegistry = m.getExtensionRegistry();
SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
soapBinding.setStyle(bi.getStyle());
soapBinding.setTransportURI(bi.getTransportURI());
bi.addExtensor(soapBinding);
for (BindingOperationInfo b : bi.getOperations()) {
for (BindingFaultInfo faultInfo : b.getFaults()) {
SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
soapFault.setUse("literal");
soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
faultInfo.addExtensor(soapFault);
}
SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);
SoapOperation soapOperation = SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
soapOperation.setSoapActionURI(soi.getAction());
soapOperation.setStyle(soi.getStyle());
boolean isRpc = "rpc".equals(soapOperation.getStyle());
b.addExtensor(soapOperation);
if (b.getInput() != null) {
List<String> bodyParts = null;
List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
if (headerInfos != null && !headerInfos.isEmpty()) {
bodyParts = new ArrayList<>();
for (MessagePartInfo part : b.getInput().getMessageParts()) {
bodyParts.add(part.getName().getLocalPart());
}
for (SoapHeaderInfo headerInfo : headerInfos) {
SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
soapHeader.setMessage(b.getInput().getMessageInfo().getName());
soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
soapHeader.setUse("literal");
bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
headerInfo.getPart().setProperty(HEADER, true);
b.getInput().addExtensor(soapHeader);
}
}
SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
body.setUse("literal");
if (isRpc) {
body.setNamespaceURI(b.getName().getNamespaceURI());
}
if (bodyParts != null) {
body.setParts(bodyParts);
}
b.getInput().addExtensor(body);
}
if (b.getOutput() != null) {
List<String> bodyParts = null;
List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
if (headerInfos != null && !headerInfos.isEmpty()) {
bodyParts = new ArrayList<>();
for (MessagePartInfo part : b.getOutput().getMessageParts()) {
bodyParts.add(part.getName().getLocalPart());
}
for (SoapHeaderInfo headerInfo : headerInfos) {
SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
soapHeader.setUse("literal");
bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
b.getOutput().addExtensor(soapHeader);
}
}
SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
body.setUse("literal");
if (isRpc) {
body.setNamespaceURI(b.getName().getNamespaceURI());
}
if (bodyParts != null) {
body.setParts(bodyParts);
}
b.getOutput().addExtensor(body);
}
}
}
use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.
the class SoapBindingFactory method createBindingInfo.
public BindingInfo createBindingInfo(ServiceInfo service, javax.wsdl.Binding binding, String ns) {
SoapBindingInfo bi = new SoapBindingInfo(service, ns);
// Copy all the extensors
initializeBindingInfo(service, binding, bi);
SoapBinding wSoapBinding = SOAPBindingUtil.getSoapBinding(bi.getExtensors(ExtensibilityElement.class));
bi.setTransportURI(wSoapBinding.getTransportURI());
bi.setStyle(wSoapBinding.getStyle());
for (BindingOperationInfo boi : bi.getOperations()) {
initializeBindingOperation(bi, boi);
}
return bi;
}
use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.
the class ServiceImpl method initializePorts.
private void initializePorts() {
try {
Definition def = bus.getExtension(WSDLManager.class).getDefinition(wsdlURL);
javax.wsdl.Service serv = def.getService(serviceName);
if (serv == null) {
throw new WebServiceException("Could not find service named " + serviceName + " in wsdl " + wsdlURL);
}
Map<String, Port> wsdlports = CastUtils.cast(serv.getPorts());
for (Port port : wsdlports.values()) {
QName name = new QName(serviceName.getNamespaceURI(), port.getName());
String address = null;
String bindingID = null;
List<? extends ExtensibilityElement> extensions = CastUtils.cast(port.getBinding().getExtensibilityElements());
if (!extensions.isEmpty()) {
ExtensibilityElement e = extensions.get(0);
if (e instanceof SoapBinding) {
bindingID = SOAPBinding.SOAP11HTTP_BINDING;
} else if (e instanceof SOAP12Binding) {
bindingID = SOAPBinding.SOAP12HTTP_BINDING;
} else if (e instanceof javax.wsdl.extensions.soap.SOAPBinding) {
bindingID = SOAPBinding.SOAP11HTTP_BINDING;
}
}
extensions = CastUtils.cast(port.getExtensibilityElements());
if (!extensions.isEmpty()) {
ExtensibilityElement e = extensions.get(0);
if (e instanceof SoapAddress) {
address = ((SoapAddress) e).getLocationURI();
} else if (e instanceof AddressType) {
address = ((AddressType) e).getLocation();
} else if (e instanceof SOAP12Address) {
address = ((SOAP12Address) e).getLocationURI();
} else if (e instanceof SOAPAddress) {
address = ((SOAPAddress) e).getLocationURI();
} else if (e instanceof HTTPAddress) {
address = ((HTTPAddress) e).getLocationURI();
}
}
addPort(name, bindingID, address);
}
} catch (WebServiceException e) {
throw e;
} catch (Throwable e) {
if (e instanceof UncheckedException && LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, e.getLocalizedMessage(), e);
}
WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
Service service = sf.create();
for (ServiceInfo si : service.getServiceInfos()) {
for (EndpointInfo ei : si.getEndpoints()) {
String bindingID = BindingID.getJaxwsBindingID(ei.getTransportId());
addPort(ei.getName(), bindingID, ei.getAddress());
}
}
}
}
use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding 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.binding.soap.wsdl.extensions.SoapBinding in project cxf by apache.
the class WSDLToSoapProcessor method setSoapBindingExtElement.
private void setSoapBindingExtElement() throws ToolException {
if (extReg == null) {
extReg = wsdlFactory.newPopulatedExtensionRegistry();
}
SOAPBindingUtil.addSOAPNamespace(wsdlDefinition, isSOAP12());
SoapBinding soapBinding = null;
try {
soapBinding = SOAPBindingUtil.createSoapBinding(extReg, isSOAP12());
} catch (WSDLException wse) {
Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
throw new ToolException(msg, wse);
}
soapBinding.setStyle((String) env.get(ToolConstants.CFG_STYLE));
binding.addExtensibilityElement(soapBinding);
}
Aggregations