Tuesday, March 15, 2011

Jersey in Tomcat+Spring environment can't find ComponentProvider. Why?

I've deployed Jersey on Tomcat and everything works perfectly (when I use the com.sun.jersey.spi.container.servlet.ServletContainer), but as soon as I change it to the com.sun.jersey.spi.spring.container.servlet.SpringServlet (according to all the tutorials I can find), I get a nasty exception:

Apr 19, 2009 5:07:35 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet ServletAdaptor as unavailable
Apr 19, 2009 5:07:35 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /myservice threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.service.ComponentProvider

Any idea what package/distribution it can reside? What am I missing?

May be I don't need it at all. I'm trying to make sure that when my resource class is loaded it'll be Autowired and initialized with the rest of the Beans it depends on. Can it be done differently?

Thanks.

From stackoverflow
  • The com.sun.jersey.spi.service.ComponentProvider interface is part of the jersey-core JAR so it's odd that you're getting that exception.

    Make sure you're using the same version of the jersey libraries together (i.e. you're using Jersey 1.0.1 libraries, not mixing 1.0 and 1.0.1 as the Spring classes got renamed between those two releases).

    Also ensure you have a ContextLoaderListener in your web.xml like so:

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    IgorM : I've removed all the conflicting version JARs and readded only from 1.0.3 - the exception disappeared. As well my JSON functionality was reduced to bare minimum, but, I guess, is a separate issue.
    safetydan : JSON support changed recently in Jersey. Make sure you're configured to use Jackson for JSON support and have the required libraries.

good all character combinations using a given length

Is there a program/tool/utility that would allow me to generate all possible character combinations (lowercase, uppercase, symbols, numbers) over a given length of characters (min-max)

From stackoverflow
  • Online:

    Desktop:

    • Free Password Generator. It's a password generator tool but you are able to

      • fix the length
      • choose to include letters/digits/catpital letters

        alt text

  • This is essentially the same field as brute-force password cracking, which might be what you are trying to achieve. Wikipedia has a reasonable article on password cracking, and lists the most popular software for the task.

  • Thanks Colin, that's what I was looking for.

MVC Preserve carriage return - line feed in html

Hi,

If have a field in my database with crlf's how do I preserve that in HTML??

Is there a standard way of doing this??

Malcolm

EDIT: I am actually doing an MVC app if that hepls.

From stackoverflow
  • I think the best way to do that is to replace the \r\n sequence with <br /> tags, using whatever scripting language your database-backed website is in.

    Other options include placing the text within a <textarea>. Or, if it is appropriate for your site, using akin to the <pre> tag (or the CSS attribute white-space: pre).

  • You can search/replace those characters with <br /> to make the text output with breaklines. You could also use the <pre> tag to specify a particular piece of text's line breaks.

Reordering items in BindingList in C#?

How would I move items in a BindingList in C#? Say, move last added item to the front, or swap with previous item?

From stackoverflow
  • A BindingList has an Items property that implements IList<>

    So you can Use Insert() and RemoveAt()

    flamey : yes, thank you :) just started learning c#, couldn't figure it out -- asked, and suddenly figured if out and came close the question :)
  • InsertItem method is something you should read about. I guess it gives you what you need.

  •     static void Main(string[] args)
        {
            BindingList<string> list = new BindingList<string>();
            list.Add("Hello");
            list.Add("World");
            list.Add("Test");
    
            MoveLastToFirst(list);
    
            Swap(list, 1, 2);
    
            foreach (string s in list)
                Console.WriteLine(s); // Prints Test World Hello
        }
    
        private static void MoveLastToFirst<T>(BindingList<T> list)
        {
            int cnt = list.Count;
            T temp = list[cnt - 1];
            list.RemoveAt(cnt - 1);
            list.Insert(0, temp);
        }
    
        private static void Swap<T>(BindingList<T> list, int first, int second)
        {
            T temp = list[first];
            list[first] = list[second];
            list[second] = temp;
        }
    

Group Union

