I have started working with Apache Camel, and have run into a situation where I need to execute following conditional block.
if(Condition A) {
then Activity A to determine Condition B;
If(Condition B) {
Then Activity B
} else {
Then Activity C
}
} else {
Do nothing and end the route.
}
Here is what i have come up with, but it is nothing more than guess. It is not written with proper understanding.
...
...
.process(new SomeActivity())
.choice()
.when(header(ConditionA).isEqualTo(Boolean.TRUE))
.process(new ActivityToSetConditionB())
.choice()
.when(header(ConditionB).isEqualTo(Boolean.TRUE))
.process(new ActivityRelatedToB())
.otherwise()
.process(new ActivityRelatedToC())
.endChoice()
.end()
I have tried to understand from Apache camel documentation and few other sources, but it does not seem very intuitive for a beginner like me. Please help me understand this with some examples.
Yes, your use of the Content based router is the correct way to deal with conditional message routing.
However, if you want to get a better understanding of Camel I highly recommend the book Camel in Action (2nd edition). You will find all the important concepts of the framework and lots of examples in the book.
Related
Is there somewhere complete, consistent and well documented source of information on error handling in loopback?
Things like error codes and their meaning, relation with http statuses. I've already read their docs and have not found anything like this.
I would like to translate all the messages to add multi language support to my app. I would also like to add my custom messages, with their code and to use it consistently with other loopback errors.
In order to achieve this, I need to intercept all the errors (I've done this already) and to know all the possible different codes, so I can translate them.
For example, if there is an error with code 555, I have to know what it means and treat it accordingly.
Any ideas?
I need to "catch" all the messages and translate them
This is the beginning of an answer. You can write an error-handling middleware that will intercept any error returned by the server. You will need in turn to implement the logic for making the translation.
module.exports = function() {
return function logError(err, req, res, next) {
if (err) {
console.log('ERR', req.url, err);
}
next();
};
};
This middleware must be configured to be called in the final phase. Save the code above in log-error.js for instance, then modify server/middleware.json
{ "final": { "./middleware/log-error": {} } }
I need a full list of loopback codes/messages
I'm pretty sure there is no such thing. Errors are build and returned all over the place in the code, not centralized anywhere.
Good afternoon,
in my project is installed elmah framework to logging exceptions. On the localhost it works fine, but when I deploy it to production it stops logging null reference exceptions. All others exceptions are logged (or I didn't find out next which is not logged).
I have set logging into SqlServer.
I can't find out what is wrong, can someone give me advice please? (How I said it loggs all exceptions what I fired but only this one is never caught)
Thank you
Well, Thomas Ardal answered right.
Problem was in the FilterConfig.cs file. Because in default settings it didn't want log any 500 errors, dangerous requests, null reference exceptions etc, i have added this lines:
public class ElmahHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
if(filterContext.Exception is HttpRequestValidationException)
{
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(filterContext.Exception));
}
}
}
and added this line to the RegisterGlobalFilters method on the first place.
filters.Add(new ElmahHandleErrorAttribute());
After that it started log some exceptions but not all. Solution is that I remove if condition and catch everything. So if anyone will have similar problem, be sure, that problem will be somewhere in filters...
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to to Convert SOAP to REST using java language?
package net.weather;
import java.sql.*;
import javax.jws.WebService;
#WebService
public class ProjectFinalWS{
Connection con;
Statement st;
ResultSet rs;
String res;
public void connectDB()
{
String url ="jdbc:mysql://localhost:3306/";
String dbName ="project";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try
{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+dbName,userName,password);
}catch(Exception e){}
}
public float getMaxTemp(String city)
{ float mxtemp=0;
connectDB();
try{
st=con.createStatement();
rs=st.executeQuery("select maxtemp from weather where city='"+city+"'");
rs.next();
mxtemp=rs.getFloat(1);
st.close();
con.close();
}
catch(Exception e){}
return mxtemp;
}
public float getMinTemp(String city)
{ float mntemp=0;
connectDB();
try{
st=con.createStatement();
rs=st.executeQuery("select mintemp from weather where city='"+city+"'");
rs.next();
mntemp=rs.getFloat(1);
st.close();
con.close();
}
catch(Exception e){}
return mntemp;
}
public float getHumidity(String city)
{ float humidity=0;
connectDB();
try{
st=con.createStatement();
rs=st.executeQuery("select humidity from weather where
city='"+city+"'");
rs.next();
humidity=rs.getFloat(1);
st.close();
con.close();
}
catch(Exception e){}
return humidity;
}
}
REST is a completely different way to think of a web service to SOAP. In particular, it operates in terms of resources, their representations and the links between them. (You also have HTTP verbs about, but for a simple query service like this one you'd probably only be using GET anyway.)
A RESTful version of that interface would work a bit like this:
A client would decide they want to know some information about a particular place, so they'd ask the service to search for that place and tell them the link to it, or at least to places that match the search criteria; since that might be several different places (think "London, UK" vs. "London, Ont." in response to a search for "London") the result will be a page that links to the characterization of each of the places. It might also say a bit about what each link means, but that's not necessary. (The format of the result can be HTML, or XML, or JSON, or any of a number of different formats; HTTP content negotiation makes for a great way to pick between them.)
Once the user has decided which place from the list they actually want information about, they follow the link and get a description of what information about that place is available. This is a document that provides links to a page that provides the max temperature, another page that provides the min temperature, and a third that provides the humidity.
To get the actual data, another link is followed and that data is served up. Since the data is a simple float, getting it back as plain text is quite reasonable.
Now, we need to map these things to URLs:
Searching: /search?place=somename (which is easy to hook up behind a place name), which contains links to…
Place: /place/{id} (where {id} is some general ID that probably is your DB's primary key; we don't want to use the name here because of the duplicate name problem), which contains links to…
Data: /place/{id}/maxTemp, /place/{id}/minTemp, /place/{id}/humidity.
We also need to have some way to do the document creation. JAXB is recommended. Links should probably be done in XML with attributes called xlink:href; using (by reference) the XLink specification like that states exactly that the content of the attribute is a link (the unambiguous statement of that is otherwise a real problem in XML due to its general nature).
Finally, you probably want to use JAX-RS to do the binding of your Java code to the service. That's way easier than writing it all yourself. That lets you get down to doing something like this (leaving out the data binding classes for brevity):
public class MyRestWeatherService {
#GET
#Path("/search")
#Produces("application/xml")
public SearchResults search(#QueryParam("place") String placeName) {
// ...
}
#GET
#Path("/place/{id}")
#Produces("application/xml")
public PlaceDescription place(#PathParam("id") String placeId) {
// ...
}
#GET
#Path("/place/{id}/maxTemp")
#Produces("text/plain")
public String getMaxTemperature(#PathParam("id") String placeId) {
// ...
}
// etc.
}
As you can see, it can go on a bit but it is not difficult to do so long as you start with a good plan of what everything means…
Thank goodness Donal Fellows pointed out the #WebService annotation. I didn't realize that this was a web service until he did.
You'll have more problems that API choices with this implementation. If you're deploying on a Java EE app server, I'd recommend using a JNDI data source and connection pool instead of hard wired database parameters and connecting for every request.
Better to close your resources in a finally block, wrapped in individual try/catch blocks.
Those empty catch blocks will drive you crazy. Bad things will happen, but you'll never know.
SOAP clients send an XML request over HTTP to a service that parses it, binds the values to inputs, uses them to fulfill the use case, and marshals a response as XML to send back.
REST asks clients to do all the same things, except instead of packaging the request parameters into an XML request they're sent via HTTP. The API is the HTTP GET, POST, DELETE. You express your method calls as URIs.
So it'll take a good knowledge of your SOAP API and some brains on your part. I don't know of any tools to do it for you.
I came across the features of IIS and it notes that I can prevent inline linking or leeching. How can I implement such a rule?
You will need to use URL rewrite to point to a resource within a web application that will be able to identify the refferer before displaying the resource to the client which called the application.
IE, rewrite the following
/images/myPhoto.JPG
to
/getResource.PHP?resource=%2Fimages%2FmyPhoto.JPG
Then inside getResource.PHP
forgive me if this isn't quite right, my php is a little sketchy, but you get the idea
header('Content-Type: image/jpeg');
if(isset($_SERVER['HTTP_REFERER'])) {
if( /*test that it fits your criteria*/ true ) {
$imagepath= $_GET['resource'];
} else {
$imagepath= "/images/stopLeaching.JPG";
}
} else {
$imagepath= $_GET['resource'];
}
$image=imagecreatefromjpeg($imagepath);
imagejpeg($image);
Is anyone using Castle MonoRail and ELMAH with success?
We are using a number of Resuces to present users with friendly error messages, but if we do this the exceptions never get as far as ELMAH as the MonoRail rescue intercepts them.
Ideally we want the user to see the rescue, but for the exception to be logged in ELMAH.
Any ideas/pointers?
Cheers,
Jay.
After looking at the links Macka posted, I wrote this simple monorail exception handler:
public class ElmahExceptionHandler : AbstractExceptionHandler {
public override void Process(IRailsEngineContext context) {
ErrorSignal.FromCurrentContext().Raise(context.LastException);
}
}
Then I registered it in web.config, monorail section:
<monorail>
<extensions>
<extension type="Castle.MonoRail.Framework.Extensions.ExceptionChaining.ExceptionChainingExtension, Castle.MonoRail.Framework"/>
</extensions>
<exception>
<exceptionHandler type="MyNamespace.ElmahExceptionHandler, MyAssembly"/>
</exception>
...
</monorail>
And that's it.
After also posting on Google Groups it looks like Atif may have pointed me in the right direction.
You might want to look into error
signaling in ELMAH. It is designed for
scenarios where you want to pass an
exception through ELMAH's pipeline
even if it is being handled/swallowed.
Here are some pointers to get started
with error signaling:
http://code.google.com/p/elmah/wiki/DotNetSlackersArticle#Error_Signa...
http://code.google.com/p/elmah/wiki/DotNetSlackersArticle#Signaling_e...
-Atif