Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.

Mike London

Ranch Hand
+ Follow
since Jul 12, 2002
Cows and Likes
Cows
Total received
13
In last 30 days
1
Total given
0
Likes
Total received
35
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike London

Norm Radder wrote:The print statement on line 5 prints the contents of the variable: output
The contents of the variable:  output was set on line 2 and not changed after that. 
What was the contents of the variable: value when line 2 was executed?  That was  put into the contents of the variable: output



The confusing part is that unless this is string immutability, I am changing the value of "value".

So "output" is a string plus a variable. I change the value of the variable, but that variable change doesn't update in the output of that string + the variable.

See attached screenshot.

Thanks,

- mike
3 weeks ago

Carey Brown wrote: This has nothing to do with String being immutable. It has to do with the order that statements are processed. On line 2 you set the variable "output" and you don't reset the variable after that so that is what is printed.

Consider:
This will print "0" as well. For the same reason.



OK, this is still confusing.

By saying value = 5, isn't that "resetting" (changing) the variable.

value is defined initially = 0, then I say value = 5.

To me, that means value now gets the value 5.

Yet, it's not reflected in the value variable.

Huh?

3 weeks ago
Hello,

I'm confused about something really basic.

Why is the output of the code below zero and not 5?



Is this because a String is immutable and I can't readily update it as I was thinking?

So. to update a String in a loop based on some value, would I need to create a new string each time?

Thanks,

- mike
3 weeks ago

Piet Souris wrote:Given that you must deal with synonyms, a Map<String, List<Word>> seems more reasonable.

With the toMap, it means that when we have two equal Strings, we need to put the two associated Words into a List. Now, that is not so easy to accomplish with the toMap method, but the alternative mappng method is in this case very much easier. I'm talking about the Collectors.groupingBy method. See the API of the Collectors class; we can use the simplest version, only specifying the key. So we get:



Unfortunately, your suggestion above throws a NullPointerException -- "NullPointerException: element cannot be mapped to a null key"

After more searching an experimentation, the code below seems to work. Not sure why this is so (needs to be so) complicated or really any better than the older simple loop that works easily. I get the "flexibility" part, but when the code syntax gets this messy and complicated to do something conceptually simple, something isn't right.

Thanks.

- mike

    
3 weeks ago

Piet Souris wrote:hi Mike,

for the toMap you need two mappers, one that maps the element to a key, and one that maps the element to a value (and if there is a possibility of having non unique keys, a BiFunction that tells what to do with the values in that case). You already have the key mapper, you need a value mapper. So the second argument would be: word -> word, or somewhat more stylish: Function.identity().

In that last case: why does the method reference: Function::identity not work?



Here's a sample program I wrote to demonstrate where I'm stuck. Searched and searched, but can't find any examples that seem right.


Need a merging function of some type but I can't get the syntax correct.

Tried different variations of "merge" but the syntax is so messy, it's difficult to get right unless you already know how to do it.

Thanks in advance,

- mike
4 weeks ago
Great info, thanks!

- mike
4 weeks ago
Hello,

I have an ArrayList with a 170K Word objects with three fields:

1. Word
2. WordType
3. Definition

What I want to do with this list now is create a Map for efficient searching.

Using the pre-Java 8 way, I can do that like this:


I get the word from the word object for the key and store the item object (the three fields) as the value.

Yet, I can't see how to do this with Java 8 syntax.

Tried to do something similar like this:



But that didn't work.

Suggestions appreciated.

Thanks,

-- mike
4 weeks ago

Rob Spoor wrote:For Twitter there is even a library you can use: http://twitter4j.org/en/. I've used this in the past for just this purpose. Just keep the rate limiting in mind.



For Twitter I'm using JTwitter. Unfortunately it doesn't directly support Maven so I had to import it into my own local repo for builds.

--

Has anyone actually read the new Terms and Conditions for Twitter developer accounts (starting in July, 2018)? There is stuff in there about agreeing to third-party audits and other onerous T's & C's.

Does that mean you're supposed to now store every Twitter search or other Twitter action done and the response in case they want to "audit" you???

