You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2006/04/08 12:58:00 UTC
svn commit: r392503 - in /webservices/axis2/trunk/java/modules:
core/src/org/apache/axis2/description/AxisService.java
core/src/org/apache/axis2/description/AxisService2OM.java
java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java
Author: deepal
Date: Sat Apr 8 03:57:56 2006
New Revision: 392503
URL: http://svn.apache.org/viewcvs?rev=392503&view=rev
Log:
-HTTP post binding
- will generate HTTP binding only if user set the following parameter in axis2.xml
<parameter name=""enableREST>true</parameter>
-in the war case we enable that by default
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java?rev=392503&r1=392502&r2=392503&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java Sat Apr 8 03:57:56 2006
@@ -20,7 +20,6 @@
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.deployment.util.PhasesInfo;
@@ -33,6 +32,7 @@
import org.apache.axis2.transport.TransportListener;
import org.apache.axis2.util.PolicyUtil;
import org.apache.axis2.util.XMLUtils;
+import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.commons.schema.XmlSchema;
@@ -464,81 +464,9 @@
}
}
String eprArray [] = (String[]) eprList.toArray(new String[eprList.size()]);
-// if (getWSDLDefinition() != null) {
-// printUsingWSDLDefinition(out, eprArray);
-// } else {
getWSDL(out, eprArray);
-// }
}
-// private void printUsingWSDLDefinition(OutputStream out, String [] serviceURL) throws AxisFault {
-// try {
-// Definition wsdlDefinition = getWSDLDefinition();
-// Iterator itr_bindings = wsdlDefinition.getBindings().values().iterator();
-// Binding binding = null;
-// while (itr_bindings.hasNext()) {
-// binding = (Binding) itr_bindings.next();
-// binding.getExtensibilityElements().clear();
-// javax.wsdl.extensions.soap.SOAPBinding soapBinding = new SOAPBindingImpl();
-// soapBinding.setStyle("document");
-// soapBinding.setTransportURI(Constants.URI_SOAP11_HTTP);
-// binding.addExtensibilityElement(soapBinding);
-//
-// Iterator bin_ops = binding.getBindingOperations().iterator();
-// while (bin_ops.hasNext()) {
-// BindingOperation bindingOperation = (BindingOperation) bin_ops.next();
-// bindingOperation.getExtensibilityElements().clear();
-// javax.wsdl.extensions.soap.SOAPOperation soapOperation = new SOAPOperationImpl();
-// soapOperation.setStyle("document");
-// soapOperation.setSoapActionURI(bindingOperation.getName());
-// bindingOperation.addExtensibilityElement(soapOperation);
-//
-// BindingInput input = bindingOperation.getBindingInput();
-// if (input != null) {
-// input.getExtensibilityElements().clear();
-// javax.wsdl.extensions.soap.SOAPBody soapBody = new SOAPBodyImpl();
-// soapBody.setUse("literal");
-// soapBody.setNamespaceURI(getTargetNamespace());
-// input.addExtensibilityElement(soapBody);
-// }
-// BindingOutput output = bindingOperation.getBindingOutput();
-// if (output != null) {
-// output.getExtensibilityElements().clear();
-// javax.wsdl.extensions.soap.SOAPBody soapBody = new SOAPBodyImpl();
-// soapBody.setUse("literal");
-// soapBody.setNamespaceURI(getTargetNamespace());
-// output.addExtensibilityElement(soapBody);
-// }
-// }
-// }
-//
-// Collection services = wsdlDefinition.getServices().values();
-//
-// for (Iterator iterator = services.iterator(); iterator.hasNext();) {
-// Service service = (Service) iterator.next();
-// service.getPorts().values().clear();
-//
-// for (int i = 0; i < serviceURL.length; i++) {
-// String url = serviceURL[i];
-// Port port = new PortImpl();
-// SOAPAddress soapAddress = new SOAPAddressImpl();
-//
-// soapAddress.setElementType(SOAPConstants.Q_ELEM_SOAP_ADDRESS);
-// soapAddress.setLocationURI(url);
-// port.addExtensibilityElement(soapAddress);
-// port.setName(getName() + "Port" + i);
-// port.setBinding(binding);
-// service.addPort(port);
-// }
-// }
-//
-// WSDLFactory.newInstance().newWSDLWriter().writeWSDL(wsdlDefinition, out);
-// out.flush();
-// } catch (Exception e) {
-// throw new AxisFault(e);
-// }
-// }
-
private void getWSDL(OutputStream out, String [] serviceURL) throws AxisFault {
AxisService2OM axisService2WOM = new AxisService2OM(this, serviceURL, "document", "literal");
try {
@@ -546,14 +474,6 @@
wsdlElement.serialize(out);
out.flush();
out.close();
-//
-// // populate it with policy information ..
-// PolicyUtil.populatePolicy(desc, this);
-//
-// WOMWriter womWriter = WOMWriterFactory.createWriter(WSDLConstants.WSDL_1_1);
-// womWriter.setdefaultWSDLPrefix("wsdl");
-// womWriter.writeWOM(desc, out);
-
} catch (Exception e) {
throw new AxisFault(e);
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java?rev=392503&r1=392502&r2=392503&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java Sat Apr 8 03:57:56 2006
@@ -5,9 +5,9 @@
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.ws.java2wsdl.Java2WSDLConstants;
-import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.axis2.wsdl.SOAPHeaderMessage;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.ws.java2wsdl.Java2WSDLConstants;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
@@ -44,11 +44,14 @@
private String targetNamespace;
private OMNamespace soap;
private OMNamespace soap12;
+ private OMNamespace http;
+ private OMNamespace mime;
private OMNamespace tns;
private OMNamespace wsdl;
private String style;
private String use;
+ private boolean generateHttp = false;
public AxisService2OM(AxisService service,
String [] serviceURL, String style, String use) {
@@ -84,6 +87,8 @@
}
soap = ele.declareNamespace(URI_WSDL11_SOAP, SOAP11_PREFIX);
soap12 = ele.declareNamespace(URI_WSDL12_SOAP, SOAP12_PREFIX);
+ http = ele.declareNamespace(HTTP_NAMESPACE, HTTP_PREFIX);
+ mime = ele.declareNamespace(MIME_NAMESPACE, MIME_PREFIX);
String prefix = getPrefix(axisService.getTargetNamespace());
if (prefix == null || "".equals(prefix)) {
prefix = DEFAULT_TARGET_NAMESPACE_PREFIX;
@@ -110,7 +115,20 @@
generatePortType(fac, ele);
generateSOAP11Binding(fac, ele);
generateSOAP12Binding(fac, ele);
+ //generateHttp
+ if (axisService.getParent() != null) {
+ AxisDescription axisdesc = axisService.getParent().getParent();
+ Parameter parameter = axisdesc.getParameter("enableREST");
+ if (parameter != null) {
+ Object value = parameter.getValue();
+ if ("true".equals(value.toString())) {
+ generateHttp = true;
+ generatePostBinding(fac, ele);
+ }
+ }
+ }
generateService(fac, ele);
+
return ele;
}
@@ -273,6 +291,9 @@
service.addAttribute(ATTRIBUTE_NAME, axisService.getName(), null);
generateSOAP11Port(fac, service);
generateSOAP12Port(fac, service);
+ if (generateHttp) {
+ generateHTTPPort(fac, service);
+ }
}
private void generateSOAP11Port(OMFactory fac, OMElement service) throws Exception {
@@ -288,6 +309,22 @@
}
}
+ private void generateHTTPPort(OMFactory fac, OMElement service) throws Exception {
+ for (int i = 0; i < url.length; i++) {
+ String urlString = url[i];
+ if (urlString.startsWith("http")) {
+ OMElement port = fac.createOMElement(PORT, wsdl);
+ service.addChild(port);
+ port.addAttribute(ATTRIBUTE_NAME, axisService.getName() + HTTP_PORT + i, null);
+ port.addAttribute(BINDING_LOCAL_NAME, tns.getPrefix() + ":" +
+ axisService.getName() + HTTP_BINDING, null);
+ OMElement extElement = fac.createOMElement("address", http);
+ port.addChild(extElement);
+ extElement.addAttribute("location", urlString, null);
+ }
+ }
+ }
+
private void generateSOAP12Port(OMFactory fac, OMElement service) throws Exception {
for (int i = 0; i < url.length; i++) {
String urlString = url[i];
@@ -464,6 +501,73 @@
fault.addAttribute(ATTRIBUTE_NAME, faultyMessge.getName(), null);
operation.addChild(fault);
writeSoapHeaders(faultyMessge, fac, fault, soap12);
+ }
+ }
+ }
+ }
+
+ private void generatePostBinding(OMFactory fac,
+ OMElement defintions) throws Exception {
+ OMElement binding = fac.createOMElement(BINDING_LOCAL_NAME, wsdl);
+ defintions.addChild(binding);
+ binding.addAttribute(ATTRIBUTE_NAME, axisService.getName() + HTTP_BINDING, null);
+ binding.addAttribute("type", tns.getPrefix() + ":" + axisService.getName() + PORT_TYPE_SUFFIX, null);
+
+ //Adding ext elements
+ OMElement httpBinding = fac.createOMElement("binding", http);
+ binding.addChild(httpBinding);
+ httpBinding.addAttribute("verb", "POST", null);
+
+ Iterator operations = axisService.getOperations();
+ while (operations.hasNext()) {
+ AxisOperation axisOperation = (AxisOperation) operations.next();
+ if (axisOperation.isControlOperation()) {
+ continue;
+ }
+ String opeartionName = axisOperation.getName().getLocalPart();
+ OMElement operation = fac.createOMElement(OPERATION_LOCAL_NAME, wsdl);
+ binding.addChild(operation);
+
+ OMElement httpOperation = fac.createOMElement("operation", http);
+ operation.addChild(httpOperation);
+ httpOperation.addAttribute("location", axisOperation.getName().getLocalPart(), null);
+
+
+ String MEP = axisOperation.getMessageExchangePattern();
+
+ if (WSDLConstants.MEP_URI_IN_ONLY.equals(MEP) ||
+ WSDLConstants.MEP_URI_IN_OPTIONAL_OUT.equals(MEP) ||
+ WSDLConstants.MEP_URI_OUT_OPTIONAL_IN.equals(MEP) ||
+ WSDLConstants.MEP_URI_ROBUST_OUT_ONLY.equals(MEP) ||
+ WSDLConstants.MEP_URI_ROBUST_IN_ONLY.equals(MEP) ||
+ WSDLConstants.MEP_URI_IN_OUT.equals(MEP)) {
+ AxisMessage inaxisMessage = axisOperation
+ .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ if (inaxisMessage != null) {
+ operation.addAttribute(ATTRIBUTE_NAME, opeartionName, null);
+ OMElement input = fac.createOMElement(IN_PUT_LOCAL_NAME, wsdl);
+ OMElement inputelement = fac.createOMElement("content", mime);
+ input.addChild(inputelement);
+ inputelement.addAttribute("type", "text/xml", null);
+ operation.addChild(input);
+ }
+ }
+
+ if (WSDLConstants.MEP_URI_OUT_ONLY.equals(MEP) ||
+ WSDLConstants.MEP_URI_OUT_OPTIONAL_IN.equals(MEP) ||
+ WSDLConstants.MEP_URI_IN_OPTIONAL_OUT.equals(MEP) ||
+ WSDLConstants.MEP_URI_ROBUST_OUT_ONLY.equals(MEP) ||
+ WSDLConstants.MEP_URI_ROBUST_IN_ONLY.equals(MEP) ||
+ WSDLConstants.MEP_URI_IN_OUT.equals(MEP)) {
+ AxisMessage outAxisMessage = axisOperation
+ .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+ if (outAxisMessage != null) {
+ OMElement output = fac.createOMElement(OUT_PUT_LOCAL_NAME, wsdl);
+ OMElement outElement = fac.createOMElement("content", mime);
+ outElement.addChild(outElement);
+ outElement.addAttribute("type", "text/xml", null);
+ operation.addChild(output);
+ writeSoapHeaders(outAxisMessage, fac, output, soap12);
}
}
}
Modified: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java?rev=392503&r1=392502&r2=392503&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java (original)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java Sat Apr 8 03:57:56 2006
@@ -36,8 +36,14 @@
String TRANSPORT_URI = "http://schemas.xmlsoap.org/soap/http";
String DEFAULT_LOCATION_URL = "http://localhost:8080/axis2/services/";
+ String HTTP_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/http/";
+ String MIME_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/mime/";
+ String HTTP_PREFIX = "http";
+ String MIME_PREFIX = "mime";
+
String BINDING_NAME_SUFFIX = "SOAP11Binding";
String SOAP12BINDING_NAME_SUFFIX = "SOAP12Binding";
+ String HTTP_BINDING = "HttpBinding";
String PORT_TYPE_SUFFIX = "PortType";
String PORT_NAME_SUFFIX = "Port";
String MESSAGE_LOCAL_NAME = "message";
@@ -56,6 +62,7 @@
String PORT = "port";
String SOAP12PORT = "SOAP12port";
String SOAP11PORT = "SOAP11port";
+ String HTTP_PORT = "Httpport";
String PART_ATTRIBUTE_NAME = "part";
String ELEMENT_ATTRIBUTE_NAME = "element";
String FAULT_LOCAL_NAME = "fault";