You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by alanchb <al...@gmail.com> on 2010/08/09 12:19:45 UTC

Connect remote ActiveMQ server via HTTP PROXY failed!

I use CMS.

For the requirement of my project, I have to connect remote ActiveMQ server
via HTTP PROXY.But having tried some way for a period of time,I had no
progress and return here for help.

I modified the Connect function in TcpSocket.cpp so that the socket can
connect the remote server via HTTP PROXY,and the connection is OK.But after
that the communication with the sever will fail!Open command and TCP
tracing,below are printed:

SEND: WireFormatInfo { commandId = 0, responseRequired = false, Magic = [
Versio
n = 5, StackTraceEnabled = true, TcpNoDelayEnabled = true, CacheEnabled =
false,
 CacheSize = 1024, TightEncodingEnabled = true, SizePrefixDisabled = false,
MaxI
 nactivityDuration = 30000, MaxInactivityDuration = 10000 }
INFO: TCP Trace: Reading:
[0000 00d9 0141 6374 6976 654d 5100 0000 0501 0000 00c7 0000 0008 0009 4361
6368
 6553 697a 6505 0000 0400 000c 4361 6368 6545 6e61 626c 6564 0101 0012 5369
7a65
 5072 6566 6978 4469 7361 626c 6564 0100 0020 4d61 7849 6e61 6374 6976 6974
7944
 7572 6174 696f 6e49 6e69 7461 6c44 656c 6179 0600 0000 0000 0027 1000 1154
6370
 4e6f 4465 6c61 7945 6e61 626c 6564 0101 0015 4d61 7849 6e61 6374 6976 6974
7944
 7572 6174 696f 6e06 0000 0000 0000 7530 0014 5469 6768 7445 6e63 6f64 696e
6745
 6e61 626c 6564 0101 0011 5374 6163 6b54 7261 6365 456e 6162 6c65 6401 01]
len:
221 bytes - tid: 2960
INFO: TCP Trace: Writing:
[0000 00d9 0141 6374 6976 654d 5100 0000 0501 0000 00c7 0000 0008 000c 4361
6368
 6545 6e61 626c 6564 0100 0009 4361 6368 6553 697a 6505 0000 0400 0015 4d61
7849
 6e61 6374 6976 6974 7944 7572 6174 696f 6e06 0000 0000 0000 7530 0020 4d61
7849
 6e61 6374 6976 6974 7944 7572 6174 696f 6e49 6e69 7461 6c44 656c 6179 0600
0000
 0000 0027 1000 1253 697a 6550 7265 6669 7844 6973 6162 6c65 6401 0000 1153
7461
 636b 5472 6163 6545 6e61 626c 6564 0101 0011 5463 704e 6f44 656c 6179 456e
6162
 6c65 6401 0100 1454 6967 6874 456e 636f 6469 6e67 456e 6162 6c65 6401 01]
len:
221 bytes - tid: 4336
RECV: WireFormatInfo { commandId = 0, responseRequired = false, Magic = [
Versio
n = 5, StackTraceEnabled = true, TcpNoDelayEnabled = true, CacheEnabled =
true, 
CacheSize = 1024, TightEncodingEnabled = true, SizePrefixDisabled = false,
MaxIn
activityDuration = 30000, MaxInactivityDuration = 10000 }

INFO: TCP Trace: Writing:
[00] len: 1 bytes - tid: 4336
INFO: TCP Trace: Writing:
[00] len: 1 bytes - tid: 4336
INFO: TCP Trace: Writing:
[00] len: 1 bytes - tid: 4336
INFO: TCP Trace: Writing:
[d9] len: 1 bytes - tid: 4336
INFO: TCP Trace: Writing:
[01] len: 1 bytes - tid: 4336
INFO: TCP Trace: Writing:
[41] len: 1 bytes - tid: 4336
decaf::net::TcpScketOutputStream::write - An established connection was
aborted by the software in your host machine
        FILE: ..\src\main\decaf\internal\net\tcp\TcpSocket.cpp, LINE: 832
        FILE: ..\src\main\decaf\internal\net\tcp\TcpSocket.cpp, LINE: 842
        FILE: ..\src\main\decaf\internal\net\tcp\TcpSocketOutputStream.cpp,
LINE: 104
        FILE: .

If I connect a common TCP server(write by myself,port is also 61616) via the
same HTTP PROXY by the same way,I can send and receive data successfully
with that server.

Have any idea based on the above infomation?Is it possible to connect
ActiveMQ server via HTTP PROXY or other PROXY?

Thanks for any help!!!

Below is the connect function I modifield:

void TcpSocket::connect( const std::string& hostname, int port, int timeout
)
throw( decaf::io::IOException,
	  decaf::net::SocketException,
	  decaf::lang::exceptions::IllegalArgumentException ) {

		  try{

			  if( port < 0 || port > 65535 ) {
				  throw IllegalArgumentException(
					  __FILE__, __LINE__, "Given port is out of range: %d", port );
			  }

			  if( this->socketHandle == NULL ) {
				  throw IOException(
					  __FILE__, __LINE__, "The socket was not yet created." );
			  }

			  // Create the Address data
			  //checkResult( apr_sockaddr_info_get(
			  // &remoteAddress, hostname.c_str(), APR_INET, (apr_port_t)port, 0,
apr_pool.getAprPool() ) );
			  checkResult( apr_sockaddr_info_get(
				  &remoteAddress, "x.x.x.x", APR_INET, 8080, 0, apr_pool.getAprPool() )
);  //x.x.x.x is http proxy ip

			  int oldNonblockSetting = 0;
			  apr_interval_time_t oldTimeoutSetting = 0;

			  // Record the old settings.
			  apr_socket_opt_get( socketHandle, APR_SO_NONBLOCK, &oldNonblockSetting
);
			  apr_socket_timeout_get( socketHandle, &oldTimeoutSetting );

			  // Temporarily make it what we want, blocking.
			  apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, 0 );

			  // Timeout and non-timeout case require very different logic.
			  if( timeout <= 0 ) {
				  apr_socket_timeout_set( socketHandle, -1 );
			  } else {
				  apr_socket_timeout_set( socketHandle, timeout * 1000 );
			  }

			  // try to Connect to the provided address.
			  checkResult( apr_socket_connect( socketHandle, remoteAddress ) );

			  // Now that we are connected, we want to go back to old settings.
			  apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, oldNonblockSetting
);
			  apr_socket_timeout_set( socketHandle, oldTimeoutSetting );

			  std::string header;

			  char sHeader[256];
			  sprintf(sHeader,"CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n\r\n",
hostname.c_str(),port,hostname.c_str(),port);
			  header = sHeader;
			  printf("Connect string:%s",sHeader);

			  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);  //Connect result:HTTP/1.0 200
Connection established
			  // Now that we connected, cache the port value for later lookups.
			  this->port = port;

		  } catch( IOException& ex ) {
			  ex.setMark( __FILE__, __LINE__);
			  try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
			  throw ex;
		  } catch( IllegalArgumentException& ex ) {
			  ex.setMark( __FILE__, __LINE__);
			  try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
			  throw ex;
		  } catch( Exception& ex ) {
			  try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
			  throw SocketException( &ex );
		  } catch( ... ) {
			  try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
			  throw SocketException(
				  __FILE__, __LINE__,
				  "TcpSocket::connect() - caught unknown exception" );
		  }
}
-- 
View this message in context: http://old.nabble.com/Connect-remote-ActiveMQ-server-via-HTTP-PROXY-failed%21-tp29386426p29386426.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Connect remote ActiveMQ server via HTTP PROXY failed!

Posted by alanchb <al...@gmail.com>.
Anyone knows?
-- 
View this message in context: http://old.nabble.com/Connect-remote-ActiveMQ-server-via-HTTP-PROXY-failed%21-tp29386426p29446223.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.