I have the following query that always give me two rows. I want to group them to one row using tbluser.userid, is it possible to group a union?

SELECT
SUM(tblfooditem.calories)
FROM tblfooditem
INNER JOIN tbluser ON tblfooditem.userid = tbluser.userid
WHERE tblfooditem.userid=?userid AND tblfooditem.date=?date
GROUP BY tbluser.userid
UNION
SELECT
SUM(tbladdedmealitem.calories)
FROM tbladdedmeal
INNER JOIN tbluser ON tbladdedmeal.userid = tbluser.userid
WHERE tbladdedmeal.userid=?userid AND tbladdedmeal.date=?date
GROUP BY tbluser.userid;
From stackoverflow
  • It's possible.

    select sum(s) from (
    SELECT
        SUM(tblfooditem.calories) S,tbl.userid
        FROM tblfooditem
        INNER JOIN tbluser ON tblfooditem.userid = tbluser.userid
        WHERE tblfooditem.userid=?userid AND tblfooditem.date=?date
        GROUP BY tbluser.userid
        UNION
        SELECT
        SUM(tbladdedmealitem.calories) S,tbl.userid
        FROM tbladdedmeal
        INNER JOIN tbluser ON tbladdedmeal.userid = tbluser.userid
        WHERE tbladdedmeal.userid=?userid AND tbladdedmeal.date=?date
        GROUP BY tbluser.userid
    ) Q
    group by Q.userid
    

Is there any way to prevent console application to close ?

Hi

Is there any way to prevent console application to close ?

(that the user can't close the program)

thank's

From stackoverflow
  • Will it be a problem for you if the user switches off the computer?

    Joey : ... or just does a taskkill /f :)
    Cerebrus : No, I think the OP wants to keep the program running even after shutdown! :P
  • Take a look at the Win32 console API.

    You could try creating a windows (non console app) and then create your own console window with AllocConsole(). As I haven't tried this I can't say if Windows will still try to kill your process.

    An alternative would be to create a background process/service to do the work.

  • Normally a console application can be aborted by pressing CTRL-C.

    You can prevent CTRL-C from aborting your application by setting the Console.TreatControlCAsInput property or handling the Console.CancelKeyPress event.

    Of course this won't stop the user from being able to kill your process, e.g. using Task Manager.

    Richard : ... or using control-Break to stop it.

Submit button doesn't work for ajax form rendered in dynamic partial view

I have some jQuery that loads a partial view and inserts it into the DOM. So far, all good.

But now I've made some changes to the rendered user control to include an Ajax form. However, the submit button for this form doesn't appear to trigger the Ajax call. From what I can tell, it's not doing anything at all. My breakpoints in the controller aren't getting triggered either.

If I use a link and add onclick="submit()", the form gets submitted, and triggers the action in my controller fine, but of course, this is doing a plain post and not an ajax post.

The form is like:

<% using(Ajax.BeginForm("actionName", new AjaxOptions {
           OnSuccess = "updatePanel" })) { %>
  <!-- form elements in here -->
  <input type="submit" />
<% } %>

I've just discovered that it does the post if I change OnSuccess to OnComplete, which I don't understand at all.

However, even though changing it to OnComplete is working, I get an exception in the microsoft ajax library, somewhere in:

try {
  a._webRequest.completed(Sys.EventArgs.Empty)
} finally {
  if (a._xmlHttpRequest!=null) {
    a._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
    a._xmlHttpRequest = null
  }
}

The cursor is higlighted at the end of finally, says Object doesn't this property or method.

I suppose I could live with that; it's just annoying testing stuff when it keeps throwing an exception in MicrosoftAjax.js and tripping the debugger in VS.

From stackoverflow
  • If you are using OnSuccess do you not need to have UpdateTarget also which is why it wasnt firing in the first place?

  • Have you made sure you're referencing the Microsoft AJAX JS files?

    You need to make sure you have...

    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    

    Somewhere in your site. By default I don't think the ASP.NET MVC Project adds these JS references.