summaryrefslogtreecommitdiffstats
path: root/wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/SoapUtil.java
diff options
context:
space:
mode:
authorhuangjian <huang.jian12@zte.com.cn>2016-09-14 23:59:44 +0800
committerhuangjian <huang.jian12@zte.com.cn>2016-09-14 23:59:44 +0800
commit906a4ce648cbcef097f7da2888f88e082a0b8d5c (patch)
treec62e060ce1c910612d0cb18bb04d4d184e51a927 /wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/SoapUtil.java
parentf84ace36fe23ab9cdb698dcce9d6dacd9f89e7a8 (diff)
Add wso2bpel-ext code
Change-Id: I774e0ede1668ee8b4ef03bb48a2fb2971fbd3757 Signed-off-by: huangjian <huang.jian12@zte.com.cn>
Diffstat (limited to 'wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/SoapUtil.java')
-rw-r--r--wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/SoapUtil.java156
1 files changed, 156 insertions, 0 deletions
diff --git a/wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/SoapUtil.java b/wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/SoapUtil.java
new file mode 100644
index 0000000..47913ae
--- /dev/null
+++ b/wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/SoapUtil.java
@@ -0,0 +1,156 @@
+/**
+ * Copyright 2016 [ZTE] and others.
+ *
+ * Licensed 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.openo.carbon.bpel.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.ConfigurationException;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.log4j.Logger;
+
+import com.eviware.soapui.impl.wsdl.WsdlInterface;
+import com.eviware.soapui.impl.wsdl.WsdlProject;
+import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader;
+import com.eviware.soapui.model.iface.Operation;
+import com.eviware.soapui.model.iface.Request;
+
+public class SoapUtil {
+ private static final Logger log = Logger.getLogger(SoapUtil.class);
+
+ private DocumentBuilderFactory docBuilderFactory;
+ private Map<String, WsdlInterface[]> wsdls = new LRULinkedHashMap<String, WsdlInterface[]>(256);
+
+ public SoapUtil() {
+ docBuilderFactory = DocumentBuilderFactory.newInstance();
+ docBuilderFactory.setNamespaceAware(true);
+ }
+
+ public Request[] getRequestTemplate(String wsdlUrl)
+ throws UnsupportedOperationException, IOException {
+ Request[] requests = new Request[0];
+ List<Request> requestList = new ArrayList<Request>();
+ Operation operationInst = null;
+ WsdlInterface[] wsdlInterfaces = getWsdlInterfaces(wsdlUrl, null);
+ for (WsdlInterface wsdlInterface : wsdlInterfaces) {
+ Operation opr = wsdlInterface.getOperationAt(0);
+ if (opr != null) {
+ operationInst = opr;
+ String requestTemplate = operationInst.getRequestAt(0).getRequestContent();
+ requestList.add(operationInst.getRequestAt(0));
+ }
+ }
+ requests = requestList.toArray(new Request[0]);
+ return requests;
+ }
+
+ /**
+ *
+ * @param wsdl
+ * @param operation
+ * @param httpClientProps
+ * @return
+ * @throws IOException
+ * @throws UnsupportedOperationException
+ */
+ private Operation getOperation(String wsdl, String operation, Properties httpClientProps)
+ throws IOException, UnsupportedOperationException {
+ WsdlInterface[] wsdlInterfaces = getWsdlInterfaces(wsdl, httpClientProps);
+ for (WsdlInterface wsdlInterface : wsdlInterfaces) {
+ Operation operationInst = wsdlInterface.getOperationByName(operation);
+
+ if (operationInst != null) {
+ return operationInst;
+ }
+ }
+ wsdls.remove(wsdl);
+ wsdlInterfaces = getWsdlInterfaces(wsdl, httpClientProps);
+ for (WsdlInterface wsdlInterface : wsdlInterfaces) {
+ Operation operationInst = wsdlInterface.getOperationByName(operation);
+ if (operationInst != null) {
+ return operationInst;
+ }
+ }
+
+ throw new UnsupportedOperationException(
+ "Operation '" + operation + "' not supported by WSDL '" + wsdl + "'.");
+ }
+
+ /**
+ *
+ * @param wsdl
+ * @param httpClientProps
+ * @return
+ * @throws IOException
+ */
+ private WsdlInterface[] getWsdlInterfaces(String wsdl, Properties httpClientProps)
+ throws IOException {
+ try {
+ WsdlInterface[] wsdlInterfaces = wsdls.get(wsdl);
+ if (wsdlInterfaces == null) {
+ WsdlProject wsdlProject = new WsdlProject();
+ WsdlLoader wsdlLoader = createWsdlLoader(wsdl, httpClientProps);
+
+ wsdlInterfaces = wsdlProject.importWsdl(wsdl, true, wsdlLoader);
+
+ wsdls.put(wsdl, wsdlInterfaces);
+ }
+ return wsdlInterfaces;
+ } catch (Exception e) {
+ e.printStackTrace();
+ log.error(e.getMessage());
+ throw new RuntimeException("Failed to import WSDL '" + wsdl + "'.");
+ }
+ }
+
+ /**
+ *
+ * @param wsdl
+ * @param httpClientProps
+ * @return
+ * @throws ConfigurationException
+ */
+ private WsdlLoader createWsdlLoader(String wsdl, Properties httpClientProps)
+ throws ConfigurationException {
+ HttpClient httpClient = new HttpClient();
+ return new ClientWsdlLoader(wsdl, httpClient);
+ }
+
+ public static void main(String[] args) {
+ SoapUtil soapUtil = new SoapUtil();
+
+ try {
+ String url = "http://10.74.151.36:9763/services/initService?wsdl";
+ Request[] requestXMLs = soapUtil.getRequestTemplate(url);
+
+ for (Request requestXML : requestXMLs) {
+ String requestJson = Xml2JsonUtil.xml2JSON(requestXML.getRequestContent());
+ System.out.println("====================================");
+ System.out.println(requestJson);
+ }
+
+ } catch (UnsupportedOperationException e1) {
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ }
+}