23 | * number - Unique number (across all products of a vendor) that identifies the licensee. Vendor can assign this
24 | * number when creating a licensee or let NetLicensing generate one. Read-only after creation of the first license for
25 | * the licensee.
26 | *
27 | * active - If set to false, the licensee is disabled. Licensee can not obtain new licenses, and validation is
28 | * disabled (tbd).
29 | *
30 | * Arbitrary additional user properties of string type may be associated with each licensee. The name of user property
31 | * must not be equal to any of the fixed property names listed above and must be none of id, productNumber.
32 | */
33 | public interface Licensee extends BaseEntity {
34 |
35 | // Methods for working with custom properties
36 |
37 | @Deprecated
38 | Map getLicenseeProperties();
39 |
40 | // Methods for interacting with other entities
41 |
42 | Product getProduct();
43 |
44 | void setProduct(Product product);
45 |
46 | Collection getLicenses();
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/TransactionSource.java:
--------------------------------------------------------------------------------
1 | package com.labs64.netlicensing.domain.vo;
2 |
3 | /**
4 | * The transaction source enumeration.
5 | */
6 | public enum TransactionSource {
7 |
8 | /**
9 | * Shop transaction.
10 | */
11 | SHOP,
12 |
13 | /**
14 | * Auto transaction for license create.
15 | */
16 | AUTO_LICENSE_CREATE,
17 |
18 | /**
19 | * Auto transaction for license update.
20 | */
21 | AUTO_LICENSE_UPDATE,
22 |
23 | /**
24 | * Auto transaction for license delete.
25 | */
26 | AUTO_LICENSE_DELETE,
27 |
28 | /**
29 | * Auto transaction for licensee create (with automatic licenses).
30 | */
31 | AUTO_LICENSEE_CREATE,
32 |
33 | /**
34 | * Auto transaction for licensee delete with forceCascade.
35 | */
36 | AUTO_LICENSEE_DELETE,
37 |
38 | /**
39 | * Transaction for update license during validate
40 | */
41 | AUTO_LICENSEE_VALIDATE,
42 |
43 | /**
44 | * Auto transaction for license template delete with forceCascade.
45 | */
46 | AUTO_LICENSETEMPLATE_DELETE,
47 |
48 | /**
49 | * Auto transaction for product module delete with forceCascade.
50 | */
51 | AUTO_PRODUCTMODULE_DELETE,
52 |
53 | /**
54 | * Auto transaction for product delete with forceCascade.
55 | */
56 | AUTO_PRODUCT_DELETE,
57 |
58 | /**
59 | * Auto transaction for transfer licenses between licensee.
60 | */
61 | AUTO_LICENSES_TRANSFER,
62 |
63 | /**
64 | * Transaction for update licenses (inactive with PT LM, Subscription).
65 | */
66 | SUBSCRIPTION_UPDATE,
67 |
68 | /**
69 | * Transaction for recurring payment.
70 | */
71 | RECURRING_PAYMENT,
72 |
73 | /**
74 | * Transaction for cancel recurring payment.
75 | */
76 | CANCEL_RECURRING_PAYMENT,
77 |
78 | /**
79 | * Transaction for obtain bundle.
80 | */
81 | OBTAIN_BUNDLE;
82 | }
83 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/VatMode.java:
--------------------------------------------------------------------------------
1 | package com.labs64.netlicensing.domain.vo;
2 |
3 | public enum VatMode {
4 |
5 | /**
6 | * VatMode: Gross
7 | */
8 | GROSS("GROSS"),
9 |
10 | /**
11 | * VatMode: Net
12 | */
13 | NET("NET");
14 |
15 | private final String value;
16 |
17 | /**
18 | * @param vatModeValue
19 | * vatMode value
20 | */
21 | VatMode(final String vatModeValue) {
22 | value = vatModeValue;
23 | }
24 |
25 | /**
26 | * Get enum value.
27 | *
28 | * @return enum value
29 | */
30 | public String value() {
31 | return value;
32 | }
33 |
34 | /*
35 | * (non-Javadoc)
36 | *
37 | * @see java.lang.Enum#toString()
38 | */
39 | @Override
40 | public String toString() {
41 | return value;
42 | }
43 |
44 | /**
45 | * Parse product VAT mode to {@link VatMode} enum.
46 | *
47 | * @param value
48 | * vatMode value
49 | * @return {@link VatMode} enum object or throws {@link IllegalArgumentException} if no corresponding
50 | * {@link VatMode} enum object found
51 | */
52 | public static VatMode parseValue(final String value) {
53 | for (final VatMode vatMode : VatMode.values()) {
54 | if (vatMode.value.equalsIgnoreCase(value)) {
55 | return vatMode;
56 | }
57 | }
58 | throw new IllegalArgumentException(value);
59 | }
60 |
61 | /**
62 | * Gets the enum safe.
63 | *
64 | * @param val
65 | * the val
66 | * @return the enum safe
67 | */
68 | public static VatMode parseValueSafe(final String val) {
69 | try {
70 | return parseValue(val);
71 | } catch (final IllegalArgumentException e) {
72 | return null;
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/test/resources/mock/netlicensing-notification-list.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | N001-TEST
8 | true
9 | Notification 1
10 | LICENSEE_CREATED
11 | WEBHOOK
12 | http://www.test1.test
13 | ${event}
14 |
15 |
16 | N002-TEST
17 | true
18 | Notification 2
19 | LICENSE_CREATED
20 | WEBHOOK
21 | http://www.test2.test
22 | ${event.timestamp}
23 |
24 |
25 | N003-TEST
26 | true
27 | Notification 3
28 | LICENSEE_CREATED
29 | WEBHOOK
30 | http://www.test3.test
31 | ${event.data}
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # [Labs64 NetLicensing](https://netlicensing.io) Client (Java)
4 |
5 | [](https://github.com/Labs64/NetLicensingClient-java/actions/workflows/netlicesning-client-ci.yml)
6 | [](https://maven-badges.herokuapp.com/maven-central/com.labs64.netlicensing/netlicensing-client)
7 | [](https://github.com/Labs64/NetLicensingClient-java/blob/master/LICENSE)
8 | [](https://netlicensing.io/wiki/restful-api)
9 | [](https://www.linkedin.com/showcase/netlicensing)
10 |
11 | Java wrapper for Labs64 NetLicensing [RESTful API](https://netlicensing.io/wiki/restful-api)
12 |
13 | Visit Labs64 NetLicensing at https://netlicensing.io
14 |
15 | ## Quick Start
16 |
17 | The recommended way to get started using [`netlicensing-client`](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.labs64.netlicensing%22) in your project is with a dependency management system – the snippets below can be copied and pasted into your build configuration.
18 |
19 | Maven:
20 | ```xml
21 |
22 |
23 | com.labs64.netlicensing
24 | netlicensing-client
25 | X.Y.Z
26 |
27 |
28 | ```
29 | Gradle:
30 | ```gradle
31 | dependencies {
32 | compile 'com.labs64.netlicensing:netlicensing-client:X.Y.Z'
33 | }
34 | ```
35 |
36 | OSGi:
37 | ```
38 | Require-Bundle: com.labs64.netlicensing.client;bundle-version="X.Y.Z"
39 | ```
40 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/AbstractRestProvider.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.provider;
14 |
15 | import com.labs64.netlicensing.provider.auth.Authentication;
16 | import com.labs64.netlicensing.provider.auth.TokenAuthentication;
17 | import com.labs64.netlicensing.provider.auth.UsernamePasswordAuthentication;
18 |
19 | /**
20 | */
21 | public abstract class AbstractRestProvider implements RestProvider {
22 |
23 | private Authentication authentication;
24 |
25 | private RestProvider.Configuration configuration;
26 |
27 | @Override
28 | public RestProvider authenticate(final Authentication authentication) {
29 | this.authentication = authentication;
30 | return this;
31 | }
32 |
33 | @Override
34 | public RestProvider authenticate(final String username, final String password) {
35 | authentication = new UsernamePasswordAuthentication(username, password);
36 | return this;
37 | }
38 |
39 | @Override
40 | public RestProvider authenticate(final String token) {
41 | authentication = new TokenAuthentication(token);
42 | return this;
43 | }
44 |
45 | protected Authentication getAuthentication() {
46 | return authentication;
47 | }
48 |
49 | @Override
50 | public void configure(final RestProvider.Configuration configuration) {
51 | this.configuration = configuration;
52 | }
53 |
54 | protected RestProvider.Configuration getConfiguration() {
55 | return configuration;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicenseeConverter.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.schema.converter;
14 |
15 | import com.labs64.netlicensing.domain.Constants;
16 | import com.labs64.netlicensing.domain.entity.Licensee;
17 | import com.labs64.netlicensing.domain.entity.impl.LicenseeImpl;
18 | import com.labs64.netlicensing.domain.entity.impl.ProductImpl;
19 | import com.labs64.netlicensing.exception.ConversionException;
20 | import com.labs64.netlicensing.schema.SchemaFunction;
21 | import com.labs64.netlicensing.schema.context.Item;
22 | import com.labs64.netlicensing.schema.context.Property;
23 |
24 | /**
25 | * Convert {@link Item} entity into {@link Licensee} object.
26 | */
27 | public class ItemToLicenseeConverter extends ItemToEntityBaseConverter {
28 |
29 | @Override
30 | public Licensee convert(final Item source) throws ConversionException {
31 | final Licensee target = super.convert(source);
32 |
33 | // Custom properties
34 | for (final Property property : source.getProperty()) {
35 | if (!LicenseeImpl.getReservedProps().contains(property.getName())) {
36 | target.getProperties().put(property.getName(), property.getValue());
37 | }
38 | }
39 |
40 | target.setProduct(new ProductImpl());
41 | target.getProduct().setNumber(
42 | SchemaFunction.propertyByName(source.getProperty(), Constants.Product.PRODUCT_NUMBER).getValue());
43 |
44 | return target;
45 | }
46 |
47 | @Override
48 | public Licensee newTarget() {
49 | return new LicenseeImpl();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Page.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.domain.vo;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * A page is a sub-list of a list of objects. It allows gain information about the position of it in the containing
19 | * entire list.
20 | *
21 | * @param
22 | */
23 | public interface Page extends Iterable {
24 |
25 | /**
26 | * Returns the number of the current page. Is always non-negative.
27 | *
28 | * @return the number of the current page.
29 | */
30 | int getPageNumber();
31 |
32 | /**
33 | * Returns the number of elements on the page.
34 | *
35 | * @return the number of elements on the page.
36 | */
37 | int getItemsNumber();
38 |
39 | /**
40 | * Returns the number of total pages.
41 | *
42 | * @return the number of total pages
43 | */
44 | int getTotalPages();
45 |
46 | /**
47 | * Returns the total amount of elements.
48 | *
49 | * @return the total amount of elements
50 | */
51 | long getTotalItems();
52 |
53 | /**
54 | * Returns if there is a next page exists.
55 | *
56 | * @return true if there is a next page exists, otherwise false.
57 | */
58 | boolean hasNext();
59 |
60 | /**
61 | * Return container content.
62 | *
63 | * @return container content
64 | */
65 | List getContent();
66 |
67 | /**
68 | * Returns if there is a content exists.
69 | *
70 | * @return true if there is a content exists, otherwise false
71 | */
72 | boolean hasContent();
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/RestResponse.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.provider;
14 |
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | //import jakarta.ws.rs.core.MultivaluedHashMap;
21 | //import jakarta.ws.rs.core.MultivaluedMap;
22 |
23 | /**
24 | * Contains info about response together with response entity.
25 | *
26 | * @param
27 | * type of response entity
28 | */
29 | public class RestResponse {
30 |
31 | private int statusCode;
32 |
33 | private Map> headers;
34 |
35 | private T entity;
36 |
37 | public int getStatusCode() {
38 | return this.statusCode;
39 | }
40 |
41 | public void setStatusCode(final int statusCode) {
42 | this.statusCode = statusCode;
43 | }
44 |
45 | public Map> getHeaders() {
46 | return this.headers;
47 | }
48 |
49 | public void setHeaders(Map> headers) {
50 | this.headers = new HashMap<>();
51 | headers.forEach((header, values) -> {
52 | List this_values;
53 | if (!this.headers.containsKey(header)) {
54 | this_values = new ArrayList<>();
55 | this.headers.put(header, this_values);
56 | } else {
57 | this_values = this.headers.get(header);
58 | }
59 | values.forEach(value -> this_values.add(value));
60 | });
61 | }
62 |
63 | public T getEntity() {
64 | return this.entity;
65 | }
66 |
67 | public void setEntity(final T entity) {
68 | this.entity = entity;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicenseTypePropertiesConverter.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.schema.converter;
14 |
15 | import com.labs64.netlicensing.domain.Constants;
16 | import com.labs64.netlicensing.domain.vo.LicenseTypeProperties;
17 | import com.labs64.netlicensing.exception.ConversionException;
18 | import com.labs64.netlicensing.schema.SchemaFunction;
19 | import com.labs64.netlicensing.schema.context.Item;
20 |
21 | /**
22 | * Converts {@link Item} entity into an implementation of {@link LicenseTypeProperties} interface.
23 | */
24 | public class ItemToLicenseTypePropertiesConverter implements Converter {
25 |
26 | @Override
27 | public LicenseTypeProperties convert(final Item source) throws ConversionException {
28 | if (!Constants.Utility.LICENSE_TYPE.equals(source.getType())) {
29 | final String sourceType = (source.getType() != null) ? source.getType() : "";
30 | throw new ConversionException(String.format("Wrong item type '%s', expected '%s'.", sourceType,
31 | Constants.Utility.LICENSE_TYPE));
32 | }
33 |
34 | final String name = SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue();
35 | return new LicenseTypePropertiesImpl(name);
36 | }
37 |
38 | private static class LicenseTypePropertiesImpl implements LicenseTypeProperties {
39 |
40 | private final String name;
41 |
42 | public LicenseTypePropertiesImpl(final String name) {
43 | this.name = name;
44 | }
45 |
46 | @Override
47 | public String getName() {
48 | return this.name;
49 | }
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/ProductModule.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.domain.entity;
14 |
15 | import java.util.Collection;
16 | import java.util.Map;
17 |
18 | /**
19 | * Product module entity used internally by NetLicensing.
20 | *
23 | * number - Unique number (across all products of a vendor) that identifies the product module. Vendor can assign
24 | * this number when creating a product module or let NetLicensing generate one. Read-only after creation of the first
25 | * licensee for the product.
26 | *
27 | * active - If set to false, the product module is disabled. Licensees can not obtain any new licenses for this
28 | * product module.
29 | *
30 | * name - Product module name that is visible to the end customers in NetLicensing Shop.
31 | *
32 | * licensingModel - Licensing model applied to this product module. Defines what license templates can be
33 | * configured for the product module and how licenses for this product module are processed during validation.
34 | */
35 | public interface ProductModule extends BaseEntity {
36 |
37 | // Methods for working with properties
38 |
39 | String getName();
40 |
41 | void setName(String name);
42 |
43 | String getLicensingModel();
44 |
45 | void setLicensingModel(String licensingModel);
46 |
47 | // Methods for working with custom properties
48 |
49 | @Deprecated
50 | Map getProductModuleProperties();
51 |
52 | // Methods for interacting with other entities
53 |
54 | Product getProduct();
55 |
56 | void setProduct(Product product);
57 |
58 | Collection getLicenseTemplates();
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicensingModelPropertiesConverter.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.schema.converter;
14 |
15 | import com.labs64.netlicensing.domain.Constants;
16 | import com.labs64.netlicensing.domain.vo.LicensingModelProperties;
17 | import com.labs64.netlicensing.exception.ConversionException;
18 | import com.labs64.netlicensing.schema.SchemaFunction;
19 | import com.labs64.netlicensing.schema.context.Item;
20 |
21 | /**
22 | * Converts {@link Item} entity into an implementation of {@link LicensingModelProperties} interface.
23 | */
24 | public class ItemToLicensingModelPropertiesConverter implements Converter {
25 |
26 | @Override
27 | public LicensingModelProperties convert(final Item source) throws ConversionException {
28 | if (!Constants.Utility.LICENSING_MODEL_PROPERTIES.equals(source.getType())) {
29 | final String sourceType = (source.getType() != null) ? source.getType() : "";
30 | throw new ConversionException(String.format("Wrong item type '%s', expected '%s'.", sourceType,
31 | Constants.Utility.LICENSING_MODEL_PROPERTIES));
32 | }
33 |
34 | final String name = SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue();
35 | return new LicensingModelPropertiesImpl(name);
36 | }
37 |
38 | private static class LicensingModelPropertiesImpl implements LicensingModelProperties {
39 |
40 | private final String name;
41 |
42 | public LicensingModelPropertiesImpl(final String name) {
43 | this.name = name;
44 | }
45 |
46 | @Override
47 | public String getName() {
48 | return this.name;
49 | }
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/ServiceException.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.exception;
14 |
15 | import java.util.List;
16 | import java.util.Map;
17 |
18 | //import jakarta.ws.rs.core.MultivaluedHashMap;
19 | //import jakarta.ws.rs.core.MultivaluedMap;
20 | //import jakarta.ws.rs.core.Response;
21 |
22 | import com.labs64.netlicensing.schema.SchemaFunction;
23 | import com.labs64.netlicensing.schema.context.Netlicensing;
24 |
25 | /**
26 | * ServiceException is thrown when error response is received from the service.
27 | */
28 | public class ServiceException extends NetLicensingException {
29 |
30 | private static final long serialVersionUID = 5253993578845477398L;
31 |
32 | private final int statusCode;
33 | private final Map> headers;
34 | private final Netlicensing errorResponse;
35 |
36 | /**
37 | * Construct a ServiceException with the service error response object.
38 | *
39 | * @param status
40 | * response status
41 | * @param headers
42 | * response headers
43 | * @param errorResponse
44 | * the service response containing the error info.
45 | */
46 | public ServiceException(final int statusCode, final Map> headers, final Netlicensing errorResponse) {
47 | super(SchemaFunction.infosToMessage(errorResponse));
48 | this.statusCode = statusCode;
49 | this.headers = headers;
50 | this.errorResponse = errorResponse;
51 | }
52 |
53 | public int getStatusCode() {
54 | return statusCode;
55 | }
56 |
57 | public Map> getHeaders() {
58 | return headers;
59 | }
60 |
61 | public Netlicensing getErrorResponse() {
62 | return errorResponse;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/test/resources/mock/netlicensing-license-list.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | LC001-TEST
8 | true
9 | TimeVolume license
10 | 10.00
11 | EUR
12 | false
13 | L001-TEST
14 | LT001-TEST
15 | 30
16 | LC001-PARENT
17 | 2014-07-07T21:30:45.574Z
18 |
19 |
20 | LC002-TEST
21 | false
22 | Test License 2
23 | 13.00
24 | EUR
25 | false
26 | L001-TEST
27 | LT001-TEST
28 | 30
29 | LC002-PARENT
30 | 2014-07-07T08:10:12.449Z
31 |
32 |
33 | LC003-TEST
34 | true
35 | Test License 3
36 | 15.00
37 | EUR
38 | false
39 | L002-TEST
40 | LT002-TEST
41 |
42 |
43 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/test/resources/mock/netlicensing-bundle-obtain.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | L001-TEST
8 | true
9 | TimeVolume license
10 | 10.00
11 | EUR
12 | false
13 | LE001-TEST
14 | LT001-TEST
15 | 30
16 | LC001-PARENT
17 | 2014-07-07T21:30:45.574Z
18 |
19 |
20 | L002-TEST
21 | false
22 | Test License 2
23 | 13.00
24 | EUR
25 | false
26 | LE001-TEST
27 | LT001-TEST
28 | 30
29 | LC002-PARENT
30 | 2014-07-07T08:10:12.449Z
31 |
32 |
33 | L003-TEST
34 | true
35 | Test License 3
36 | 15.00
37 | EUR
38 | false
39 | LE001-TEST
40 | LT001-TEST
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/test/resources/mock/netlicensing-transaction-list.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | TR001TEST
8 | true
9 | CLOSED
10 | AUTO_LICENSE_UPDATE
11 | 2014-07-08T13:24:02.843Z
12 | 2014-07-08T13:24:02.843Z
13 | true
14 | 1
15 | 19
16 | GROSS
17 |
18 |
19 | TR002TEST
20 | true
21 | PENDING
22 | AUTO_LICENSEE_CREATE
23 | 2014-07-08T13:24:02.824Z
24 | 2014-07-08T13:24:02.824Z
25 | true
26 | 1
27 | 19
28 | GROSS
29 |
30 |
31 | TR003TEST
32 | true
33 | CANCELLED
34 | AUTO_PRODUCT_DELETE
35 | 2014-06-20T23:28:05.571Z
36 | 2014-06-20T23:28:05.571Z
37 | true
38 | 1
39 | 19
40 | GROSS
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToProductModuleConverter.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.schema.converter;
14 |
15 | import com.labs64.netlicensing.domain.Constants;
16 | import com.labs64.netlicensing.domain.entity.ProductModule;
17 | import com.labs64.netlicensing.domain.entity.impl.ProductImpl;
18 | import com.labs64.netlicensing.domain.entity.impl.ProductModuleImpl;
19 | import com.labs64.netlicensing.exception.ConversionException;
20 | import com.labs64.netlicensing.schema.SchemaFunction;
21 | import com.labs64.netlicensing.schema.context.Item;
22 | import com.labs64.netlicensing.schema.context.Property;
23 |
24 | /**
25 | * Convert {@link Item} entity into {@link ProductModule} object.
26 | */
27 | public class ItemToProductModuleConverter extends ItemToEntityBaseConverter {
28 |
29 | @Override
30 | public ProductModule convert(final Item source) throws ConversionException {
31 | final ProductModule target = super.convert(source);
32 |
33 | target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue());
34 | target.setLicensingModel(SchemaFunction.propertyByName(source.getProperty(),
35 | Constants.ProductModule.LICENSING_MODEL).getValue());
36 |
37 | target.setProduct(new ProductImpl());
38 | target.getProduct().setNumber(
39 | SchemaFunction.propertyByName(source.getProperty(), Constants.Product.PRODUCT_NUMBER).getValue());
40 |
41 | // Custom properties
42 | for (final Property property : source.getProperty()) {
43 | if (!ProductModuleImpl.getReservedProps().contains(property.getName())) {
44 | target.getProperties().put(property.getName(), property.getValue());
45 | }
46 | }
47 |
48 | return target;
49 | }
50 |
51 | @Override
52 | public ProductModule newTarget() {
53 | return new ProductModuleImpl();
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/util/XMLDSigValidatorCustom.java:
--------------------------------------------------------------------------------
1 | package com.labs64.netlicensing.util;
2 |
3 | import java.security.Key;
4 |
5 | import javax.annotation.Nonnull;
6 | import javax.xml.crypto.KeySelector;
7 | import javax.xml.crypto.dsig.XMLSignature;
8 | import javax.xml.crypto.dsig.XMLSignatureException;
9 |
10 | import org.w3c.dom.Document;
11 | import org.w3c.dom.Element;
12 | import org.w3c.dom.NodeList;
13 |
14 | import com.helger.commons.ValueEnforcer;
15 | import com.helger.xmldsig.XMLDSigSetup;
16 | import com.helger.xmldsig.XMLDSigValidationResult;
17 | import com.helger.xmldsig.XMLDSigValidator;
18 |
19 | public class XMLDSigValidatorCustom {
20 |
21 | private XMLDSigValidatorCustom() {
22 | }
23 |
24 | /**
25 | * Verify whether Document contains XML signature.
26 | * @param aDoc document to be verified
27 | * @return true if Document contains XML signature
28 | */
29 | public static boolean containsSignature(@Nonnull final Document aDoc) {
30 | return XMLDSigValidator.containsSignature(aDoc);
31 | }
32 |
33 | /**
34 | * Validate XML (imline) signature.
35 | * @param aDoc Document containing inline sign certificate
36 | * @return XMLDSig validation result
37 | * @throws XMLSignatureException
38 | */
39 | public static XMLDSigValidationResult validateSignature(@Nonnull final Document aDoc)
40 | throws XMLSignatureException {
41 | return validateSignature(aDoc, null);
42 | }
43 |
44 | /**
45 | * Validate XML (detached) signature.
46 | * @param aDoc Document signature
47 | * @return XMLDSig validation result
48 | * @throws XMLSignatureException
49 | */
50 | public static XMLDSigValidationResult validateSignature(@Nonnull final Document aDoc, final Key aKey)
51 | throws XMLSignatureException {
52 | ValueEnforcer.notNull(aDoc, "Document");
53 |
54 | // Find Signature element.
55 | final NodeList aSignatureNL = aDoc.getElementsByTagNameNS(XMLSignature.XMLNS, XMLDSigSetup.ELEMENT_SIGNATURE);
56 | if (aSignatureNL.getLength() != 1) {
57 | throw new IllegalArgumentException("Cannot find exactly one Signature element.");
58 | }
59 | final Element aSignatureElement = (Element) aSignatureNL.item(0);
60 |
61 | if (aKey == null) {
62 | return XMLDSigValidator.validateSignature(aDoc, aSignatureElement);
63 | } else {
64 | return XMLDSigValidator.validateSignature(aDoc, aSignatureElement, KeySelector.singletonKeySelector(aKey));
65 | }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/LicenseeImpl.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.domain.entity.impl;
14 |
15 | import java.util.ArrayList;
16 | import java.util.Collection;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | import com.labs64.netlicensing.domain.Constants;
21 | import com.labs64.netlicensing.domain.entity.License;
22 | import com.labs64.netlicensing.domain.entity.Licensee;
23 | import com.labs64.netlicensing.domain.entity.Product;
24 |
25 | /**
26 | * Default implementation of {@link com.labs64.netlicensing.domain.entity.Licensee}.
27 | */
28 | public class LicenseeImpl extends BaseEntityImpl implements Licensee {
29 |
30 | private static final long serialVersionUID = 2704374141788131247L;
31 |
32 | private Product product;
33 |
34 | private Collection licenses;
35 |
36 | /**
37 | * @see BaseEntityImpl#getReservedProps()
38 | */
39 | public static List getReservedProps() {
40 | final List reserved = BaseEntityImpl.getReservedProps();
41 | reserved.add(Constants.Product.PRODUCT_NUMBER); // maps to 'product'
42 | reserved.add(Constants.IN_USE);
43 | reserved.add(Constants.Vendor.VENDOR_NUMBER); // used by shop, therefore disallowed for user
44 | return reserved;
45 | }
46 |
47 | @Override
48 | public Product getProduct() {
49 | return product;
50 | }
51 |
52 | @Override
53 | public void setProduct(final Product product) {
54 | product.getLicensees().add(this);
55 | this.product = product;
56 | }
57 |
58 | @Override
59 | public Collection getLicenses() {
60 | if (licenses == null) {
61 | licenses = new ArrayList();
62 | }
63 | return licenses;
64 | }
65 |
66 | public void setLicenses(final Collection licenses) {
67 | this.licenses = licenses;
68 | }
69 |
70 | @Override
71 | public Map getLicenseeProperties() {
72 | return getProperties();
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToTokenConverter.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.schema.converter;
14 |
15 | import com.labs64.netlicensing.domain.Constants;
16 | import com.labs64.netlicensing.domain.entity.Token;
17 | import com.labs64.netlicensing.domain.entity.impl.TokenImpl;
18 | import com.labs64.netlicensing.domain.vo.TokenType;
19 | import com.labs64.netlicensing.exception.ConversionException;
20 | import com.labs64.netlicensing.schema.SchemaFunction;
21 | import com.labs64.netlicensing.schema.context.Item;
22 | import com.labs64.netlicensing.schema.context.Property;
23 | import com.labs64.netlicensing.util.DateUtils;
24 |
25 | /**
26 | * Convert {@link Item} entity into {@link Token} object.
27 | */
28 | public class ItemToTokenConverter extends ItemToEntityBaseConverter {
29 |
30 | @Override
31 | public Token convert(final Item source) throws ConversionException {
32 | final Token target = super.convert(source);
33 |
34 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Token.EXPIRATION_TIME).getValue() != null) {
35 | target.setExpirationTime(DateUtils.parseDate(SchemaFunction.propertyByName(
36 | source.getProperty(), Constants.Token.EXPIRATION_TIME).getValue()).getTime());
37 | }
38 |
39 | target.setTokenType(TokenType.parseString(SchemaFunction.propertyByName(source.getProperty(),
40 | Constants.Token.TOKEN_TYPE).getValue()));
41 | target.setVendorNumber(SchemaFunction.propertyByName(source.getProperty(),
42 | Constants.Token.TOKEN_PROP_VENDORNUMBER).getValue());
43 |
44 | // Custom properties
45 | for (final Property property : source.getProperty()) {
46 | if (!TokenImpl.getReservedProps().contains(property.getName())) {
47 | target.getProperties().put(property.getName(), property.getValue());
48 | }
49 | }
50 |
51 | return target;
52 | }
53 |
54 | @Override
55 | public Token newTarget() {
56 | return new TokenImpl();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToCountryConverter.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.schema.converter;
14 |
15 | import jakarta.xml.bind.DatatypeConverter;
16 |
17 | import com.labs64.netlicensing.domain.Constants;
18 | import com.labs64.netlicensing.domain.entity.Country;
19 | import com.labs64.netlicensing.domain.entity.impl.CountryImpl;
20 | import com.labs64.netlicensing.exception.ConversionException;
21 | import com.labs64.netlicensing.schema.SchemaFunction;
22 | import com.labs64.netlicensing.schema.context.Item;
23 |
24 | /**
25 | * Convert {@link Item} entity into {@link Country} object.
26 | */
27 | public class ItemToCountryConverter extends ItemToEntityBaseConverter {
28 |
29 | @Override
30 | public Country convert(final Item source) throws ConversionException {
31 | final Country target = super.convert(source);
32 |
33 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.CODE).getValue() != null) {
34 | target.setCode(SchemaFunction.propertyByName(source.getProperty(), Constants.Country.CODE).getValue());
35 | }
36 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.NAME).getValue() != null) {
37 | target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.Country.NAME).getValue());
38 | }
39 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.VAT_PERCENT).getValue() != null) {
40 | target.setVatPercent(DatatypeConverter.parseDecimal(
41 | SchemaFunction.propertyByName(source.getProperty(), Constants.Country.VAT_PERCENT).getValue()));
42 | }
43 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.IS_EU).getValue() != null) {
44 | target.setIsEu(Boolean
45 | .valueOf(SchemaFunction.propertyByName(source.getProperty(), Constants.Country.IS_EU).getValue()));
46 | }
47 | return target;
48 | }
49 |
50 | @Override
51 | public Country newTarget() {
52 | return new CountryImpl();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/util/JAXBUtils.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.util;
14 |
15 | import java.io.ByteArrayInputStream;
16 | import java.io.ByteArrayOutputStream;
17 | import java.io.InputStream;
18 |
19 | import jakarta.xml.bind.JAXBContext;
20 | import jakarta.xml.bind.JAXBElement;
21 | import jakarta.xml.bind.JAXBException;
22 | import jakarta.xml.bind.Marshaller;
23 | import jakarta.xml.bind.Unmarshaller;
24 | import javax.xml.transform.stream.StreamSource;
25 |
26 | /**
27 | */
28 | public final class JAXBUtils {
29 |
30 | public static T readObject(final String resource, final Class expectedType) throws JAXBException {
31 | return readObjectFromInputStream(JAXBUtils.class.getClassLoader().getResourceAsStream(resource), expectedType);
32 | }
33 |
34 | public static T readObjectFromString(final String content, final Class expectedType) throws JAXBException {
35 | return readObjectFromInputStream(new ByteArrayInputStream(content.getBytes()), expectedType);
36 | }
37 |
38 | public static T readObjectFromInputStream(final InputStream inputStream, final Class expectedType) throws JAXBException {
39 | final JAXBContext jaxbContext = JAXBContext.newInstance(expectedType);
40 | final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
41 | final JAXBElement element = unmarshaller.unmarshal(new StreamSource(inputStream), expectedType);
42 | return element.getValue();
43 | }
44 |
45 | public static String xmlEntityToString(final T entity) {
46 | try {
47 | final JAXBContext jaxbContext = JAXBContext.newInstance(entity.getClass());
48 | final Marshaller marshaller = jaxbContext.createMarshaller();
49 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
50 | final ByteArrayOutputStream out = new ByteArrayOutputStream();
51 | marshaller.marshal(entity, out);
52 | return out.toString();
53 | } catch (final JAXBException e) {
54 | throw new RuntimeException("Cannot convert object to string.", e);
55 | }
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Composition.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.domain.vo;
14 |
15 | import java.io.Serializable;
16 | import java.util.HashMap;
17 | import java.util.Map;
18 | import java.util.Map.Entry;
19 |
20 | public class Composition implements Serializable {
21 |
22 | private static final long serialVersionUID = 1L;
23 |
24 | private Map properties;
25 |
26 | private String value;
27 |
28 | public Composition() { // list
29 | value = null;
30 | }
31 |
32 | public Composition(final String value) { // property value
33 | this.value = value;
34 | }
35 |
36 | public Map getProperties() {
37 | if (properties == null) {
38 | properties = new HashMap();
39 | }
40 | return properties;
41 | }
42 |
43 | public String getValue() {
44 | return value;
45 | }
46 |
47 | public void setValue(final String value) {
48 | this.value = value;
49 | }
50 |
51 | public void put(final String key, final String value) {
52 | getProperties().put(key, new Composition(value));
53 | }
54 |
55 | public void put(final String key, final Composition value) {
56 | getProperties().put(key, value);
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | final StringBuilder sb = new StringBuilder();
62 | if (value == null) {
63 | sb.append("{");
64 | if (properties == null) {
65 | sb.append("");
66 | } else {
67 | boolean first = true;
68 | for (final Entry prop : properties.entrySet()) {
69 | if (first) {
70 | first = false;
71 | } else {
72 | sb.append(", ");
73 | }
74 | sb.append(prop.getKey()).append("=").append(prop.getValue());
75 | }
76 | }
77 | sb.append("}");
78 | } else {
79 | sb.append(value);
80 | }
81 | return sb.toString();
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/NetLicensingClient/src/test/java/com/labs64/netlicensing/service/NetLicensingServiceTest.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.service;
14 |
15 | import jakarta.ws.rs.GET;
16 | import com.labs64.netlicensing.provider.HttpMethod;
17 | import jakarta.ws.rs.Path;
18 | import jakarta.ws.rs.core.Response;
19 |
20 | import org.junit.jupiter.api.BeforeAll;
21 | import org.junit.jupiter.api.Test;
22 |
23 | import com.labs64.netlicensing.domain.vo.Context;
24 | import com.labs64.netlicensing.exception.RestException;
25 | import com.labs64.netlicensing.schema.context.ObjectFactory;
26 |
27 | import static org.junit.jupiter.api.Assertions.assertThrows;
28 |
29 | /**
30 | * Common integration tests for {@link NetLicensingService}.
31 | */
32 | public class NetLicensingServiceTest extends BaseServiceTest {
33 |
34 | // *** NLIC Tests ***
35 |
36 | private static Context context;
37 |
38 | @BeforeAll
39 | public static void setup() {
40 | context = createContext();
41 | }
42 |
43 | @Test
44 | public void testNotExistingService() throws Exception {
45 | assertThrows(RestException.class, () -> {
46 | NetLicensingService.getInstance().request(context, HttpMethod.GET, "non-existing-service", null, null);
47 | });
48 | }
49 |
50 | @Test
51 | public void testUnsupportedStatusCode() throws Exception {
52 | assertThrows(RestException.class, () -> {
53 | NetLicensingService.getInstance().request(context, HttpMethod.GET, "unsupported-status-code", null, null);
54 | });
55 | }
56 |
57 | // *** NLIC test mock resource ***
58 |
59 | @Override
60 | protected java.lang.Class> getResourceClass() {
61 | return NLICResource.class;
62 | }
63 |
64 | @Path(REST_API_PATH)
65 | public static class NLICResource {
66 |
67 | private final ObjectFactory objectFactory = new ObjectFactory();
68 |
69 | @Path("unsupported-status-code")
70 | @GET
71 | public Response getUnsupportedStatusCode() {
72 | return Response.status(Response.Status.PARTIAL_CONTENT)
73 | .entity(objectFactory.createNetlicensing())
74 | .build();
75 | }
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/demo/NetLicensingClientDemo.java:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * https://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package com.labs64.netlicensing.demo;
14 |
15 | import org.apache.commons.cli.CommandLine;
16 | import org.apache.commons.cli.CommandLineParser;
17 | import org.apache.commons.cli.DefaultParser;
18 | import org.apache.commons.cli.HelpFormatter;
19 | import org.apache.commons.cli.Options;
20 | import org.apache.commons.cli.ParseException;
21 |
22 | import com.labs64.netlicensing.examples.NetLicensingExample;
23 |
24 | public class NetLicensingClientDemo {
25 |
26 | public static void main(final String[] args) {
27 | final Options options = new Options();
28 | options.addOption("l", false, "list available examples");
29 | options.addOption("r", true, "run specified example");
30 |
31 | final CommandLineParser parser = new DefaultParser();
32 | CommandLine cmd;
33 | try {
34 | cmd = parser.parse(options, args);
35 | } catch (final ParseException e) {
36 | final HelpFormatter formatter = new HelpFormatter();
37 | formatter.printHelp("java -jar netlicensing-client-demo.jar