Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration to HttpClient #6951

Merged
merged 56 commits into from Jan 18, 2018
Merged

migration to HttpClient #6951

merged 56 commits into from Jan 18, 2018

Conversation

NilsWild
Copy link
Contributor

@NilsWild NilsWild commented Jan 5, 2018

see: #6281

  • Please make sure the below checklist is followed for Pull Requests.

  • Travis tests are green

  • Tests are added where necessary

  • Documentation is added/updated where necessary

  • Coding Rules & Commit Guidelines as per our CONTRIBUTING.md document are followed

Copy link
Member

@deepu105 deepu105 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had quick look from my mobile, will take a closer look later

import { PaginationConfig } from './blocks/config/uib-pagination.config';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this import above local imports

import { BrowserModule } from '@angular/platform-browser';
import { Ng2Webstorage } from 'ngx-webstorage';
import { Ng2Webstorage<%_ if (authenticationType === 'jwt') { _%>, LocalStorageService, SessionStorageService <%_ } _%> } from 'ngx-webstorage';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline template should use <% %> syntax

import { AuthExpiredInterceptor } from './blocks/interceptor/auth-expired.interceptor';
import { ErrorHandlerInterceptor } from './blocks/interceptor/errorhandler.interceptor';
import { NotificationInterceptor } from './blocks/interceptor/notification.interceptor';
import { JhiEventManager } from 'ng-jhipster';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this import above local imports along with other library imports

}

get(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/configprops').map((res: Response) => {
return this.http.get('management/configprops', { observe: 'response' }).map((res: HttpResponse<any>) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the server api url removed?


return this.http.post(SERVER_API_URL + 'api/authentication', data, { headers });
return this.http.post(SERVER_API_URL + 'api/authentication', data, { headers: headers});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why switched from shorthand?

<%_ if (authenticationType === 'jwt' || authenticationType === 'uaa') { _%>
{
provide: HTTP_INTERCEPTORS,
useFactory: (injector) => new AuthExpiredInterceptor(injector),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked, this part? (I am not sure)AOT is handling this correctly in the new version...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use useClass here?

@@ -30,10 +30,10 @@ export class SessionsService {
constructor(private http: Http) { }

findAll(): Observable<Session[]> {
return this.http.get(this.resourceUrl).map((res: Response) => res.json());
return this.http.get<Session[]>(this.resourceUrl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really liked this one 👍 It clearly states what is gonna be there ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried to type everything i stubled over not sure though if i really did it eveywhere so far

}, (err: any) => {
if (err instanceof HttpErrorResponse) {
if (err.status === 401) {
<% if (authenticationType === 'jwt') { %>
const loginService: LoginService = this.injector.get(LoginService);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any possibility to remove the injector completely? This looks like hacky, can't we inject these services straight

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will try that tomorrow it should at least work for login service not sure what happens with Principal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok tried to remove it and it doesnt work as it woudl create a cyclic dependenncy becuase login service uses HttpClient that uses the interceptor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, Injector is used to avoid cyclic dependency hell in angular

}

const token = this.localStorage.retrieve('authenticationToken') || this.sessionStorage.retrieve('authenticationToken');
if (!!token) {
options.headers.append('Authorization', 'Bearer ' + token);
request = request.clone({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it mutate the entire headers? If there are any headers set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no according to this implementation https://github.com/angular/angular/blob/5.1.3/packages/common/http/src/request.ts#L67-L385

setHeaders adds the header. headers would mutate all headers.

badnaming on angular site though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused too... so just wanted to make sure...

}

find(login: string): Observable<User> {
return this.http.get(`${this.resourceUrl}/${login}`).map((res: Response) => res.json());
return this.http.get(`${this.resourceUrl}/${login}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get<User>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep missed it here like i said not sure if i added types everywhere

@sendilkumarn
Copy link
Member

@NilsWild awesome work 👍

@NilsWild
Copy link
Contributor Author

NilsWild commented Jan 6, 2018

will take a closer look tomorrow 2:05 am now :D

@pascalgrimaud
Copy link
Member

Yes, impressive work for a 1st contribution, @NilsWild !

@deepu105
Copy link
Member

@NilsWild we would love more inconvenience from you then 😺

@NilsWild
Copy link
Contributor Author

Failed: Angular could not be found on the page http://localhost:8080/.If this is not an Angular application, you may need to turn off waiting for Angular.

any idea what may cause this?

@sendilkumarn
Copy link
Member

Hopefully application cannot run on the browser (it should have had some errors)

@deepu105
Copy link
Member

deepu105 commented Jan 12, 2018 via email

@sendilkumarn
Copy link
Member

@NilsWild Please be never sorry when contributing to opensource 👍 This is an amazing work 👍

@jdubois
Copy link
Member

jdubois commented Jan 12, 2018

Yes what you did @NilsWild is awesome! Thanks so much.

@NilsWild
Copy link
Contributor Author

Thank you all

@deepu105 failed for same reason

@deepu105 deepu105 changed the base branch from master to spring-boot-2 January 13, 2018 14:23
@deepu105 deepu105 changed the base branch from spring-boot-2 to master January 13, 2018 14:23
@deepu105
Copy link
Member

@mraible need your help here, the ngx-mariadb-oauth2-sass-infinispan build is failing and I tried it locally and seems like protractor tests are failing as the keycloak login screen appears as soon as I launch the application, even before clicking sign in, I guess something changed due to the new Angular Http client used here, probably the way interceptors work. Could you take a look?

@mraible
Copy link
Contributor

mraible commented Jan 13, 2018 via email

@NilsWild
Copy link
Contributor Author

@deepu105 thanks for the hint i think i got it stupid mistake by me

@mraible

@deepu105
Copy link
Member

@mraible no hurry at all and I guess @NilsWild got it. @NilsWild if you are stuck please let Matt know

@NilsWild
Copy link
Contributor Author

build looks good now :D

@deepu105
Copy link
Member

@jhipster/developers can somebody take this on a test drive?

@kamilcieslak
Copy link
Contributor

  • while writing tests for app/shared/model package I've noticed, that _request-util.ts:createRequestOption
    changed its behavior
  • previous implementation only took into consideration predefined parameters (page, size, sort, query and filter), leaving alone other passed parameters
  • new implementation will add all passed properties to output/query parameters

Is that desired behavior?

@NilsWild
Copy link
Contributor Author

NilsWild commented Jan 14, 2018

Hm... actually i just kept the implementation with some slightly modifications in method parameters (to keep the signature as it is right now) that was discussed in the corresponding issue. As you pass a "req" - the request options as an object - i think it should also be the desired behavior to create httpParams out of those.

Just my opinion atm.

@deepu105
Copy link
Member

I'm merging this so we have time to check

@deepu105 deepu105 merged commit ed69799 into jhipster:master Jan 18, 2018
@deepu105
Copy link
Member

@NilsWild both your PR merged. I also released ng-jhipster 0.4.0, so you can upgrade to that and remove angular/http
Thanks for your huge work

@jdubois
Copy link
Member

jdubois commented Jan 18, 2018

Yes thank you for your awesome work!!

@NilsWild
Copy link
Contributor Author

@deepu105 i create a new pull request for that purpose?

thanks to everyone for the kind words

@sendilkumarn
Copy link
Member

yeah sure please.

@jdubois jdubois added this to the 4.14.0 milestone Jan 30, 2018
pascalgrimaud added a commit to pascalgrimaud/jhipster-registry that referenced this pull request Mar 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants