summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.3/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--branches/sca-java-1.3/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java165
1 files changed, 63 insertions, 102 deletions
diff --git a/branches/sca-java-1.3/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java b/branches/sca-java-1.3/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java
index 8e2e40c753..2342e7f6ef 100644
--- a/branches/sca-java-1.3/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java
+++ b/branches/sca-java-1.3/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java
@@ -58,6 +58,7 @@ import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyRegistry;
import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaExternal;
/**
* A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work
@@ -86,6 +87,68 @@ public class TuscanyListingAgent extends ListingAgent {
return serviceName;
}
+ /**
+ * Override ?xsd processing so that WSDL documents with XSD imports
+ * and includes work correctly. When we move to Axis2 1.4, we may
+ * be able to use SchemaSupplier to do this in a cleaner way.
+ */
+ @Override
+ public void processListService(HttpServletRequest req,
+ HttpServletResponse res)
+ throws IOException, ServletException {
+
+ String url = req.getRequestURL().toString();
+ String query = req.getQueryString();
+ int xsd = query.indexOf("xsd");
+ if (xsd >= 0) {
+ String serviceName = extractServiceName(url);
+ HashMap services = configContext.getAxisConfiguration().getServices();
+ if ((services != null) && !services.isEmpty()) {
+ Object serviceObj = services.get(serviceName);
+ if (serviceObj != null) {
+ String xsds = req.getParameter("xsd");
+ if (xsds != null && !"".equals(xsds)) {
+ // a schema name (perhaps with path) is present
+ AxisService axisService = (AxisService)serviceObj;
+ ArrayList schemas = axisService.getSchema();
+ for (Object rootSchema : axisService.getSchema()) {
+ XmlSchema schema = getSchema(((XmlSchema)rootSchema), xsds);
+ if (schema != null) {
+ // found the schema
+ res.setContentType("text/xml");
+ OutputStream out = res.getOutputStream();
+ schema.write(new OutputStreamWriter(out, "UTF8"));
+ out.flush();
+ out.close();
+ return;
+ }
+ }
+ }
+ }
+ }
+ }
+ // in all other cases, delegate to the Axis2 code
+ super.processListService(req, res);
+ }
+
+ private XmlSchema getSchema(XmlSchema parentSchema, String name) {
+ for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) {
+ Object obj = iter.next();
+ if (obj instanceof XmlSchemaExternal) {
+ XmlSchemaExternal extSchema = (XmlSchemaExternal)obj;
+ if (extSchema.getSchemaLocation().endsWith(name)) {
+ return extSchema.getSchema();
+ } else {
+ XmlSchema schema = getSchema(extSchema.getSchema(), name);
+ if (schema != null) {
+ return schema;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
private String findAxisServiceName(String path) {
HashMap services = configContext.getAxisConfiguration().getServices();
if (services == null) {
@@ -130,106 +193,4 @@ public class TuscanyListingAgent extends ListingAgent {
}
}
- private String extractHostAndPort(String filePart, boolean isHttp) {
- int ipindex = filePart.indexOf("//");
- String ip = null;
- if (ipindex >= 0) {
- ip = filePart.substring(ipindex + 2, filePart.length());
- int seperatorIndex = ip.indexOf(":");
- int slashIndex = ip.indexOf("/");
- String port;
- if (seperatorIndex >= 0) {
- port = ip.substring(seperatorIndex + 1, slashIndex);
- ip = ip.substring(0, seperatorIndex);
- } else {
- ip = ip.substring(0, slashIndex);
- port = "80";
- }
- if (isHttp) {
- configContext.setProperty(RUNNING_PORT, port);
- }
- }
- return ip;
- }
-
- private Policy findPolicy(String id, AxisDescription des) {
-
- List policyElements = des.getPolicyInclude().getPolicyElements();
- PolicyRegistry registry = des.getPolicyInclude().getPolicyRegistry();
-
- Object policyComponent;
-
- Policy policy = registry.lookup(id);
-
- if (policy != null) {
- return policy;
- }
-
- for (Iterator iterator = policyElements.iterator(); iterator.hasNext();) {
- policyComponent = iterator.next();
-
- if (policyComponent instanceof Policy) {
- // policy found for the id
-
- if (id.equals(((Policy) policyComponent).getId())) {
- return (Policy) policyComponent;
- }
- }
- }
-
- AxisDescription child;
-
- for (Iterator iterator = des.getChildren(); iterator.hasNext();) {
- child = (AxisDescription) iterator.next();
- policy = findPolicy(id, child);
-
- if (policy != null) {
- return policy;
- }
- }
-
- return null;
- }
-
- /**
- * Hack to get ?wsdl working with soap 1.2
- * Fixed in Axis2 1.3
- */
- private void patchSOAP12Port(AxisService as) throws AxisFault {
- Parameter wsld4jdefinition = as.getParameter(WSDLConstants.WSDL_4_J_DEFINITION);
- Definition definition = (Definition) wsld4jdefinition.getValue();
- setPortAddress(definition, null, as);
- }
-
- /**
- * This is a copy of the AxisService setPortAddress patched to work with SOAP 1.2 Addresses
- * Fixed in Axis2 1.3
- */
- private void setPortAddress(Definition definition, String requestIP, AxisService axisService) throws AxisFault {
- Iterator serviceItr = definition.getServices().values().iterator();
- while (serviceItr.hasNext()) {
- Service serviceElement = (Service) serviceItr.next();
- Iterator portItr = serviceElement.getPorts().values().iterator();
- while (portItr.hasNext()) {
- Port port = (Port) portItr.next();
- List list = port.getExtensibilityElements();
- for (int i = 0; i < list.size(); i++) {
- Object extensibilityEle = list.get(i);
- String locationURI = null;
- if (requestIP == null) {
- locationURI = axisService.getEPRs()[0];
- } else {
-// can't do this as the method's not visible, but Tuscany doesn't use this path anyway
-// locationURI = axisService.getEPRs(requestIP)[0]);
- }
- if (extensibilityEle instanceof SOAPAddress) {
- ((SOAPAddress) extensibilityEle).setLocationURI(locationURI);
- } else if (extensibilityEle instanceof SOAP12Address) {
- ((SOAP12Address) extensibilityEle).setLocationURI(locationURI);
- }
- }
- }
- }
- }
-
}