//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
hta = new HTTPAddress(InetAddress.getLocalHost().getHostName(),port, false);
#DOTNET_INCLUDE_END*/
} catch( UnknownHostException ukhexc ) {
throw new MTPException("Cannot activate MTP on default address: Unknown Host");
} catch( MalformedURLException mexc ) {
throw new MTPException("Cannot activate MTP on default address: Malformed URL");
} catch( NumberFormatException nfexc ) {
throw new MTPException("Cannot activate MTP on default address: Invalid port");
}
}
port = hta.getPortNo();
if((port <= 0) || (port > 65535)) {
throw new MTPException("Invalid port number "+ta.getPort());
}
// Parse other profile parameters
numKA = Integer.parseInt(p.getParameter(PREFIX+"numKeepAlive",MAX_KA));
policy = (p.getParameter(PREFIX+"policy",POLICY).equals("aggressive"))?true:false;
int outPort = Integer.parseInt(p.getParameter(PREFIX+"outPort",OUT_PORT));
ka = new KeepAlive(numKA, outPort, policy);
keepAlive = numKA > 0;
proxyHost = p.getParameter(PREFIX+"proxyHost",null);
if (proxyHost != null) {
useProxy = true;
proxyPort = Integer.parseInt(p.getParameter(PREFIX+"proxyPort",PROXY_PORT));
}
saxClass = p.getParameter(PREFIX+"parser",null);
timeout = Integer.parseInt(p.getParameter(PREFIX+"timeout",TIMEOUT));
//#PJAVA_EXCLUDE_BEGIN
try{
HTTPSocketFactory.getInstance().configure(p, hta);
} catch(Exception e){
throw new MTPException("Error configuring Socket Factory", e);
}
//#PJAVA_EXCLUDE_END
// System.out.println("Parameters set:");
// System.out.println("- KA "+numKA);
// System.out.println("- Policy "+policy);
// System.out.println("- Out port "+outPort);
// System.out.println("- Proxy host "+proxyHost);
// System.out.println("- Proxy port "+proxyPort);
// System.out.println("- Parser "+saxClass);
// System.out.println("- Timeout "+timeout);
} catch (ClassCastException cce) {
throw new MTPException("User supplied transport address not supported.");
} catch( NumberFormatException nexc ) {
throw new MTPException(nexc.getMessage());
}
//Creation of the Server
try {
//Create object server
HTTPServer srv = new HTTPServer(port,disp,numKA,saxClass,timeout, changePortIfBusy);
int actualPort = srv.getLocalPort();
if (actualPort != port) {
// The selected port is busy and a new one was selected --> Update the transport address
boolean useHttps = "https".equalsIgnoreCase(hta.getProto());
//#DOTNET_EXCLUDE_BEGIN
hta = new HTTPAddress(InetAddress.getLocalHost().getCanonicalHostName(),actualPort, useHttps);
//#DOTNET_EXCLUDE_END
/*#DOTNET_INCLUDE_BEGIN
hta = new HTTPAddress(InetAddress.getLocalHost().getHostName(),actualPort, useHttps);
#DOTNET_INCLUDE_END*/
}
//Save the reference to HTTPServer
addr2srv.put(hta.toString(),srv);
//Execute server
srv.start();
protocols = new String[]{hta.getProto()};
return hta;
} catch( Exception e ) {
throw new MTPException("While activating MTP got exception "+e);
}
}