Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Jimi Svedenholm

Ranch Hand
+ Follow
since May 19, 2001
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jimi Svedenholm


We use Weblogic 10.3 in a project I'm working on, and we have a few existing web services that are created by some simple java classes with the javax.jws.WebService annotation. Ie Weblogic generates the wsdl for us.

But now we want to add a new service, where the wsdl is written already, by a third party. So we use wsdl2java to generate some foundation classes, and then we write our implementation class that contains all the logic. But when we try to deploy this webservice in Weblogic it complains with this strange error message:

Unable to deploy EJB: coi-service-list-0.0.1-SNAPSHOT.jar from coi-service-list-0.0.1-SNAPSHOT.jar:

[HTTP:101216]Servlet: "/listOfUpdatedDocuments" failed to preload on startup in Web application: "/coi-service".
java.lang.IllegalStateException: Literal Array item type is not found.
at weblogic.wsee.bind.runtime.internal.LiteralArrayHelper.createLiteralArrayType(
at weblogic.wsee.bind.runtime.internal.Deploytime109MappingHelper.registerType(
at weblogic.wsee.bind.runtime.internal.Deploytime109MappingHelper.registerType(
at weblogic.wsee.bind.runtime.internal.RuntimeBindingsBuilderImpl.createRuntimeBindings(
at weblogic.wsee.deploy.EJBDeployInfo.createWsService(
at weblogic.wsee.deploy.DeployInfo.createWsPort(
at weblogic.wsee.server.servlet.BaseWSServlet.init(
at javax.servlet.GenericServlet.init(

After finding absolutely no documentation whatsoever for this error we tried a few different things, and after some tests we concluded that the problem was that we have a complex type that in turn contains a sequence of complex types. When we as a test tried changing the inner complex type to a string, then the deploy worked.

This is the types-part of our schema:

<xs:schema targetNamespace=""
<xs:complexType name="document">
<xs:element name="documentId" type="xs:string"/>
<xs:element name="documentStatus" type="xs:string"/>
<xs:complexType name="documentArray">
<xs:element name="document" type="tns:document" minOccurs="0" maxOccurs="unbounded"/>

As I mentioned before, the wsdl is provided, and we can't modify it. So we need to make Weblogic be able to handle it as it is.

Then as a small test, we tried skipping the wsdl temporarilly, and deploy the ejb with just the java code. Then, to our surprice, the deployment worked like a charm, and the web service worked when we tried it using the built in test client in Weblogic. And when we look at the generated wsdl it looks pretty much identical to the original wsdl. So how come Weblogic couldn't handle the original wsdl, but can handle the java-code and then generate a wsdl that is practically the same as the one that it couldn't handle in the first place?

My guess is that when Weblogic starts with the java classes, it automatically knows what java class each complex type should be mapped to, something that it doesn't know when it starts with the wsdl. What we really would want is to be able to provide the wsdl for Weblogic, and make it use the mappings defined as XmlType annotations in the java classes. Can that be done? If not, how can we make Weblogic understand that we want it to use our java classes for specific complex types? Oh, and one more thing, I think we must restrict our web service to JAX-RPC 1.1.

9 years ago

I'm using the cxf-codegen-plugin for Maven to generate java classes for from a WSDL, for a web service. The problem is that the classes(types?) and properties have swedish names, and some names contains 'å', 'ä' or 'ö'. For example the name "fält", meaning "field". So with default configuration CXF and JAXB generates the file "Fä" etc. Also, notice the capital L, it isn't part of the WSDL, maybe a bug in CXF/JAXB causes it. Any way, I would prefer not having java classes with these characters in them so I tried to use a JAXB binding file to bind all the swedish names to english names. Names that doesn't contain åäö works just fine. For example the class/type "rad" ("row") I now can map to But I can't make JAXB map "fält" to "". It just says:

Thrown by JAXB: SCD "~tns:fΣlt" didnt match any schema component

Notice that I didn't type the 'Σ' in the xml binding file. I typed in the 'ä' character, but either CXF/JAXB interprets the character incorrectly (even though the file and xml encoding is UTF-8), or it is just my console window (in windows xp) that can't display it correctly. I also tried using the unicode entity &#229; I also looked at both the WSDL file and the binding file using the program SuperEdi, and it displays the 'ä' character correctly, and identifies the file as UTF-8.
I have also tried entering the capital L instead of lowercase l, with no difference.
Does anyone know how I can make CXF/JAXB rename these classes/types/properties? Maybe there is some regex/wildcard syntax I can use so I can write something like "f*lt"?

Here is my binding file:

9 years ago

Ashish Sarin wrote:Hi Jimi,

I think switching between servlet and portlet can be tricky, but this is where you can only choose to go the servlet way. I would suggest that you use portlet to render form and use AJAX for uploading files , which'll save the effort to switch between portlets and servlets. You may some details in this Liferay Wiki article (which also contains the source code):


Hi Ashish,

Thanks for the tip! I don't understand how I have missed DWR. Some simple tests proved that this should work just fine.

9 years ago

I've gotten into a situation with the CMS we use in a project, where we need to build a form for a portlet, and that form should have some file fields. I planed to use Spring portlet MVC and their form solution, so that I get my bean/command object populated from the form inputs, and also be able to validate the form with ease.

Now, the problem is that the CMS has some servlet filter that reads any multipart/form-data information from the request, making it unavailable for me in the portlet.

When I asked the CMS support about this they said that the filter is an internal-only feature, and even though it is possible to get access to the data (ie the files) that the filter has "absorbed", it is not recommended nor supported, since they might change this implementation at any time. The only recommendation they had for me was to post the form to a servlet in the "portlet webapp", since that would not be subjected to the filter.

I tried their solution, and sure thing, I can now get access to the file data using CommonsMultipartResolver. But I still need to somehow show the form page again after the files has been handled. So now I'm faced with two options, that both have serious disadvantages:

1. I do a forward* to the actionURL of the portlet

2. I do a redirect

The problem with the forward is that I noticed that the onSubmitAction method is never triggered, instead the showForm method is triggered. For some reason my actionURL is handled as a RenderRequest instead of an ActionRequest when I do the forward from the servlet. The result is that my command object is not populated with the form values, and no validation is done. So all that happens is that a new empty form is displayed.

Also, a forward causes the URL in the browser to point to the servlet that the POST was issued for, and that is quite ugly. And this causes the relative urls on the page to stop working (even if that can be fixed by using only absolute urls everywhere).

The problem with the redirect is that I have to store everything in the session for retrieval in the portlet (using the APPLICATION scope). To append all the POST parameters as request parameters on the actionURL is not an option, since the form contains quite a few different input fields, and combined together the URL could be quite long.

What I really would want is a way to make the Spring Portlet MVC form population and validation work without having to do a bunch of manual spring-form stuff. But is that possible given the existing conditions?

If not, is there a good way to use Spring Portlet MVC form classes as regular tools somehow?

Or maybe my best choice is to just bite the bullet and do all the bean field population and validation manually?


* using getServletContext().getContext("/").getRequestDispatcher(actionURL).forward(multipartRequest, response);
9 years ago
I just noticed that by increasing the schedule count and the thread pool size to 20 I got *much* better numbers. Now they are practically perfect. But is that what it takes? Using a lot of threads? And some simple tests incidates that the longer the execution time can be, the more schedules and threads are needed. Seems like there must be a more optimal solution.
10 years ago

This is a follow up on my thread "Util library to help make my code run *slower*?". After using ScheduledExecutorService.scheduleAtFixedRate for a while now I noticed that it was not as good as I first thought. What I want to do is to schedule X number of concurrent threads to run in an evenly distributed fashion. Lets say I want them to execute at most 10 times per second. So if I have 10 threads I want them to execute at the following times counted in milliseconds from the start:

0, 100, 200, 300, 400, 500 etc..

I thought I would accomplice this by setting the delay of the first schedule to 0 ms, the second one to 100 ms etc, and using 1000 ms as a period for all. But that didn't work at all. All the threads gets executed in a bunch on every second, almost exactly.

This is the code:

My TestRunner class simply prints some time information, like the time since the last run, and that number is very low (mostly 0ms, but once in a while maybe 15ms) but then every second it goes up to about 1000ms. Ie it is triggered in bursts rather then in the distributed fashion I expected.

Also, the TestRunner finishes by sleeping for 50ms, simulating doing some real work. But that should not effect the scheduler since it is on a fixed rate lower then 1000ms.

As a side note I first tried using only a single schedule, with a period of 100ms, but the second I started increasing the sleeptime in TestRunner above 100ms it started to effect the time in between runs. And when I increased the sleep time to 1000 ms with the code above it meant that the thread ran once every second. And that is of course what is expected, if one reads the documentation for scheduleAtFixedRate.

So then I tried the method scheduleWithFixedDelay, with this code:

That works great, as long as the sleep time in TestRunner is constant and not to large. When the sleep time comes close to constant 1000ms I notice occasional trigger bursts, but otherwise they trigger happened in about 90 and 110 ms intervalls. And the higher the sleep time I choose, the bursts occurs more frequently, but that is expected, and in reallity I will never expect that the execution time for a single "task" is this high each time. However, the execution time might vary, so to simulate that I made the TestRunner sleep a random time between 50 and 500ms. And when I started the test it indicated good numbers at first, but after having run for about 5 seconds the numbers become all screwed up. Sometimes the time between two runs is 0ms, and sometimes it is almost 600ms. The average is still good, but I want them distributed more evenly.

So then I figured I should try using the scheduleAtFixedRate-method again, and using the same code as above it gave me perfect numbers as long as the sleep time was under 1000ms. But when I let the random sleep time be between 50 and 1500ms then it didn't take long until I saw the same extreme numbers, just as before. It seems that the schedule has been "shaken" by this occational long execution time, and that it can't "recover". And as before, the average is good (close to perfect, even), but I want them distributed more evenly. I don't want anything lower then lets say 80ms between two triggers, while still maintaining a good average. A very few extreme exceptions (maybe once out of a 100) can of course be allowed, but not as many as I am seeing now (only about 25% is within 90ms-110ms).

Basically, what I want is to have a single schedule with fixed delay, but that is executed over more then one thread.

Can anyone give some tips on how I can acchieve this? I'm not looking for perfect numbers, or real time scheduling. I'm just looking for a "good enough" solution where X number of tasks execute concurrently in a somewhat evenly distributed pattern, with Y number of executions per second and where each execution can take between lets say 10ms and 2000ms but most likely in the 200-700ms range, and it should be able to maintain this even distribution for a longer period of time.

10 years ago

Marco Ehrentreich wrote:Hi Jimi,

as I said it's hard to decide what would be a good solution in your specific case without knowing all details. So I can only come up with some (hopefully) useful advices...

For the size of your tasks I agree that it doesn't make much sense to make it smaller than one POST request at a time. Of course it doesn't make much sense to split one request and risk timeouts etc.

I'm still not sure what's the big deal with the delay you want to specify as late as possible. If you would use such a DelayQueue I don't see why it should be a problem to prepare a collection of task and built and populate the queue just when you know what the delay should be. You could even destroy the queue and build a new one if the delay changes in-between.

But I've found a specific ExecutorService in the JDK's concurrent util package which looks even more promising than the DelayQueue: ScheduledExecutorService
It's in general better and more high-level not to take care of the thread handling yourself but to use the ExecutorService facility for this. I just didn't know about this specific executor before. But it seems to do pretty much what you need.

There's a small example in the API doc, too. You'd basically have to encapsulate your working tasks (of sending a POST request) inside a Runnable or Future and enqueue it into the ExecutorService as soon as you know the delay between jobs.

The only other more flexible but also more complex solution for scheduling of jobs I know of, would be the Quartz framework. But for my understanding of what you're trying to achieve this would be overkill.

Hope this one is more helpful


I looked at the ScheduledExecutorService before, but for some reason I didn't really take notice to the method scheduleAtFixedRate. But I did so now, and after some simple tests I think I can conclude that I know how to use it to achieve my goals.

Thank you for your time and effort in helping me, Marco.

10 years ago

Marco Ehrentreich wrote:Hi Jimi,

mabey Java's DelayQueue is of any help for you. Another interesting library I've found with a quick Google search seems to be this Task Queue API although I must admit that I haven't yet used neither the DelayQueue nor this API.

Thanks for your tips. I have already looked at the DelayQueue, and the problem with that is that I don't know what delays to use when the queue is created. The Task Queue API looks promising, but I must say that I am a bit confused of all this talk about URLs. As if they assume the API will be used in a web server context. Also it seems a bit complex, and it is still experimental.

Anyway, I think no matter which solution or API you use there will be some work to be done on your side. You can't just simply slow down the execution of your Java code. So you have to define some kind of "steps" you want to be executed with a delay. I don't know the details of your project but I'm pretty sure that there will be no API available which can in a magical way figure out which steps of your program to slow down in a reasonable way.

Well, of course I know I have to do *some* work on my side.
But for the simple case, I was thinking of using this util class in a way like this:

Ie a very simple configuration, and then two simple methods to keep track of in the job execution threads. I was actually writing on a class that would do this, but then realised that it could already exist, so then I decided to ask in this forum.

Perhaps you should dissect the whole work to be done in smaller "working packages" or however you want to name it an use something like the DelayQueue to enqueue these tasks and execute them with some delay between each task.

Well, as I said, simply sleeping a specific number of milliseconds between each task is not enough for my needs. And regarding smaller "working packages", each task is in my case to do a http get/post, and I don't think I can divide that in any smaller parts.
10 years ago

Does anyone know of any util library that can help ones code to run slower?

Some background: I am currently working on some code that will do GET and POST http requests to web servers (within the same local network), and I would like a way to be able to control the speed that it does sends these requests, if there are a queue of requests waiting to be sent.

I know the simple way is to just make the thread sleep a few ms after each request, but I would like some more detailed control. I would like to be able to send a maximum of lets say 10 requests per second, and these 10 requests should be distributed equally (roughly) over that second (ie i don't want it to send 10 requests rapidly, and then do a pause until the second has finished and then sending 10 more requests rapidly). And preferably it should be able to do this in a multithreaded way.

I am aware that this should be fully possible do to using java.util.concurrent, but that is so low level that I would have to write most of the logic any way, and I figured that this need should already have come up in other projects, so maybe there already exists some util library that does this. Or?

Of course, if someone could give some simple example on how one could use java.util.concurrent to do this without having to write all the logic from scratch, then please tell. The main problem I'm having when I read the documentation for java.util.concurrent is that I can't figure out how to make the threads triggers happen when I want them to. Because the delays between each trigger depends on how often this and the other threads has been triggered lately.

Of course, since I use Httpclient to make the request, it would be nice to know if someone knows how to make it send its requests in this way. Ie I would then have multiple threads using httpclient, and httpclient makes sure that the requests for all these threads are sent with a maximum number per second. The only configuration I have seen is the number of concurrent connections allowed for a single host, but that is not the same thing.

10 years ago

David Newton wrote:Sure, it could be done with Jetty, why not? Or any other container in which you could write a servlet (or whatever).

Well, I know it can be done. I just wanted to know if anyone know of any existing framework that helps me test this. Just as there are frameworks that help produce the http requests when one wants to test a servlet, I thought there might be some framework that helps me test this reverse scenario.

I'm not convinced yet you'd *need* to, though--if you construct a request and want to unit-test that request, aren't you basically unit testing HttpClient?

Well, the way I see it I wouldn't be unit testing htttpclient itself, but instead my own usage of it. And as far as I can tell there are no exact instructions on how to use the httpclient to produce requests in the format that I need (as described in the GSA documentation, see the link in my first post).
10 years ago

I am currently working in a project that uses the Google Search Appliance (GSA), and although its default usage is to act as a web crawler it can be fed so called "Feeds" that can be just as simple as a list of URLs to crawl, up to a list of content (ie the full content) that it should index. These Feeds are in XML format, and are fed to the GSA by doing a HTTP POST to it. I have written the code that does the POST call, but now I have a few problems:

I have no easy access to the GSA server, and it is used in a live environment already, so I am not allowed to do "all sorts of testing". So for now I can not know for sure that the code I have written (using HttpClient) performs the POST correctly so that the GSA will accept it. By using the DEBUG logging mode I managed to get HttpClient print out various information about the request it sends (when I tried it against some random web server). But that information wasn't perfectly clear, so I still don't know if it is in exactly the right format.

But even if it I could confirm that it *is* in the right format, I would very much be able to have a unit test that verifies that, instead of relying on analyzing some debug printouts. So I started looking around, but couldn't find anything really useful in this area. I found a lot of information about how to test a servlet, and mocking http requests. But what I want is the exact opposite. I want to mock a servlet that can take real http requests, and then verify that the requests are in certain format. And I want this mocked servlet to be deployed in a temporary web server on the fly for the duration of the unit test listening on localhost, so I don't have to have any external dependencies.

Does anyone has any tips on how to go on with this? Can this be done with Jetty? Also, if someone is an expert in the HTTP protocol and HttpClient, then maybe he/she could tell me right away if I my code seems about right:

Here is the documentation for the GSA Feeds:

And here is the section that describes what the HTTP POST should look like:

Here is their example of what the post should look like:

Here is my code that sends the request:

And here is the relevant the debug output:

What worries me is that it doesn't output any information about the "feedtype", "datasource" and "data" parts that are added. If I remove the line where I add the "data" part, then it prints out a lot more information, regarding "feedtype" and "datasource":

Is there no way of making it print out this information when I add the "data" part too? Is it because it sends it in a binary form? If so, is there a way to send it in regular urlencoded form? Because that is what the GSA expects. And the file I send *is* a regular plain text xml file. And regarding this, I have no idea why the GSA want it in urlencoded format, because they say:

You should post the feed using enctype="multipart/form-data". Although the search appliance supports uploads using enctype="application/x-www-form-urlencoded", this encoding type is not recommended for large amounts of data.

...and when sending so called "Content Feeds" the data sent can be quite large. Up to 1GB. Isn't it terribly inefficient to urlencode 1GB text data? But still, that is what they seem to demand that I do, even though they don't want me to specify enctype="application/x-www-form-urlencoded", so that confuses me a bit.

Oh, and I use httpcomponents httpclient 4.0.1 if anyone wonders.

10 years ago

abalfazl hossein wrote:
Can't we write our own method to return a string?If it is all about return a string....

Yes, you can most definitely write your own toString method for your own objects. If you haven't tried to do that yet then I suggest that you do. If you have any problems then you can post your code here and maybe someone can point out the error in your code.

May someone explain more about this:

a string representation of the object

Well, that is really only the short description. If you click the link "toString()" you will see the longer description. In short, this method should return a String that represents this object. For example, if the object is an instance of a class named Person, then to toString() method could return a String containing the persons name, phone number etc. Like: "John Doe, 1-23-456-789".
10 years ago

amrita singhal wrote:

Here lies your problem. The lower case 'm' stands for minutes, not month. You should use upper case 'M' instead. And you should only use two 'M's, not three, since three (ie 'MMM') means the month spelled out as a word instead of a number.

Try this instead:

As a tip for future troubleshooting. When you encounter problems, always try to print out the different variable values in your code, to see if they are what you expect. If you would have printed out the dat1 and dat2 values you would have seen that the dates were wrong, thus you would know that the bug is in the parsing of the date.
10 years ago

Anand Sivathanu wrote:let us see this example

here vector's elements() will return a enumeration
then see e.nextElement() which give each object during iteration.
We already know that Enumeration is an interface ,
here how the nextElement() works
How it is possible?

When you use the method elements() what you get is not an instance of the Enumeration interface, since interfaces can't be instantiated. Instead you get some class that *implements* the Enumeration interface. You don't get to know what class that is (unless you look at the source code of the Vector class), but you don't really need to know that. All you need to know is that the object returned provides all the functionality declared by the Enumeration interface.
10 years ago
One other way to solve this could be to do it in a more object oriented way. For example create an operator class for each logical operator (I guess only AND, OR and XOR are relevant) and make each type be responsible for calculating the result of its operation, given two operands. And create some factory class that takes an string as input and outputs an instance of the corresponding operator class. So if the input is "AND" then the output is an instance of the AndOperator class.

And then create one class that is responsible for assigning the operands to the operators. Note that when you have an expression like "a OP1 b OP2 c" this is easier said then done. I mean, which operator should the b-operand belong to? And if we say that it belongs to OP1, then what should be the "left" operand for OP2?
Well the answer to this lies in the operator precedence. AND comes before OR, so if the expression is "a AND b OR c" then the AND operator should get the operands "a" and "b". So what should the OR operator get as left operand? Well, the result of the AND operation! And if you design this cleverly you don't have to know the result of the AND operation when you assign the operands for the OR operation. I'll give you a hint: the operand fields doesn't have to be regular primitive booleans, they can actually be operators themselves.

I actually wrote something like this in school some years back, and it was quite fun.
10 years ago