diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index b7163ad016..0000000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,9 +0,0 @@ -blank_issues_enabled: false -contact_links: -- name: '📚 Create an Issue' - about: Create an issue if something does not work as expected or suggest new functionality/improvements to the product suite. - url: https://github.com/wso2/api-manager/issues/new/choose -- name: '💬 Slack Channel' - url: 'https://apim-slack.wso2.com/' - about: | - Chat with the community to get quick clarifications for your questions. diff --git a/README.md b/README.md index 1a1e8468f0..7e5dafcbb3 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Please follow the steps below to build WSO2 Micro Integrator from the source cod 2. Run the maven command `mvn clean install` from the root directory of the repository. 3. The generated Micro Integrator distribution can be found at `micro-integrator/distribution/target/wso2mi-.zip`. -Please note that the product can be build using only JDK 8 but the integration tests can be run in either JDK 8 or 11. +Please note that the product can be build using only JDK 11 but the integration tests can be run in either JDK 11 or 17. #### Building the Docker image diff --git a/components/data/data-services/org.wso2.micro.integrator.dataservices.common/src/main/java/org/wso2/micro/integrator/dataservices/common/DBConstants.java b/components/data/data-services/org.wso2.micro.integrator.dataservices.common/src/main/java/org/wso2/micro/integrator/dataservices/common/DBConstants.java index 0e3b0089a1..343ede65a1 100644 --- a/components/data/data-services/org.wso2.micro.integrator.dataservices.common/src/main/java/org/wso2/micro/integrator/dataservices/common/DBConstants.java +++ b/components/data/data-services/org.wso2.micro.integrator.dataservices.common/src/main/java/org/wso2/micro/integrator/dataservices/common/DBConstants.java @@ -673,6 +673,8 @@ private MongoDB() { public static final String CONNECT_TIMEOUT = "mongoDB_connectTimeout"; public static final String MAX_WAIT_TIME = "mongoDB_maxWaitTime"; public static final String SOCKET_TIMEOUT = "mongoDB_socketTimeout"; + public static final String SSL_ENABLED = "mongoDB_ssl_enabled"; + public static final String AUTH_SOURCE = "mongoDB_auth_source"; public static final String CONNECTIONS_PER_HOST = "mongoDB_connectionsPerHost"; public static final String THREADS_ALLOWED_TO_BLOCK_CONN_MULTIPLIER = "mongoDB_threadsAllowedToBlockForConnectionMultiplier"; public static final String RESULT_COLUMN_NAME = "Document"; diff --git a/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/DataServiceFault.java b/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/DataServiceFault.java index b3dd5318f0..762ad951dd 100644 --- a/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/DataServiceFault.java +++ b/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/DataServiceFault.java @@ -18,6 +18,7 @@ package org.wso2.micro.integrator.dataservices.core; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -70,7 +71,7 @@ public class DataServiceFault extends Exception { /** * This map contains all the properties related to data services fault message */ - private Map propertyMap = new HashMap(); + private Map propertyMap = new LinkedHashMap<>(); public DataServiceFault(Throwable nestedException, String code, String dsFaultMessage) { super(nestedException); @@ -103,9 +104,11 @@ public static OMElement extractFaultMessage(Throwable throwable) { keyElement.addChild(dataServiceKeyElement); } } else { - OMText valueElement = fac.createOMText( - keyElement, rootEntry.getValue().toString()); - keyElement.addChild(valueElement); + if (rootEntry.getValue() != null) { + OMText valueElement = fac.createOMText( + keyElement, rootEntry.getValue().toString()); + keyElement.addChild(valueElement); + } } root.addChild(keyElement); } @@ -173,40 +176,54 @@ public String getMessage() { /** * Returns a detailed description of the data service fault. */ - public String getFullMessage() { - StringBuffer buff = new StringBuffer(); - if (this.getDsFaultMessage() != null) { - buff.append("DS Fault Message: " + this.getDsFaultMessage() + "\n"); - } - if (this.getCode() != null) { - buff.append("DS Code: " + this.getCode() + "\n"); - getPropertyMap().put(DBConstants.FaultParams.DS_CODE, this.getCode()); - } - if (this.getSourceDataService() != null) { - buff.append("Source Data Service:-\n"); - buff.append(this.getSourceDataService().toString()); - Map sourcePropertyMap = new HashMap(); - sourcePropertyMap.put(DBConstants.FaultParams.DATA_SERVICE_NAME, this.getSourceDataService().getName()); + public String getFullMessage() { + StringBuffer buff = new StringBuffer(); + if (this.getDsFaultMessage() != null) { + buff.append("DS Fault Message: " + this.getDsFaultMessage() + "\n"); + } + // if skipCurrentParams is not set to true, we don't have current params in WSDL + // so no need to add a null value + if (!("true".equalsIgnoreCase(DBUtils.getCurrentParamsDisabledProperty()))) { + if (this.getCurrentParams() != null) { + buff.append("Current Params: " + this.getCurrentParams() + "\n"); + getPropertyMap().put(DBConstants.FaultParams.CURRENT_PARAMS, this.getCurrentParams().toString()); + } else { + getPropertyMap().put(DBConstants.FaultParams.CURRENT_PARAMS, null); + } + } + if (this.getCurrentRequestName() != null) { + buff.append("Current Request Name: " + this.getCurrentRequestName() + "\n"); + getPropertyMap().put(DBConstants.FaultParams.CURRENT_REQUEST_NAME, this.getCurrentRequestName()); + } else { + getPropertyMap().put(DBConstants.FaultParams.CURRENT_REQUEST_NAME, null); + } + if (this.getCause() != null) { + buff.append("Nested Exception:-\n" + this.getCause() + "\n"); + getPropertyMap().put(DBConstants.FaultParams.NESTED_EXCEPTION, this.getCause().toString()); + } else { + getPropertyMap().put(DBConstants.FaultParams.NESTED_EXCEPTION, null); + } + if (this.getSourceDataService() != null) { + buff.append("Source Data Service:-\n"); + buff.append(this.getSourceDataService().toString()); + Map sourcePropertyMap = new LinkedHashMap<>(); sourcePropertyMap.put(DBConstants.FaultParams.LOCATION, this.getSourceDataService().getRelativeDsLocation()); + sourcePropertyMap.put(DBConstants.FaultParams.DEFAULT_NAMESPACE, this.getSourceDataService().getDefaultNamespace()); sourcePropertyMap.put(DBConstants.FaultParams.DESCRIPTION, this.getSourceDataService().getDescription() != null ? this.getSourceDataService().getDescription() : "N/A"); - sourcePropertyMap.put(DBConstants.FaultParams.DEFAULT_NAMESPACE, this.getSourceDataService().getDefaultNamespace()); + sourcePropertyMap.put(DBConstants.FaultParams.DATA_SERVICE_NAME, this.getSourceDataService().getName()); getPropertyMap().put(DBConstants.FaultParams.SOURCE_DATA_SERVICE, sourcePropertyMap); - } - if (this.getCurrentRequestName() != null) { - buff.append("Current Request Name: " + this.getCurrentRequestName() + "\n"); - getPropertyMap().put(DBConstants.FaultParams.CURRENT_REQUEST_NAME, this.getCurrentRequestName()); - } - if (this.getCurrentParams() != null && !("true".equalsIgnoreCase(DBUtils.getCurrentParamsDisabledProperty()))) { - buff.append("Current Params: " + this.getCurrentParams() + "\n"); - getPropertyMap().put(DBConstants.FaultParams.CURRENT_PARAMS, this.getCurrentParams().toString()); - } - if (this.getCause() != null) { - buff.append("Nested Exception:-\n" + this.getCause() + "\n"); - getPropertyMap().put(DBConstants.FaultParams.NESTED_EXCEPTION, this.getCause().toString()); - } - return buff.toString(); - } + } else { + getPropertyMap().put(DBConstants.FaultParams.SOURCE_DATA_SERVICE, null); + } + if (this.getCode() != null) { + buff.append("DS Code: " + this.getCode() + "\n"); + getPropertyMap().put(DBConstants.FaultParams.DS_CODE, this.getCode()); + } else { + getPropertyMap().put(DBConstants.FaultParams.DS_CODE, null); + } + return buff.toString(); + } @Override public String toString() { diff --git a/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/description/config/MongoConfig.java b/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/description/config/MongoConfig.java index a7974b35eb..1999e5b2a5 100644 --- a/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/description/config/MongoConfig.java +++ b/components/data/data-services/org.wso2.micro.integrator.dataservices.core/src/main/java/org/wso2/micro/integrator/dataservices/core/description/config/MongoConfig.java @@ -143,6 +143,11 @@ private MongoClientOptions extractMongoOptions(Map properties) { builder.threadsAllowedToBlockForConnectionMultiplier( Integer.parseInt(threadsAllowedToBlockForConnectionMultiplier)); } + + String sslEnabled = (properties.get(DBConstants.MongoDB.SSL_ENABLED)); + if (Boolean.parseBoolean(sslEnabled)) { + builder.sslEnabled(true); + } return builder.build(); } @@ -169,17 +174,23 @@ private MongoCredential createCredential(Map properties) throws String authenticationType = properties.get(DBConstants.MongoDB.AUTHENTICATION_TYPE); String username = properties.get(DBConstants.MongoDB.USERNAME); String password = properties.get(DBConstants.MongoDB.PASSWORD); - String database = properties.get(DBConstants.MongoDB.DATABASE); + String authSource = properties.get(DBConstants.MongoDB.AUTH_SOURCE); + if (authSource == null || authSource.isEmpty()) { + // For MONGODB-CR, SCRAM-SHA-1, and SCRAM-SHA-256, PLAIN the default auth source is the database tyring to connect + // refer: https://docs.mongodb.com/ruby-driver/master/reference/authentication/ + // since database is mandatory, we will not address the case where DB is not defined. + authSource = properties.get(DBConstants.MongoDB.DATABASE); + } if (authenticationType != null) { switch (authenticationType) { case DBConstants.MongoDB.MongoAuthenticationTypes.PLAIN: - credential = MongoCredential.createPlainCredential(username, database, password.toCharArray()); + credential = MongoCredential.createPlainCredential(username, authSource, password.toCharArray()); break; case DBConstants.MongoDB.MongoAuthenticationTypes.SCRAM_SHA_1: - credential = MongoCredential.createScramSha1Credential(username, database, password.toCharArray()); + credential = MongoCredential.createScramSha1Credential(username, authSource, password.toCharArray()); break; case DBConstants.MongoDB.MongoAuthenticationTypes.MONGODB_CR: - credential = MongoCredential.createMongoCRCredential(username, database, password.toCharArray()); + credential = MongoCredential.createMongoCRCredential(username, authSource, password.toCharArray()); break; case DBConstants.MongoDB.MongoAuthenticationTypes.GSSAPI: credential = MongoCredential.createGSSAPICredential(username); diff --git a/components/mediation/extensions/org.wso2.micro.integrator.security.handlers/utsecurity/src/org/wso2/micro/integrator/security/pox/POXSecurityHandler.java b/components/mediation/extensions/org.wso2.micro.integrator.security.handlers/utsecurity/src/org/wso2/micro/integrator/security/pox/POXSecurityHandler.java index 3f50b1e4f7..dbf414e2ec 100644 --- a/components/mediation/extensions/org.wso2.micro.integrator.security.handlers/utsecurity/src/org/wso2/micro/integrator/security/pox/POXSecurityHandler.java +++ b/components/mediation/extensions/org.wso2.micro.integrator.security.handlers/utsecurity/src/org/wso2/micro/integrator/security/pox/POXSecurityHandler.java @@ -151,7 +151,12 @@ public InvocationResponse invoke(MessageContext msgCtx) throws AxisFault { if (faultCodeObject instanceof SOAP11FaultCodeImpl) { faultCode = ((SOAP11FaultCodeImpl) faultCodeObject).getTextContent(); } else if (faultCodeObject instanceof SOAP12FaultCodeImpl) { - faultCode = ((SOAP12FaultSubCodeImpl) ((SOAP12FaultCodeImpl) faultCodeObject).getSubCode()).getTextContent(); + if (null != ((SOAP12FaultCodeImpl) faultCodeObject).getSubCode()) { + faultCode = ((SOAP12FaultSubCodeImpl) ((SOAP12FaultCodeImpl) faultCodeObject) + .getSubCode()).getTextContent(); + } else { + faultCode = ((SOAP12FaultCodeImpl)faultCodeObject).getTextContent(); + } } if (faultCode != null && faultCode.contains("FailedAuthentication")) { // this is standard error code according to the WS-Sec diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/Constants.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/Constants.java index 8f40854531..3a22eea641 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/Constants.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/Constants.java @@ -42,10 +42,11 @@ public class Constants { public static final String USER_NAME = "username"; public static final String PASSWORD = "password"; public static final String SERVICE_CATALOG_EXECUTOR_THREADS = "executor_threads"; - - public static final String SERVICE_CATALOG_PUBLISH_ENDPOINT = "api/am/service-catalog/v1/services/import?overwrite" + - "=true"; - public static final String SERVICE_CATALOG_GET_SERVICES_ENDPOINT = "api/am/service-catalog/v1/services"; + public static final String SERVICE_CATALOG_API_VERSION_PROPERTY = "service-catalog.api.version"; + public static final String SERVICE_CATALOG_DEFAULT_API_VERSION = "v1"; + public static final String SERVICE_CATALOG_ENDPOINT_PREFIX = "api/am/service-catalog/"; + public static final String SERVICE_CATALOG_PUBLISH_ENDPOINT = "/services/import?overwrite=true"; + public static final String SERVICE_CATALOG_GET_SERVICES_ENDPOINT = "/services"; // creating the payload.zip related constants public static final String SERVICE_CATALOG = "ServiceCatalog"; diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/ServiceCatalogUtils.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/ServiceCatalogUtils.java index 295e8748ab..1a49bb3731 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/ServiceCatalogUtils.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/ServiceCatalogUtils.java @@ -36,7 +36,6 @@ import org.wso2.micro.application.deployer.CarbonApplication; import org.wso2.micro.core.util.CarbonException; import org.wso2.micro.core.util.StringUtils; -import org.wso2.micro.integrator.core.util.MicroIntegratorBaseUtils; import org.wso2.micro.integrator.initializer.deployment.application.deployer.CappDeployer; import org.wso2.securevault.SecretResolver; import org.wso2.securevault.SecretResolverFactory; @@ -83,6 +82,15 @@ public class ServiceCatalogUtils { private static String resolvedUrl; private static String lineSeparator; private static Map parsedConfigs; + private static final String API_VERSION; + + static { + String apiVersion = System.getProperty(SERVICE_CATALOG_API_VERSION_PROPERTY); + if (apiVersion == null) { + apiVersion = SERVICE_CATALOG_DEFAULT_API_VERSION; + } + API_VERSION = apiVersion; + } /** * Update the service url by injecting env variables. @@ -241,11 +249,10 @@ public static Map getAllServices(Map apimConfigs (apimConfigs.get(USER_NAME) + ":" + apimConfigs.get(PASSWORD)).getBytes()); // create get all services url - if (APIMHost.endsWith("/")) { - APIMHost = APIMHost + SERVICE_CATALOG_GET_SERVICES_ENDPOINT; - } else { - APIMHost = APIMHost + "/" + SERVICE_CATALOG_GET_SERVICES_ENDPOINT; + if (!APIMHost.endsWith("/")) { + APIMHost = APIMHost + "/"; } + APIMHost = APIMHost + SERVICE_CATALOG_ENDPOINT_PREFIX + API_VERSION + SERVICE_CATALOG_GET_SERVICES_ENDPOINT; try { HttpsURLConnection connection = (HttpsURLConnection) new URL(APIMHost).openConnection(); @@ -303,11 +310,10 @@ private static int uploadZip(Map apimConfigs, String attachmentF String APIMHost = apimConfigs.get(APIM_HOST); // create POST URL - if (APIMHost.endsWith("/")) { - APIMHost = APIMHost + SERVICE_CATALOG_PUBLISH_ENDPOINT; - } else { - APIMHost = APIMHost + "/" + SERVICE_CATALOG_PUBLISH_ENDPOINT; + if (!APIMHost.endsWith("/")) { + APIMHost = APIMHost + "/"; } + APIMHost = APIMHost + SERVICE_CATALOG_ENDPOINT_PREFIX + API_VERSION + SERVICE_CATALOG_PUBLISH_ENDPOINT; String encodeBytes = Base64.getEncoder().encodeToString( diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java index abefdef5b8..e241d6bbf4 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java @@ -114,7 +114,7 @@ public boolean accept(File dir, String name) { String packageName = retrievePackageName(connectorExtractedPath); // Retrieve connector name - String connectorName = connectorZip.getName().substring(0, connectorZip.getName().indexOf('-')); + String connectorName = connectorZip.getName().substring(0, connectorZip.getName().lastIndexOf('-')); QName qualifiedName = new QName(packageName, connectorName); File importFile = new File(importsDir, qualifiedName.toString() + ".xml"); diff --git a/components/org.wso2.micro.integrator.security/src/main/java/org/wso2/micro/integrator/security/handler/RESTBasicAuthHandler.java b/components/org.wso2.micro.integrator.security/src/main/java/org/wso2/micro/integrator/security/handler/RESTBasicAuthHandler.java index f0da9171e4..e79731607a 100644 --- a/components/org.wso2.micro.integrator.security/src/main/java/org/wso2/micro/integrator/security/handler/RESTBasicAuthHandler.java +++ b/components/org.wso2.micro.integrator.security/src/main/java/org/wso2/micro/integrator/security/handler/RESTBasicAuthHandler.java @@ -104,7 +104,7 @@ public Map getProperties() { public boolean processSecurity(String credentials) { String decodedCredentials = new String(new Base64().decode(credentials.getBytes())); String username = decodedCredentials.split(":")[0]; - String password = decodedCredentials.split(":")[1]; + String password = decodedCredentials.split(":",2)[1]; UserStoreManager userStoreManager; try { userStoreManager = MicroIntegratorSecurityUtils.getUserStoreManager(); diff --git a/distribution/src/resources/config-tool/default.json b/distribution/src/resources/config-tool/default.json index 671c5644ef..44b4780af6 100644 --- a/distribution/src/resources/config-tool/default.json +++ b/distribution/src/resources/config-tool/default.json @@ -680,6 +680,9 @@ "cache_delay": "2" }, - "user_store.base_dn": "dc=wso2,dc=org" + "user_store.base_dn": "dc=wso2,dc=org", + + "transport.jms.sender_class": "org.apache.axis2.transport.jms.JMSSender", + "transport.jms.listener_class": "org.apache.axis2.transport.jms.JMSListener" } diff --git a/distribution/src/resources/config-tool/templates/conf/axis2/axis2.xml.j2 b/distribution/src/resources/config-tool/templates/conf/axis2/axis2.xml.j2 index e849e2b0ec..b25accba9a 100644 --- a/distribution/src/resources/config-tool/templates/conf/axis2/axis2.xml.j2 +++ b/distribution/src/resources/config-tool/templates/conf/axis2/axis2.xml.j2 @@ -290,30 +290,18 @@ {% endfor %} {% endif %} - {% if transport.jms.listener_enable is defined %} - {% if transport.jms.listener_enable and transport.jms.listener|length==0 %} - - {% elif transport.jms.listener_enable %} - - {% for listener in transport.jms.listener %} - - {% for name,value in listener.parameter.items() %} - {{value}} - {% endfor %} - - {% endfor %} - - {% endif %} + {% if transport.jms.listener|length==0 %} + {% elif transport.jms.listener|length>0 %} - + {% for listener in transport.jms.listener %} - + {% for name,value in listener.parameter.items() %} - {{value}} + {{value}} {% endfor %} - + {% endfor %} - + {% endif %} {% if transport.fix.listener.enable == true %} @@ -565,30 +553,18 @@ {% endif %} {% endif %} - {% if transport.jms.sender_enable is defined %} - {% if transport.jms.sender_enable and transport.jms.sender|length==0 %} - - {% elif transport.jms.sender_enable %} - - {% for sender in transport.jms.sender %} - - {% for name,value in sender.parameter.items() %} - {{value}} - {% endfor %} - - {% endfor %} - - {% endif %} + {% if transport.jms.sender|length==0 %} + {% elif transport.jms.sender|length>0 %} - + {% for sender in transport.jms.sender %} - + {% for name,value in sender.parameter.items() %} - {{value}} + {{value}} {% endfor %} - + {% endfor %} - + {% endif %} {% if transport.local.sender.nonblocking.enable == true %} diff --git a/integration/dataservice-hosting-tests/tests-integration/tests/src/test/java/org/wso2/ei/dataservice/integration/test/fault/ErrorMessageVerifyTestCase.java b/integration/dataservice-hosting-tests/tests-integration/tests/src/test/java/org/wso2/ei/dataservice/integration/test/fault/ErrorMessageVerifyTestCase.java new file mode 100644 index 0000000000..3c469160e6 --- /dev/null +++ b/integration/dataservice-hosting-tests/tests-integration/tests/src/test/java/org/wso2/ei/dataservice/integration/test/fault/ErrorMessageVerifyTestCase.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.ei.dataservice.integration.test.fault; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.ei.dataservice.integration.test.DSSIntegrationTest; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +import static org.testng.Assert.assertTrue; + +/** + * Test case to verify the element ordering of a DSS soap fault. + */ +public class ErrorMessageVerifyTestCase extends DSSIntegrationTest { + + @BeforeClass(alwaysRun = true) + public void serviceDeployment() throws Exception { + super.init(); + } + + @AfterClass(alwaysRun = true) + public void destroy() throws Exception { + cleanup(); + } + + @Test(groups = {"wso2.dss"}, description = "Check element ordering of a DSS soap fault") + public void verifyDSSErrorMessageTestCase() throws Exception { + String serviceEndPoint = "http://localhost:8480/services/ResourcesServiceTest/product"; + + // cannot use HttpRequestUtil.doPOST() because it fails when response is 500 + URL urlObj = new URL(serviceEndPoint); + HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection(); + connection.setRequestMethod("POST"); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Type", "application/xml"); + connection.setRequestProperty("Accept", "application/xml"); + + byte[] postDataBytes = "invalid".getBytes(StandardCharsets.UTF_8); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(postDataBytes); + } + int responseCode = connection.getResponseCode(); + Assert.assertEquals(responseCode, 500, "Response code mismatched"); + + try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()))) { + String line; + StringBuilder response = new StringBuilder(); + while ((line = reader.readLine()) != null) { + response.append(line); + } + int currentParamsIndex = response.indexOf(":current_params>"); + int requestNameIndex = response.indexOf(":current_request_name>"); + int nestedExceptionIndex = response.indexOf(":nested_exception"); + int dataServiceIndex = response.indexOf(":source_data_service>"); + int locationIndex = response.indexOf(":location>"); + int namespaceIndex = response.indexOf(":default_namespace>"); + int descriptionIndex = response.indexOf(":description>"); + int serviceNameIndex = response.indexOf(":data_service_name>"); + int dsCodeIndex = response.indexOf(":ds_code>"); + assertTrue(currentParamsIndex < requestNameIndex, + "current_params should be before current_request_name"); + assertTrue(requestNameIndex < nestedExceptionIndex, + "current_request_name should be before nested_exception"); + assertTrue(nestedExceptionIndex < dataServiceIndex, + "nested_exception should be before source_data_service"); + assertTrue(dataServiceIndex < locationIndex, + "source_data_service should be before location"); + assertTrue(locationIndex < namespaceIndex, + "location should be before default_namespace"); + assertTrue(namespaceIndex < descriptionIndex, + "default_namespace should be before description"); + assertTrue(descriptionIndex < serviceNameIndex, + "description should be before data_service_name"); + assertTrue(serviceNameIndex < dsCodeIndex, + "data_service_name should be before ds_code"); + } + } +} diff --git a/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/testng.xml b/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/testng.xml index fbed17de05..53beb5c352 100755 --- a/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/testng.xml +++ b/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/testng.xml @@ -83,6 +83,12 @@ + + + + + +