I found the solution. it works for me, if you have better way, feel free to
share ....

private String proxy(String url) throws IOException {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new
UsernamePasswordCredentials("USERNAME", "PASSWORD");
provider.setCredentials(AuthScope.ANY, credentials);
try (CloseableHttpClient httpClient =
HttpClientBuilder.create().setDefaultCredentialsProvider(provider)
.build();) {
HttpGet request = new HttpGet(url);
HttpResponse response = httpClient.execute(request);
BufferedReader rd = new BufferedReader(new
InputStreamReader(response.getEntity().getContent()));
StringBuffer body = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
body.append(line + System.lineSeparator());
}
return body.toString();
}
}


@Override
public void configure() throws Exception {
from("jetty:http://0.0.0.0:8080/myapp?matchOnUriPrefix=true
").routeId("webserviceproxyroute")
.process(exchange -> {
exchange.getOut()
.setBody(proxy("http://remotehost/webservice?wsdl";));
}).log(LoggingLevel.INFO, "Response  \n ${body}");
}


I used below code as proxy to download wsdl file from remote webservice,
but it does not work. only get html back instead of wsdl file


  <route>
    <from uri="servlet:myapp?matchOnUriPrefix=true"/>
    <to 
uri="http://realserverhostname:8090/webservice?wsdl&amp;bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
  </route>



Ps:



Of couse using browser I am able to open
http://realserverhostname:8090/webservice?wsdl as wsdl file

via camel route It only got something like below
 <html><body><p>Mocked Interfaces in project </p><ul><li><a
href="/xxx?WSDL&interface=xxx">xxx</a></li><li><a
href="/xxx?WSDL&interfacexxx">xxx</a></li></ul></p></body></html>


Any hints or ideas?

Reply via email to