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 di...@apache.org on 2004/03/23 14:11:49 UTC
cvs commit: ws-axis/java/src/org/apache/axis/transport/http SocketHolder.java HTTPSender.java
dims 2004/03/23 05:11:49
Modified: java/src/org/apache/axis/transport/http HTTPSender.java
Added: java/src/org/apache/axis/transport/http SocketHolder.java
Log:
Fix for multithread test failures. we cannot store the Socket as a member variable since we seem to use one instance of HTTPSender.
Revision Changes Path
1.112 +22 -22 ws-axis/java/src/org/apache/axis/transport/http/HTTPSender.java
Index: HTTPSender.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/transport/http/HTTPSender.java,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -r1.111 -r1.112
--- HTTPSender.java 22 Mar 2004 03:45:42 -0000 1.111
+++ HTTPSender.java 23 Mar 2004 13:11:49 -0000 1.112
@@ -61,11 +61,6 @@
URL targetURL;
/**
- * Socket
- */
- Socket sock;
-
- /**
* invoke creates a socket connection, sends the request SOAP message and then
* reads the response SOAP message back from the SOAP server
*
@@ -85,14 +80,16 @@
String host = targetURL.getHost();
int port = targetURL.getPort();
+ SocketHolder socketHolder = new SocketHolder(null);
+
// Send the SOAP request to the server
- InputStream inp = writeToSocket(msgContext, targetURL,
+ InputStream inp = writeToSocket(socketHolder, msgContext, targetURL,
otherHeaders, host, port, useFullURL);
// Read the response back from the server
Hashtable headers = new Hashtable();
- inp = readHeadersFromSocket(msgContext, inp, headers);
- readFromSocket(msgContext, inp, headers);
+ inp = readHeadersFromSocket(socketHolder, msgContext, inp, headers);
+ readFromSocket(socketHolder, msgContext, inp, headers);
} catch (Exception e) {
log.debug(e);
throw AxisFault.makeFault(e);
@@ -112,16 +109,16 @@
* @param otherHeaders buffer for storing additional headers that need to be sent
* @param useFullURL flag to indicate if the complete URL has to be sent
*
- * @return the socket
- *
* @throws IOException
*/
- private Socket getSocket(
+ private void getSocket(
+ SocketHolder sockHolder,
String protocol,
String host, int port, StringBuffer otherHeaders, BooleanHolder useFullURL)
throws Exception {
SocketFactory factory = SocketFactoryFactory.getFactory(protocol, getOptions());
- return factory.create(host, port, otherHeaders, useFullURL);
+ Socket sock = factory.create(host, port, otherHeaders, useFullURL);
+ sockHolder.setSocket(sock);
}
/**
@@ -136,7 +133,8 @@
*
* @throws IOException
*/
- private InputStream writeToSocket(MessageContext msgContext, URL tmpURL,
+ private InputStream writeToSocket(SocketHolder sockHolder,
+ MessageContext msgContext, URL tmpURL,
StringBuffer otherHeaders, String host, int port,
BooleanHolder useFullURL)
throws Exception {
@@ -376,14 +374,14 @@
header.append("\r\n"); //The empty line to start the BODY.
- sock = getSocket(targetURL.getProtocol(), host, port, otherHeaders, useFullURL);
+ getSocket(sockHolder, targetURL.getProtocol(), host, port, otherHeaders, useFullURL);
// optionally set a timeout for the request
if (msgContext.getTimeout() != 0) {
- sock.setSoTimeout(msgContext.getTimeout());
+ sockHolder.getSocket().setSoTimeout(msgContext.getTimeout());
}
- OutputStream out = sock.getOutputStream();
+ OutputStream out = sockHolder.getSocket().getOutputStream();
if (!posting) {
out.write(header.toString()
@@ -403,7 +401,7 @@
// it wants us send anything more.
out.flush();
Hashtable cheaders= new Hashtable ();
- inp = readHeadersFromSocket(msgContext, null, cheaders);
+ inp = readHeadersFromSocket(sockHolder, msgContext, null, cheaders);
int returnCode= -1;
Integer Irc= (Integer)msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
if(null != Irc) {
@@ -464,7 +462,8 @@
return inp;
}
- private InputStream readHeadersFromSocket(MessageContext msgContext,
+ private InputStream readHeadersFromSocket(SocketHolder sockHolder,
+ MessageContext msgContext,
InputStream inp,
Hashtable headers)
throws IOException {
@@ -474,7 +473,7 @@
String name, value;
int returnCode = 0;
if(null == inp) {
- inp = new BufferedInputStream(sock.getInputStream());
+ inp = new BufferedInputStream(sockHolder.getSocket().getInputStream());
}
if (headers == null) {
@@ -569,7 +568,8 @@
*
* @throws IOException
*/
- private InputStream readFromSocket(MessageContext msgContext,
+ private InputStream readFromSocket(SocketHolder socketHolder,
+ MessageContext msgContext,
InputStream inp,
Hashtable headers)
throws IOException {
@@ -617,7 +617,7 @@
// Temporary Redirect (HTTP: 307)
// close old connection
inp.close();
- sock.close();
+ socketHolder.getSocket().close();
// remove former result and set new target url
msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
msgContext.setProperty(MessageContext.TRANS_URL, location);
@@ -675,7 +675,7 @@
}
- outMsg = new Message( new SocketInputStream(inp, sock), false,
+ outMsg = new Message( new SocketInputStream(inp, socketHolder.getSocket()), false,
contentType, contentLocation);
// Transfer HTTP headers of HTTP message to MIME headers of SOAP message
MimeHeaders mimeHeaders = outMsg.getMimeHeaders();
1.1 ws-axis/java/src/org/apache/axis/transport/http/SocketHolder.java
Index: SocketHolder.java
===================================================================
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.axis.transport.http;
import java.net.Socket;
/**
* hold a Socket.
* @author Davanum Srinivas (dims@yahoo.com)
*/
public class SocketHolder {
/** Field value */
private Socket value = null;
public SocketHolder(Socket value) {
this.value = value;
}
public Socket getSocket() {
return value;
}
public void setSocket(Socket value) {
this.value = value;
}
}