use of com.predic8.membrane.core.resolver.ResourceRetrievalException in project service-proxy by membrane.
the class WSDLPublisherInterceptor method handleRequest.
@Override
public Outcome handleRequest(final Exchange exc) throws Exception {
if (!"GET".equals(exc.getRequest().getMethod()))
return Outcome.CONTINUE;
try {
String resource = null;
if (exc.getRequestURI().endsWith("?wsdl") || exc.getRequestURI().endsWith("?WSDL")) {
processDocuments(exc);
exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = wsdl));
exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
}
if (exc.getRequestURI().contains("?xsd=")) {
Map<String, String> params = URLParamUtil.getParams(router.getUriFactory(), exc);
if (params.containsKey("xsd")) {
int n = Integer.parseInt(params.get("xsd"));
String path;
processDocuments(exc);
synchronized (paths) {
if (!paths.containsKey(n)) {
exc.setResponse(Response.forbidden("Unknown parameter. You may only retrieve documents referenced by the WSDL.").build());
return Outcome.ABORT;
}
path = paths.get(n);
}
exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = path));
exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
}
}
if (resource != null) {
WSDLInterceptor wi = new WSDLInterceptor();
wi.setRewriteEndpoint(false);
wi.setPathRewriter(new RelativePathRewriter(exc, resource));
wi.handleResponse(exc);
return Outcome.RETURN;
}
} catch (NumberFormatException e) {
exc.setResponse(HttpUtil.setHTMLErrorResponse(Response.internalServerError(), "Bad parameter format.", ""));
return Outcome.ABORT;
} catch (ResourceRetrievalException e) {
exc.setResponse(Response.notFound().build());
return Outcome.ABORT;
}
return Outcome.CONTINUE;
}
use of com.predic8.membrane.core.resolver.ResourceRetrievalException in project service-proxy by membrane.
the class FileSchemaWebAppResolver method resolve.
@Override
public InputStream resolve(String url) throws ResourceRetrievalException {
if (url.startsWith("file:"))
url = url.substring(5);
log.debug("loading resource from: " + url);
InputStream is = ctx.getResourceAsStream(url);
if (is == null)
throw new ResourceRetrievalException(url);
return is;
}
use of com.predic8.membrane.core.resolver.ResourceRetrievalException in project service-proxy by membrane.
the class ApiManagementConfiguration method updateAfterLocationChange.
public void updateAfterLocationChange() throws IOException {
if (!isLocalFile(location)) {
log.info("Loading configuration from [" + location + "]");
if (location.startsWith("etcd")) {
handleEtcd(location);
} else {
try {
parseAndConstructConfiguration(getResolver().resolve(location));
} catch (ResourceRetrievalException e) {
log.error("Could not retrieve resource");
return;
}
}
return;
} else {
if (location.isEmpty())
location = "api.yaml";
final String newLocation = ResolverMap.combine(getCurrentDir(), location);
log.info("Loading configuration from [" + newLocation + "]");
InputStream is = null;
try {
is = getResolver().resolve(newLocation);
} catch (ResourceRetrievalException e) {
log.error("Could not retrieve resource");
return;
}
parseAndConstructConfiguration(is);
try {
getResolver().observeChange(newLocation, new Consumer<InputStream>() {
@Override
public void call(InputStream inputStream) {
log.info("Loading configuration from [" + newLocation + "]");
if (!getContextLost()) {
try {
parseAndConstructConfiguration(inputStream);
getResolver().observeChange(newLocation, this);
} catch (ResourceRetrievalException ignored) {
} catch (IOException ignored) {
}
}
}
});
} catch (Exception warn) {
URL url = null;
try {
url = new URL(newLocation);
} catch (MalformedURLException ignored) {
}
String schema = "";
if (url != null) {
schema = url.getProtocol();
}
log.warn("Could not observe AMC location for " + schema);
}
}
}
use of com.predic8.membrane.core.resolver.ResourceRetrievalException in project service-proxy by membrane.
the class HTTPSchemaResolver method resolve.
public InputStream resolve(String url) throws ResourceRetrievalException {
try {
Exchange exc = new Request.Builder().method(Request.METHOD_GET).url(uriFactory, url).header(Header.USER_AGENT, Constants.PRODUCT_NAME + " " + Constants.VERSION).buildExchange();
Response response = getHttpClient().call(exc).getResponse();
response.readBody();
if (response.getStatusCode() != 200) {
ResourceRetrievalException rde = new ResourceRetrievalException(url, response.getStatusCode());
throw rde;
}
return new ByteArrayInputStream(ByteUtil.getByteArrayData(response.getBodyAsStreamDecoded()));
} catch (ResourceRetrievalException e) {
throw e;
} catch (Exception e) {
ResourceRetrievalException rre = new ResourceRetrievalException(url, e);
throw rre;
}
}
use of com.predic8.membrane.core.resolver.ResourceRetrievalException in project service-proxy by membrane.
the class WSDLPublisherInterceptor method processDocuments.
private void processDocuments(Exchange exc) throws Exception {
// exc.response is set to garbage and should be discarded after this method
synchronized (paths) {
try {
while (true) {
String doc = documents_to_process.poll();
if (doc == null)
break;
log.debug("WSDLPublisherInterceptor: processing " + doc);
exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), doc));
WSDLInterceptor wi = new WSDLInterceptor();
wi.setRewriteEndpoint(false);
wi.setPathRewriter(new RelativePathRewriter(exc, doc));
wi.handleResponse(exc);
}
} catch (ResourceRetrievalException e) {
log.error("Could not recursively load all documents referenced by '" + wsdl + "'.", e);
}
}
}
Aggregations