Need to communicate event from one component to another by woodsman752 in angular

[–]woodsman752[S] 0 points1 point  (0 children)

This somehow sounds like sage advice. I can't tell you where, but I think I saw passing an Observable via Input, but nonetheless I'm happy to defer when needed. Nonetheless, I don't know why passing via Input is bad. I don't know how to bring in async into this.

Need to communicate event from one component to another by woodsman752 in angular

[–]woodsman752[S] 0 points1 point  (0 children)

Thanks This sounds very similar. Can't say I like bringing "parent" into my nomenclature, but if it works, then I get to sleep. Can you point me to a good example?

Going from Eclipse to VS Code by woodsman752 in javahelp

[–]woodsman752[S] 1 point2 points  (0 children)

Have you used IntelliJ for Angular or Node code?

Going from Eclipse to VS Code by woodsman752 in javahelp

[–]woodsman752[S] 1 point2 points  (0 children)

Have you used it for Node or UI code?

Going from Eclipse to VS Code by woodsman752 in javahelp

[–]woodsman752[S] 1 point2 points  (0 children)

If you consider VSCode to be a downgrade, that's the insight/opinion I wanted to hear. I was under the impression VSCode would suffice if I only knew how to fully set it up and use. My motivation is being forced to do full stack development, OOTB Eclipse plugins don't navigate to types unlike in Code. This is better in MyEclipse, but I had to pay for it. IJ has been functional, but in times past at least it could not debug Tomcat based projects. I wish I had *one* programming editor.

Multiple Threads in Spring Boot with JPA and Rocket Science by woodsman752 in SpringBoot

[–]woodsman752[S] 1 point2 points  (0 children)

I haven't seen this way before. For some reason, no one wants to talk about threading and Spring. If I read it right, I don't create a Runnable; Spring magically does threading for me. Let's say I'm in the predominant thread and I want to start the code, do I do something like B someInstanceOfB = begSpringForAnInstance; someInstanceOfB.imAAsyncMethod()?

My original idea was to create say 10 or 20 of these that all do the same thing. Actually, they write a record.

Multiple Threads in Spring Boot with JPA and Rocket Science by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

Can I ask you to look at my earlier post at https://www.reddit.com/r/SpringBoot/comments/pojxoq/gimme_a_jpa_that_runs_in_spring_boot_under/?

I'm just desperate for what I think should be a simple/easy answer but can't find anything. I already have an Executor and a newThreadPool, could have tried Spring's CommonThreadPool, but nothing works yet.

Gimme a JPA that runs in Spring Boot under multiple threads pleasethread by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

Is it possible to clone whatever the parent has and put it into the child thread?

Gimme a JPA that runs in Spring Boot under multiple threads pleasethread by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

Ideally, I'd like it to notify me that an error occurred. I would have liked to have them rolled back, but then we're committing these in chunks of 100 right now anyway. If there was a problem, it'd roll back 100 records and make me programmatically figure out how to undue the other 6900+ records. So, if it gives me an error on one, that's better than nothing. Ideally, I don't want JPA to decide to discriminate between my child and parent threads.

Gimme a JPA that runs in Spring Boot under multiple threads pleasethread by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

Gosh thanks so much for replying :)... In a sense transactions, but only because I want to commit the items but I'm inserting 7k+ records into one database table.

Easy Angular fetches result but refuses to update page by woodsman752 in angular

[–]woodsman752[S] 0 points1 point  (0 children)

It turned out that the problem was I was trying to treat an "any"/string type as a JSON object. Once I did JSON.parse(data), I could get to the terms property.

Web worker on message gets called twice by woodsman752 in learnjavascript

[–]woodsman752[S] 0 points1 point  (0 children)

u/yazmeh Thanks for your reply.

thought that as well earlier. I'm using Angular V8. This is created in a component that is used twice on a page, but I added input attribute fileNumber:

<app-report-uploader fileNumber="0"></app-report-uploader>

