[jboss-svn-commits] JBL Code SVN: r31416 - in labs/jbossesb/branches/JBESB_4_7_CP/product: rosetta/src/org/jboss/internal/soa/esb/publish and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Feb 4 17:59:53 EST 2010
Author: dward
Date: 2010-02-04 17:59:52 -0500 (Thu, 04 Feb 2010)
New Revision: 31416
Added:
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisherContractInfoCache.java
Modified:
labs/jbossesb/branches/JBESB_4_7_CP/product/contract-web/src/main/webapp/contract.jsp
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ActionContractPublisher.java
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractProvider.java
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/Service.java
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisher.java
labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WsdlEndpointTransformer.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-01.xml
labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-04.xml
Log:
Fix for JBESB-3161 and JBESB-3166 .
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/contract-web/src/main/webapp/contract.jsp
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/contract-web/src/main/webapp/contract.jsp 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/contract-web/src/main/webapp/contract.jsp 2010-02-04 22:59:52 UTC (rev 31416)
@@ -1,18 +1,19 @@
-<%@ page import="java.util.List" %>
-<%@ page import="org.jboss.soa.esb.listeners.config.ServicePublisher" %>
-<%@ page import="org.jboss.soa.esb.services.registry.RegistryFactory" %>
-<%@ page import="org.jboss.soa.esb.services.registry.Registry" %>
-<%@ page import="org.jboss.soa.esb.services.registry.RegistryException" %>
-<%@ page import="org.jboss.soa.esb.services.registry.ServiceNotFoundException" %>
-<%@ page import="java.util.ArrayList" %>
-<%@ page import="org.jboss.soa.esb.addressing.EPR" %>
-<%@ page import="java.net.URI" %>
-<%@ page import="org.jboss.internal.soa.esb.publish.ContractInfo" %>
-<%@ page import="org.jboss.internal.soa.esb.publish.ContractPublisher" %>
-<%@ page import="org.jboss.internal.soa.esb.publish.ContractReferencePublisher" %>
-<%@ page import="org.jboss.internal.soa.esb.publish.Publisher" %>
-<%@ page import="org.jboss.internal.soa.esb.publish.ServletContractPublisher" %>
-<%@ page import="org.jboss.soa.esb.Service" %>
+<%@page import="java.net.URI"%>
+<%@page import="java.util.ArrayList"%>
+<%@page import="java.util.List"%>
+<%@page import="org.jboss.internal.soa.esb.publish.ContractInfo"%>
+<%@page import="org.jboss.internal.soa.esb.publish.ContractPublisher"%>
+<%@page import="org.jboss.internal.soa.esb.publish.ContractReferencePublisher"%>
+<%@page import="org.jboss.internal.soa.esb.publish.Publisher"%>
+<%@page import="org.jboss.internal.soa.esb.publish.ServletContractPublisher"%>
+<%@page import="org.jboss.soa.esb.Service"%>
+<%@page import="org.jboss.soa.esb.addressing.EPR"%>
+<%@page import="org.jboss.soa.esb.listeners.config.ServicePublisher"%>
+<%@page import="org.jboss.soa.esb.listeners.config.ServicePublisherContractInfoCache"%>
+<%@page import="org.jboss.soa.esb.services.registry.Registry"%>
+<%@page import="org.jboss.soa.esb.services.registry.RegistryException"%>
+<%@page import="org.jboss.soa.esb.services.registry.RegistryFactory"%>
+<%@page import="org.jboss.soa.esb.services.registry.ServiceNotFoundException"%>
<%
Registry registry = RegistryFactory.getRegistry();
String targetServiceCat = request.getParameter("serviceCat");
@@ -59,20 +60,39 @@
if (contractPublisher == null) {
continue;
}
-
- if(contractPublisher instanceof ServletContractPublisher) {
- contractInfo = ((ServletContractPublisher)contractPublisher).getContractInfo(contractPublisherEPR, request);
+ ServicePublisherContractInfoCache contractInfoCache = ServicePublisher.getContractInfoCache();
+ if (contractPublisher instanceof ServletContractPublisher) {
+ contractInfo = contractInfoCache.getContractInfo(servicePublisher, contractPublisherEPR, request);
} else {
- contractInfo = contractPublisher.getContractInfo(contractPublisherEPR);
+ contractInfo = contractInfoCache.getContractInfo(servicePublisher, contractPublisherEPR);
}
-
+
if (contractInfo != null) {
- contractData = contractInfo.getData();
- if (contractData != null) {
- response.setContentType(contractInfo.getMimeType());
- }
+ // check for a resource request
+ boolean isResourceRequest = false;
+ String query = request.getQueryString();
+ if (query != null && query.toLowerCase().startsWith("wsdl")) {
+ String resource = request.getParameter("resource");
+ if (resource != null) {
+ isResourceRequest = true;
+ contractData = contractInfo.getResource(resource);
+ }
+ }
+ if (isResourceRequest) {
+ if (contractData != null) {
+ response.setCharacterEncoding("UTF-8");
+ }
+ } else {
+ contractData = contractInfo.getData();
+ }
+ if (contractData != null) {
+ response.setContentType(contractInfo.getMimeType());
+ }
}
- if (contractData == null) {
+
+ if (contractData != null) {
+ contractData = contractData.replaceAll( "@REQUEST_URL@", request.getRequestURL().toString() );
+ } else {
// will trigger HttpServletResponse.SC_NOT_FOUND below
contractPublisherEPR = null;
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ActionContractPublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ActionContractPublisher.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ActionContractPublisher.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -3,6 +3,8 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.listeners.config.Action;
@@ -32,12 +34,15 @@
if ( pub.getClass().getName().equals(MockContractPublisher) ) {
return pub;
}
- final Class<?>[] ifaces;
+ final List<Class<?>> ifaces_list = new ArrayList<Class<?>>();
+ ifaces_list.add(ActionContractPublisher.class);
if (pub instanceof ServletContractPublisher) {
- ifaces = new Class[]{ActionContractPublisher.class, ServletContractPublisher.class};
- } else {
- ifaces = new Class[]{ActionContractPublisher.class};
+ ifaces_list.add(ServletContractPublisher.class);
}
+ if (pub instanceof ContractProvider) {
+ ifaces_list.add(ContractProvider.class);
+ }
+ final Class<?>[] ifaces_array = ifaces_list.toArray(new Class<?>[ifaces_list.size()]);
InvocationHandler handler = new InvocationHandler() {
private final ClassLoader new_loader = Thread.currentThread().getContextClassLoader();
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -50,7 +55,7 @@
}
}
};
- return (ActionContractPublisher)Proxy.newProxyInstance(pub.getClass().getClassLoader(), ifaces, handler);
+ return (ActionContractPublisher)Proxy.newProxyInstance(pub.getClass().getClassLoader(), ifaces_array, handler);
}
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -19,7 +19,6 @@
*/
package org.jboss.internal.soa.esb.publish;
-import java.io.File;
import java.util.HashMap;
import java.util.Map;
@@ -36,7 +35,7 @@
private String mimeType = null;
private String data = null;
- private Map<String,File> fileResources = new HashMap<String,File>();
+ private Map<String,String> resources = new HashMap<String,String>();
/**
* Public constructor.
@@ -88,21 +87,21 @@
}
/**
- * Gets a file resource.
- * @param the file resource key
- * @return the file resource value
+ * Gets a resource.
+ * @param the resource key
+ * @return the resource value
*/
- public File getFileResource(String key) {
- return fileResources.get(key);
+ public String getResource(String key) {
+ return resources.get(key);
}
/**
- * Puts a file resource.
- * @param key the file resource key
- * @param value the file resource value
+ * Puts a resource.
+ * @param key the resource key
+ * @param value the resource value
*/
- public void putFileResource(String key, File value) {
- fileResources.put(key, value);
+ public void putResource(String key, String value) {
+ resources.put(key, value);
}
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractProvider.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractProvider.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractProvider.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -22,6 +22,8 @@
import java.io.IOException;
import java.util.Properties;
+import org.jboss.soa.esb.Service;
+
/**
* ContractProvider.
*
@@ -32,8 +34,8 @@
public void setContractProperties(Properties contractProperties);
- public ContractInfo provideContract() throws IOException;
+ public ContractInfo provideContract(Service service) throws IOException;
- public ContractInfo provideContract(String endpointAddressOverride) throws IOException;
+ public ContractInfo provideContract(Service service, String endpointAddressOverride) throws IOException;
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/Service.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/Service.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/Service.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -99,4 +99,8 @@
return new Service(category, name);
}
+
+ public static Service getService(String category, String name) {
+ return (category != null && category.trim().length() > 0 && name != null && name.trim().length() > 0) ? new Service(category, name) : null;
+ }
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisher.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisher.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -26,6 +26,7 @@
private String description;
private Publisher publisher;
private static Map<ManagedLifecycleController, Map<Service, List<ServicePublisher>>> SERVICE_PUBLISHERS = new LinkedHashMap<ManagedLifecycleController, Map<Service, List<ServicePublisher>>>();
+ private static ServicePublisherContractInfoCache CONTRACT_INFO_CACHE = new ServicePublisherContractInfoCache();
/**
* Public constructor.
@@ -159,7 +160,20 @@
* @param controller Controller.
*/
public static synchronized void removeServicePublishers(ManagedLifecycleController controller) {
- SERVICE_PUBLISHERS.remove(controller);
+ final Map<Service, List<ServicePublisher>> removedMap = SERVICE_PUBLISHERS.remove(controller);
+ if (removedMap != null) {
+ synchronized (CONTRACT_INFO_CACHE) {
+ for (List<ServicePublisher> servicePublisherList : removedMap.values()) {
+ if (servicePublisherList != null) {
+ for (ServicePublisher servicePublisher : servicePublisherList) {
+ if (servicePublisher != null) {
+ CONTRACT_INFO_CACHE.removeContractInfos(servicePublisher);
+ }
+ }
+ }
+ }
+ }
+ }
}
/**
@@ -212,4 +226,9 @@
return publishers;
}
+
+ // used by contract.jsp
+ public static ServicePublisherContractInfoCache getContractInfoCache() {
+ return CONTRACT_INFO_CACHE;
+ }
}
Added: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisherContractInfoCache.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisherContractInfoCache.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisherContractInfoCache.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2010
+ */
+package org.jboss.soa.esb.listeners.config;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.internal.soa.esb.publish.ContractInfo;
+import org.jboss.internal.soa.esb.publish.ContractPublisher;
+import org.jboss.internal.soa.esb.publish.ServletContractPublisher;
+import org.jboss.soa.esb.addressing.EPR;
+
+/**
+ * ServicePublisher ContractInfo cache.
+ *
+ * @author dward at jboss.org
+ */
+public class ServicePublisherContractInfoCache
+{
+
+ private final Map<Key,ContractInfo> CACHE = new ConcurrentHashMap<Key,ContractInfo>();
+
+ public ServicePublisherContractInfoCache() {}
+
+ public synchronized ContractInfo getContractInfo(ServicePublisher servicePublisher, EPR epr)
+ {
+ return getContractInfo(servicePublisher, epr, null);
+ }
+
+ public synchronized ContractInfo getContractInfo(ServicePublisher servicePublisher, EPR epr, HttpServletRequest request)
+ {
+ Key key = new Key(servicePublisher, epr, request);
+ ContractInfo value = CACHE.get(key);
+ if (value == null)
+ {
+ ContractPublisher contractPublisher = servicePublisher.getContractPublisher();
+ if (contractPublisher != null)
+ {
+ if (contractPublisher instanceof ServletContractPublisher && request != null)
+ {
+ value = ( (ServletContractPublisher)contractPublisher ).getContractInfo(epr, request);
+ }
+ else
+ {
+ value = contractPublisher.getContractInfo(epr);
+ }
+ if (value != null)
+ {
+ CACHE.put(key, value);
+ }
+ }
+ }
+ return value;
+ }
+
+ public synchronized void removeContractInfos(ServicePublisher servicePublisher)
+ {
+ Set<Key> keySet = CACHE.keySet();
+ for (Key key : keySet)
+ {
+ if ( key.servicePublisher.equals(servicePublisher) )
+ {
+ keySet.remove(key);
+ }
+ }
+ }
+
+ private static class Key
+ {
+
+ private ServicePublisher servicePublisher;
+ private EPR epr;
+ private String serviceCat;
+ private String serviceName;
+ private String protocol;
+
+ private Key(ServicePublisher servicePublisher, EPR epr, HttpServletRequest request)
+ {
+ AssertArgument.isNotNull(servicePublisher, "servicePublisher");
+ AssertArgument.isNotNull(epr, "epr");
+ this.servicePublisher = servicePublisher;
+ this.epr = epr;
+ serviceCat = getParameter(request, "serviceCat");
+ serviceName = getParameter(request, "serviceName");
+ protocol = getParameter(request, "protocol");
+ }
+
+ private static String getParameter(HttpServletRequest request, String name)
+ {
+ String value = null;
+ if (request != null)
+ {
+ value = request.getParameter(name);
+ if (value != null)
+ {
+ value = value.trim();
+ if (value.length() == 0)
+ {
+ value = null;
+ }
+ }
+ }
+ return value;
+ }
+
+ // Eclipse-generated
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Key other = (Key) obj;
+ if (epr == null) {
+ if (other.epr != null)
+ return false;
+ } else if (!epr.equals(other.epr))
+ return false;
+ if (protocol == null) {
+ if (other.protocol != null)
+ return false;
+ } else if (!protocol.equals(other.protocol))
+ return false;
+ if (serviceCat == null) {
+ if (other.serviceCat != null)
+ return false;
+ } else if (!serviceCat.equals(other.serviceCat))
+ return false;
+ if (serviceName == null) {
+ if (other.serviceName != null)
+ return false;
+ } else if (!serviceName.equals(other.serviceName))
+ return false;
+ if (servicePublisher == null) {
+ if (other.servicePublisher != null)
+ return false;
+ } else if (!servicePublisher.equals(other.servicePublisher))
+ return false;
+ return true;
+ }
+
+ // Eclipse-generated
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((epr == null) ? 0 : epr.hashCode());
+ result = prime * result
+ + ((protocol == null) ? 0 : protocol.hashCode());
+ result = prime * result
+ + ((serviceCat == null) ? 0 : serviceCat.hashCode());
+ result = prime * result
+ + ((serviceName == null) ? 0 : serviceName.hashCode());
+ result = prime
+ * result
+ + ((servicePublisher == null) ? 0 : servicePublisher
+ .hashCode());
+ return result;
+ }
+
+ }
+
+}
Property changes on: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ServicePublisherContractInfoCache.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -19,13 +19,9 @@
*/
package org.jboss.soa.esb.listeners.gateway.http;
-import java.io.BufferedReader;
import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Reader;
import java.io.Writer;
import java.util.Enumeration;
import java.util.Map;
@@ -104,7 +100,7 @@
try {
ContractProvider contractProvider = ContractProviderLifecycleResource.getContractProvider(serviceCategory, serviceName);
if (contractProvider != null) {
- contract = contractProvider.provideContract(config.getInitParameter(Servlet.ENDPOINT_ADDRESS));
+ contract = contractProvider.provideContract(service, config.getInitParameter(Servlet.ENDPOINT_ADDRESS));
}
} catch (LifecycleResourceException lre) {
throw new ServletException(lre);
@@ -244,7 +240,7 @@
private ConfigTree toConfigTree(ServletConfig config) {
ConfigTree configTree = new ConfigTree("config");
- Enumeration configNames = config.getInitParameterNames();
+ Enumeration<?> configNames = config.getInitParameterNames();
while(configNames.hasMoreElements()) {
String name = (String) configNames.nextElement();
@@ -273,32 +269,27 @@
}
private void handleWsdlRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setCharacterEncoding("UTF-8");
- String mimeType = (contract != null ? contract.getMimeType() : "text/xml");
- resp.setContentType(mimeType);
- String data = null;
- String resource = req.getParameter("resource");
- if (resource == null) {
- data = (contract != null ? contract.getData() : "<definitions/>");
- } else {
- if (contract != null) {
- File file = contract.getFileResource(resource);
- if (file != null && file.exists() && file.canRead()) {
- Reader reader = null;
- try {
- reader = new BufferedReader(new FileReader(file));
- data = StreamUtils.readReader(reader);
- } finally {
- try { if (reader != null) reader.close(); } catch (Throwable t) {}
- }
- }
+ String mimeType;
+ String data;
+ if (contract != null) {
+ mimeType = contract.getMimeType();
+ String resource = req.getParameter("resource");
+ if (resource != null) {
+ data = contract.getResource(resource);
+ } else {
+ data = contract.getData();
}
- }
- if (data != null) {
- data = data.replaceAll( "@REQUEST_URL@", req.getRequestURL().toString() );
+ if (data != null) {
+ data = data.replaceAll( "@REQUEST_URL@", req.getRequestURL().toString() );
+ } else {
+ data = "";
+ }
} else {
- data = "";
+ mimeType = "text/xml";
+ data = "<definitions/>";
}
+ resp.setCharacterEncoding("UTF-8");
+ resp.setContentType(mimeType);
resp.setContentLength(data.length());
Writer writer = new BufferedWriter(resp.getWriter());
writer.write(data);
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -39,6 +39,7 @@
import org.jboss.internal.soa.esb.publish.ServletContractPublisher;
import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.Service;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.http.HttpClientFactory;
import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
@@ -138,7 +139,7 @@
ContractInfo contract;
try {
// Generate the WSDL...
- contract = getContractInfo(wsdlAddress);
+ contract = getContractInfo(Service.getService(targetServiceCat, targetServiceName), wsdlAddress);
String data = contract.getData();
if (data != null) {
contract.setData( updateWsdl(data, epr, targetServiceCat, targetServiceName, targetProtocol) );
@@ -156,7 +157,7 @@
}
}
- public ContractInfo getContractInfo(String wsdlAddress) throws IOException {
+ public ContractInfo getContractInfo(Service service, String wsdlAddress) throws IOException {
return new ContractInfo( "text/xml", getWsdl(wsdlAddress) );
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -34,6 +34,7 @@
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.routing.http.HttpMethodFactory;
import org.jboss.soa.esb.http.HttpClientFactory;
+import org.jboss.soa.esb.util.ClassUtil;
/**
* {@link HttpClientFactory} based WSLD loader.
@@ -65,8 +66,11 @@
}
HttpMethodBase httpMethod;
+ // short-circuits
if(url.startsWith("file")) {
return new URL(url).openStream();
+ } else if(url.startsWith("classpath://")) {
+ return ClassUtil.getResource(url.substring(12, url.length()), getClass()).openStream();
}
try {
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WsdlEndpointTransformer.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WsdlEndpointTransformer.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WsdlEndpointTransformer.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -19,16 +19,16 @@
*/
package org.jboss.soa.esb.actions.soap;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.log4j.Logger;
+import org.milyn.SmooksException;
+import org.milyn.container.ExecutionContext;
import org.milyn.delivery.dom.DOMVisitAfter;
-import org.milyn.container.ExecutionContext;
-import org.milyn.SmooksException;
import org.milyn.xml.DomUtils;
import org.w3c.dom.Element;
-import org.apache.log4j.Logger;
-import java.net.URI;
-import java.net.URISyntaxException;
-
/**
* Smooks transformer for transforming the WSDL for ESB endpoints.
*
@@ -68,22 +68,37 @@
if(location != null) {
try {
- URI locationURI = new URI(location);
+ // used just to trigger a URISyntaxException so we can break out fast
+ @SuppressWarnings("unused")
+ URI locationURI = new URI(location);
+
String targetServiceCat = (String) executionContext.getAttribute(WsdlEndpointTransformer.TARGET_CAT);
String targetServiceName = (String) executionContext.getAttribute(WsdlEndpointTransformer.TARGET_NAME);
String targetProtocol = (String) executionContext.getAttribute(WsdlEndpointTransformer.TARGET_PROTOCOL);
- String addParams = "serviceCat=" + targetServiceCat + "&serviceName=" + targetServiceName + "&protocol=" + targetProtocol;
-
- if(locationURI.getQuery() != null) {
- element.setAttribute("location", (locationURI.toString() + "&" + addParams));
- } else {
- element.setAttribute("location", (locationURI.toString() + "?" + addParams));
- }
+
+ StringBuilder locationBuilder = new StringBuilder(location);
+ appendParam(locationBuilder, "serviceCat", targetServiceCat);
+ appendParam(locationBuilder, "serviceName", targetServiceName);
+ appendParam(locationBuilder, "protocol", targetProtocol);
+
+ element.setAttribute( "location", locationBuilder.toString() );
} catch (URISyntaxException e) {
logger.info("Not processing WSDL import '" + location + "'. Invalid URI.");
}
}
}
+
+ private void appendParam(StringBuilder builder, String name, String value) throws URISyntaxException {
+ if (value != null && value.length() > 0) {
+ String qPrefix = "?" + name + "=";
+ String aPrefix = "&" + name + "=";
+ String location = builder.toString();
+ if (!location.contains(qPrefix) && !location.contains(aPrefix)) {
+ builder.append(new URI(location).getQuery() == null ? qPrefix : aPrefix);
+ builder.append(value);
+ }
+ }
+ }
private void transformBinding(Element element, ExecutionContext executionContext) {
URI endpointURI = (URI) executionContext.getAttribute(ENDPOINT_URI);
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -45,6 +45,7 @@
import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
import org.jboss.ws.metadata.wsdl.WSDLEndpoint;
import org.jboss.ws.metadata.wsdl.WSDLService;
+import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -139,15 +140,22 @@
public SOAPProxy(ConfigTree config) throws ConfigurationException
{
payloadProxy = new MessagePayloadProxy(config);
+ SOAPProxyWsdlLoader wsdl_loader = SOAPProxyWsdlLoader.newLoader(config);
WSDLDefinitions wsdl_def;
try
{
- wsdl_def = SOAPProxyWsdlLoader.loadDefinitions(config);
+ wsdl_loader.load(false);
+ URL wsdl_url = wsdl_loader.getURL();
+ wsdl_def = WSDLDefinitionsFactory.newInstance().parse(wsdl_url);
}
catch (IOException ioe)
{
throw new ConfigurationException(ioe);
}
+ finally
+ {
+ wsdl_loader.cleanup();
+ }
for ( WSDLBinding wsdl_bind : wsdl_def.getBindings() )
{
for ( WSDLBindingOperation wsdl_bind_oper : wsdl_bind.getOperations() )
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -19,20 +19,18 @@
*/
package org.jboss.soa.esb.actions.soap.proxy;
-import java.io.BufferedInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
-import java.net.URL;
import java.util.Properties;
import org.jboss.internal.soa.esb.publish.ContractInfo;
import org.jboss.internal.soa.esb.publish.ContractProvider;
-import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.Service;
import org.jboss.soa.esb.actions.soap.AuthBASICWsdlContractPublisher;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
/**
* SOAPProxy wsdl contract publisher.
@@ -43,38 +41,44 @@
{
@Override
- public ContractInfo getContractInfo(String wsdlAddress) throws IOException
+ public ContractInfo getContractInfo(Service service, String wsdlAddress) throws IOException
{
Properties properties = getActionProperties();
- ConfigTree config = new ConfigTree("config");
+ ConfigTree config;
+ if (service != null)
+ {
+ ConfigTree parent_config = new ConfigTree("parent_config");
+ parent_config.setAttribute( ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, service.getCategory() );
+ parent_config.setAttribute( ListenerTagNames.SERVICE_NAME_TAG, service.getName() );
+ config = new ConfigTree("config", parent_config);
+ }
+ else
+ {
+ config = new ConfigTree("config");
+ }
for ( Object key : properties.keySet() )
{
String name = (String)key;
String value = properties.getProperty(name);
config.setAttribute(name, value);
}
- ContractInfo contract = new ContractInfo();
- SOAPProxyWsdlLoader loader = SOAPProxyWsdlLoader.newLoader(config, contract);
- String mimeType = "text/xml";
- String data = null;
- InputStream is = null;
+ SOAPProxyWsdlLoader wsdl_loader;
try
{
- URL url = loader.getURL();
- if (url != null)
- {
- is = new BufferedInputStream( url.openStream() );
- data = StreamUtils.readStreamString(is, "UTF-8");
- }
+ wsdl_loader = SOAPProxyWsdlLoader.newLoader(config);
}
+ catch (ConfigurationException ce)
+ {
+ throw (IOException)(new IOException(ce.getMessage()).initCause(ce));
+ }
+ try
+ {
+ return wsdl_loader.load(true);
+ }
finally
{
- try { if (is != null) is.close(); } catch (Throwable t) {}
- loader.cleanup();
+ wsdl_loader.cleanup();
}
- contract.setMimeType(mimeType);
- contract.setData(data);
- return contract;
}
public void setContractProperties(Properties contractProperties)
@@ -82,12 +86,12 @@
setActionProperties(contractProperties);
}
- public ContractInfo provideContract() throws IOException
+ public ContractInfo provideContract(Service service) throws IOException
{
- return provideContract(null);
+ return provideContract(service, null);
}
- public ContractInfo provideContract(String endpointAddressOverride) throws IOException
+ public ContractInfo provideContract(Service service, String endpointAddressOverride) throws IOException
{
ContractInfo contract;
if (endpointAddressOverride != null)
@@ -106,7 +110,7 @@
{
// !!! *HAS* TO BE THE *SUPER* CLASS' IMPLEMENTATION !!!
// --> AbstractWsdlContractPublisher.getContractInfo(String) <--
- contract = super.getContractInfo( getWsdlAddress() );
+ contract = super.getContractInfo( service, getWsdlAddress() );
}
return contract;
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -21,11 +21,16 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -36,16 +41,15 @@
import javax.management.ObjectName;
import org.jboss.internal.soa.esb.publish.ContractInfo;
+import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.soap.AuthBASICWsdlContractPublisher;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.util.xml.DOMUtils;
import org.jboss.util.xml.DOMWriter;
import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
-import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
-import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -64,8 +68,43 @@
public abstract class SOAPProxyWsdlLoader
{
+ private ConfigTree config;
+ private String address;
+ private boolean rewriteHost;
+ private String serviceCat;
+ private String serviceName;
+ private Puller puller = null;
private File tempDir = null;
+ private ContractInfo contract;
+ private boolean rewriteLocation;
+ private File primary_file;
+ private List<File> cleanup_files = new ArrayList<File>();
+
+ protected SOAPProxyWsdlLoader(ConfigTree config, String address, boolean rewriteHost)
+ {
+ this.config = config;
+ this.address = address;
+ this.rewriteHost = rewriteHost;
+ ConfigTree parent_config = config.getParent();
+ serviceCat = (parent_config != null ? parent_config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG) : null);
+ serviceName = (parent_config != null ? parent_config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG) : null);
+ }
+
+ public String getAddress()
+ {
+ return address;
+ }
+
+ public synchronized Puller getPuller()
+ {
+ if (puller == null)
+ {
+ puller = new Puller(config);
+ }
+ return puller;
+ }
+
private File getTempDir() throws IOException
{
if (tempDir == null)
@@ -80,7 +119,7 @@
tempDir = (File)mbeanServer.getAttribute(new ObjectName("jboss.system:type=ServerConfig"), "ServerTempDir");
}
catch (JMException ignored) {}
- String tempName = SOAPProxyWsdlLoader.class.getName();
+ String tempName = SOAPProxyWsdlLoader.class.getSimpleName();
if ( tempDir == null || !tempDir.exists() )
{
File tempFile = File.createTempFile(tempName + "-", ".tmp");
@@ -100,303 +139,236 @@
return File.createTempFile( prefix + "-", suffix, getTempDir() );
}
- public abstract URL getURL() throws MalformedURLException;
-
- public void cleanup() {}
-
- public static WSDLDefinitions loadDefinitions(ConfigTree config) throws IOException
+ public ContractInfo load(boolean rewriteLocation) throws IOException
{
- SOAPProxyWsdlLoader loader = newLoader(config, null);
- WSDLDefinitions definitions;
+ contract = new ContractInfo();
+ this.rewriteLocation = rewriteLocation;
+ String address = getAddress();
+ String protocol = URI.create(address).getScheme();
+ primary_file = createTempFile(protocol, ".wsdl");
+ cleanup_files.add(primary_file);
+ getPuller().pull(address, primary_file);
+ primary_file = filterFile(address, primary_file, ".wsdl", protocol);
+ // populate the primary member variables (mimeType + data)
+ String mimeType = "text/xml";
+ String data = null;
+ InputStream is = null;
try
{
- URL url = loader.getURL();
- definitions = WSDLDefinitionsFactory.newInstance().parse(url);
+ URL url = getURL();
+ if (url != null)
+ {
+ is = new BufferedInputStream( url.openStream() );
+ data = StreamUtils.readStreamString(is, "UTF-8");
+ }
}
finally
{
- loader.cleanup();
+ try { if (is != null) is.close(); } catch (Throwable t) {}
}
- return definitions;
+ contract.setMimeType(mimeType);
+ contract.setData(data);
+ return contract;
}
- public static SOAPProxyWsdlLoader newLoader(ConfigTree config, ContractInfo contract) throws IOException
+ private File filterFile(String url, File origFile, String suffix, String protocol) throws IOException
{
- String address;
+ BufferedInputStream bis = null;
+ Element wsdlElement;
try
{
- address = config.getRequiredAttribute("wsdl");
+ bis = new BufferedInputStream( origFile.toURL().openStream() );
+ wsdlElement = DOMUtils.parse(bis);
}
- catch (ConfigurationException ce)
+ finally
{
- throw new IOException( ce.getMessage() );
+ try { if (bis != null) bis.close(); } catch (Throwable t) {}
}
- if ( address.startsWith("http://") || address.startsWith("https://") )
+ if ( findRelative(url, wsdlElement, protocol) )
{
- return new HttpSOAPProxyWsdlLoader(address, config, contract);
- }
- else if ( address.startsWith("file://") )
- {
- return new FileSOAPProxyWsdlLoader( address.substring(7, address.length()) );
- }
- else if ( address.startsWith("classpath://") )
- {
- return new ClasspathSOAPProxyWsdlLoader( address.substring(12, address.length()) );
- }
- else if ( address.startsWith("internal://") )
- {
- return new InternalSOAPProxyWsdlLoader( address.substring(11, address.length()) );
- }
- throw new IOException("unrecognized wsdl address: " + address);
- }
-
- static class HttpSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
- {
-
- private AuthBASICWsdlContractPublisher file_puller;
- private ContractInfo contract;
- private File wsdl_temp_file;
- private List<File> cleanup_files = new ArrayList<File>();
-
- public HttpSOAPProxyWsdlLoader(String url, final ConfigTree config, ContractInfo contract) throws IOException
- {
- // re-using the HTTPClient and AuthBASIC stuff...
- file_puller = new AuthBASICWsdlContractPublisher()
- {
- @Override
- public Properties getActionProperties()
- {
- Properties props = new Properties();
- for ( String key : config.getAttributeNames() )
- {
- String value = config.getAttribute(key);
- if (value != null)
- {
- props.setProperty(key, value);
- }
- }
- return props;
- }
- };
- this.contract = contract;
- wsdl_temp_file = createTempFile("http", ".wsdl");
- cleanup_files.add(wsdl_temp_file);
- pullFile(url, wsdl_temp_file);
- wsdl_temp_file = filterFile(url, wsdl_temp_file, ".wsdl");
- }
-
- private void pullFile(String url, File file) throws IOException
- {
- BufferedInputStream bis = null;
+ File rewriteFile = createTempFile(protocol, suffix);
+ cleanup_files.add(rewriteFile);
BufferedOutputStream bos = null;
try
{
- String wsdl_string = file_puller.getWsdl(url);
- bis = new BufferedInputStream( new ByteArrayInputStream(wsdl_string.getBytes()) );
- bos = new BufferedOutputStream( new FileOutputStream(file) );
- byte[] buf = new byte[1024];
- int read = 0;
- while ( (read = bis.read(buf)) != -1 )
- {
- bos.write(buf, 0, read);
- }
- bos.flush();
+ bos = new BufferedOutputStream( new FileOutputStream(rewriteFile) );
+ DOMWriter writer = new DOMWriter(bos);
+ writer.setPrettyprint(true);
+ writer.print(wsdlElement);
}
finally
- {
+ {
try { if (bos != null) bos.close(); } catch (Throwable t) {}
- try { if (bis != null) bis.close(); } catch (Throwable t) {}
}
+ origFile.delete();
+ cleanup_files.remove(origFile);
+ origFile = rewriteFile;
}
-
- // JBESB-3076
- private File filterFile(String url, File origFile, String suffix) throws IOException
+ return origFile;
+ }
+
+ private boolean findRelative(String url, Element wsdlElement, String protocol) throws IOException
+ {
+ boolean rewrite = false;
+ NodeList nlist = wsdlElement.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
{
- BufferedInputStream bis = null;
- Element wsdlElement;
- try
+ Node childNode = nlist.item(i);
+ if (childNode.getNodeType() == Node.ELEMENT_NODE)
{
- bis = new BufferedInputStream( origFile.toURL().openStream() );
- wsdlElement = DOMUtils.parse(bis);
- }
- finally
- {
- try { if (bis != null) bis.close(); } catch (Throwable t) {}
- }
- if ( findRelative(url, wsdlElement) )
- {
- File rewriteFile = createTempFile("http", suffix);
- cleanup_files.add(rewriteFile);
- BufferedOutputStream bos = null;
- try
+ Element childElement = (Element)childNode;
+ String nodeName = childElement.getLocalName();
+ if ( "import".equals(nodeName) || "include".equals(nodeName) )
{
- bos = new BufferedOutputStream( new FileOutputStream(rewriteFile) );
- DOMWriter writer = new DOMWriter(bos);
- writer.setPrettyprint(true);
- writer.print(wsdlElement);
- }
- finally
- {
- try { if (bos != null) bos.close(); } catch (Throwable t) {}
- }
- origFile.delete();
- cleanup_files.remove(origFile);
- origFile = rewriteFile;
- }
- return origFile;
- }
-
- private boolean findRelative(String url, Element wsdlElement) throws IOException
- {
- boolean rewrite = false;
- NodeList nlist = wsdlElement.getChildNodes();
- for (int i = 0; i < nlist.getLength(); i++)
- {
- Node childNode = nlist.item(i);
- if (childNode.getNodeType() == Node.ELEMENT_NODE)
- {
- Element childElement = (Element)childNode;
- String nodeName = childElement.getLocalName();
- if ( "import".equals(nodeName) || "include".equals(nodeName) )
+ Attr locationAttr = childElement.getAttributeNode("schemaLocation");
+ if (locationAttr == null)
{
- Attr locationAttr = childElement.getAttributeNode("schemaLocation");
- if (locationAttr == null)
+ locationAttr = childElement.getAttributeNode("location");
+ }
+ if (locationAttr != null)
+ {
+ String location = fixRelative( url, locationAttr.getNodeValue() );
+ int locationSuffixPos = location.lastIndexOf(".");
+ String locationSuffix = (locationSuffixPos > -1 ? location.substring(locationSuffixPos, location.length()) : ".tmp");
+ locationSuffix = locationSuffix.trim();
+ if (locationSuffix.length() == 0)
{
- locationAttr = childElement.getAttributeNode("location");
+ locationSuffix = ".tmp";
}
- if (locationAttr != null)
+ File locationFile = createTempFile(protocol, locationSuffix);
+ cleanup_files.add(locationFile);
+ getPuller().pull(location, locationFile);
+ locationFile = filterFile(location, locationFile, locationSuffix, protocol);
+ String locationFileName = locationFile.getName();
+ if (rewriteLocation)
{
- String location = fixRelative( url, locationAttr.getNodeValue() );
- int locationSuffixPos = location.lastIndexOf(".");
- String locationSuffix = (locationSuffixPos > -1 ? location.substring(locationSuffixPos, location.length()) : ".tmp");
- locationSuffix = locationSuffix.trim();
- if (locationSuffix.length() == 0)
+ String locationResource = getPuller().pull(locationFile);
+ contract.putResource(locationFileName, locationResource);
+ StringBuilder locationBuilder = new StringBuilder("@REQUEST_URL@?wsdl");
+ locationBuilder.append("&resource=").append(locationFileName);
+ if (serviceCat != null)
{
- locationSuffix = ".tmp";
+ locationBuilder.append("&serviceCat=").append(serviceCat);
}
- File locationFile = createTempFile("http", locationSuffix);
- cleanup_files.add(locationFile);
- pullFile(location, locationFile);
- locationFile = filterFile(location, locationFile, locationSuffix);
- String locationFileName = locationFile.getName();
- if (contract != null)
+ if (serviceName != null)
{
- contract.putFileResource(locationFileName, locationFile);
- locationAttr.setNodeValue("@REQUEST_URL@?wsdl&resource=" + locationFileName);
+ locationBuilder.append("&serviceName=").append(serviceName);
}
- else
- {
- locationAttr.setNodeValue(locationFileName);
- }
- rewrite = true;
+ String contractProtocol = (!protocol.toLowerCase().equals("https") ? "http" : "https");
+ locationBuilder.append("&protocol=").append(contractProtocol);
+ locationAttr.setNodeValue( locationBuilder.toString() );
}
- }
- if ( findRelative(url, childElement) )
- {
+ else
+ {
+ locationAttr.setNodeValue(locationFileName);
+ }
rewrite = true;
}
}
+ if ( findRelative(url, childElement, protocol) )
+ {
+ rewrite = true;
+ }
}
- return rewrite;
}
-
- static String fixRelative(String wsdl_url, String location)
+ return rewrite;
+ }
+
+ String fixRelative(String base_url, String location)
+ {
+ location = location.replaceAll("/./", "/");
+ if ( !location.startsWith("http://") && !location.startsWith("https://") )
{
- location = location.replaceAll("/./", "/");
- if ( !location.startsWith("http://") && !location.startsWith("https://") )
+ while ( location.startsWith("./") )
{
- String wsdl_host = wsdl_url.substring( 0, wsdl_url.indexOf("/", wsdl_url.indexOf("://")+3) );
- while ( location.startsWith("./") )
+ location = location.substring( 2, location.length() );
+ }
+ if ( location.startsWith("/") )
+ {
+ if (rewriteHost)
{
- location = location.substring( 2, location.length() );
+ String base_host = base_url.substring( 0, base_url.indexOf("/", base_url.indexOf("://")+3) );
+ location = base_host + location;
}
- if (location.startsWith("/"))
- {
- location = wsdl_host + location;
- }
- else
- {
- int count = 0;
- while ( location.startsWith("../") )
- {
- location = location.substring( 3, location.length() );
- count++;
- }
- String newLocation = wsdl_url.substring( 0, wsdl_url.lastIndexOf("/") );
- for (int c = 0; c < count; c++)
- {
- newLocation = newLocation.substring( 0, newLocation.lastIndexOf("/") );
- }
- location = newLocation + "/" + location;
- }
}
- return location;
- }
-
- public URL getURL() throws MalformedURLException
- {
- return wsdl_temp_file.toURL();
- }
-
- @Override
- public void cleanup()
- {
- for (File file : cleanup_files)
+ else
{
- if (contract == null)
+ int count = 0;
+ while ( location.startsWith("../") )
{
- file.delete();
+ location = location.substring( 3, location.length() );
+ count++;
}
- else
+ String newLocation = base_url.substring( 0, base_url.lastIndexOf("/") );
+ for (int c = 0; c < count; c++)
{
- file.deleteOnExit();
+ newLocation = newLocation.substring( 0, newLocation.lastIndexOf("/") );
}
+ location = newLocation + "/" + location;
}
}
-
+ return location;
}
- private static class FileSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
+ public URL getURL() throws MalformedURLException
{
-
- private File wsdl_orig_file;
-
- public FileSOAPProxyWsdlLoader(String path)
+ return primary_file.toURL();
+ }
+
+ public void cleanup()
+ {
+ for (File file : cleanup_files)
{
- wsdl_orig_file = new File(path);
+ file.delete();
}
-
- public URL getURL() throws MalformedURLException
+ }
+
+ public static SOAPProxyWsdlLoader newLoader(ConfigTree config) throws ConfigurationException
+ {
+ SOAPProxyWsdlLoader loader;
+ String address = config.getRequiredAttribute("wsdl");
+ if ( address.startsWith("http://") || address.startsWith("https://") )
{
- return wsdl_orig_file.toURL();
+ loader = new DefaultSOAPProxyWsdlLoader(config, address, true);
}
-
+ else if ( address.startsWith("file://") || address.startsWith("classpath://") )
+ {
+ loader = new DefaultSOAPProxyWsdlLoader(config, address, false);
+ }
+ else if ( address.startsWith("internal://") )
+ {
+ loader = new InternalSOAPProxyWsdlLoader(config, address);
+ }
+ else
+ {
+ throw new ConfigurationException("unrecognized wsdl address: " + address);
+ }
+ return loader;
}
- private static class ClasspathSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
+ static class DefaultSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
{
- private URL wsdl_url;
-
- public ClasspathSOAPProxyWsdlLoader(String resource)
+ public DefaultSOAPProxyWsdlLoader(ConfigTree config, String address, boolean rewriteHost)
{
- wsdl_url = ClassUtil.getResource(resource, SOAPProxyWsdlLoader.class);
+ super(config, address, rewriteHost);
}
- public URL getURL() throws MalformedURLException
- {
- return wsdl_url;
- }
-
}
private static class InternalSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
{
- private URL wsdl_url;
+ public InternalSOAPProxyWsdlLoader(ConfigTree config, String address)
+ {
+ super(config, address, true);
+ }
- public InternalSOAPProxyWsdlLoader(String end_name) throws IOException
+ @Override
+ public String getAddress()
{
+ String end_addr = super.getAddress();
+ String end_name = end_addr.substring( 11, end_addr.length() );
SPIProvider spi_prov = SPIProviderResolver.getInstance().getProvider();
EndpointRegistryFactory end_reg_fact = spi_prov.getSPI(EndpointRegistryFactory.class);
EndpointRegistry end_reg = end_reg_fact.getEndpointRegistry();
@@ -415,21 +387,81 @@
ServerEndpointMetaData end_meta = end.getAttachment(ServerEndpointMetaData.class);
if (end_meta == null)
{
- throw new IOException("cannot obtain metadata for internal endpoint: " + end_name);
+ throw new RuntimeException("cannot obtain metadata for internal endpoint: " + end_name);
}
- wsdl_url = end_meta.getServiceMetaData().getWsdlLocation();
+ return end_meta.getServiceMetaData().getWsdlLocation().toString();
}
else
{
- throw new IOException("unrecognized internal endpoint: " + end_name);
+ throw new RuntimeException("unrecognized internal endpoint: " + end_name);
}
}
- public URL getURL() throws MalformedURLException
+ }
+
+ private static class Puller extends AuthBASICWsdlContractPublisher
+ {
+
+ private ConfigTree config;
+
+ public Puller(ConfigTree config)
{
- return wsdl_url;
+ this.config = config;
}
+ @Override
+ public Properties getActionProperties()
+ {
+ Properties props = new Properties();
+ for ( String key : config.getAttributeNames() )
+ {
+ String value = config.getAttribute(key);
+ if (value != null)
+ {
+ props.setProperty(key, value);
+ }
+ }
+ return props;
+ }
+
+ public void pull(String url, File file) throws IOException
+ {
+ BufferedInputStream bis = null;
+ BufferedOutputStream bos = null;
+ try
+ {
+ // re-using the HTTPClient and AuthBASIC stuff...
+ String data = getWsdl(url);
+ bis = new BufferedInputStream( new ByteArrayInputStream(data.getBytes()) );
+ bos = new BufferedOutputStream( new FileOutputStream(file) );
+ byte[] buf = new byte[1024];
+ int read = 0;
+ while ( (read = bis.read(buf)) != -1 )
+ {
+ bos.write(buf, 0, read);
+ }
+ bos.flush();
+ }
+ finally
+ {
+ try { if (bos != null) bos.close(); } catch (Throwable t) {}
+ try { if (bis != null) bis.close(); } catch (Throwable t) {}
+ }
+ }
+
+ public String pull(File file) throws IOException
+ {
+ Reader reader = new BufferedReader( new FileReader(file) );
+ try
+ {
+ return StreamUtils.readReader(reader);
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+
}
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java 2010-02-04 22:59:52 UTC (rev 31416)
@@ -22,6 +22,8 @@
import static org.junit.Assert.assertEquals;
import junit.framework.JUnit4TestAdapter;
+import org.jboss.soa.esb.actions.soap.proxy.SOAPProxyWsdlLoader.DefaultSOAPProxyWsdlLoader;
+import org.jboss.soa.esb.helpers.ConfigTree;
import org.junit.Test;
/**
@@ -33,7 +35,7 @@
{
@Test
- public void testHttp_fixRelative()
+ public void test_fixRelative()
{
String[][] relativeHttpResources = new String[][] {
new String[] {"http://foo.com/services/MyService.wsdl", "/schemas/MySchema.xsd", "http://foo.com/schemas/MySchema.xsd"},
@@ -49,9 +51,10 @@
new String[] {"http://foo.com/services/old/MyService.wsdl", ".././../test/MySchema.xsd", "http://foo.com/test/MySchema.xsd"},
new String[] {"http://foo.com/services/old/MyService.wsdl", ".././../test/./MySchema.xsd", "http://foo.com/test/MySchema.xsd"},
};
+ SOAPProxyWsdlLoader loader = new DefaultSOAPProxyWsdlLoader(new ConfigTree("config"), null, true);
for (String[] r : relativeHttpResources)
{
- String actual = SOAPProxyWsdlLoader.HttpSOAPProxyWsdlLoader.fixRelative(r[0], r[1]);
+ String actual = loader.fixRelative(r[0], r[1]);
String expected = r[2];
assertEquals(expected, actual);
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-01.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-01.xml 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-01.xml 2010-02-04 22:59:52 UTC (rev 31416)
@@ -1,5 +1,5 @@
<definitions name="GoodbyeWorldWSService" targetNamespace="http://webservice_war1/goodbyeworld" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice_war1/goodbyeworld" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <import location="http://127.0.0.1:8080/contract/contract.jsp?wsdl&resource=MTOMEndpoint_PortType61314.wsdl&serviceCat=&serviceName=&protocol=" namespace="http://org.jboss.ws/xop/doclit"/>
+ <import location="http://127.0.0.1:8080/contract/contract.jsp?wsdl&resource=MTOMEndpoint_PortType61314.wsdl" namespace="http://org.jboss.ws/xop/doclit"/>
<types/>
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-04.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-04.xml 2010-02-04 21:11:28 UTC (rev 31415)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wsdl-transform.expected-04.xml 2010-02-04 22:59:52 UTC (rev 31416)
@@ -1,5 +1,5 @@
<definitions name="GoodbyeWorldWSService" targetNamespace="http://webservice_war1/goodbyeworld" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice_war1/goodbyeworld" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <import location="http://127.0.0.1:8080/contract/contract.jsp?wsdl&resource=MTOMEndpoint_PortType61314.wsdl&serviceCat=&serviceName=&protocol=" namespace="http://org.jboss.ws/xop/doclit"/>
+ <import location="http://127.0.0.1:8080/contract/contract.jsp?wsdl&resource=MTOMEndpoint_PortType61314.wsdl" namespace="http://org.jboss.ws/xop/doclit"/>
<types/>
<message name="GoodbyeWorldWS_sayGoodbyeWithoutResponse">
<part name="String_1" type="xsd:string"/>
More information about the jboss-svn-commits
mailing list