I download the CMS source code,and modified the TcpSocket::connect function
in TcpSocket.cpp in order to tunnel http proxy.Below is the code I modified
or added:
void TcpSocket::connect(const char* host, int port, int timeout) throw (
SocketException ) {
try{
if( isConnected() ) {
throw SocketException( __FILE__, __LINE__,
"Socket::connect - Socket already connected. host: %s,
port: %d", host, port );
}
// Create the Address data
checkResult( apr_sockaddr_info_get(
&socketAddress, HTTP_PROXY_IP, APR_INET, HTTP_PROXY_PORT, 0,
apr_pool.getAprPool() ) );
// Create the actual socket.
checkResult( apr_socket_create(
&socketHandle, socketAddress->family, SOCK_STREAM,
APR_PROTO_TCP, apr_pool.getAprPool() ) );
// To make blocking-with-timeout sockets, we have to set it to
// 'APR_SO_NONBLOCK==1(on) and timeout>0'. On Unix, we have no
// problem to specify 'APR_SO_NONBLOCK==0(off) and timeout>0'.
// Unfortunately, we have a problem on Windows. Setting the
// mode to 'APR_SO_NONBLOCK==0(off) and timeout>0' causes
// blocking-with-system-timeout sockets on Windows.
//
//
http://dev.ariel-networks.com/apr/apr-tutorial/html/apr-tutorial-13.html
// If we have a connection timeout specified, temporarily set the
socket to
// non-blocking so that we can timeout the connect operation. We'll
restore
// to blocking mode right after we connect.
apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, (timeout>0)?1:0
);
apr_socket_timeout_set( socketHandle, timeout );
// try to Connect to the provided address.
checkResult(apr_socket_connect( socketHandle, socketAddress ));
// Now that we are connected, we want to go back to blocking.
apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, 0 );
apr_socket_timeout_set( socketHandle, -1 );
char sHeader[256];
sprintf(sHeader,"CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n\r\n",
host,port,host,port);
apr_size_t size = strlen(sHeader)+1;
apr_socket_send(socketHandle, sHeader, &size);
char buf[256];
size = 256;
apr_socket_recv(socketHandle, buf, &size);
printf("Connect result:%s",buf);
//the data received:HTTP/1.0 200 Connection
established
std::string strBuf = strupr(buf);
if (!strBuf.substr(0, 4).compare("http") && strBuf.find("200")
> 0 )
{
//connect remote server via http proxy
successfully!
}
// Create an input/output stream for this socket.
inputStream = new SocketInputStream( socketHandle );
outputStream = new SocketOutputStream( socketHandle );
} catch( SocketException& ex ) {
ex.setMark( __FILE__, __LINE__);
try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
throw ex;
} catch( ... ) {
try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
throw SocketException(
__FILE__, __LINE__,
"TcpSocket::connect() - caught unknown exception" );
}
}
printf("Connect result:%s",buf); shows this:
Connect result:HTTP/1.0 200 Connection established which means TCP socket
connect remote server via http proxy successfully.
Unfortunately some exception was throwed:
CMSException:OpenWireFormatNegotiator::oneway Wire format negotiation
timeout: peer did not send his wire format.
FILE:
..\src\main\activemq\wireformat\openwire\OpenWireFormatNegotiator.cpp, LINE:
71
FILE:
..\src\main\activemq\wireformat\openwire\OpenWireFormatNegotiator.cpp, LINE:
80
FILE: ..\src\main\activemq\transport\correlator\ResponseCorrelator.cpp,
LINE: 131
FILE: ..\src\main\activemq\core\ActiveMQConnection.cpp, LINE: 629
FILE: ..\src\main\activemq\core\ActiveMQConnection.cpp, LINE: 326
FILE: ..\src\main\activemq\core\ActiveMQConnectionFactory.cpp, LINE: 151
It seems like that the data sent via http proxy is not the right format(open
wire format).
My questions are:
1. Is it the right way(the code I modified) to link remote MQ server via
HTTP proxy?
2. If the way is right,how to resolve the data format problem?
Any help will be appreciated!
--
View this message in context:
http://old.nabble.com/Try-to-link-MQ-server-via-http-proxy%2Cbut-data-format-seems-is-wrong...-tp28978532p28978532.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.