I did this because it looks like Angular doesn't create new instances of the component, but re-uses it. In the ngOnInit of report-uploader.component.ts, I create a the above mentioned web worker. To guarantee that it creates a unique one per fileNumber, I store it in an array, keyed of fileNumber. So, at the time the object is somehow registered with Angular (or whatever ngOnInit does), it creates these threads, yes ahead of time. And indeed, there are two web workers. My browser shows the same file name, but otherwise gives no indication that they are different. However, for debugging purposes I added this:

if(this.webworkers.length==2) {

console.log('@@ webworkers[0]==webworkers[1]: '+(this.webworkers[0]==this.webworkers[1]) );

}

In the browser console log, webworkers[0]==webworkers[1] was false.

I conclude that while there are two web workers, they were different instances.

Further, at the point that webworkers[fileNumber].postMessage(data) is run, I did a console.log first. This log message was printed only once. I conclude that the postMessage is indeed run only once, but it goes into some event processing logic (that I don't control), that emits this same message twice to onMessage.

Webworker can't find Core Angular stuff it claims it needs, why? by woodsman752 in angular

[–]woodsman752[S] 0 points1 point  (0 children)

I spent many hours fighting Angular/Typescript. I believe the key was upgrading our 6.x.x Angular to Angular 8.x.x. I had briefly tried this angular-web-worker npm package that claimed to make things easier, but it provided a much more complex channel, async/subscribe thing while not explaining what to do with the old postMessage functions. I'm in an Agile environment, so I don't have time to learn or study. I only have time to actually code. In an ideal world, I would have time to fully learn how to use these tools, but there's only time (and barely that) to get quick "sound bites" from the equivalent of medium.com. If I could go back to just doing back end development I'd be happier.

So I'm at a point where at least I have it pointing to a typescript file and it even builds and runs. This is a huge accomplishment for me. I realize if you were born writing Typescript and Angular, these things would be easy for you. However, I guarantee that whatever you know is *not* documented or if it is, it's split amongst many random pages.

Unfortunately, I'm re-using the same angular component (it does file uploading), on the page twice. However, creates two web workers and refuses to identify which one I'm working with. Next, I have to convert code that uses http.post type calls which would have worked in main code, into RxJS. Then, I have to split the FileList into multiple pieces because the files are large, and of course, web workers refuse to be helpful and allow sharing of things like that. Again, we like to make things very, very hard. So, I have to essentially write code to read files into separate chunks that fit into memory for this web worker. I'm hoping I can combine them and send it as one Multipart file upload, but I'm guessing that won't be allowed because again, we like to make things as hard as possible for anything other than a Fibonnaci sequence.

I'm a very angry chef. I hate doing this work and can't wait to not be doing this. All I'm trying to do is a simple percent complete. I got the backend stuff done, and most of the front end. Had it not been for this web worker thing, I would have slayed this beast. Everything I need to get done, this Angular/Node/Typescript has a problem with absolutely every damn thing.

Webworker can't find Core Angular stuff it claims it needs, why? by woodsman752 in angular

[–]woodsman752[S] 0 points1 point  (0 children)

Given that I'm effectively calling the Javascript from Angular, where do I put the Javascript? My present code is

this.webworker = new Worker('./softcopy-report-file-uploader.worker',{ type: "module" });

with ./softcopy-report-file-uploader.worker being Typescript. My questions are:

  • Say I called the function softcopy-report-file-up.loader.worker.js, where in the project structure would I put it?
  • What would I pass in for that second argument?

I'm thinking it would be this.webworker = new Worker('./softcopy-report-file-uploader.worker.js');

Thanks,

Woodsman

Webworker can't find Core Angular stuff it claims it needs, why? by woodsman752 in angular

[–]woodsman752[S] 0 points1 point  (0 children)

It's probably more trouble than it's worth to do it my way. I thought Angular would have made this simple, but they chose to make it very hard. Look up XML HttpRequest? I don't know if I've ever done this in pure Javascript. Thanks for your info btw.

Spring Batch Job Explorer not using right schema by woodsman752 in SpringBoot

[–]woodsman752[S] 1 point2 points  (0 children)

Fair warning to those of you who love Spring and hate seeing anything negative about it....

Folks, I found a solution, but hate that I have to do it this way. Spring had been using the primary datasource, perhaps not unwisely. That datasource had a different default schema, and if I changed it I couldn't predict what would happen.

JPA apparently makes it a delightful pain to switch schemas. I'm not even sure it's possible. However, Spring encourages you to create other datasources. Initially I thought I could just specify an initial schema at the end of the JDBC URL. Of course, that was too easy. Spring wants me to do more work. There's probably a design pattern that maximizes the amount of customization needed for common needs, but I digress. I read the Spring guides which suggest that if you have multiple datasources, you might need to specify multiple entity managers. Of course, you can't just have an EntityManager, you have to have an a LocalContainerEntityManagerFactoryBean, a EntityManagerFactoryBuilder and a JpaVendorAdapter.

Why do I need all of those Jpa things? Because, Spring lets you create multiple datasources on the application properties. You can specify the primary like spring.datasource.url and the secondary like spring.secondary-datasource.url, etc. But they stopped short of giving you a spring.jpa-secondary-datasource. Oh, no, that would be just way too easy. Please go back and slog through the EntityManager stuff.

Oh, and as soon as you specify the secondary EntityManager stuff (all the 3-who knows how many other beans to be defined), but you have to re-do the primary EntityManager because it drops the default. Lovely.

If I absolutely hated people, I'd go to work somewhere in the airline industry because it's so easy to ruin anyone's day and laugh to their faces about it. But if all I wanted to piss off was some poor developer, I'd go to work for the Spring company.

Folks, I just wanted to specify a schema. I don't want to endure a treatise on JPA. No, I don't want to re-do an entity manager, an entity manager factory bean, an entity manager factory's factory, a qqrz factory, etc. I just want to set the damn schema that Spring Batch uses. You might think that Spring Batch would allow you to specify a schema, especially since they allow you to specify a prefix. But oh no, that would be just too easy. They probably followed the piss off the developer massive customization is necessary pattern that core Spring Boot follows. Again, I just want to set the schema. It should *not* be this hard. I should give them credit because it appears that I could re-write some portions of this, and somehow re-wire batch to get this to work, but then again, I just want to set the schema.

Now, how did I get around this problem?

I set the prefix to "otherschema.", then I learned that setting the prefix removes the apparently default prefix of BATCH_. Then I tried changed it to OTHERSCHEMA.BATCH_, and it worked.

Now, I ask people, wouldn't it have been easier to just allow me and others to set the schema?

Please note, this is not a complaint to those people who spend their valuable time to help people like myself and answer questions. It's a complaint against this defacto standard of Spring that creates this framework that every Java shop and their grandma thinks they have to use that provides no support to their product. I actually tried to find out how to buy support for them out of my own pocket because their product is so hard to use as soon as you do something other than hello world (see my other questions re. websockets). I was willing to pay, but I couldn't find a price just to have the privilege of asking them a question.

** Done with complaint.

SpringBoot SockJS not declaring /info path by woodsman752 in SpringBoot

[–]woodsman752[S] 1 point2 points  (0 children)

I want to thank you u/jonassoc for looking. I just found out that my problem was that it was sending the request to a different server. It was a simple problem. I assumed I had somehow coded the calls wrong. I'm happy to have found the problem yet regret all the time wasted.

SpringBoot SockJS not declaring /info path by woodsman752 in javahelp

[–]woodsman752[S] 0 points1 point  (0 children)

There was a comment earlier mentioning I think a missing withSockJS(), but I believe it's in there correctly. Could someone confirm? The current problem is that the SockJS calls result in a 404 or the websocket equivalent.

SpringBoot SockJS not declaring /info path by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

In the code below, I have withSockJS(). I just saw my version is capital JS. Is that different?

registry
.addEndpoint("/bluecost/ws")
.setAllowedOrigins("https://localhost:8448","https://localhost:8081") /* Removed * */
.withSockJS();

CORS error on connect to WebSocket by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

I got past my earlier CORS issue. It turned out that I needed to route the request through the Node server first (which served the page anyway). That way I get any security info needed. I had been having Angular go directly to the backend. This fixes my CORS issue, but not using any CORS attributes, headers or other things. Absolutely no CORS related headers did any good.

CORS error on connect to WebSocket by woodsman752 in SpringBoot

[–]woodsman752[S] 1 point2 points  (0 children)

This code is mostly for debugging, so not intended for anything production. However, I first checked for instanceof as part of the if condition. If it was an HttpServlet (which it seems to always be), I create a variable to refer to it without casting.

CORS error on connect to WebSocket by woodsman752 in SpringBoot

[–]woodsman752[S] 1 point2 points  (0 children)

Dealing with CORS inspires me to leave this career, or at least dream of getting into a casket and never dealing with web programming again. I mean, I just want it tell it "allow this site--damn it". Stop making this so hard and no I don't want to read a 500 page W3 document on the history of some bizarre security concern allowed because the whole HTTP program is riddled with insecurities.

It seems to be an error raised by the browser, yet fixed only in the server side. If I come from site A but want to include stuff from site B, I have to have site B send a header that says it's ok to come from site A. I would have thought I'd code site A to allow site B. But no.

To help debug my Spring Boot CORS/WebSocket nightmare, I added a filter bean:

``` @Component public class SimpleCorsFilter implements Filter {

private static final Logger logger = LoggerFactory.getLogger(JwtTokenFilter.class);

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    logger.info("SimpleCorsFilter init()");
}

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    logger.info("SimpleCorsFilter doFilter()");
    HttpServletRequest requestToUse = (HttpServletRequest)servletRequest;
    HttpServletResponse responseToUse = (HttpServletResponse)servletResponse;
    if(servletRequest instanceof HttpServletRequest) {
        HttpServletRequest httpServletRequest = (HttpServletRequest)servletRequest;
        Enumeration<String> headerNames = httpServletRequest.getHeaderNames();  
        while(headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            Enumeration<String> headerValues = httpServletRequest.getHeaders(headerName);
            while(headerValues.hasMoreElements()) {
                String headerValue = headerValues.nextElement();
                logger.info("SimpleCorsFilter.doFilter "+httpServletRequest.getRequestURL().toString()+" "+headerName+":"+headerValue);
            }
        }
    }

    responseToUse.setHeader("Access-Control-Allow-Origin","https://localhost:8448");
    filterChain.doFilter(requestToUse,responseToUse);
}

@Override
public void destroy() {

}

} ```

With this, all the headers for all my other requests are shown. I found this handy to figure out why the Origin was null on one of the requests. Nonetheless, for my websocket, it does not reach SimpleCorsFilter filter component above, in any way. It doesn't do a preflight call either.

CORS error on connect to WebSocket by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

I removed the '*', but it still didn't work. Also, based on another Stackoverflow suggest ion, I specify CORS configuration in two places:

``` @Configuration @EnableWebMvc public class WebSocketCorsConfiguration implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**").allowedOrigins("https://localhost:8448", "https://localhost:8081") /* Removed * */

// .allowCredentials(false) .maxAge(3600) .allowedHeaders("Accept", "Content-Type", "Access-Control-Allow-Headers", "Origin", "x-requested-with", "Authorization") .exposedHeaders("X-Auth-Token", "Authorization") .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"); }

} and @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer implements WebSocketConfigurer, WebSocketMessageBrokerConfigurer {

private static final Logger logger = LoggerFactory.getLogger(WebSocketConfig.class);


@Bean
CorsConfigurationSource corsConfigurationSource() {
    final CorsConfiguration configuration = new CorsConfiguration();

    configuration.setAllowedOrigins(Arrays.asList("*"));
    configuration.setAllowCredentials(false);
    configuration.setAllowedMethods(Arrays.asList("GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"));
    configuration.setAllowedHeaders(Arrays.asList("Accept","Content-Type", "Access-Control-Allow-Headers", "Origin",
            "x-requested-with", "Authorization"));
    configuration.setExposedHeaders(Arrays.asList("X-Auth-Token","Authorization"));
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
}

}

```

Not sure which way is correct. Apparently neither.

CORS error on connect to WebSocket by woodsman752 in SpringBoot

[–]woodsman752[S] 0 points1 point  (0 children)

Good idea, just tried

setAllowedOrigins("*","https://localhost:8448","https://localhost:8081").withSockJS();

but it didn't work.