beat-it / 01-jsf

1 stars 1 forks source link

Problém pri PUT /cart #4

Closed ladislavP closed 7 years ago

ladislavP commented 7 years ago

Neviem kde robím chybu, ale pri requeste PUT /cart dostávam chybu. Telo requestu {deliveryType: this.state.delivery, paymentMethod: this.state.payment} Error 2016-12-03 13:40:41,412 ERROR [io.undertow.request] (default task-52) UT005023: Exception handling request to /service/cart: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:77) at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:220) at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:175) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:418) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at org.wildfly.swarm.generated.FaviconErrorHandler.handleRequest(FaviconErrorHandler.java:62) at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:94) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException at org.beat.it.frontend.transformer.cart.PersonTransformer.transform(PersonTransformer.java:15) at org.beat.it.frontend.transformer.cart.PersonTransformer$Proxy$_$$_WeldClientProxy.transform(Unknown Source) at org.beat.it.frontend.rest.cart.CartResource.cart(CartResource.java:68) at org.beat.it.frontend.rest.cart.CartResource$Proxy$_$$_WeldClientProxy.cart(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402) ... 43 more

pdudits commented 7 years ago

Musíš posielať hlavičku "Authorization: Bearer ". Token ti príde v každom response.

A aby si ju vedel prečítať v klientovi potrebuješ verziu zo včera večera, kde som opravil CORS hlavičky.

U mňa to vyzerá takto: https://github.com/beat-it/01-angular2/blob/deadline/src/app/backend.ts#L31

ladislavP commented 7 years ago

Dakujem za skoru odpoved. Authorizaciu samozrejme zasielam. Pridavam este cisty HTTP request:

`PUT /service/cart HTTP/1.1 Host: localhost:8080 Authorization: Bearer n6l9goh1vbas06f958kmndvrmc Content-Type: application/json Cache-Control: no-cache Postman-Token: a71a1a5f-7ccb-287b-292f-97554fda154e

{ "deliveryType": "KURIER", "paymentMethod": "CARD_ONLINE" }`

fpt-nessian commented 7 years ago

na PUT /service/cart cakame toto DTO

private String deliveryType;
private String paymentMethod;
private PersonDTO person;
private BillingDetailsDTO billingAddress;
private AddressDTO address;

priklad:

Request method: PUT Request path: http://localhost:8080/service/cart Proxy: Request params: Query params: Form params: Path params: Multiparts: Headers: Accept=application/json, application/javascript, text/javascript Authorization=Bearer tlmioavhpbinaa7qn1c1ndqtoq Content-Type=application/json; charset=UTF-8 Cookies: Body: { "deliveryType": "KURIER", "paymentMethod": "DOBIERKA", "person": { "forename": "Martin", "surname": "Petruna", "email": "dabrockij@gmail.com", "phone": "0907471133" }, "billingAddress": { "billingAddress": { "street": "Moldavska 10", "city": "Kosice", "zip": "04011", "country": "Slovakia" }, "company": { "name": "Prodium s.r.o.", "dic": "123", "ico": "456", "icDph": "789" } }, "address": { "street": "Moldavska 10", "city": "Kosice", "zip": "04011", "country": "Slovakia" } }

pdudits commented 7 years ago

No ako som ti vcera pisal, @fpt-nessian , asi sme cakali ze mozme dat aj parcialnu zmenu a dozvediet sa vysledok, nech nemusime duplikovat logiku backendu (ano, ide o tri scitania, ktore by sme museli spravit 😀).

Ja uz to mam takmer tak spravene a poslem PR, ale na to treba, aby postupnost requestov bola ina:

PUT /cart spravi parcialnu zmenu a vratit novy stav kosika (hlavne preratany payment).

POST /cart/order by bolo na potvrdenie objednavky a az vtedy by mal byt sprocesovany a vyprazdneny.

ladislavP commented 7 years ago

Ja mam scitania urobene... ja som chcel parcialnu zmenu na to aby som si ulozil vyplnene data po odoslani prveho a druheho kroku kosika.

V prvom kroku kosika si pouzivatel vyberie SPOSOB DOPRAVY A PLATBY, po odoslani iba tychto udajov sa ulozia do objektu kosika. Ked teraz v tomto moemnte dam refresh tak by mi tieto udaje prisli pri dopyte na GET /cart. V druhom kroku je obrovsky formular, po dokonceni kroku urobim PUT /cart aby sa udaje ulozili aby som nemusel po refresh opat vsetko vypisovat. A kedze sa jedna o example podla mna vobec netreba mat aj end-point POST /cart/order. Staci aby sa dali ulozit jednotlive kroky kosika. Aspon za mna.

fpt-nessian commented 7 years ago

Ok pridam aj moznost parcialnej zmeny. Resp. teda pockame na @pdudits pull request?