Ciao a tutti,
devo raggiungere un database su un server fisico protetto da vpn.
Mi hanno aperto una porta sul server Windows che ospita il database (MySql), ho installato un programma java sul server con un HttpHandler che ascolta le richieste, esegue una query sul database e ritorna il risultato.
L’ Handler è chiamato da una pagina php su un server Windows online che posso contattare da qualunque applicazione.
Il problema è che quando provo la pagina php sul computer locale funziona , se la metto sul server online da errore : Failed to connect to IP port PORTA: Bad access - Codice errore: 7
Programma java HttpHandler
codice:
HttpServer server = HttpServer.create(new InetSocketAddress(PORTA), 0);
MyHandler MH=new MyHandler();
server.createContext("/test", MH);
static class MyHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
t.sendResponseHeaders(200, jsonString.length());
OutputStream os = t.getResponseBody();
os.write(jsonString.getBytes());
os.close();
Pagina Php
Codice PHP:
$urlWs="IP:PORTA/test";
$tuCurl = curl_init();
curl_setopt($tuCurl,CURLOPT_URL,$urlWs);
curl_setopt($tuCurl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($tuCurl,CURLOPT_HEADER, false);
curl_setopt($tuCurl, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($tuCurl, CURLOPT_TIMEOUT,30);
curl_setopt($tuCurl, CURLOPT_FOLLOWLOCATION, true);
$result=curl_exec($tuCurl);
if($result === false) {…}
else {…}
curl_close($tuCurl);
File web.config del server online con la pagina php
codice HTML:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".jnlp" mimeType="application/x-java-jnlp-file" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
<directoryBrowse enabled="false" />
<httpErrors errorMode="Detailed" />
</system.webServer>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern="^/\.well-known/pki-validation/(.*)$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<identity impersonate="true" />
<trust level="Medium" />
<sessionState mode="InProc" sqlCommandTimeout="30" />
</system.web>
</configuration>
Grazie.