Seems like a very nasty agreement. A developer repellent.

WTF?

- mike
1 month ago
Hello,

I have a client who wants to screen-scrape sites like Facebook, Twitter, and other social media sites for content based on key-word searches.

Since Facebook, for example, as I understand it, doesn't publicly display user postings, what are the limitations with screen scraping social media sites in general?

I found several good libraries like HTMLUnit, and Jaunt, but am wondering about the feasibility of such a project in the first place.

Thanks for any suggestions!

-mike
1 month ago
PROBLEM SOLVED!

Turns out I had a redundant Content-Type as URL Encoded.

Since I was already URLEncoding the Base64Encoded file, this extra Request header made some files not extract correctly.

Working fine on SpringBoot 2.0.4 now also.

Thanks again to all.

- mike
1 month ago
Thanks for the replies!

As I mentioned, most of the PDFs work fine in Springboot. The Apache Tika framework is the "converter". The PDF binary data comes encoded as text so Spring shouldn't be coughing up a hairball on this Request.

Additionally, as I didn't mention initially, the exact same logic but using Spark Java REST framework works perfectly.

Thus, it's not the encoding.

I tried to upgrade to SpringBoot 2.0.4.RELEASE this morning, but my project would no longer build. I'll work on that and see if that helps.

This problem seems to be possibly related to the size of the request as the same thing happens with a huge text file (Spring only).

Thanks,

-- Mike
1 month ago
Hello,

I have a (mostly) working Apache Tika implementation in a SpringBoot service.

From the third-party application, I pass the binary PDF file content first wrapped by a Base64Encode function, then wrapped again by a URLEncode function (just to be sure...) to the service (then decode both steps in the service to get the PDF binary file back after this transmission). Once I have the binary file re-constructed in the service, I then extract the text content and return it as the service's Response using the Tika library.

However, I found a "problem" PDF that gives me an odd Spring message. (Extracting the PDF in standalone Tika works fine.)

The error is a 400. Bad Request. "org.springframework.http.converter.HttpMessageNotReadableException".

I tried to set a break-point right in the first line of code in the controller but the 400 problem happens before that.

The Charles HTTP Proxy reports a "broken pipe".

Again, most files, including PDFs work fine, so I'm baffled what's going on with this one. This particular "problem" PDF does have lots of symbols, equations, and graphs, but it works standalone so I'm not sure what to try next.

I did upgrade SpringBoot to 1.5.15.RELEASE, but that made no difference.

Would appreciate any suggestions.

Thanks,

- mike
1 month ago

Rob Spoor wrote:You don't need @RequestBody, only @RequestParam. Unlike JAX-RS (which uses @QueryParam), this does not only check for query parameters but all request parameters. If it can be returned by ServletRequest.getParameter it can be injected as @RequestParam. An example:

Note that these parameters are all required; to make them optional you need to explicitly state this (and use either the value or name annotation property). You can also define default values:

See https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html for more information.



Interesting. I couldn't get this to work, but I did finally get my request parameters working.

Here's what I tried using your idea above in my SpringBoot POST method:



It complains that the variables are not present (tried with and without the trailing "=").

Thanks,

- mike
1 month ago

Rob Spoor wrote:If you can't use 4 method parameters all annotated with @RequestParameter, you can always have the HttpServletRequest as a method parameter and query its parameters.



Yes, passing four parameters from a third-party application in the RequestBody.

So. is it possible to annotate the @RequestBody piece of the POST method to indicate the four POST variables using @RequestParamater so I can get them exactly with no string parsing madness?

Syntax example?

Thanks,

- mike
1 month ago
Hello,

I am POSTing four parameters to a SpringBoot POST method.

The problem is, there doesn't seem to be any way to easily get each parameter that I've found so I'm using substring methods to try to get each parameter's data out. This approach is fraught with problems since it assumes where your "&" characters are relative to other parts of the POST string.

Just really looking for any ideas how to handle the multi-POST situation in code.

This POST issue is a huge problem for me right now.

Thanks in advance,

-- mike
1 month ago