use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getParameters.
/**
* Returns parameters, given http binding operation, verb and content type
*
* @param bindingOperation {@link BindingOperation} object
* @param verb HTTP verb
* @param contentType Content type
* @return parameters, given http binding operation, verb and content type
*/
private List<WSDLOperationParam> getParameters(BindingOperation bindingOperation, String verb, String contentType) {
List<WSDLOperationParam> params = new ArrayList<>();
Operation operation = bindingOperation.getOperation();
// or content type is not provided
if (APIMWSDLUtils.canContainBody(verb) && !APIMWSDLUtils.hasFormDataParams(contentType)) {
WSDLOperationParam param = new WSDLOperationParam();
param.setName("Payload");
param.setParamType(WSDLOperationParam.ParamTypeEnum.BODY);
params.add(param);
if (log.isDebugEnabled()) {
log.debug("Adding default Param for operation:" + operation.getName() + ", contentType: " + contentType);
}
return params;
}
if (operation != null) {
Input input = operation.getInput();
if (input != null) {
Message message = input.getMessage();
if (message != null) {
Map map = message.getParts();
map.forEach((name, partObj) -> {
WSDLOperationParam param = new WSDLOperationParam();
param.setName(name.toString());
if (log.isDebugEnabled()) {
log.debug("Identified param for operation: " + operation.getName() + " param: " + name);
}
if (APIMWSDLUtils.canContainBody(verb)) {
if (log.isDebugEnabled()) {
log.debug("Operation " + operation.getName() + " can contain a body.");
}
// In POST, PUT operations, parameters always in body according to HTTP Binding spec
if (APIMWSDLUtils.hasFormDataParams(contentType)) {
param.setParamType(WSDLOperationParam.ParamTypeEnum.FORM_DATA);
if (log.isDebugEnabled()) {
log.debug("Param " + name + " type was set to formData.");
}
}
// no else block since if content type is not form-data related, there can be only one
// parameter which is payload body. This is handled in the first if block which is
// if (canContainBody(verb) && !hasFormDataParams(contentType)) { .. }
} else {
// In GET operations, parameters always query or path as per HTTP Binding spec
if (isUrlReplacement(bindingOperation)) {
param.setParamType(WSDLOperationParam.ParamTypeEnum.PATH);
if (log.isDebugEnabled()) {
log.debug("Param " + name + " type was set to Path.");
}
} else {
param.setParamType(WSDLOperationParam.ParamTypeEnum.QUERY);
if (log.isDebugEnabled()) {
log.debug("Param " + name + " type was set to Query.");
}
}
}
Part part = (Part) partObj;
param.setDataType(part.getTypeName().getLocalPart());
if (log.isDebugEnabled()) {
log.debug("Param " + name + " data type was set to " + param.getDataType());
}
params.add(param);
});
}
}
}
return params;
}
use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getOperation.
/**
* Retrieves WSDL operation given the binding operation and http verb
*
* @param bindingOperation {@link BindingOperation} object
* @param verb HTTP verb
* @return WSDL operation for the given binding operation and http verb
*/
private WSDLOperation getOperation(BindingOperation bindingOperation, String verb) {
WSDLOperation wsdlOperation = null;
for (Object boExtElement : bindingOperation.getExtensibilityElements()) {
if (boExtElement instanceof HTTPOperation) {
HTTPOperation httpOperation = (HTTPOperation) boExtElement;
if (!StringUtils.isBlank(httpOperation.getLocationURI())) {
wsdlOperation = new WSDLOperation();
wsdlOperation.setVerb(verb);
wsdlOperation.setURI(APIMWSDLUtils.replaceParentheses(httpOperation.getLocationURI()));
if (log.isDebugEnabled()) {
log.debug("Found HTTP Binding operation; name: " + bindingOperation.getName() + " [" + wsdlOperation.getVerb() + " " + wsdlOperation.getURI() + "]");
}
if (APIMWSDLUtils.canContainBody(verb)) {
String boContentType = getContentType(bindingOperation.getBindingInput());
wsdlOperation.setContentType(boContentType != null ? boContentType : TEXT_XML_MEDIA_TYPE);
}
List<WSDLOperationParam> paramList = getParameters(bindingOperation, verb, wsdlOperation.getContentType());
wsdlOperation.setParameters(paramList);
}
}
}
return wsdlOperation;
}
use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam in project carbon-apimgt by wso2.
the class SOAPOperationBindingUtils method populateSoapOperationParameters.
/**
* gets parameters from the soap operation and populates them in {@link WSDLSOAPOperation}
*
* @param soapOperations soap binding operations
*/
private static void populateSoapOperationParameters(Set<WSDLSOAPOperation> soapOperations) {
String[] primitiveTypes = { "string", "byte", "short", "int", "long", "float", "double", "boolean" };
List primitiveTypeList = Arrays.asList(primitiveTypes);
if (soapOperations != null) {
for (WSDLSOAPOperation operation : soapOperations) {
String resourcePath;
String operationName = operation.getName();
operation.setSoapBindingOpName(operationName);
operation.setHttpVerb(HTTPConstants.HTTP_METHOD_POST);
if (operationName.toLowerCase().startsWith("get") && operation.getInputParameterModel() != null && operation.getInputParameterModel().size() <= 1) {
Map<String, Property> properties = null;
if (operation.getInputParameterModel().size() > 0 && operation.getInputParameterModel().get(0) != null) {
properties = operation.getInputParameterModel().get(0).getProperties();
}
if (properties == null) {
operation.setHttpVerb(HTTPConstants.HTTP_METHOD_GET);
} else if (properties.size() <= 1) {
for (String property : properties.keySet()) {
String type = properties.get(property).getType();
if (!(type.equals(ObjectProperty.TYPE) || type.equals(ArrayProperty.TYPE) || type.equals(RefProperty.TYPE))) {
operation.setHttpVerb(HTTPConstants.HTTP_METHOD_GET);
}
}
}
}
resourcePath = operationName;
resourcePath = resourcePath.substring(0, 1).toLowerCase() + resourcePath.substring(1, resourcePath.length());
operation.setName(resourcePath);
if (log.isDebugEnabled()) {
log.debug("REST resource path for SOAP operation: " + operationName + " is: " + resourcePath);
}
List<WSDLOperationParam> params = operation.getParameters();
if (log.isDebugEnabled() && params != null) {
log.debug("SOAP operation: " + operationName + " has " + params.size() + " parameters");
}
if (params != null) {
for (WSDLOperationParam param : params) {
if (param.getDataType() != null) {
String dataTypeWithNS = param.getDataType();
String dataType = dataTypeWithNS.substring(dataTypeWithNS.indexOf(":") + 1);
param.setDataType(dataType);
if (!primitiveTypeList.contains(dataType)) {
param.setComplexType(true);
}
}
}
}
}
} else {
log.info("No SOAP operations found in the WSDL");
}
}
Aggregations