Apache Camel Route cannot find Endpoint - apache-camel

I created a cxf route for my application like this:
from("cxfrs:{{url}}?resourceClasses=MyImpl&bindingStyle=SimpleConsumer")
.to("${header.operationName}").end();
from("direct:{{getUser}}")
.bean("userImpl", "getUserByName")
.marshal().json(JsonLibrary.Jackson)
.to("log:foo");
from("direct:{{login}}")
.bean("userImpl", "loginUser")
.marshal().json(JsonLibrary.Jackson)
.to("log:foo");
If I try get my operationName in a processor, I can get it, but if I call this route, I have this message:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 500 No consumers available on endpoint: Endpoint[direct://$%7Bheader.operationName%7D]. Exchange[ID-NBSPO049-64311-1498773394077-0-2] while invoking public java.lang.String com.itau.ea4.implementacao.UserImpl.loginUser(java.lang.String,java.lang.String) with params [teste, 1234].</title>
</head>
<body>
<h2>HTTP ERROR 500</h2>
<p>Problem accessing /user/login. Reason:
<pre> No consumers available on endpoint: Endpoint[direct://$%7Bheader.operationName%7D]. Exchange[ID-NBSPO049-64311-1498773394077-0-2] while invoking public java.lang.String com.itau.ea4.implementacao.UserImpl.loginUser(java.lang.String,java.lang.String) with params [teste, 1234].</pre>
</p>
<hr>
<i>
<small>Powered by Jetty://</small>
</i>
<hr/>
</body>
What's wrong with my route?
And why my header cannot is recognized?

The problem is in:
.to("${header.operationName}")
"to(...)" doesn't support dynamic data so in your case it actually tries to send to endpoint "direct:{header.operationName}".
To use dynamic value from header you can use toD (from Camel 2.19) or recipientsList with one recipient (Camel before 2.19)

Related

Removing .html from end of url in javalin

I'm using Javalin to serve my static web pages, which I've never done before. I know it's possible in Nginx to remove the .html from the end of your url but still route to the correct page, for example mysite.com/login would replace mysite.com/login.html but still point towards my login.html file. Is this possible in Javalin?
I've tried looking into the config (StaticFileConfig) but couldn't seem to find anything that would solve this problem
Here are two examples of what was discussed in the comments to the question, for future visitors:
The first example assumes there is a simple HTML file in the application's resources/html folder.
The test.html file:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Hello world.</div>
</body>
</html>
The /test handler:
public static void main(String[] args) {
Javalin.create(config -> {
})
.get("/test", ctx -> {
ctx.contentType(ContentType.TEXT_HTML);
InputStream in = App.class.getResourceAsStream("/html/test.html");
ctx.result(in);
})
.start(8080);
}
If you choose to configure Javalin with Thymeleaf, and if you place your HTML file in the default location expected by Thymeleaf (resources/thymeleaf), then you can do this:
.get("/test", ctx -> {
Map<String, Object> model = new HashMap<>();
ctx.render("test.html", model);
})
In this case, the model used by Thymeleaf for rendering is empty because you don't need to make any substitutions in your HTML file (it's not a template). But it's a short step from this to using dynamic Thymeleaf templates.
I followed what andrewJames was saying and that worked for me. I was hoping there would be a cleaner way of doing this, as I'm just copy pasting the same code for every endpoint and changing the file path, but this works.

SOLR: when trying to delete all documents, error response body is a html string. How can I get error expressed as json instead?

Trying to reset an index (delete all documents) via a POST request.
curl -X POST -H 'Content-Type: application/json' 'http://localhost:8983/solr/my_core/update?wt=json' --data-binary '
{
"delete": { "query":"*:*" }
}'
When there is an error, I don't get json string back in the body. Instead, I am getting html string
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/my_core/update. Reason:
<pre> Not Found</pre></p>
</body>
</html>
Is there a way I can get the error expressed as json in the response body instead?
Thank you!
The error message is telling you that the Solr installation and its core or handler wasn't found. The message is not generated as a result from your query; in that case it wouldn't be a 404. This is either created by having the wrong path (i.e. it's not /solr/) , the requested core (/my_core/), or the request handler (/update) not being found.
You might be on Windows and using single quotes under cmd - which will not do what you expect, and could up as part of the URL instead. Try with double quotes (") instead, and if that doesn't work, check that the URL works in your browser.
The error response is HTML so that it will display correctly in a browser. In other words, it's human readable.
The response code -- HTTP code 404 -- is the only part of that error which is meant for machine consumption.
The format of the response will only be whatever was requested (json by default in recent Solr versions) if the request succeeds. This one didn't succeed.

google cloud engine metadata query

I have set a metadata groupip="10.0.0.2 10.0.0.3 10.0.0.4" in the project metadata. I am trying to query it using the following command:
curl 'http://metadata/computeMetadata/v1/projectid/groupip/' -H "Metadata-Flavor: Google"
As answer instead of the IP's I am getting the following:
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}bod
y{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/im
ages/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;t
ext-decoration:none}a img{border:0}#media screen and (max-width:772px){body{background:none;margin-top:0;max-width:
none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp
.png) no-repeat;margin-left:-5px}#media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.c
om/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//w
ww.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}#media only screen and (-webkit-min-d
evice-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.
png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/computeMetadata/v1/projectid/groupip/</code> was not found on this server. <ins>Th
at’s all we know.</ins>
In the same way that you get an instance's metadata via instance/attributes/xyz, so you can get the project's metadata via project/attributes/xyz.
curl http://metadata/computeMetadata/v1/project/attributes/groupip -H "Metadata-Flavor: Google"
To make sure you actually added the project-level metadata correctly, list all project attributes:
And more generally, keep shortening the URL to list ancestors:

