displayMessage("Please provide a URL");
return;
}
// Create ConnectionFactory
final ConnectionFactory factory = new ConnectionFactory();
// Register as listener
factory.setConnectionAttemptListener(this);
// Set connection mode
switch (_connectionMode.getSelectedIndex()) {
case 0:
factory.setConnectionMode(ConnectionFactory.ACCESS_READ);
break;
case 1:
factory.setConnectionMode(ConnectionFactory.ACCESS_WRITE);
break;
case 2:
factory.setConnectionMode(ConnectionFactory.ACCESS_READ_WRITE);
break;
}
// Set connection timeout
factory.setTimeoutSupported(_timeoutSupported.getChecked());
factory.setEndToEndDesired(_endToEndDesired.getChecked());
factory.setEndToEndRequired(_endToEndRequired.getChecked());
try {
final String connectionTimeoutText = _connectionTimeout.getText();
if (connectionTimeoutText != null
&& connectionTimeoutText.trim().length() > 0) {
// Parse connection timeout text into long
final long connectionTimeout =
Long.parseLong(connectionTimeoutText);
if (connectionTimeout >= 0) {
// Set connection timeout value
factory.setConnectionTimeout(connectionTimeout);
}
}
} catch (final NumberFormatException nfe) {
displayMessage("Long.parseLong(String) threw : " + nfe.toString());
}
// Set connection security settings for tls/ssl
factory.setEndToEndDesired(_endToEndDesired.getChecked());
factory.setEndToEndRequired(_endToEndRequired.getChecked());
// Set time limit
final long timeLimit = Long.parseLong(_timeLimit.getText());
if (timeLimit > 0) {
factory.setTimeLimit(timeLimit);
}
// Set attempts limit
final int attemptsLimit = Integer.parseInt(_attemptsLimit.getText());
if (attemptsLimit > 0) {
factory.setAttemptsLimit(attemptsLimit);
}
// Set retry factor
final long retryFactor = Long.parseLong(_retryFactor.getText());
if (retryFactor > 0) {
factory.setRetryFactor(retryFactor);
}
// Set TCP Cellular options
if (_tcpApn.getText().trim().length() != 0
|| _tcpApnUser.getText().trim().length() != 0
|| _tcpApnPassword.getText().trim().length() != 0) {
final TcpCellularOptions tcpOptions = new TcpCellularOptions();
tcpOptions.setApn(_tcpApn.getText().trim());
tcpOptions.setTunnelAuthUsername(_tcpApnUser.getText().trim());
tcpOptions.setTunnelAuthPassword(_tcpApnPassword.getText().trim());
factory.setTransportTypeOptions(
TransportInfo.TRANSPORT_TCP_CELLULAR, tcpOptions);
}
// Set WAP Options
if (!_wapGatewayApn.getText().trim().equals("")
|| !_wapGatewayIp.getText().trim().equals("")
|| !_wapGatewayPort.getText().trim().equals("")
|| !_wapSourceIp.getText().trim().equals("")
|| !_wapSourcePort.getText().trim().equals("")
|| !_wapUser.getText().trim().equals("")
|| !_wapPassword.getText().trim().equals("")
|| _wapEnableWTLS.getChecked()) {
final WapOptions wapOptions = new WapOptions();
wapOptions.setWapGatewayApn(_wapGatewayApn.getText().trim());
wapOptions.setWapGatewayIp(_wapGatewayIp.getText().trim());
wapOptions.setWapGatewayPort(_wapGatewayPort.getText().trim());
wapOptions.setWapSourceIp(_wapSourceIp.getText().trim());
wapOptions.setWapSourcePort(_wapSourcePort.getText().trim());
wapOptions.setTunnelAuthUsername(_wapUser.getText().trim());
wapOptions.setTunnelAuthPassword(_wapPassword.getText().trim());
wapOptions.setWapEnableWTLS(_wapEnableWTLS.getChecked());
factory.setTransportTypeOptions(TransportInfo.TRANSPORT_WAP,
wapOptions);
}
// Set BisB options
factory.setTransportTypeOptions(TransportInfo.TRANSPORT_BIS_B,
new BisBOptions(_bisBConnectionType.getText().trim()));
// Get preferred transports option
int[] preferredTransports = null;
if (_transportSelection.getChecked()) {
if (_order1.getSelectedIndex() == 0
&& _order2.getSelectedIndex() == 0
&& _order3.getSelectedIndex() == 0
&& _order4.getSelectedIndex() == 0
&& _order5.getSelectedIndex() == 0
&& _order6.getSelectedIndex() == 0) {
// Display a warning if none of the preferred transport is
// specified when "Preferred Transports" check box is checked
displayMessage("Please select at least one transport or uncheck \"Preferred Transports\"");
return;
}
// Get rid of the "none" elements
final IntVector transportIdsVector = new IntVector();
if (_order1.getSelectedIndex() != 0) {
transportIdsVector.addElement(_order1.getSelectedIndex());
}
if (_order2.getSelectedIndex() != 0) {
transportIdsVector.addElement(_order2.getSelectedIndex());
}
if (_order3.getSelectedIndex() != 0) {
transportIdsVector.addElement(_order3.getSelectedIndex());
}
if (_order4.getSelectedIndex() != 0) {
transportIdsVector.addElement(_order4.getSelectedIndex());
}
if (_order5.getSelectedIndex() != 0) {
transportIdsVector.addElement(_order5.getSelectedIndex());
}
if (_order6.getSelectedIndex() != 0) {
transportIdsVector.addElement(_order6.getSelectedIndex());
}
transportIdsVector.trimToSize();
preferredTransports = transportIdsVector.getArray();
}
// Process disallowed transports
final IntVector disallowedTransports = new IntVector();
if (_disallowDirectTCP.getChecked()) {
disallowedTransports
.addElement(TransportInfo.TRANSPORT_TCP_CELLULAR);
}
if (_disallowWap.getChecked()) {
disallowedTransports.addElement(TransportInfo.TRANSPORT_WAP);
}
if (_disallowWap2.getChecked()) {
disallowedTransports.addElement(TransportInfo.TRANSPORT_WAP2);
}
if (_disallowMds.getChecked()) {
disallowedTransports.addElement(TransportInfo.TRANSPORT_MDS);
}
if (_disallowBisB.getChecked()) {
disallowedTransports.addElement(TransportInfo.TRANSPORT_BIS_B);
}
if (_disallowWifi.getChecked()) {
disallowedTransports.addElement(TransportInfo.TRANSPORT_TCP_WIFI);
}
// Trim excess
disallowedTransports.trimToSize();
// Configure the factory if needed
if (disallowedTransports.size() > 0) {
factory.setDisallowedTransportTypes(disallowedTransports.getArray());
}
// Get the connection
Status.show("Attempting Connection...", 500);
final Thread t =