43
WebStore #maven JAX-WS SOAP WS, Stateful Session Bean, PMD, JavaDoc Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 8 Dávid Bedők 2018-03-03 v1.0 Dávid Bedők (UNI-OBUDA) WebStore () 2018-03-03 v1.0 1 / 43

WebStore #maven - JAX-WS SOAP WS, Stateful Session Bean ......DávidBedők (UNI-OBUDA)WebStore(wsdl-overview.tex) 2018-03-03v1.0 6/43 The parts of the WSDL refer to each ot-her.Theservice

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

  • WebStore #mavenJAX-WS SOAP WS, Stateful Session Bean, PMD, JavaDoc

    Óbuda University, Java Enterprise EditionJohn von Neumann Faculty of InformaticsLab 8

    Dávid Bedők2018-03-03v1.0

    Dávid Bedők (UNI-OBUDA) WebStore () 2018-03-03 v1.0 1 / 43

  • SOAP webservices

    . 1998, 2000 (v1.1), 2003 (v1.2 W3C recommendation)

    . Simple Object Access Protocol (SOAP), but after the version 1.2 wedo not use the ’expanded’ form

    . For an XML SOAP Request message an XML SOAP Response messagewill arrived (an XSD describes the type information)

    . Web Services Description Language (WSDL) describes thecommunication and the rules

    . In general it is sent via HTTP(S) (as in case of the RESTfulwebservices), but this is only a frequent option here

    . Highly extensible, great and sophisticated, guided by standards

    . Encryption and digital signature supprt - Web Services Security(WS-Security, WSS)

    . Universal Description Discovery and Integration (UDDI),webservice registration in finders

    Dávid Bedők (UNI-OBUDA) WebStore (soap-ws.tex) 2018-03-03 v1.0 2 / 43

  • Top-Down vs. Bottom-Up approach

    . Top-down approach: we create a WSDL then we are generated therequired Java classes (stubs (XSD) and service classes based on theWSDL).

    . Bottom-up approach: we create Java code (stubs, services withannotations) then we are generate a WSDL.

    Regarding the clientTo create a client application we only need the WSDL (which is an XMLdocument, so that file is the key for the cross-language behavior). This filecontains the XSD(s) which grants the type-safe communication betweenthe client and the server.

    Dávid Bedők (UNI-OBUDA) WebStore (topdown-vs-bottomup.tex) 2018-03-03 v1.0 3 / 43

  • ConfigurationSOAP message format (four combinations)

    . Encoding Style/Communication Style (named attribute in the WSDL)• Document/Message-Oriented : freely formable XML content• RPC : more bound (more detailed often) but easier to process by machi-

    nes. Encoding Models (named attribute in the WSDL)

    • Literal : the content must fit the type information of the XSD (XSD va-lidation). We can easily transform this message to something else withXSLT transformation (e.g. : create XHTML documents for a webpage/web-application)

    • Encoded : only predefined XSD types can be used (cumbersome valida-tion)

    In case of Document style we have the change to validate the SOAPResponse, but the same thing in case of RPC is very circumstantial. Wewill choose the Document/literal SOAP message format in the blueprintproject.

    Dávid Bedők (UNI-OBUDA) WebStore (configuration-message.tex) 2018-03-03 v1.0 4 / 43

  • ConfigurationParameter Stlye

    . Parameter Style (different references inside the WSDL)• BARE : Do not wrap anything in the SOAP messages. If we wo-

    uld like readable results we have to create wrapper classes for theparameters and the return values.

    • WRAPPED : the parameters of the requests and the responseswill be wrapped around the messages (more transparent but itgenerates bigger SOAP messages)

    We will choose the WRAPPED Parameter Style in the blueprint project.

    Dávid Bedők (UNI-OBUDA) WebStore (configuration-parameter.tex) 2018-03-03 v1.0 5 / 43

  • WSDL overviewBased on the implemented webstore blueprint� �1 2 3 [..]

    4 5 [..]6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 � �

    Dávid Bedők (UNI-OBUDA) WebStore (wsdl-overview.tex) 2018-03-03 v1.0 6 / 43

    The parts of the WSDL refer to each ot-her. The service refers the binding, thebinding refers the portType and withinthat the operation(s), the portType’soperation(s) refer(s) the message(s)and the message(s) refer(s) the items ofthe types (XSD of the WSDL).

  • SOAP messages - Request and Response� �1 2 3 4 5 6 � �

    SOAP Request

    The http://schemas.xmlsoap.org/soap/envelope/ namespace defines the basic elements andattributes (e.g. :. Envelope, Header, Body, etc.), while the http://www.qwaevisz.hu/WebStorenamespace defines the application’s domain (e.g. : ListAllProducts,ListAllProductsResponse).� �1 2 3 4 5 6 7 8 9

    10 11 12 � �

    SOAP ResponseDávid Bedők (UNI-OBUDA) WebStore (soap-messages.tex) 2018-03-03 v1.0 7 / 43

    http://schemas.xmlsoap.org/soap/envelope/http://www.qwaevisz.hu/WebStore

  • WebStoreSOAP webservices

    Task : Create a webstore application where you can buy various brands TV.The application will store the (stock) items in memory and do not deal withthe authentication of the users.Build a SOAP webservice which able to query the stock items and another one which handles the user’s webbasket.The webbasket stores items (brand, name, price) during the lifetime of heuser-session. If the user buys from the same item more than one, changeonly the quantity in his/her basket.

    [gradle|maven]\jboss\webstore

    Dávid Bedők (UNI-OBUDA) WebStore (webstore.tex) 2018-03-03 v1.0 8 / 43

  • WebStoreRequirements

    . The customer may set an identifier for the basket and he/she can ret-rieve that value later (only demonstration purpose). If we try to reacha nameless basket the system gives us a SOAP Fault error message.

    . We will implement a Stateful Session Bean to handle the state of thewebbasket.

    . We are going to use the SOAP-UI application as a SOAP client app-lication, but we will write a custom standalone Java client applicationas well.

    Dávid Bedők (UNI-OBUDA) WebStore (requirements.tex) 2018-03-03 v1.0 9 / 43

  • Project structureLocation of the modules

    Dávid Bedők (UNI-OBUDA) WebStore (webstore-overview.tex) 2018-03-03 v1.0 10 / 43

  • Persistence layerws-persistence project

    � �1 @Local2 public interface StoreHolder {3 void create(Product product);4 Product read(String name);5 List readAll(String nameTerm);6 List readAll(Brand brand);7 List readAll ();8 void delete(String name);9 }� �

    StoreHolder.java� �1 @Local2 public interface PersistenceService {3 void create(Product product) throws PersistenceException;4 Product read(String name) throws PersistenceException;5 List readAll(String nameTerm) throws PersistenceException;6 List readAll(Brand brand) throws PersistenceException;7 List readAll () throws PersistenceException;8 void delete(String name) throws PersistenceException;9 }� �

    PersistenceService.java

    Dávid Bedők (UNI-OBUDA) WebStore (persistence-services.tex) 2018-03-03 v1.0 11 / 43

    The StoreHolder Singlet-on Session Bean stores (andinitializes) the domain types(Brand and Product), and thePersistenceService StatelessSession Bean ensures access forthe services of the EJB layer.

  • Datamodelws-persistence and ws-ejbservice project

    . Persistence layer• Brand : PHILIPS, SONY, PANASONIC• Product : brand (Brand), name (String), price (int)

    . EJB Service layer• BrandStub : PHILIPS, SONY, PANASONIC• ProductStub : brand (BrandStub), name (String), price (int)• BasketItem : product (ProductStub), quantity (int)• Basket : identifier (String), items (List)• ServiceError : code (int), message (String)

    XML annotationsThe stubs are decorated with the XML Bind annotations, because we have to serializethese instances into SOAP XML messages.@XmlAccessorType(XmlAccessType.FIELD) : The annotations are defined on the fields.@XmlAccessorType(XmlAccessType.PROPERTY) : The annotations are defined on thegetter methods.

    Dávid Bedők (UNI-OBUDA) WebStore (domain.tex) 2018-03-03 v1.0 12 / 43

    The Basket class contains thebusiness methods to handlethe webbasket (increment(),decrement(), getSize(),getTotal()).

  • XML Binding� �

    1 @XmlAttribute(name = "productName")2 private String name;� �The name of the product is an example for the FIELD based XML binding.The SOAP business name differs from the source code names (differentnaming rules). With the @XmlAttribute annotation we can create XMLattribute of course, where the widespread spelling is camelCase. We cannotuse @XmlAttribute annotation in complex types.� �1 @XmlAttribute(name = "total")2 public int getTotalPrice () {..}� �We can present the total value of the basket with a computed field in theXML message. Here we can use only the PROPERTY based binding.� �1 @XmlElement(name = "Items")2 public List getItems () {..}� �In case of lists, arrays or sets we can use the @XmlElement annotation.According to the current config this name will be the group name of theitems. The widespread spelling of the elements is the CamelCase writing,which differs from the rules of the Java naming.

    Dávid Bedők (UNI-OBUDA) WebStore (stub-xml-bind.tex) 2018-03-03 v1.0 13 / 43

  • EJB Service - Error handlingws-ejbservice project

    We are going to create SOAP Fault custom message (XML) from thestate of the ServiceError. Of course the EJB layer will throws an exception(ServiceException) in case of error, in which we will pack an error code(WebStoreError enum: IDENTIFIER, PERSISTENCE, PRODUCT, BASKET).

    Dependency between layersTowards the public interfaces (SOAP) the EJB service layer will create stubs fromthe Product and Brand instances (as we have known before, with the help ofthe ProductConverter Stateless Session Bean). Notice that regardless of thepersistence layer’s type (currently we store the data in memory), the structure ofthe EJB service layer remained the same. At this time the conversion seems to usoverkill (or the entire persistence layer at all), with that little technique we will ableto introduce the RDBMS storage at this application without rewriting the servicelayer (the storage layer does not depend on the logical layer).

    Dávid Bedők (UNI-OBUDA) WebStore (ejbservice-error-handling.tex) 2018-03-03 v1.0 14 / 43

  • EJB Service - Servicesws-ejbservice project� �1 @Local2 public interface WebBasketService {3 void setIdentifier(String identifier) throws ServiceException;4 String getIdentifier () throws ServiceException;5 int getBasketSize () throws ServiceException;6 void addItem(String productName) throws ServiceException;7 void removeItem(String productName) throws ServiceException;8 Basket getContent () throws ServiceException;9 }� �

    WebBasketService.java� �1 @Local2 public interface StoreService {3 void add(ProductStub product) throws ServiceException;4 ProductStub get(String name) throws ServiceException;5 List list(String nameTerm) throws ServiceException;6 List list(BrandStub brand) throws ServiceException;7 List getAll () throws ServiceException;8 void remove(String name) throws ServiceException;9 }� �

    StoreService.javaDávid Bedők (UNI-OBUDA) WebStore (ejbservice-services.tex) 2018-03-03 v1.0 15 / 43

    Stateful Session Bean

    Stateless Session Bean

  • Stateful Session Bean

    . The implementation class has the @Stateful annotation.

    . The class may contain instance fields. The states of these fields areinterpreted per sessions. If the same session calls an other method ofthe same SFSB, the EJB container will give an instance with the samestate to serve the request.

    . The method which has the @PostConstruct annotation will beexecuted when a new session calls a business method inside the bean.

    . The method which has the @Remove annotation will be executed whenthe session becomes invalid or it does not reachble any more (e.g. :timeout).

    State managementBeside the Stateful Session Bean the Singleton Session Bean is also able to store state,but the lifecycle of that is similar to the Stateless Session Bean, because here we do notneed activation and passivation.

    Dávid Bedők (UNI-OBUDA) WebStore (stateful-session-bean.tex) 2018-03-03 v1.0 16 / 43

  • Session BeanStates and Lifecycles

    . In case of Stateless and Singleton Session Beans or Message-DrivenBeans

    • Does not exist state• Ready state (ready to execute a business method via proxy)

    . In case of Stateful Session Beans• Does not exist state• Ready state (active, ready to execute a business method)• Passive state

    ◦ The container writes the state of the bean to ’secondarystorage’ from memory (it would be useful later but currentlythe user does not use it).

    ◦ @PrePassivate and @PostActivate methods can becreated

    @PostConstruct and @PreDestroy methods can be created anywhere

    Dávid Bedők (UNI-OBUDA) WebStore (session-beans-lifecycle.tex) 2018-03-03 v1.0 17 / 43

  • WebStoreService - Framews-webservice project

    WSDL : http://localhost:8080/webstore/WebStoreService?wsdl� �1 package hu.qwaevisz.webstore.webservice;2 [..]3 @WebService(name = "WebStore", serviceName = "WebStoreService", targetNamespace =

    "http :// www.qwaevisz.hu/WebStore")4 @SOAPBinding(style = Style.DOCUMENT , use = Use.LITERAL , parameterStyle =

    ParameterStyle.WRAPPED)5 public class WebStoreService {6 [..]7 @EJB8 private StoreService storeService;9

    10 @WebMethod(action = "http ://www.qwaevisz.hu/WebStore/getProduct", operationName ="GetProduct")

    11 @WebResult(name = "Product")12 public ProductStub getProduct(@WebParam(name = "Name") String name) throws

    WebStoreServiceException {13 try {14 return this.storeService.get(name);15 } catch (ServiceException e) {16 throw new WebStoreServiceException(e.getMessage (), e.getError ());17 }18 }19 [..]20 }� �

    WebStoreService.javaDávid Bedők (UNI-OBUDA) WebStore (webstoreservice-frame.tex) 2018-03-03 v1.0 18 / 43

    We can set the namespace with the help ofthe @WebService annotation, and configurethe service with the @SOAPBinding annotati-on.

    http://localhost:8080/webstore/WebStoreService?wsdl

  • WebStoreService - GetProductws-webservice project

    The method which has the @WebMethod annotation will be an operation/messagepair in the webservice. We can configure it via the attributes of the annotation(e.g. : it’s name in the WSDL). If the name of the operation is GetProduct (andthis will be a independent element in the SOAP Request), than the response in theSOAP Response will be inside a GetProductResponse element.� �1 @WebMethod(action = "http ://www.qwaevisz.hu/WebStore/getProduct", operationName =

    "GetProduct")2 @WebResult(name = "Product")3 public ProductStub getProduct(@WebParam(name = "Name") String name) throws

    WebStoreServiceException {4 [..]5 }� �The @WebResult annotation will be the wrapper of the return value. TheProductStub instance will be closed into a Product element in the SOAP Respon-se. If we do not specify the @WebResult, the ’return’ will be its default value (the@XmlRootElement annotation does not matter in that case). With the @WebParamannotation you can define the XML element names of the request (in the examplewe will need a Name element to define the name of the product).

    Dávid Bedők (UNI-OBUDA) WebStore (webstoreservice-getproduct.tex) 2018-03-03 v1.0 19 / 43

  • SOAP messages - GetProduct� �1 2 3 4 5 SD85 4K HDR6 7 8 � �

    SOAP Request� �1 2 3 4 5 6 7 � �

    SOAP Response

    Handling error casesIf the WebMethod throws an exception than a SOAP Fault will begenerated. Otherwise the instance of the return value will be serialized asan XML.Dávid Bedők (UNI-OBUDA) WebStore (soap-messages-getproduct.tex) 2018-03-03 v1.0 20 / 43

    The brand, productName and price attribute names are come fromthe ProductStub’s XML Bind annotations.

  • WSDL - Retrieve a productType information� �1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [..]29 � �

    Dávid Bedők (UNI-OBUDA) WebStore (wsdl-getproduct-types.tex) 2018-03-03 v1.0 21 / 43

    The type information comes partly fromthe http://www.w3.org/2001/XMLSchemanamespace elements (e.g. : int, string)and party from the application’s ownhttp://www.qwaevisz.hu/WebStorenamespace.

    http://www.w3.org/2001/XMLSchemahttp://www.qwaevisz.hu/WebStore

  • WSDL - Retrieve a productDefine messages� �1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [..]27 28 � �Dávid Bedők (UNI-OBUDA) WebStore (wsdl-getproduct-messages.tex) 2018-03-03 v1.0 22 / 43

    Therse refer the type definition.

    Because of the perspicuity theexample does not contain theWSDL parts of the error handling.

  • SOAP WebService - Error handlingSOAP Fault

    If an error occurs at the server side it would be elegant if we will send aSOAP Fault message as a response. The SOAP Fault marks the event(faultcode and faultstring), and it may give details optionally(detail). Latter could be a result of the XML serialization of the exceptionclass.� �1 2 3 4 soap:Server 5 Product does not exist in the catalog (name: lorem).6 7 8 209 Product does not exist in the catalog (name: lorem).

    10 11 12 13 14 � �

    Dávid Bedők (UNI-OBUDA) WebStore (soap-fault.tex) 2018-03-03 v1.0 23 / 43

  • ServiceError DTOws-ejbservice project� �1 package hu.qwaevisz.webstore.ejbservice.domain;2 [..]3 @XmlRootElement(name = "ServiceError")4 public class ServiceError implements Serializable {56 private final int code;7 private final String message;89 public ServiceError () { this(0, null); }

    1011 public ServiceError(final int code , final String message) { [..] }1213 @XmlElement(name = "code")14 public int getCode () {15 return this.code;16 }1718 @XmlElement(name = "message")19 public String getMessage () {20 return this.message;21 }2223 @Override24 public String toString () {25 return "ServiceError [code=" + this.code + ", message=" + this.message + "]";26 }27 }� �

    ServiceError.javaDávid Bedők (UNI-OBUDA) WebStore (service-error-dto.tex) 2018-03-03 v1.0 24 / 43

    JAX-B : Be default the XML serialization uses@XmlAccessorType(XmlAccessType.PROPERTY) con-figuration (so we put the annotation to the gettermethods).

  • Custom SOAP Fault messagews-webservice project� �1 package hu.qwaevisz.webstore.webservice.exception;2 [..]3 @WebFault(name = "WebStoreServiceFault", targetNamespace =

    "http :// www.qwaevisz.hu/WebStore")4 public class WebStoreServiceException extends Exception {5 private final ServiceError faultInfo;6 public WebStoreServiceException(String message , ServiceError

    faultInfo) {7 super(message);8 this.faultInfo = faultInfo;9 }

    10 public WebStoreServiceException(String message , ServiceErrorfaultInfo , Throwable cause) {

    11 super(message , cause);12 this.faultInfo = faultInfo;13 }14 public ServiceError getFaultInfo () {15 return this.faultInfo;16 }17 }� �

    WebStoreServiceException.javaDávid Bedők (UNI-OBUDA) WebStore (custom-soap-fault.tex) 2018-03-03 v1.0 25 / 43

    If the exception has a @WebFault anno-tation and the @WebMethod throws aninstance of the that exception it will becaused a SOAP Fault message.

    The message attribute will be thefaultstring in the SOAP Fault (youcan change that in your application ofcourse).

    The XML serialized return value of thegetFaultInfo() getter method will bethe detail content of the SOAP Fault(you have to use that method name).

  • SmartBear: SoapUIFunction and End-to-End test application/platform

    . https://www.soapui.org/

    . Version: v5.4.0

    . Install : next-next-finish

    . Free, open-source, but there is a commercial Pro variation as well

    . Function/End-to-End testing• SOAP webservices• RESTful webservices• JMS support (integrated HermesJMS library)

    . high level security support (encryption, digital signatures, etc.)

    Dávid Bedők (UNI-OBUDA) WebStore (soap-ui.tex) 2018-03-03 v1.0 26 / 43

    https://www.soapui.org/

  • SmartBear: SoapUICreate SOAP client based on the WSDL

    File | New SOAP project. Project name: WebStore. Initial WSDL:http://localhost:8080/webstore/WebStoreService?wsdl

    . Create sample requests for all operations

    . Creates a TestSuite for the imported WSDL

    That is all?Yes, that is it. The WSDL contains all the necessary information, an fullyfunctional client application may by generated. There is nothing special aboutthis, we can do the same with a CLI command. The WSDL can be loadedfrom a file (offline generation).

    Dávid Bedők (UNI-OBUDA) WebStore (soap-ui-create-client.tex) 2018-03-03 v1.0 27 / 43

    http://localhost:8080/webstore/WebStoreService?wsdl

  • WebStoreService - AddProductws-webservice project

    � �1 @WebMethod(action = "http ://www.qwaevisz.hu/WebStore/addProduct",

    operationName = "AddProduct")2 public void addProduct(@WebParam(name = "Product") ProductStub

    product) throws WebStoreServiceException {3 [..]4 }� �� �1 2 3 � �

    SOAP Request� �1 � �SOAP Response

    Dávid Bedők (UNI-OBUDA) WebStore (add-product.tex) 2018-03-03 v1.0 28 / 43

  • Online purchase process - I

    SOAP Request SOAP Response� �1 2 423 � �

    � �1 � �

    � �1 � �

    � �1 2 423 � �� �

    1 2 SD85 4K

    HDR3 � �

    � �1 � �

    Stateful service in the background → You do not need to add the Identifierin the later requests (this behavior is attempted to simulate this request). Thecontainer keeps the state for you per user-sessions. In case of Stateless service wehave to store the data for example in an in-memory database, and we have to usethe identifier in each request.

    Dávid Bedők (UNI-OBUDA) WebStore (purchase-step-1.tex) 2018-03-03 v1.0 29 / 43

    We buy two peaces from one of the TV (so we send thesame message twice) and put another one into our basketas well.

  • Online purchase process - II

    SOAP Request SOAP Response� �1 � �

    � �1 2 23 � �

    � �1 � �

    � �1 2 3 4

    5 6 7

    8 9

    10 � �Dávid Bedők (UNI-OBUDA) WebStore (purchase-step-2.tex) 2018-03-03 v1.0 30 / 43

  • Java WebService client application

    The webservices (both SOAP and RESTful) are language independent tech-nologies. In case of SOAP WS we only need the WSDL to create a client in anyprogramming language. SoapUI is written by Java, but we only use the WSDLto generate a client application. To create a SOAP WS client application weonly need to send XML documents to an endpoint, typically over HTTP.But it is even easier to create a client if we get to know the wsimport CLItool, which is part of the JDK.� �1 > cd ws-client2 > wsimport -s src/main/java -d bin -keep -p

    hu.qwaevisz.webstore.client.generatedhttp :// localhost :8080/ webstore/WebStoreService?wsdl� �

    The ws-client project will be the client application. We would like to ge-nerate the client classes of the given WSDL under the given package name(hu.qwaevisz.webstore.client.generated) and into the given src/main/javasource directory.

    Dávid Bedők (UNI-OBUDA) WebStore (java-client.tex) 2018-03-03 v1.0 31 / 43

  • Client applicationws-client project� �1 URL endpoint = new

    URL("http :// localhost :8080/ webstore/WebStoreService?wsdl");23 WebStoreService service = new WebStoreService(endpoint);4 WebStore webStore = service.getWebStorePort ();56 try {7 List products = webStore.listAllProducts ();89 for (ProductStub product : products) {

    10 System.out.println("Product: " + product.getBrand () + ":" +product.getProductName () + " ( price: " +product.getPrice () + " $ )");

    11 }12131415 } catch (WebStoreServiceException e) {16 e.printStackTrace ();17 }� �

    Application.javaDávid Bedők (UNI-OBUDA) WebStore (application.tex) 2018-03-03 v1.0 32 / 43

    We would not need the given URLin that example because when wegeneratged the client classes weuse the original WSDL with theright endpoint URL. But the end-point URL is ofter removed fromthe WSDL for security reason, sothe client application has to set itas you see in the example.

  • Communication types

    Dávid Bedők (UNI-OBUDA) WebStore (communication.tex) 2018-03-03 v1.0 33 / 43

  • WebLogic variantModifications

    The application could work without major modification under WebLogic aswell. Only the following should be considered:

    . use JDK logging instead of log4j

    . weblogic expects that the @Remote lifecycle method will be businessmethod as well so we need to put that abstract method in theinterface of the Stateful Session Bean� �

    1 [..]2 @Local3 public interface WebBasketService {4 [..]56 void remove ();7 }� �

    WebBasketService.java

    Dávid Bedők (UNI-OBUDA) WebStore (weblogic.tex) 2018-03-03 v1.0 34 / 43

  • PMDSource code analyzer

    . https://pmd.github.io/

    . Version: v6.1.0

    . Supported languages: Java, JavaScript, PLSQL, Apache Velocity,XML, XSL

    . Documentation: https://pmd.github.io/pmd-6.1.0/

    . Each Rule is part of a RuleSet.

    . There are predefined RuleSets for Java, but we can create customones as well.

    . Rule : name, description, priority, example, implementation class andoptional set of properties (e.g. : CyclomaticComplexity rule has a’reportLevel’ Integer property).

    Dávid Bedők (UNI-OBUDA) WebStore (pmd.tex) 2018-03-03 v1.0 35 / 43

    https://pmd.github.io/https://pmd.github.io/pmd-6.1.0/

  • PMDPriorities

    1. Change absolutely required. Behavior is critically broken/buggy.2. Change highly recommended. Behavior is quite likely to be

    broken/buggy.3. Change recommended. Behavior is confusing, perhaps buggy, and/or

    against standards/best practices.4. Change optional. Behavior is not likely to be buggy, but more just flies

    in the face of standards/style/good taste.5. Change highly optional. Nice to have, such as a consistent naming

    policy for package/class/fields.

    Dávid Bedők (UNI-OBUDA) WebStore (pmd-priority.tex) 2018-03-03 v1.0 36 / 43

  • PMD and Maven integrationroot project� �1 2 3 3.84 5 6 7 8 9 org.apache.maven.plugins

    10 maven -pmd -plugin 11 ${ version.plugin.pmd}12 13 14 /rulesets/java/basic.xml15 /rulesets/java/braces.xml16 17 18 19 20 21 22 � �

    pom.xmlDávid Bedők (UNI-OBUDA) WebStore (pmd-maven.tex) 2018-03-03 v1.0 37 / 43

    All the rule of the given ruleset mustbe valid for all projects. The execu-te the pmd validation run the follo-wing command: ’mvn clean packagepmd:pmd’.

  • PMD rule set descriptorspmd-bin-[version].zip | pmd-bin-[version].zip | lib | pmd-java-6.1.0.jar |rulesets | java | *.xml� �1 2 The Basic ruleset ..3 [..]4

    10 Avoid jumbled ..11 312 13 14 15 16 17 18 19 � �

    basic.xmlDávid Bedők (UNI-OBUDA) WebStore (pmd-rulesets.tex) 2018-03-03 v1.0 38 / 43

    Copy these XML files into therulesets directory of theroot Gradle project (e.g. :rulesets/basic.xml).

  • PMD fine tuningws-ejbservice project

    We can create an own ruleset file with ease if we pick up existing rules andrule sets and we change its properties if needed.� �1 2 78 Custom ruleset 9

    10 11 12 13 � �

    ruleset.xml

    Dávid Bedők (UNI-OBUDA) WebStore (pmd-finetuning-maven.tex) 2018-03-03 v1.0 39 / 43

  • PMD fine tuningDefine own ruleset based on existing ones� �1 23 45 6 7 89

    11 112 1314 15 16 17 18 � �

    ws-ejbservice | config | pmd | ruleset.xml

    Dávid Bedők (UNI-OBUDA) WebStore (pmd-custom-ruleset.tex) 2018-03-03 v1.0 40 / 43

  • javadoc

    The javadoc is a built-in document creation tool of the JDK ([JDK-HOME]/bin). We have to add the location of the source code (-sourcepath), thepackage (com.ericsson.webstore.dummy) what we want to describe. Bydefault it will create HTML documents via oracle java standard doclet).� �1 > javadoc -sourcepath ws -dummy/src/main/java

    hu.qwaevisz.webstore.dummy� �If we need outer sources/libraries to compile to the source files (e.g. : weuse a custom doclet or any third party library) then we have to add thesedependencies (-classpath) as well.� �1 > javadoc -classpath ws-common/build/classes/main -sourcepath

    ws -dummy/src/main/java hu.qwaevisz.webstore.dummy� �

    Dávid Bedők (UNI-OBUDA) WebStore (javadoc.tex) 2018-03-03 v1.0 41 / 43

  • javadoc and Maven integrationcreate javadoc with the help of Maven� �1 2 [..]3 4 2.10.4 5 6 [..]7 8 9

    10 11 org.apache.maven.plugins 12 maven -javadoc -plugin 13 ${ version.plugin.javadoc}14 15 16 17 18 � �

    pom.xml� �1 > mvn site� �

    Dávid Bedők (UNI-OBUDA) WebStore (javadoc-maven.tex) 2018-03-03 v1.0 42 / 43

  • Doclet

    . Doclets are programs written in the Java programming language thatuse the doclet API to specify the content and format of the output ofthe javadoc tool.

    . By default, the javadoc tool uses the ’standard’ doclet provided bySun to generate API documentation in HTML form.

    . The real power of the javadoc is to create an own doclet to generatean up-to-date documentation.

    The path of the doclet’s source can be set with the docletpath argument(we may use jar files as well1), the value of the doclet argument will bethe full qualified name of the doclet class.� �1 > javadoc -classpath ws-common\build\classes\main -docletpath

    ws -doclet\build\classes\main -doclethu.qwaevisz.webstore.doclet.WebStoreDoclet -sourcepathws -dummy\src\main\java -ws -filename ws.xmlhu.qwaevisz.webstore.dummy� �

    1 If you would like to list more than one jar file you have to use ";" separationcharacter in case of win, and ":" character in case of nix.

    Dávid Bedők (UNI-OBUDA) WebStore (doclet.tex) 2018-03-03 v1.0 43 / 43