wpf webBrowser NavigateToString script error

I want to use the Wpf webBrowser control to render math equations.
I've downloaded MathJax, and included it in my Visual studio project.
I've tryed to load one of the MathJax example. This is the html code i'm using:
<!DOCTYPE html>
<html>
<head>
<title>MathJax MathML Test Page</title>
<!-- Copyright (c) 2010-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript" src="MathJax-Reduced/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full"></script>
</head>
<body>
<p>
When
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><mo>≠</mo><mn>0</mn>
</math>,
there are two solutions to
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo> <mi>b</mi><mi>x</mi>
<mo>+</mo> <mi>c</mi> <mo>=</mo> <mn>0</mn>
</math>
and they are
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mi>x</mi> <mo>=</mo>
<mrow>
<mfrac>
<mrow>
<mo>−</mo>
<mi>b</mi>
<mo>±</mo>
<msqrt>
<msup><mi>b</mi><mn>2</mn></msup>
<mo>−</mo>
<mn>4</mn><mi>a</mi><mi>c</mi>
</msqrt>
</mrow>
<mrow> <mn>2</mn><mi>a</mi> </mrow>
</mfrac>
</mrow>
</math>
</p>
</body>
</html>
Everything is working fine with the following code:
string curDir = Directory.GetCurrentDirectory();
this.webBrowser1.Navigate(new Uri(String.Format("file:///{0}/test-1.html", curDir)));
But if i try this code:
string s = File.ReadAllText(Directory.GetCurrentDirectory() + "\\test-1.html");
this.webBrowser1.NavigateToString(s);
i get a Script Error:
An error has occurred in the script on this page.
Line: 1
Char: 1
Error: Syntax Error
Code: 0
URL: about:MathJax-Reduced/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full
What's wrong? It would be really helpful to use something similar to the last code, so i can avoid to save a file just to load it...
Note that the URL in the error is about:MathJax-Reduced/unpacked..., which is an about URL not the file:// URL that you had in the first case. I suspect that is the cause of the problem. That suggests that the NavigateToString function is using about:blank or a similar URL as the base URL for the page, so MathJax is getting the wrong path to itself. Note that you lose the actual page location when reading it from the file and loading it as a string. That means you may have to load MathJax from an absolute URL rather than a relative one (i.e., include the file:// and path to the MathJax-Reduced directory).

Composite C1 4.0 Beta and MVC Player outputting 2nd html and body tags

I have setup and installed the Composite C1 4.0 beta, along with the latest MVC Player build (from 12/7/2012 nightly), but whenever I call the MVCPlayer function, it outputs additional tags on the page. For example, I am calling a MVCPlayer function for breadcrums. This is the output:
..... before breadcrum content .....
<a name="site-nav" class="screen-reader"></a>
<html xmlns="http://www.w3.org/1999/xhtml">
<head />
<body>
<html>
<head />
<body>
<!-- START BREADCRUM SECTION -->
<ul id="breadcrumbs">
<li>Homep</li>
<li>Events</li>
</ul>
<!-- END BREADCRUM SECTION -->
</body>
</html>
</body>
</html>
<div class="clear"></div>
</div>
..... rest of page .....
As you can see, it is in the middle of the page. The MVCPlayer is returning an XDocument in the render function. So, how do I get rid of the extra tags before the START & END BREADCRUM SECTION comments? The page renders fine, but this is impacting the ability for me to use a page filter to add additional content to the output, such as switching out image tag src's so I can use a jquery script to perform lazy loading images (see http://www.appelsiini.net/projects/lazyload).
Any thoughts?
Thanks!
Chad
The output of the actual breadcrums page is simply <ul><li>...</li></ul>, and there are no errors in the log files. The MVC Player actually adds the additional code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head />
<body>
</body>
</html>
In the Player.cs file, here is the code:
var sbHtml = new StringBuilder();
sbHtml
.Append(#"<html xmlns=""http://www.w3.org/1999/xhtml"">
<head/>
<body>")
.Append(responseWriter.ToString())
.Append(#"
</body>
</html>");
try
{
return XDocument.Parse(sbHtml.ToString());
}
I was able to modify the /Renderers/Page.aspx.cs and changed this line to "strip" out the extra tags:
Original:
xhtml = _renderingContext.FormatXhtml(xhtml);
Updated:
xhtml = _renderingContext.FormatXhtml(xhtml.Replace(#"<html xmlns=""http://www.w3.org/1999/xhtml"">", "").Replace("<html>", "").Replace("<head />", "").Replace("<head></head>", "").Replace("<body>", "").Replace("</body>", "").Replace("</html>", ""));
I'm sure there is a better solution than this? :)
Chad
It could be that somewhere else on the the page you have markup which makes the whole result document and invalid XHTML, and therefore the system cannot process it correctly.
Try to
a) Check the log files to see if there any related warnings
b) validate the output xhtml http://www.xmlvalidation.com/

Resources