gdaniels 2002/10/14 06:11:17
Modified: java/src/org/apache/axis/client Call.java
java/src/org/apache/axis/soap SOAP12Constants.java
java/src/org/apache/axis/transport/http HTTPSender.java
Log:
Enable SOAP 1.2 webmethod feature.
Use it like this:
Call call = new Call("http://localhost/~glen/soap.xml");
call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);
call.setScopedProperty("soap12.webMethod", "GET");
call.invoke();
SOAPEnvelope env = call.getResponseMessage().getSOAPEnvelope();
Code changes:
- Allow Call to proceed with a null requestMessage in the MC
- Refactor HTTPSender a bit, check for SOAP1.2+webmethod, and
respect what's in the MC if we find anything.
For now, I avoided any kind of "map a SOAP request with parameters into
a URL", and just went with passing the URL you want directly into Call,
since that seemed the easiest way to get the feature implemented. We
can expand on this later if desired.
Revision Changes Path
1.185 +24 -21 xml-axis/java/src/org/apache/axis/client/Call.java
Index: Call.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Call.java,v
retrieving revision 1.184
retrieving revision 1.185
diff -u -r1.184 -r1.185
--- Call.java 11 Oct 2002 21:16:11 -0000 1.184
+++ Call.java 14 Oct 2002 13:11:16 -0000 1.185
@@ -200,9 +200,6 @@
// The desired return Java type, so we can do conversions if needed
private Class returnJavaType = null;
- // If a parameter is sent as a header, this flag will be set to true;
- private boolean headerParameters = false;
-
public static final String SEND_TYPE_ATTR = "send_type_attr" ;
public static final String TRANSPORT_NAME = "transport_name" ;
public static final String TRANSPORT_PROPERTY= "java.protocol.handler.pkgs";
@@ -2173,19 +2170,22 @@
} else {
// No direct config, so try the namespace of the first body.
reqMsg = msgContext.getRequestMessage();
- reqEnv = reqMsg.getSOAPEnvelope();
- SOAPBodyElement body = reqEnv.getFirstBody();
+ if (reqMsg != null) {
+ reqEnv = reqMsg.getSOAPEnvelope();
- // Does this make any sense to anyone? If not, we should remove it.
- // --Glen 03/16/02
- //if ( body.getPrefix() == null ) body.setPrefix( "m" );
- if ( body.getNamespaceURI() == null ) {
- throw new AxisFault("Call.invoke",
- Messages.getMessage("cantInvoke00",
body.getName()),
- null, null);
- } else {
- msgContext.setTargetService(body.getNamespaceURI());
+ SOAPBodyElement body = reqEnv.getFirstBody();
+
+ // Does this make any sense to anyone? If not, we should
remove it.
+ // --Glen 03/16/02
+ //if ( body.getPrefix() == null ) body.setPrefix( "m" );
+ if ( body.getNamespaceURI() == null ) {
+ throw new AxisFault("Call.invoke",
+ Messages.getMessage("cantInvoke00",
body.getName()),
+ null, null);
+ } else {
+ msgContext.setTargetService(body.getNamespaceURI());
+ }
}
}
@@ -2201,13 +2201,16 @@
msgContext.getTargetService()));
}
- reqEnv = msgContext.getRequestMessage().getSOAPEnvelope();
-
- // If we have headers to insert, do so now.
- for (int i = 0 ; myHeaders != null && i < myHeaders.size() ; i++ ) {
- reqEnv.addHeader((SOAPHeaderElement)myHeaders.get(i));
+ Message requestMessage = msgContext.getRequestMessage();
+ if (requestMessage != null) {
+ reqEnv = requestMessage.getSOAPEnvelope();
+
+ // If we have headers to insert, do so now.
+ for (int i = 0 ; myHeaders != null && i < myHeaders.size() ; i++ ) {
+ reqEnv.addHeader((SOAPHeaderElement)myHeaders.get(i));
+ }
}
-
+
// set up transport if there is one
if (transport != null) {
transport.setupMessageContext(msgContext, this, service.getEngine());
@@ -2282,7 +2285,7 @@
Thread thread = new Thread(runnable);
thread.start();
}
-
+
/**
* Get the output parameters (if any) from the last invocation.
*
1.7 +5 -0 xml-axis/java/src/org/apache/axis/soap/SOAP12Constants.java
Index: SOAP12Constants.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/soap/SOAP12Constants.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SOAP12Constants.java 23 Aug 2002 19:07:19 -0000 1.6
+++ SOAP12Constants.java 14 Oct 2002 13:11:17 -0000 1.7
@@ -72,6 +72,11 @@
Constants.ELEM_FAULT);
private static QName roleQName = new QName(Constants.URI_SOAP12_ENV,
Constants.ATTR_ROLE);
+
+ // Public constants for SOAP 1.2
+
+ /** MessageContext property name for webmethod */
+ public static final String PROP_WEBMETHOD = "soap12.webmethod";
public String getEnvelopeURI() {
return Constants.URI_SOAP12_ENV;
1.89 +157 -144 xml-axis/java/src/org/apache/axis/transport/http/HTTPSender.java
Index: HTTPSender.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/transport/http/HTTPSender.java,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- HTTPSender.java 8 Oct 2002 22:23:59 -0000 1.88
+++ HTTPSender.java 14 Oct 2002 13:11:17 -0000 1.89
@@ -58,13 +58,14 @@
import org.apache.axis.Constants;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
+import org.apache.axis.soap.SOAP12Constants;
+import org.apache.axis.soap.SOAPConstants;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.components.net.BooleanHolder;
import org.apache.axis.components.net.SocketFactory;
import org.apache.axis.components.net.SocketFactoryFactory;
import org.apache.axis.encoding.Base64;
import org.apache.axis.handlers.BasicHandler;
-import org.apache.axis.utils.JavaUtils;
import org.apache.axis.utils.Messages;
import org.apache.commons.logging.Log;
@@ -119,11 +120,13 @@
}
// Send the SOAP request to the server
- InputStream inp= writeToSocket(sock, msgContext, targetURL,
+ InputStream inp = writeToSocket(sock, msgContext, targetURL,
otherHeaders, host, port, useFullURL);
// Read the response back from the server
- readFromSocket(sock, msgContext, inp, null);
+ Hashtable headers = new Hashtable();
+ inp = readHeadersFromSocket(sock, msgContext, inp, headers);
+ readFromSocket(sock, msgContext, inp, headers);
} catch (Exception e) {
log.debug(e);
throw AxisFault.makeFault(e);
@@ -177,7 +180,6 @@
String userID = null;
String passwd = null;
String reqEnv = null;
- InputStream inp= null; //In case it is necessary to read before the full
respose.
userID = msgContext.getUsername();
passwd = msgContext.getPassword();
@@ -231,10 +233,23 @@
.append(cookie2).append("\r\n");
}
}
+
StringBuffer header = new StringBuffer();
- // byte[] request = reqEnv.getBytes();
- header.append(HTTPConstants.HEADER_POST).append(" ");
+ String webMethod = null;
+ boolean posting = true;
+
+ // If we're SOAP 1.2, allow the web method to be set from the
+ // MessageContext.
+ if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS)
+ webMethod = msgContext.getStrProp(SOAP12Constants.PROP_WEBMETHOD);
+ if (webMethod == null) {
+ webMethod = HTTPConstants.HEADER_POST;
+ } else {
+ posting = webMethod.equals(HTTPConstants.HEADER_POST);
+ }
+
+ header.append(webMethod).append(" ");
if (useFullURL.value) {
header.append(tmpURL.toExternalForm());
} else {
@@ -244,8 +259,6 @@
: tmpURL.getFile()));
}
-
-
Message reqMessage = msgContext.getRequestMessage();
boolean http10 = true; //True if this is to use HTTP 1.0 / false HTTP 1.1
@@ -324,12 +337,14 @@
header.append(" ");
header.append(http10 ? HTTPConstants.HEADER_PROTOCOL_10 :
HTTPConstants.HEADER_PROTOCOL_11)
- .append("\r\n")
- .append(HTTPConstants.HEADER_CONTENT_TYPE)
- .append(": ")
- .append(reqMessage.getContentType(msgContext.getSOAPConstants()))
- .append("\r\n")
- .append( HTTPConstants.HEADER_ACCEPT ) //Limit to the types that
are meaningful to us.
+ .append("\r\n");
+ if (posting) {
+ header.append(HTTPConstants.HEADER_CONTENT_TYPE)
+ .append(": ")
+
.append(reqMessage.getContentType(msgContext.getSOAPConstants()))
+ .append("\r\n");
+ }
+ header.append( HTTPConstants.HEADER_ACCEPT ) //Limit to the types that are
meaningful to us.
.append( ": ")
.append( HTTPConstants.HEADER_ACCEPT_APPL_SOAP)
.append( ", ")
@@ -361,20 +376,22 @@
.append(action)
.append("\"\r\n");
- if (!httpChunkStream) {
- //Content length MUST be sent on HTTP 1.0 requests.
- header.append(HTTPConstants.HEADER_CONTENT_LENGTH)
- .append(": ")
- .append(reqMessage.getContentLength())
- .append("\r\n");
- } else {
- //Do http chunking.
- header.append(HTTPConstants.HEADER_TRANSFER_ENCODING)
- .append(": ")
- .append(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)
- .append("\r\n");
+ if (posting) {
+ if (!httpChunkStream) {
+ //Content length MUST be sent on HTTP 1.0 requests.
+ header.append(HTTPConstants.HEADER_CONTENT_LENGTH)
+ .append(": ")
+ .append(reqMessage.getContentLength())
+ .append("\r\n");
+ } else {
+ //Do http chunking.
+ header.append(HTTPConstants.HEADER_TRANSFER_ENCODING)
+ .append(": ")
+ .append(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)
+ .append("\r\n");
+ }
}
-
+
if (null != httpConnection) {
header.append(HTTPConstants.HEADER_CONNECTION);
header.append(": ");
@@ -389,36 +406,46 @@
header.append("\r\n"); //The empty line to start the BODY.
OutputStream out = sock.getOutputStream();
+
+ if (!posting) {
+ out.write(header.toString()
+ .getBytes(HTTPConstants.HEADER_DEFAULT_CHAR_ENCODING));
+ out.flush();
+ return null;
+ }
+
+ InputStream inp = null;
if (httpChunkStream) {
out.write(header.toString()
.getBytes(HTTPConstants.HEADER_DEFAULT_CHAR_ENCODING));
- if(httpContinueExpected ){ //We need to get a reply from the server as
to whether
- // it wants us send anything more.
- out.flush();
- Hashtable cheaders= new Hashtable ();
- inp=readFromSocket(sock, msgContext, null, cheaders);
- int returnCode= -1;
- Integer Irc=
(Integer)msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
- if(null != Irc) returnCode= Irc.intValue();
- if(100 == returnCode){ // got 100 we may continue.
- //Need todo a little msgContext house keeping....
- msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
- msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
- }
- else{ //If no 100 Continue then we must not send anything!
- String statusMessage= (String)
+ }
+
+ if(httpContinueExpected ){ //We need to get a reply from the server as to
whether
+ // it wants us send anything more.
+ out.flush();
+ Hashtable cheaders= new Hashtable ();
+ inp = readHeadersFromSocket(sock, msgContext, null, cheaders);
+ int returnCode= -1;
+ Integer Irc=
(Integer)msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
+ if(null != Irc) returnCode= Irc.intValue();
+ if(100 == returnCode){ // got 100 we may continue.
+ //Need todo a little msgContext house keeping....
+ msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
+ msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
+ }
+ else{ //If no 100 Continue then we must not send anything!
+ String statusMessage= (String)
msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
-
- AxisFault fault = new AxisFault("HTTP", "(" + returnCode+ ")" +
statusMessage, null, null);
-
- fault.setFaultDetailString(Messages.getMessage("return01",
- "" + returnCode, ""));
- throw fault;
- }
-
-
+
+ AxisFault fault = new AxisFault("HTTP", "(" + returnCode+ ")" +
statusMessage, null, null);
+
+ fault.setFaultDetailString(Messages.getMessage("return01",
+ "" + returnCode,
""));
+ throw fault;
}
+ }
+ if (httpChunkStream) {
ChunkedOutputStream chunkedOutputStream = new ChunkedOutputStream(out);
out = new BufferedOutputStream(chunkedOutputStream, 8 * 1024);
try {
@@ -429,35 +456,6 @@
out.flush();
chunkedOutputStream.eos();
} else {
- //No chunking...
- if(httpContinueExpected ){ //We need to get a reply from the server as
to whether
- // it wants us send anything more.
- out.flush();
- Hashtable cheaders= new Hashtable ();
- inp=readFromSocket(sock, msgContext, null, cheaders);
- int returnCode= -1;
- Integer Irc= (Integer)
msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
- if(null != Irc) returnCode= Irc.intValue();
- if(100 == returnCode){ // got 100 we may continue.
- //Need todo a little msgContext house keeping....
- msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE,
- null);
- msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE,
- null);
- }
- else{ //If no 100 Continue then we must not send anything!
- String statusMessage= (String)
-
msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
-
- AxisFault fault = new AxisFault("HTTP", "(" + returnCode+ ")" +
statusMessage, null, null);
-
- fault.setFaultDetailString(Messages.getMessage("return01",
- "" + returnCode, ""));
- throw fault;
- }
-
-
- }
out = new BufferedOutputStream(out, 8 * 1024);
try {
out.write(header.toString()
@@ -474,33 +472,24 @@
log.debug("---------------------------------------------------");
log.debug(header + reqEnv);
}
+
return inp;
}
-
- /**
- * Reads the SOAP response back from the server
- *
- * @param sock socket
- * @param msgContext message context
- *
- * @throws IOException
- */
- private InputStream readFromSocket(Socket sock, MessageContext
msgContext,InputStream inp, Hashtable headers )
+
+ private InputStream readHeadersFromSocket(Socket sock,
+ MessageContext msgContext,
+ InputStream inp,
+ Hashtable headers)
throws IOException {
- Message outMsg = null;
- byte b;
+ byte b = 0;
int len = 0;
int colonIndex = -1;
- boolean headersOnly= false;
- if(null != headers){
- headersOnly= true;
- }else{
- headers= new Hashtable();
- }
String name, value;
- String statusMessage = "";
int returnCode = 0;
if(null == inp) inp = new BufferedInputStream(sock.getInputStream());
+
+ if (headers == null)
+ headers = new Hashtable();
// Should help performance. Temporary fix only till its all stream oriented.
// Need to add logic for getting the version # and the return code
@@ -509,7 +498,6 @@
/* Logic to read HTTP response headers */
boolean readTooMuch = false;
- b = 0;
for (ByteArrayOutputStream buf = new ByteArrayOutputStream(4097); ;) {
if (!readTooMuch) {
b = (byte) inp.read();
@@ -572,18 +560,41 @@
returnCode = Integer.parseInt(tmp);
msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE,
new Integer(returnCode));
- statusMessage = name.substring(start + end + 1);
msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE,
- statusMessage);
+ name.substring(start + end + 1));
} else {
headers.put(name.toLowerCase(), value);
}
len = 0;
}
}
+
+ return inp;
+ }
- if(headersOnly){
- return inp;
+ /**
+ * Reads the SOAP response back from the server
+ *
+ * @param sock socket
+ * @param msgContext message context
+ *
+ * @throws IOException
+ */
+ private InputStream readFromSocket(Socket sock,
+ MessageContext msgContext,
+ InputStream inp,
+ Hashtable headers)
+ throws IOException {
+ Message outMsg = null;
+ byte b;
+
+ Integer rc = (Integer)msgContext.getProperty(
+ HTTPConstants.MC_HTTP_STATUS_CODE);
+ int returnCode = 0;
+ if (rc != null) {
+ returnCode = rc.intValue();
+ } else {
+ // No return code?? Should have one by now.
}
/* All HTTP headers have been read. */
@@ -607,52 +618,54 @@
while (-1 != (b = (byte) inp.read())) {
buf.write(b);
}
- AxisFault fault = new AxisFault("HTTP", "(" + returnCode + ")" +
statusMessage, null, null);
+ String statusMessage = msgContext.getStrProp(
+ HTTPConstants.MC_HTTP_STATUS_MESSAGE);
+ AxisFault fault = new AxisFault("HTTP", "(" + returnCode + ")" +
+ statusMessage, null, null);
fault.setFaultDetailString(Messages.getMessage("return01",
"" + returnCode, buf.toString()));
throw fault;
}
- if (b != -1) { // more data than just headers.
- String contentLocation =
- (String) headers
- .get(HTTPConstants.HEADER_CONTENT_LOCATION.toLowerCase());
-
- contentLocation = (null == contentLocation)
- ? null
- : contentLocation.trim();
-
- String contentLength =
- (String) headers
- .get(HTTPConstants.HEADER_CONTENT_LENGTH.toLowerCase());
-
- contentLength = (null == contentLength)
- ? null
- : contentLength.trim();
-
- String transferEncoding =
- (String) headers
- .get(HTTPConstants.HEADER_TRANSFER_ENCODING.toLowerCase());
- if (null != transferEncoding
- && transferEncoding.trim()
- .equals(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) {
- inp = new ChunkedInputStream(inp);
- }
-
- outMsg = new Message( new SocketInputStream(inp, sock), false,
contentType,
- contentLocation);
- outMsg.setMessageType(Message.RESPONSE);
- msgContext.setResponseMessage(outMsg);
- if (log.isDebugEnabled()) {
- if (null == contentLength) {
- log.debug("\n"
- + Messages.getMessage("no00", "Content-Length"));
- }
- log.debug("\n" + Messages.getMessage("xmlRecd00"));
- log.debug("-----------------------------------------------");
- log.debug((String) outMsg.getSOAPPartAsString());
- }
+ String contentLocation =
+ (String) headers
+ .get(HTTPConstants.HEADER_CONTENT_LOCATION.toLowerCase());
+
+ contentLocation = (null == contentLocation)
+ ? null
+ : contentLocation.trim();
+
+ String contentLength =
+ (String) headers
+ .get(HTTPConstants.HEADER_CONTENT_LENGTH.toLowerCase());
+
+ contentLength = (null == contentLength)
+ ? null
+ : contentLength.trim();
+
+ String transferEncoding =
+ (String) headers
+ .get(HTTPConstants.HEADER_TRANSFER_ENCODING.toLowerCase());
+ if (null != transferEncoding
+ && transferEncoding.trim()
+ .equals(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) {
+ inp = new ChunkedInputStream(inp);
+ }
+
+
+ outMsg = new Message( new SocketInputStream(inp, sock), false,
+ contentType, contentLocation);
+ outMsg.setMessageType(Message.RESPONSE);
+ msgContext.setResponseMessage(outMsg);
+ if (log.isDebugEnabled()) {
+ if (null == contentLength) {
+ log.debug("\n"
+ + Messages.getMessage("no00", "Content-Length"));
+ }
+ log.debug("\n" + Messages.getMessage("xmlRecd00"));
+ log.debug("-----------------------------------------------");
+ log.debug((String) outMsg.getSOAPPartAsString());
}
// if we are maintaining session state,