diff --git a/restcomm/pom.xml b/restcomm/pom.xml index ba929e98f7..542fa45c50 100644 --- a/restcomm/pom.xml +++ b/restcomm/pom.xml @@ -102,7 +102,6 @@ 7.0.50 1.2.0 1.2.0 - 1.13 4.5.2 4.1.3 2.3.1 @@ -333,16 +332,12 @@ - com.sun.jersey - jersey-server - ${jersey.version} + org.glassfish.jersey.containers + jersey-container-servlet + 2.25.1 - - com.sun.jersey - jersey-client - ${jersey.version} - + stax diff --git a/restcomm/restcomm.application/src/main/webapp/WEB-INF/web.xml b/restcomm/restcomm.application/src/main/webapp/WEB-INF/web.xml index 01b2f813b9..757e768627 100644 --- a/restcomm/restcomm.application/src/main/webapp/WEB-INF/web.xml +++ b/restcomm/restcomm.application/src/main/webapp/WEB-INF/web.xml @@ -7,12 +7,16 @@ Jersey - com.sun.jersey.spi.container.servlet.ServletContainer + org.glassfish.jersey.servlet.ServletContainer - com.sun.jersey.spi.container.ContainerResponseFilters - org.restcomm.connect.http.cors.CorsFilter + jersey.config.server.provider.packages + org.restcomm.connect.http + + jersey.config.server.provider.classnames + org.restcomm.connect.http.cors.CorsFilter + diff --git a/restcomm/restcomm.extension.api/pom.xml b/restcomm/restcomm.extension.api/pom.xml index 049c7861c6..5b89d3673b 100644 --- a/restcomm/restcomm.extension.api/pom.xml +++ b/restcomm/restcomm.extension.api/pom.xml @@ -19,12 +19,11 @@ - - com.sun.jersey - jersey-core - ${jersey.version} - + + org.glassfish.jersey.containers + jersey-container-servlet + joda-time joda-time diff --git a/restcomm/restcomm.http/pom.xml b/restcomm/restcomm.http/pom.xml index cd231a1e7c..3e8586fb33 100644 --- a/restcomm/restcomm.http/pom.xml +++ b/restcomm/restcomm.http/pom.xml @@ -48,27 +48,16 @@ httpasyncclient - - com.sun.jersey - jersey-server - - - - com.sun.jersey - jersey-client - - - - com.sun.jersey - jersey-servlet - ${jersey.version} - - com.thoughtworks.xstream xstream + + org.glassfish.jersey.containers + jersey-container-servlet + + org.restcomm restcomm-connect.commons diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java index b52ff468b0..9080e34756 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java @@ -21,7 +21,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.sun.jersey.core.util.MultivaluedMapImpl; import com.thoughtworks.xstream.XStream; import org.apache.commons.configuration.Configuration; import org.apache.shiro.crypto.hash.Md5Hash; @@ -70,6 +69,7 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; import static javax.ws.rs.core.MediaType.APPLICATION_XML; import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE; +import javax.ws.rs.core.MultivaluedHashMap; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.CONFLICT; import static javax.ws.rs.core.Response.Status.NOT_FOUND; @@ -409,7 +409,7 @@ protected Response putAccount(final MultivaluedMap data, final M accountsDao.addAccount(account); // Create default SIP client data - MultivaluedMap clientData = new MultivaluedMapImpl(); + MultivaluedMap clientData = new MultivaluedHashMap(); String username = data.getFirst("EmailAddress").split("@")[0]; clientData.add("Login", username); clientData.add("Password", data.getFirst("Password")); diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/cors/CorsFilter.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/cors/CorsFilter.java index 9dcb847f88..743b9d736b 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/cors/CorsFilter.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/cors/CorsFilter.java @@ -20,9 +20,8 @@ package org.restcomm.connect.http.cors; -import com.sun.jersey.spi.container.ContainerRequest; -import com.sun.jersey.spi.container.ContainerResponse; -import com.sun.jersey.spi.container.ContainerResponseFilter; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; import org.apache.commons.lang.StringUtils; @@ -33,11 +32,11 @@ import org.restcomm.connect.commons.configuration.sources.ConfigurationSource; import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import javax.ws.rs.ext.Provider; import java.io.File; +import java.io.IOException; +import javax.ws.rs.container.ContainerRequestContext; /** * @author otsakir@gmail.com - Orestis Tsakiridis @@ -46,35 +45,37 @@ public class CorsFilter implements ContainerResponseFilter { private final Logger logger = Logger.getLogger(CorsFilter.class); - @Context - private HttpServletRequest servletRequest; + /*@Context + private HttpServletRequest servletRequest;*/ // we initialize this lazily upon first request since it can't be injected through the @Context annotation (it didn't work) + @Context private ServletContext lazyServletContext; String allowedOrigin; + + // We return Access-* headers only in case allowedOrigin is present and equals to the 'Origin' header. @Override - public ContainerResponse filter(ContainerRequest cres, ContainerResponse response) { - initLazily(servletRequest); - String requestOrigin = cres.getHeaderValue("Origin"); + public void filter(ContainerRequestContext cres, ContainerResponseContext response) throws IOException { + initLazily(); + String requestOrigin = cres.getHeaderString("Origin"); if (requestOrigin != null) { // is this is a cors request (ajax request that targets a different domain than the one the page was loaded from) if (allowedOrigin != null && allowedOrigin.startsWith(requestOrigin)) { // no cors allowances make are applied if allowedOrigins == null // only return the origin the client informed - response.getHttpHeaders().add("Access-Control-Allow-Origin", requestOrigin); - response.getHttpHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization"); - response.getHttpHeaders().add("Access-Control-Allow-Credentials", "true"); - response.getHttpHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD"); - response.getHttpHeaders().add("Access-Control-Max-Age", "1209600"); + response.getHeaders().add("Access-Control-Allow-Origin", requestOrigin); + response.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization"); + response.getHeaders().add("Access-Control-Allow-Credentials", "true"); + response.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD"); + response.getHeaders().add("Access-Control-Max-Age", "1209600"); } } - return response; } - private void initLazily(ServletRequest request) { - if (lazyServletContext == null) { - ServletContext context = request.getServletContext(); + private void initLazily() { + if (allowedOrigin == null) { + ServletContext context = lazyServletContext; String rootPath = context.getRealPath("/"); rootPath = StringUtils.stripEnd(rootPath,"/"); // remove trailing "/" character String restcommXmlPath = rootPath + "/WEB-INF/conf/restcomm.xml"; diff --git a/restcomm/restcomm.identity/pom.xml b/restcomm/restcomm.identity/pom.xml index 93bf5463d8..71cf330e84 100644 --- a/restcomm/restcomm.identity/pom.xml +++ b/restcomm/restcomm.identity/pom.xml @@ -45,21 +45,10 @@ provided - - com.sun.jersey - jersey-server - - - - com.sun.jersey - jersey-client - - - - com.sun.jersey - jersey-servlet - ${jersey.version} - + + org.glassfish.jersey.containers + jersey-container-servlet + com.thoughtworks.xstream diff --git a/restcomm/restcomm.provisioning.number.voxbone/pom.xml b/restcomm/restcomm.provisioning.number.voxbone/pom.xml index 43b8559b9c..ab3367bd6c 100644 --- a/restcomm/restcomm.provisioning.number.voxbone/pom.xml +++ b/restcomm/restcomm.provisioning.number.voxbone/pom.xml @@ -28,11 +28,11 @@ mail - - com.sun.jersey - jersey-client - - + + org.glassfish.jersey.containers + jersey-container-servlet + + com.google.code.gson gson diff --git a/restcomm/restcomm.provisioning.number.voxbone/src/main/java/org/restcomm/connect/provisioning/number/voxbone/VoxbonePhoneNumberProvisioningManager.java b/restcomm/restcomm.provisioning.number.voxbone/src/main/java/org/restcomm/connect/provisioning/number/voxbone/VoxbonePhoneNumberProvisioningManager.java index 1c3988a174..e6b06a0bed 100644 --- a/restcomm/restcomm.provisioning.number.voxbone/src/main/java/org/restcomm/connect/provisioning/number/voxbone/VoxbonePhoneNumberProvisioningManager.java +++ b/restcomm/restcomm.provisioning.number.voxbone/src/main/java/org/restcomm/connect/provisioning/number/voxbone/VoxbonePhoneNumberProvisioningManager.java @@ -36,11 +36,12 @@ import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.ClientResponse.Status; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; /** * @author jean.deruelle@telestax.com @@ -93,31 +94,32 @@ public void init(Configuration phoneNumberProvisioningConfiguration, Configurati listDidsURI = uri + "/inventory/did"; Configuration callbackUrlsConfiguration = phoneNumberProvisioningConfiguration.subset("callback-urls"); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); + Client jerseyClient = ClientBuilder.newClient().register(feature); - WebResource webResource = jerseyClient.resource(voiceURI); + WebTarget webResource = jerseyClient.target(voiceURI); String body = "{\"voiceUri\":{\"voiceUriProtocol\":\"SIP\",\"uri\":\"" + callbackUrlsConfiguration.getString("voice[@url]") + "\"}}"; - ClientResponse clientResponse = webResource.accept(CONTENT_TYPE).type(CONTENT_TYPE).put(ClientResponse.class,body); - String voiceURIResponse = clientResponse.getEntity(String.class); + Response clientResponse = webResource.request(CONTENT_TYPE).put(Entity.entity(body,CONTENT_TYPE)); + + String voiceURIResponse = clientResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("response " + voiceURIResponse); JsonParser parser = new JsonParser(); JsonObject jsonVoiceURIResponse = parser.parse(voiceURIResponse).getAsJsonObject(); - if (clientResponse.getClientResponseStatus() == Status.OK) { + if (clientResponse.getStatus() == Response.Status.OK.getStatusCode()) { JsonObject voxVoiceURI = jsonVoiceURIResponse.get("voiceUri").getAsJsonObject(); voiceUriId = voxVoiceURI.get("voiceUriId").getAsString(); - } else if (clientResponse.getClientResponseStatus() == Status.UNAUTHORIZED) { + } else if (clientResponse.getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) { JsonObject error = jsonVoiceURIResponse.get("errors").getAsJsonArray().get(0).getAsJsonObject(); throw new IllegalArgumentException(error.get("apiErrorMessage").getAsString()); } else { - webResource = jerseyClient.resource(voiceURI); - clientResponse = webResource.queryParam(PAGE_NUMBER,"0").queryParam(PAGE_SIZE,"300").accept(CONTENT_TYPE).type(CONTENT_TYPE).get(ClientResponse.class); + webResource = jerseyClient.target(voiceURI); + clientResponse = webResource.queryParam(PAGE_NUMBER,"0").queryParam(PAGE_SIZE,"300").request(CONTENT_TYPE).get(); - String listVoiceURIResponse = clientResponse.getEntity(String.class); + String listVoiceURIResponse = clientResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("response " + listVoiceURIResponse ); @@ -182,10 +184,10 @@ public List searchForNumbers(String country, PhoneNumberSearchFilte logger.debug("searchPattern " + listFilters.getFilterPattern()); } - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); + Client jerseyClient = ClientBuilder.newClient().register(feature); - WebResource webResource = jerseyClient.resource(searchURI); + WebTarget webResource = jerseyClient.target(searchURI); // https://developers.voxbone.com/docs/v3/inventory#path__didgroup.html webResource = webResource.queryParam(COUNTRY_CODE_PARAM,iso3Country); @@ -215,10 +217,10 @@ public List searchForNumbers(String country, PhoneNumberSearchFilte } else { webResource = webResource.queryParam(PAGE_SIZE, "50"); } - ClientResponse clientResponse = webResource.accept(CONTENT_TYPE).type(CONTENT_TYPE) - .get(ClientResponse.class); + Response clientResponse = webResource.request(CONTENT_TYPE) + .get(); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("response " + response); @@ -242,13 +244,13 @@ public List searchForNumbers(String country, PhoneNumberSearchFilte @Override public boolean buyNumber(PhoneNumber phoneNumberObject, PhoneNumberParameters phoneNumberParameters) { String phoneNumber = phoneNumberObject.getPhoneNumber(); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); + Client jerseyClient = ClientBuilder.newClient().register(feature); - WebResource webResource = jerseyClient.resource(createCartURI); - ClientResponse clientResponse = webResource.accept(CONTENT_TYPE).type(CONTENT_TYPE).put(ClientResponse.class,"{}"); + WebTarget webResource = jerseyClient.target(createCartURI); + Response clientResponse = webResource.request(CONTENT_TYPE).put(Entity.entity("{}",CONTENT_TYPE)); - String createCartResponse = clientResponse.getEntity(String.class); + String createCartResponse = clientResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("createCartResponse " + createCartResponse); @@ -258,49 +260,46 @@ public boolean buyNumber(PhoneNumber phoneNumberObject, PhoneNumberParameters ph String cartIdentifier = voxCart.get("cartIdentifier").getAsString(); try { - Client addToCartJerseyClient = Client.create(); - addToCartJerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + Client addToCartJerseyClient = ClientBuilder.newClient().register(feature); + - WebResource addToCartWebResource = addToCartJerseyClient.resource(createCartURI + "/" + cartIdentifier + "/product"); + WebTarget addToCartWebResource = addToCartJerseyClient.target(createCartURI + "/" + cartIdentifier + "/product"); String addToCartBody = "{\"didCartItem\":{\"didGroupId\":\"" + phoneNumber + "\",\"quantity\":\"1\"}}"; - ClientResponse addToCartResponse = addToCartWebResource.accept(CONTENT_TYPE).type(CONTENT_TYPE).post(ClientResponse.class,addToCartBody); + Response addToCartResponse = addToCartWebResource.request(CONTENT_TYPE).post(Entity.entity(addToCartBody,CONTENT_TYPE)); - if (addToCartResponse.getClientResponseStatus() == Status.OK) { - String addToCartResponseString = addToCartResponse.getEntity(String.class); + if (addToCartResponse.getStatus() == Response.Status.OK.getStatusCode()) { + String addToCartResponseString = addToCartResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("addToCartResponse " + addToCartResponseString); JsonObject jsonAddToCartResponse = parser.parse(addToCartResponseString).getAsJsonObject(); if(jsonAddToCartResponse.get("status").getAsString().equalsIgnoreCase("SUCCESS")) { - Client checkoutCartJerseyClient = Client.create(); - checkoutCartJerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + Client checkoutCartJerseyClient = ClientBuilder.newClient().register(feature); - WebResource checkoutCartWebResource = checkoutCartJerseyClient.resource(createCartURI + "/" + cartIdentifier + "/checkout"); - ClientResponse checkoutCartResponse = checkoutCartWebResource.queryParam("cartIdentifier", cartIdentifier).accept(CONTENT_TYPE).type(CONTENT_TYPE).get(ClientResponse.class); + WebTarget checkoutCartWebResource= checkoutCartJerseyClient.target(createCartURI + "/" + cartIdentifier + "/checkout"); + Response checkoutCartResponse = checkoutCartWebResource.queryParam("cartIdentifier", cartIdentifier).request(CONTENT_TYPE).get(); - if (checkoutCartResponse.getClientResponseStatus() == Status.OK) { - String checkoutCartResponseString = checkoutCartResponse.getEntity(String.class); + if (checkoutCartResponse.getStatus() == Response.Status.OK.getStatusCode()) { + String checkoutCartResponseString = checkoutCartResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("checkoutCartResponse " + checkoutCartResponseString); JsonObject jsonCheckoutCartResponse = parser.parse(checkoutCartResponseString).getAsJsonObject(); if(jsonCheckoutCartResponse.get("status").getAsString().equalsIgnoreCase("SUCCESS")) { String orderReference = jsonCheckoutCartResponse.get("productCheckoutList").getAsJsonArray().get(0).getAsJsonObject().get("orderReference").getAsString(); - Client listDidsJerseyClient = Client.create(); - listDidsJerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + Client listDidsJerseyClient = ClientBuilder.newClient().register(feature); - WebResource listDidsWebResource = listDidsJerseyClient.resource(listDidsURI); - ClientResponse listDidsResponse = listDidsWebResource. + WebTarget listDidsWebResource = listDidsJerseyClient.target(listDidsURI); + Response listDidsResponse = listDidsWebResource. queryParam("orderReference", orderReference). queryParam(PAGE_NUMBER, "0"). queryParam(PAGE_SIZE, "50"). - accept(CONTENT_TYPE). - type(CONTENT_TYPE). - get(ClientResponse.class); + request(CONTENT_TYPE). + get(); - if (listDidsResponse.getClientResponseStatus() == Status.OK) { - String listDidsResponseString = listDidsResponse.getEntity(String.class); + if (listDidsResponse.getStatus() == Response.Status.OK.getStatusCode()) { + String listDidsResponseString = listDidsResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("listDidsResponse " + listDidsResponseString); @@ -328,7 +327,7 @@ public boolean buyNumber(PhoneNumber phoneNumberObject, PhoneNumberParameters ph } } else { if(logger.isDebugEnabled()) - logger.debug("Couldn't buy Phone Number " + phoneNumber + ". Response status was: "+ addToCartResponse.getClientResponseStatus()); + logger.debug("Couldn't buy Phone Number " + phoneNumber + ". Response status was: "+ addToCartResponse.getStatus()); } } catch (final Exception e) { logger.warn("Couldn't reach uri for buying Phone Numbers" + uri, e); @@ -340,21 +339,21 @@ public boolean buyNumber(PhoneNumber phoneNumberObject, PhoneNumberParameters ph @Override public boolean updateNumber(PhoneNumber phoneNumberObj, PhoneNumberParameters phoneNumberParameters) { String phoneNumber = phoneNumberObj.getFriendlyName(); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); + Client jerseyClient = ClientBuilder.newClient().register(feature); - WebResource webResource = jerseyClient.resource(updateURI); + WebTarget webResource = jerseyClient.target(updateURI); String body = "{\"didIds\":[\"" + phoneNumber + "\"],\"voiceUriId\":\"" + voiceUriId + "\"}"; - ClientResponse clientResponse = webResource.accept(CONTENT_TYPE).type(CONTENT_TYPE).post(ClientResponse.class,body); + Response clientResponse = webResource.request(CONTENT_TYPE).post(Entity.entity(body,CONTENT_TYPE)); - String voiceURIResponse = clientResponse.getEntity(String.class); + String voiceURIResponse = clientResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("response " + voiceURIResponse); // JsonParser parser = new JsonParser(); // JsonObject jsonCreateCartResponse = parser.parse(voiceURIResponse).getAsJsonObject(); - if (clientResponse.getClientResponseStatus() == Status.OK) { + if (clientResponse.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else { return false; @@ -364,22 +363,23 @@ public boolean updateNumber(PhoneNumber phoneNumberObj, PhoneNumberParameters ph @Override public boolean cancelNumber(PhoneNumber phoneNumberObj) { String phoneNumber = phoneNumberObj.getFriendlyName(); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); - WebResource webResource = jerseyClient.resource(cancelURI); + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); + Client jerseyClient = ClientBuilder.newClient().register(feature); + + WebTarget webResource = jerseyClient.target(cancelURI); String body = "{\"didIds\":[\"" + phoneNumber + "\"]}"; - ClientResponse clientResponse = webResource.accept(CONTENT_TYPE).type(CONTENT_TYPE).post(ClientResponse.class,body); + Response clientResponse = webResource.request(CONTENT_TYPE).post(Entity.entity(body,CONTENT_TYPE)); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("response " + response); // JsonParser parser = new JsonParser(); // JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); - if (clientResponse.getClientResponseStatus() == Status.OK) { + if (clientResponse.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else { return false; @@ -388,16 +388,16 @@ public boolean cancelNumber(PhoneNumber phoneNumberObj) { @Override public List getAvailableCountries() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); + Client jerseyClient = ClientBuilder.newClient().register(feature); - WebResource webResource = jerseyClient.resource(countriesURI); + WebTarget webResource = jerseyClient.target(countriesURI); // http://www.voxbone.com/apidoc/resource_InventoryServiceRest.html#path__country.html - ClientResponse clientResponse = webResource.queryParam(PAGE_NUMBER,"0").queryParam(PAGE_SIZE,"300").accept(CONTENT_TYPE).type(CONTENT_TYPE) - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam(PAGE_NUMBER,"0").queryParam(PAGE_SIZE,"300").request(CONTENT_TYPE) + .get(); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); if(logger.isDebugEnabled()) logger.debug("response " + response); diff --git a/restcomm/restcomm.testsuite/pom.xml b/restcomm/restcomm.testsuite/pom.xml index f0a9494c46..42ffd7e099 100644 --- a/restcomm/restcomm.testsuite/pom.xml +++ b/restcomm/restcomm.testsuite/pom.xml @@ -93,15 +93,8 @@ - com.sun.jersey - jersey-server - ${jersey.version} - - - - com.sun.jersey - jersey-client - ${jersey.version} + org.glassfish.jersey.containers + jersey-container-servlet @@ -435,7 +428,7 @@ maven-surefire-plugin 2.19.1 - -Xms256m -Xmx2048m -XX:MaxPermSize=1024m ${jacocoArgLine} + -Xms256m -Xmx2048m -XX:MaxPermSize=1024m false @@ -464,7 +457,7 @@ classes 5 - -Xms256m -Xmx2048m -XX:MaxPermSize=512m ${jacocoArgLine} + -Xms256m -Xmx2048m -XX:MaxPermSize=512m @@ -496,7 +489,7 @@ classes 5 - -Xms256m -Xmx2048m -XX:MaxPermSize=512m ${jacocoArgLine} + -Xms256m -Xmx2048m -XX:MaxPermSize=512m diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/RestcommRvdProjectsMigratorTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/RestcommRvdProjectsMigratorTool.java index abc2c566c1..4e937fc33d 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/RestcommRvdProjectsMigratorTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/RestcommRvdProjectsMigratorTool.java @@ -26,9 +26,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; /** * @author guilherme.jansen@telestax.com @@ -69,11 +69,11 @@ public static RestcommRvdProjectsMigratorTool getInstance() { public JsonArray getEntitiesList(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, Endpoint endpoint, String propertyName) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getEntitiesUrl(deploymentUrl, adminAccountSid, endpoint); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget webResource = jerseyClient.target(url); + String response = webResource.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonArray jsonResponse; if (propertyName == null) { @@ -109,14 +109,14 @@ private String getEntityUrl(String deploymentUrl, String accountSid, Endpoint en public JsonObject getEntity(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, String applicationSid, Endpoint endpoint) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getEntityUrl(deploymentUrl, adminAccountSid, endpoint, applicationSid); - WebResource webResource = jerseyClient.resource(url); + WebTarget webResource = jerseyClient.target(url); String response = null; JsonObject jsonResponse = null; try { - response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + response = webResource.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); jsonResponse = parser.parse(response).getAsJsonObject(); } catch (Exception e) { diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/WebTargetUtil.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/WebTargetUtil.java new file mode 100644 index 0000000000..c95a656481 --- /dev/null +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/WebTargetUtil.java @@ -0,0 +1,34 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + + +package org.restcomm.connect.testsuite; + +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MultivaluedMap; + +public class WebTargetUtil { + public static WebTarget addQueryMap(WebTarget target, MultivaluedMap params){ + for (String kAux : params.keySet()) { + target.queryParam(kAux, params.get(kAux)); + } + return target; + } +} diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointClosingTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointClosingTest.java index 51ee3ce46c..686f974394 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointClosingTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointClosingTest.java @@ -21,10 +21,10 @@ package org.restcomm.connect.testsuite.http; import com.github.tomakehurst.wiremock.junit.WireMockRule; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MultivaluedHashMap; import junit.framework.Assert; import org.apache.log4j.Logger; import org.jboss.arquillian.container.test.api.Deployer; @@ -51,6 +51,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import javax.ws.rs.client.Entity; import org.junit.experimental.categories.Category; import org.restcomm.connect.commons.annotations.UnstableTests; @@ -84,10 +85,10 @@ public void before() { public void removeAccountAndSendNotifications() throws InterruptedException { String closedParentSid = "ACA1000000000000000000000000000000"; Client jersey = getClient(toplevelSid, toplevelKey); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/" + closedParentSid) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/" + closedParentSid) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Status","closed"); - ClientResponse response = resource.put(ClientResponse.class,params); + Response response = resource.request().put(Entity.form(params)); Assert.assertEquals(200, response.getStatus()); // wait until all asynchronous request have been sent to RVD verify(6, postRequestedFor(urlMatching("/restcomm-rvd/services/notifications")) @@ -113,17 +114,17 @@ public void removeAccountAndReleaseProvidedNumbers() { String closedParentSid = "ACA2000000000000000000000000000000"; Client jersey = getClient(toplevelSid, toplevelKey); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/" + closedParentSid) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/" + closedParentSid) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Status","closed"); - ClientResponse response = resource.put(ClientResponse.class,params); + Response response = resource.request().put(Entity.form(params)); Assert.assertEquals(200, response.getStatus()); // make sure the request reached nexmo verify(postRequestedFor(urlMatching("/nexmo/number/cancel/.*/.*/US/12223334444"))); verify(postRequestedFor(urlMatching("/nexmo/number/cancel/.*/.*/US/12223334445"))); // confirm that numbers that were not successfully released, are still in the database - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + closedParentSid + "/IncomingPhoneNumbers/PH00000000000000000000000000000002.json") ); - response = resource.get(ClientResponse.class); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + closedParentSid + "/IncomingPhoneNumbers/PH00000000000000000000000000000002.json") ); + response = resource.request().get(); Assert.assertEquals(200, response.getStatus()); } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java index 23809d954b..52466ee172 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java @@ -34,11 +34,11 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.client.Client;import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MultivaluedHashMap; import org.junit.experimental.categories.Category; import org.restcomm.connect.commons.annotations.FeatureAltTests; import org.restcomm.connect.commons.annotations.FeatureExpTests; @@ -151,7 +151,7 @@ public void testGetAccount() { @Category(FeatureExpTests.class) public void testGetAccountAccess(){ // check non-existent user receives a 401 - ClientResponse response = RestcommAccountsTool.getInstance().getAccountResponse(deploymentUrl.toString(), "nonexisting@company.com", "badpassword", adminAccountSid); + Response response = RestcommAccountsTool.getInstance().getAccountResponse(deploymentUrl.toString(), "nonexisting@company.com", "badpassword", adminAccountSid); assertEquals("Non-existing user should get a 401", 401, response.getStatus()); // check InsufficientPerimssion errors- 403. Try to get administrator account with unprivileged accoutn creds response = RestcommAccountsTool.getInstance().getAccountResponse(deploymentUrl.toString(), unprivilegedUsername, unprivilegedAuthToken, adminAccountSid); @@ -166,7 +166,7 @@ public void testGetAccountByFriendlyName() { try { JsonObject adminAccount = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(), adminFriendlyName, adminAuthToken, adminUsername); - } catch (UniformInterfaceException e) { + } catch (WebApplicationException e) { code = e.getResponse().getStatus(); } // Logins using friendly name are not allowed anymore @@ -318,7 +318,7 @@ public void testUpdateAccountByEmail() { @Category(FeatureExpTests.class) public void testUpdateAccountRoleAccessControl() { // non-admins should not be able to change their role - ClientResponse response = RestcommAccountsTool.getInstance().updateAccountResponse(deploymentUrl.toString(), + Response response = RestcommAccountsTool.getInstance().updateAccountResponse(deploymentUrl.toString(), updatedRoleUsername, updateRoleAuthToken, updatedRoleAccountSid, null, null, null, "Administrator", null ); assertEquals("Should return a 403 when non-admin tries to update role", 403, response.getStatus() ); // admin, should be able to change their sub-account role @@ -336,7 +336,7 @@ public void testUpdateAccountRoleAccessControl() { @Category(FeatureExpTests.class) public void testCreateAccountAccess(){ // 'unprivilaged should not be able to create accounts and receive a 403 - ClientResponse response = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), + Response response = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), unprivilegedUsername, unprivilegedAuthToken, "notcreated@company.com", "not-created-password"); assertEquals("403 not returned", 403, response.getStatus()); } @@ -352,10 +352,10 @@ public void testCreateAdministratorAccountFails() { @Test @Category(FeatureExpTests.class) public void testCreateAccountTwiceFails() { - ClientResponse createResponse1 = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, + Response createResponse1 = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, "twice@company.com", "RestComm12"); assertEquals("Account twice@company.com could not be created even once", 200, createResponse1.getStatus()); - ClientResponse createResponse2 = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, + Response createResponse2 = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, "twice@company.com", "RestComm12"); assertEquals("Did not retrieve a conflict HTTP status (409) while creating accounts with same email address", 409, createResponse2.getStatus()); } @@ -407,9 +407,9 @@ public void testCreateAccountCheckClientExisted() throws Exception { @Test @Category(FeatureExpTests.class) public void testCreateAccountFourthLevelFails() { - ClientResponse response = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), "grandchild@company.com", commonAuthToken, "fourthlevelAccount@company.com", "RestComm12"); + Response response = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), "grandchild@company.com", commonAuthToken, "fourthlevelAccount@company.com", "RestComm12"); assertEquals(400, response.getStatus()); - //Assert.assertTrue(response.getEntity(String.class).contains("")) + //Assert.assertTrue(response.readEntity(String.class).contains("")) } @Test @@ -477,10 +477,10 @@ public void testCloseAccountCheckClient() throws Exception { assertTrue(thinhPhone.unregister(thinhContact, 0)); // close the account Client jersey = getClient(adminUsername, adminPassword); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/"+subAccountEmail) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/"+subAccountEmail) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Status","closed"); - ClientResponse response = resource.put(ClientResponse.class,params); + Response response = resource.request().put(Entity.form(params)); assertEquals(200, response.getStatus()); //RestcommAccountsTool.getInstance().removeAccount(deploymentUrl.toString(), adminUsername, adminAuthToken, // subAccountResponse.get("sid").getAsString()); @@ -502,44 +502,44 @@ public void testCloseAccountNested() { Client jersey = getClient("removed-top@company.com", commonAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/"+removed1Sid) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/"+removed1Sid) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Status","closed"); - ClientResponse response = resource.put(ClientResponse.class,params); + Response response = resource.request().put(Entity.form(params)); // the closed account should be available assertEquals(200, response.getStatus()); JsonParser parser = new JsonParser(); - JsonObject jsonObject = parser.parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject(); // make sure the account status is set to closed assertEquals("closed", jsonObject.get("status").getAsString()); // assert removed accounts children are closed too - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/"+removed11Sid) ); - response = resource.get(ClientResponse.class); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/"+removed11Sid) ); + response = resource.request().get(); assertEquals(200, response.getStatus()); parser = new JsonParser(); - jsonObject = parser.parse(response.getEntity(String.class)).getAsJsonObject(); + jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject(); assertEquals("closed", jsonObject.get("status").getAsString()); // assert the applications of the account are removed - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Applications/AP00000000000000000000000000000001.json" ) ); - assertEquals(404, resource.get(ClientResponse.class).getStatus()); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Applications/AP00000000000000000000000000000001.json" ) ); + assertEquals(404, resource.request().get().getStatus()); // assert IncomingPhoneNumbers of the account are removed - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/IncomingPhoneNumbers/PN00000000000000000000000000000001.json" ) ); - assertEquals(404, resource.get(ClientResponse.class).getStatus()); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/IncomingPhoneNumbers/PN00000000000000000000000000000001.json" ) ); + assertEquals(404, resource.request().get().getStatus()); // assert notification are removed - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Notifications/NO00000000000000000000000000000001.json" ) ); - assertEquals(404, resource.get(ClientResponse.class).getStatus()); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Notifications/NO00000000000000000000000000000001.json" ) ); + assertEquals(404, resource.request().get().getStatus()); // assert recordings are removed - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Recordings/RE00000000000000000000000000000001.json" ) ); - assertEquals(404, resource.get(ClientResponse.class).getStatus()); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Recordings/RE00000000000000000000000000000001.json" ) ); + assertEquals(404, resource.request().get().getStatus()); // assert transcriptions are removed - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Transcriptions/TR00000000000000000000000000000001.json" ) ); - assertEquals(404, resource.get(ClientResponse.class).getStatus()); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Transcriptions/TR00000000000000000000000000000001.json" ) ); + assertEquals(404, resource.request().get().getStatus()); // assert outgoing caller ids are removed - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/OutgoingCallerIds/PN00000000000000000000000000000001.json" ) ); - assertEquals(404, resource.get(ClientResponse.class).getStatus()); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/OutgoingCallerIds/PN00000000000000000000000000000001.json" ) ); + assertEquals(404, resource.request().get().getStatus()); // assert clients are removed - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Clients/CL00000000000000000000000000000001.json" ) ); - assertEquals(404, resource.get(ClientResponse.class).getStatus()); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/"+removed1Sid+"/Clients/CL00000000000000000000000000000001.json" ) ); + assertEquals(404, resource.request().get().getStatus()); // we won't test Announcements removal . There is no retrieval method yet. } @@ -558,14 +558,14 @@ public void testGetAccounts() throws InterruptedException { @Test @Category(FeatureExpTests.class) public void testGetAccountsAccess() { - ClientResponse response = RestcommAccountsTool.getInstance().getAccountsResponse(deploymentUrl.toString(), guestUsername, guestAuthToken); + Response response = RestcommAccountsTool.getInstance().getAccountsResponse(deploymentUrl.toString(), guestUsername, guestAuthToken); assertEquals("Guest account should get get a 403 when retrieving accounts", 403, response.getStatus()); } @Ignore // ignored since account removal is disables as of #1270 @Test public void testRemoveAccountAccess(){ - ClientResponse response = RestcommAccountsTool.getInstance().removeAccountResponse(deploymentUrl.toString(), unprivilegedUsername, unprivilegedAuthToken, removedSid + ".json" ); + Response response = RestcommAccountsTool.getInstance().removeAccountResponse(deploymentUrl.toString(), unprivilegedUsername, unprivilegedAuthToken, removedSid + ".json" ); assertEquals("Unprivileged account should receive a 403 while removing an account", 403, response.getStatus()); response = RestcommAccountsTool.getInstance().removeAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, removedSid + ".json"); assertEquals("Administrator should receive a 200 OK when removing an account", 200, response.getStatus()); @@ -576,16 +576,16 @@ public void testRemoveAccountAccess(){ */ @Test public void testAccountAcccessUsingRoles() { - ClientResponse response = RestcommAccountsTool.getInstance().getAccountResponse(deploymentUrl.toString(),unprivilegedUsername, unprivilegedAuthToken, unprivilegedSid); + Response response = RestcommAccountsTool.getInstance().getAccountResponse(deploymentUrl.toString(),unprivilegedUsername, unprivilegedAuthToken, unprivilegedSid); assertEquals(200,response.getStatus()); } @Test public void testPasswordStrengthForAccountCreate() { - ClientResponse response = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), + Response response = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, "weak@company.com", "1234"); assertEquals("Weak password account creation should fail with 400", 400, response.getStatus()); - Assert.assertTrue("Response error message should contain 'weak' term", response.getEntity(String.class).toLowerCase().contains("weak")); + Assert.assertTrue("Response error message should contain 'weak' term", response.readEntity(String.class).toLowerCase().contains("weak")); response = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, "weak@company.com", "1234asdf!@#"); assertEquals(200, response.getStatus()); @@ -594,9 +594,9 @@ public void testPasswordStrengthForAccountCreate() { @Test public void testPasswordStrengthForAccountUpdate() { // updating an account with weak password should fail - ClientResponse response = RestcommAccountsTool.getInstance().updateAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, "updated-weak@company.com", null, "1234", null, null, null ); + Response response = RestcommAccountsTool.getInstance().updateAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, "updated-weak@company.com", null, "1234", null, null, null ); assertEquals(400, response.getStatus()); - Assert.assertTrue("Response should contain 'weak' term", response.getEntity(String.class).toLowerCase().contains("weak")); + Assert.assertTrue("Response should contain 'weak' term", response.readEntity(String.class).toLowerCase().contains("weak")); // updating an account with strong password should succeed response = RestcommAccountsTool.getInstance().updateAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, "updated-weak@company.com", null, "RestComm12", null, null, null ); assertEquals(200, response.getStatus()); @@ -606,7 +606,7 @@ public void testPasswordStrengthForAccountUpdate() { @Category(FeatureExpTests.class) public void createAccountInSpecificOrganizationPermissionTest() { // child should not be able to create account in specified org that it does not belong to - ClientResponse clientResponse = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), + Response clientResponse = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), childUsername, childAuthToken, createdUsernanme, createdPassword, null, organizationSid2); assertEquals(403, clientResponse.getStatus()); @@ -615,7 +615,7 @@ public void createAccountInSpecificOrganizationPermissionTest() { @Test public void createAccountInSpecificOrganizationRoleTest() { // child should be able to create account in specified org that it belong to - ClientResponse clientResponse = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), + Response clientResponse = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), childUsername, childAuthToken, createdUsernanme2, createdPassword, null, organizationSid1); assertEquals(200, clientResponse.getStatus()); @@ -631,7 +631,7 @@ public void createAccountInSpecificOrganizationRoleTest() { public void createAccountInSpecificOrganizationInvalidRequestTest() { //super admin tries to create account with invalid organization Sid - ClientResponse clientResponse = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), + Response clientResponse = RestcommAccountsTool.getInstance().createAccountResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, createdUsernanme3, createdPassword, null, "blabla"); assertEquals(400, clientResponse.getStatus()); @@ -645,7 +645,7 @@ public void createAccountInSpecificOrganizationInvalidRequestTest() { @Category({UnstableTests.class, FeatureAltTests.class}) public void testGetAccountsOfASpecificOrganization() { //getAccounts without any parameters - ClientResponse response = RestcommAccountsTool.getInstance().getAccountsResponse(deploymentUrl.toString(), adminUsername, adminAuthToken); + Response response = RestcommAccountsTool.getInstance().getAccountsResponse(deploymentUrl.toString(), adminUsername, adminAuthToken); if(logger.isDebugEnabled()) logger.debug("getAccounts without filter Response: "+response); assertEquals(200, response.getStatus()); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ApplicationsEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ApplicationsEndpointTest.java index 44f6ba70db..a292ae4ac2 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ApplicationsEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ApplicationsEndpointTest.java @@ -49,7 +49,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.core.MultivaluedHashMap; import org.junit.experimental.categories.Category; import org.restcomm.connect.commons.annotations.UnstableTests; @@ -84,7 +84,7 @@ public void testCreateAndGetApplication() throws ParseException, IllegalArgument String friendlyName, voiceCallerIdLookup, rcmlUrl, kind; // Test create application via POST - MultivaluedMap applicationParams = new MultivaluedMapImpl(); + MultivaluedMap applicationParams = new MultivaluedHashMap(); applicationParams.add("FriendlyName", friendlyName = "APPCreateGet"); applicationParams.add("VoiceCallerIdLookup", voiceCallerIdLookup = "true"); applicationParams.add("RcmlUrl", rcmlUrl = "/restcomm/rcmlurl/test"); @@ -138,7 +138,7 @@ public void testGetApplicationAndNumbers() throws ParseException, IllegalArgumen @Test public void testUpdateApplication() throws ParseException, IllegalArgumentException, ClientProtocolException, IOException { // Create application - MultivaluedMap applicationParams = new MultivaluedMapImpl(); + MultivaluedMap applicationParams = new MultivaluedHashMap(); applicationParams.add("FriendlyName", "APPUpdate"); applicationParams.add("VoiceCallerIdLookup", "true"); applicationParams.add("RcmlUrl", "/restcomm/rcmlurl/test"); @@ -150,7 +150,7 @@ public void testUpdateApplication() throws ParseException, IllegalArgumentExcept // Define new values to the application attributes (POST test) String friendlyName, voiceCallerIdLookup, rcmlUrl, kind; - MultivaluedMap applicationParamsUpdate = new MultivaluedMapImpl(); + MultivaluedMap applicationParamsUpdate = new MultivaluedHashMap(); applicationParamsUpdate.add("FriendlyName", friendlyName = "APPUpdate2"); applicationParamsUpdate.add("VoiceCallerIdLookup", voiceCallerIdLookup = "false"); applicationParamsUpdate.add("RcmlUrl", rcmlUrl = "/restcomm/rcmlurl/test2"); @@ -175,7 +175,7 @@ public void testUpdateApplication() throws ParseException, IllegalArgumentExcept assertTrue(applicationJson.get("kind").getAsString().equals(kind)); // Define new values to the application attributes (PUT test) - applicationParamsUpdate = new MultivaluedMapImpl(); + applicationParamsUpdate = new MultivaluedHashMap(); applicationParamsUpdate.add("FriendlyName", friendlyName = "APPUpdate23"); applicationParamsUpdate.add("VoiceCallerIdLookup", voiceCallerIdLookup = "true"); applicationParamsUpdate.add("RcmlUrl", rcmlUrl = "/restcomm/rcmlurl/test23"); @@ -202,7 +202,7 @@ public void testUpdateApplication() throws ParseException, IllegalArgumentExcept @Test public void testDeleteApplication() throws IllegalArgumentException, ClientProtocolException, IOException { // Create application - MultivaluedMap applicationParams = new MultivaluedMapImpl(); + MultivaluedMap applicationParams = new MultivaluedHashMap(); applicationParams.add("FriendlyName", "APPDelete"); applicationParams.add("VoiceCallerIdLookup", "true"); applicationParams.add("RcmlUrl", "/restcomm/rcmlurl/test"); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ClientsEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ClientsEndpointTest.java index 676a46ec0f..b02d0e6d74 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ClientsEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ClientsEndpointTest.java @@ -33,11 +33,12 @@ import org.restcomm.connect.commons.annotations.FeatureExpTests; import org.restcomm.connect.commons.annotations.UnstableTests; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import junit.framework.Assert; @@ -144,36 +145,36 @@ public void createClientTestNoVoiceUrl() throws ClientProtocolException, IOExcep public void clientRemovalBehaviour() { // A developer account should be able to remove his own client Client jersey = getClient(developerUsername, developeerAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + removedClientSid ) ); - ClientResponse response = resource.delete(ClientResponse.class); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + removedClientSid ) ); + Response response = resource.request().delete(); Assert.assertEquals("Developer account could not remove his client", 200, response.getStatus()); // re-removing the client should return a 404 (not a 200) - response = resource.delete(ClientResponse.class); + response = resource.request().delete(); Assert.assertEquals("Removing a non-existing client did not return 404", 404, response.getStatus()); } @Test@Category(FeatureExpTests.class) public void createClientWithWeakPasswordShouldFail() throws IOException { Client jersey = getClient(developerUsername, developeerAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Login","weakClient"); params.add("Password","1234"); // this is a very weak password - ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + Response response = resource.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); Assert.assertEquals(400, response.getStatus()); - Assert.assertTrue("Response should contain 'weak' term", response.getEntity(String.class).toLowerCase().contains("weak")); + Assert.assertTrue("Response should contain 'weak' term", response.readEntity(String.class).toLowerCase().contains("weak")); } @Test@Category(FeatureExpTests.class) public void updateClientWithWeakPasswordShouldFail() { String updateClientSid = "CL00000000000000000000000000000001"; Client jersey = getClient(developerUsername, developeerAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + updateClientSid ) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + updateClientSid ) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Password","1234"); // this is a very weak password - ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).put(ClientResponse.class, params); + Response response = resource.request(MediaType.APPLICATION_JSON).put(Entity.form(params)); Assert.assertEquals(400, response.getStatus()); - Assert.assertTrue("Response should contain 'weak' term", response.getEntity(String.class).toLowerCase().contains("weak")); + Assert.assertTrue("Response should contain 'weak' term", response.readEntity(String.class).toLowerCase().contains("weak")); } /** @@ -187,20 +188,20 @@ public void updateClientWithWeakPasswordShouldFail() { @Test@Category(FeatureExpTests.class) public void createClientTestWithInvalidCharacters() throws ClientProtocolException, IOException, ParseException, InterruptedException { Client jersey = getClient(developerUsername, developeerAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Login","maria.test@telestax.com"); // login contains @ sign params.add("Password","RestComm1234!"); - ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + Response response = resource.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); Assert.assertEquals(400, response.getStatus()); - Assert.assertTrue("Response should contain 'invalid' term", response.getEntity(String.class).toLowerCase().contains("invalid")); + Assert.assertTrue("Response should contain 'invalid' term", response.readEntity(String.class).toLowerCase().contains("invalid")); } /** * addSameClientNameInDifferentOrganizations * https://github.com/RestComm/Restcomm-Connect/issues/2106 * We should be able to add same client in different organizations - * + * */ @Test public void addSameClientNameInDifferentOrganizations() { @@ -208,46 +209,46 @@ public void addSameClientNameInDifferentOrganizations() { * Add client maria in Organization - default.restcomm.com */ Client jersey = getClient(developerUsername, developeerAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Login","maria"); params.add("Password","RestComm1234!"); - ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + Response response = resource.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); Assert.assertEquals(200, response.getStatus()); - + //try to add same client again in same organization - should not be allowed /*jersey = getClient(developerUsername, developeerAuthToken); - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); - params = new MultivaluedMapImpl(); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); + params = new MultivaluedHashMap(); params.add("Login","maria"); params.add("Password","RestComm1234!"); - response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + response = resource.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); Assert.assertEquals(409, response.getStatus());*/ /* * Add client maria in Organization - org2.restcomm.com */ jersey = getClient(developerOrg2AccountSid, developeerOrg2AuthToken); - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerOrg2AccountSid + "/Clients.json" ) ); - params = new MultivaluedMapImpl(); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerOrg2AccountSid + "/Clients.json" ) ); + params = new MultivaluedHashMap(); params.add("Login","maria"); params.add("Password","RestComm1234!"); - response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + response = resource.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); Assert.assertEquals(200, response.getStatus()); - + } @Test@Category({FeatureAltTests.class, UnstableTests.class}) public void createClientTestWithIsPushEnabled() throws IOException, ParseException, InterruptedException { Client jersey = getClient(developerUsername, developeerAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients.json" ) ); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Login","bob"); // login contains @ sign params.add("Password","RestComm1234!"); params.add("IsPushEnabled", "true"); - ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + Response response = resource.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); Assert.assertEquals(200, response.getStatus()); - Assert.assertTrue("Response should contain 'push_client_identity'", response.getEntity(String.class).contains("push_client_identity")); + Assert.assertTrue("Response should contain 'push_client_identity'", response.readEntity(String.class).contains("push_client_identity")); } @Test@Category(FeatureAltTests.class) @@ -255,18 +256,18 @@ public void updateClientTestWithIsPushEnabled() throws IOException, ParseExcepti String sid = CreateClientsTool.getInstance().createClient(deploymentUrl.toString(), developerAccountSid, developeerAuthToken, "agafox", "RestComm1234", null); // add push_client_identity Client jersey = getClient(developerUsername, developeerAuthToken); - WebResource resource = jersey.resource(getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + sid + ".json" )); - MultivaluedMap params = new MultivaluedMapImpl(); + WebTarget resource = jersey.target(getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + sid + ".json" )); + MultivaluedMap params = new MultivaluedHashMap(); params.putSingle("IsPushEnabled", "true"); - ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).put(ClientResponse.class, params); + Response response = resource.request(MediaType.APPLICATION_JSON).put(Entity.form(params)); Assert.assertEquals(200, response.getStatus()); - Assert.assertTrue("Response should contain 'push_client_identity'", response.getEntity(String.class).contains("push_client_identity")); + Assert.assertTrue("Response should contain 'push_client_identity'", response.readEntity(String.class).contains("push_client_identity")); // remove push_client_identity - resource = jersey.resource(getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + sid + ".json")); + resource = jersey.target(getResourceUrl("/2012-04-24/Accounts/" + developerAccountSid + "/Clients/" + sid + ".json")); params.putSingle("IsPushEnabled", "false"); - response = resource.accept(MediaType.APPLICATION_JSON).put(ClientResponse.class, params); + response = resource.request(MediaType.APPLICATION_JSON).put(Entity.form(params)); Assert.assertEquals(200, response.getStatus()); - Assert.assertFalse("Response shouldn't contain 'push_client_identity'", response.getEntity(String.class).contains("push_client_identity")); + Assert.assertFalse("Response shouldn't contain 'push_client_identity'", response.readEntity(String.class).contains("push_client_identity")); } protected String getResourceUrl(String suffix) { @@ -284,8 +285,8 @@ protected String getResourceUrl(String suffix) { } protected Client getClient(String username, String password) { - Client jersey = Client.create(); - jersey.addFilter(new HTTPBasicAuthFilter(username, password)); + Client jersey = ClientBuilder.newClient(); + jersey.register(HttpAuthenticationFeature.basic(username, password)); return jersey; } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CorsRelaxTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CorsRelaxTest.java index 045562688f..ee171c4ffe 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CorsRelaxTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CorsRelaxTest.java @@ -20,9 +20,9 @@ package org.restcomm.connect.testsuite.http; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; import junit.framework.Assert; import org.apache.log4j.Logger; import org.jboss.arquillian.container.test.api.Deployer; @@ -62,21 +62,21 @@ public class CorsRelaxTest extends EndpointTest { // Tests cors headers existence when retrieving an account @Test public void corsHeadersAreReturnedForAccount() { - // Bypass jersey restriction for "Origin" header. By default it can't be added to a WebResource object. + // Bypass jersey restriction for "Origin" header. By default it can't be added to a WebTarget object. System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); - Client jersey = Client.create(); + Client jersey = ClientBuilder.newClient(); // make a preflight OPTIONS request using an origin present in restcomm.xml/rcmlserver i.e. http://testing.restcomm.com - WebResource resource = jersey.resource(getResourceUrl("/2012-04-24/Accounts.json/ACae6e420f425248d6a26948c17a9e2acf")); - ClientResponse response = resource.header("Origin", "http://testing.restcomm.com").options(ClientResponse.class); + WebTarget resource = jersey.target(getResourceUrl("/2012-04-24/Accounts.json/ACae6e420f425248d6a26948c17a9e2acf")); + Response response = resource.request().header("Origin", "http://testing.restcomm.com").options(Response.class); Assert.assertEquals(200, response.getStatus()); - MultivaluedMap headers = response.getHeaders(); + MultivaluedMap headers = response.getStringHeaders(); String originHeader = headers.getFirst("Access-Control-Allow-Origin"); Assert.assertEquals("http://testing.restcomm.com",originHeader); // make a preflight OPTIONS request using an origin NOT present in restcomm.xml/rcmlserver i.e. http://otherhost.restcomm.com - WebResource resource2 = jersey.resource(getResourceUrl("/restcomm/2012-04-24/Accounts.json/ACae6e420f425248d6a26948c17a9e2acf")); - ClientResponse response2 = resource2.header("Origin", "http://otherhost.restcomm.com").options(ClientResponse.class); - originHeader = response2.getHeaders().getFirst("Access-Control-Allow-Origin"); + WebTarget resource2 = jersey.target(getResourceUrl("/restcomm/2012-04-24/Accounts.json/ACae6e420f425248d6a26948c17a9e2acf")); + Response response2 = resource2.request().header("Origin", "http://otherhost.restcomm.com").options(Response.class); + originHeader = response2.getStringHeaders().getFirst("Access-Control-Allow-Origin"); Assert.assertEquals(200, response2.getStatus()); Assert.assertNull(originHeader); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CreateGatewaysTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CreateGatewaysTool.java index 79105afce6..e209be3218 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CreateGatewaysTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/CreateGatewaysTool.java @@ -5,10 +5,11 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; /** * @author gvagenas @@ -41,16 +42,16 @@ public JsonObject createGateway(String deploymentUrl, String friendlyName, Strin String restcommUsername = "ACae6e420f425248d6a26948c17a9e2acf"; String restcommPassword = "77f8c12cc7b8f8423e5c38b035249166"; - + String url = "http://"+restcommUsername+":"+restcommPassword+"@" + endpoint + "/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Management/Gateways.json"; - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(restcommUsername, restcommPassword)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(restcommUsername, restcommPassword)); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("FriendlyName", friendlyName); params.add("UserName", username); params.add("Password", password); @@ -58,29 +59,29 @@ public JsonObject createGateway(String deploymentUrl, String friendlyName, Strin params.add("Register", register); params.add("TTL", ttl); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); return jsonObject; } - + public JsonObject updateGateway(String deploymentUrl, String sid, String friendlyName, String username, String password, String proxy, String register, String ttl) { String endpoint = getEndpoint(deploymentUrl).replaceAll("http://", ""); String restcommUsername = "ACae6e420f425248d6a26948c17a9e2acf"; String restcommPassword = "77f8c12cc7b8f8423e5c38b035249166"; - + String url = "http://"+restcommUsername+":"+restcommPassword+"@" + endpoint + "/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Management/Gateways/"+sid+".json"; - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(restcommUsername, restcommPassword)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(restcommUsername, restcommPassword)); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); if (friendlyName != null) params.add("FriendlyName", friendlyName); if (username != null) params.add("UserName", username); if (password != null) params.add("Password", password); @@ -88,30 +89,30 @@ public JsonObject updateGateway(String deploymentUrl, String sid, String friendl if (register != null) params.add("Register", register); if (ttl != null) params.add("TTL", ttl); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); return jsonObject; } - + public void deleteGateway(String deploymentUrl, String sid) { String endpoint = getEndpoint(deploymentUrl).replaceAll("http://", ""); String restcommUsername = "ACae6e420f425248d6a26948c17a9e2acf"; String restcommPassword = "77f8c12cc7b8f8423e5c38b035249166"; - + String url = "http://"+restcommUsername+":"+restcommPassword+"@" + endpoint + "/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Management/Gateways/"+sid+".json"; - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(restcommUsername, restcommPassword)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(restcommUsername, restcommPassword)); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - webResource.accept(MediaType.APPLICATION_JSON).delete(); + WebTarget.request(MediaType.APPLICATION_JSON).delete(); } - + } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EmailEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EmailEndpointTest.java index 9786222587..726157a86a 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EmailEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EmailEndpointTest.java @@ -3,10 +3,10 @@ import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.GreenMailUtil; import com.icegreen.greenmail.util.ServerSetupTest; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import org.apache.log4j.Logger; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; @@ -28,6 +28,7 @@ import javax.ws.rs.core.MultivaluedMap; import java.io.IOException; import java.net.URL; +import javax.ws.rs.client.Entity; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -74,24 +75,24 @@ public void sendEmailTest() throws MessagingException, IOException { final Mail emailMsg = new Mail("hascode@localhost", "someone@localhost.com","Testing Email Service" ,"This is the subject of the email service testing", "someone2@localhost.com, test@localhost.com, test3@localhost.com", "someone3@localhost.com, test2@localhost.com"); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAuthToken)); String url = deploymentUrl + "2012-04-24/Accounts/" + adminAccountSid + "/Email/Messages.json"; - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); final String subject = "Test Email Subject"; final String body = "Test body"; - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("From", "restcomm@company.com"); params.add("To", "user@company.com"); params.add("Subject", subject ); params.add("Body", body); - // webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + // WebTarget = WebTarget.queryParams(params); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); assertNotNull(response); logger.info("Response: "+response); assertTrue(mailServer.waitForIncomingEmail(1)); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EndpointTest.java index d43660d86e..f1c3d34496 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/EndpointTest.java @@ -20,8 +20,8 @@ package org.restcomm.connect.testsuite.http; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.test.api.ArquillianResource; import org.junit.After; @@ -64,8 +64,8 @@ protected String getResourceUrl(String suffix) { } protected Client getClient(String username, String password) { - Client jersey = Client.create(); - jersey.addFilter(new HTTPBasicAuthFilter(username, password)); + Client jersey = ClientBuilder.newClient(); + jersey.register(HttpAuthenticationFeature.basic(username, password)); return jersey; } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ExtensionsConfigurationTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ExtensionsConfigurationTest.java index 15267fb141..f890c1f27a 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ExtensionsConfigurationTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ExtensionsConfigurationTest.java @@ -1,7 +1,7 @@ package org.restcomm.connect.testsuite.http; import com.google.gson.JsonObject; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.core.MultivaluedHashMap; import org.apache.log4j.Logger; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; @@ -64,7 +64,7 @@ public class ExtensionsConfigurationTest { @Test public void testCreateAndUpdateJsonConfiguration() throws UnsupportedEncodingException { String extensionName = "testExtension"; - MultivaluedMap configurationParams = new MultivaluedMapImpl(); + MultivaluedMap configurationParams = new MultivaluedHashMap(); configurationParams.add("ExtensionName", extensionName); configurationParams.add("ConfigurationData", jsonConfiguration); @@ -80,7 +80,7 @@ public void testCreateAndUpdateJsonConfiguration() throws UnsupportedEncodingExc String extensionSid = extension.get("sid").getAsString(); - MultivaluedMap updatedConfigurationParams = new MultivaluedMapImpl(); + MultivaluedMap updatedConfigurationParams = new MultivaluedHashMap(); updatedConfigurationParams.add("ExtensionName", extensionName); updatedConfigurationParams.add("ConfigurationData", updatedJsonConfiguration); @@ -94,7 +94,7 @@ public void testCreateAndUpdateJsonConfiguration() throws UnsupportedEncodingExc @Test public void testCreateJsonConfigurationAndGetBySid() throws UnsupportedEncodingException { String extensionName = "testExtension2"; - MultivaluedMap configurationParams = new MultivaluedMapImpl(); + MultivaluedMap configurationParams = new MultivaluedHashMap(); configurationParams.add("ExtensionName", extensionName); configurationParams.add("ConfigurationData", jsonConfiguration); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/GeolocationEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/GeolocationEndpointTest.java index 11f595465d..fd54b662c3 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/GeolocationEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/GeolocationEndpointTest.java @@ -63,7 +63,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.core.MultivaluedHashMap; /** * @author Fernando Mendioroz @@ -124,7 +124,7 @@ public void testCreateAndGetImmediateGeolocation() // Test create Immediate type of Geolocation via POST (only mandatory parameters) // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("StatusCallback", "http://192.1.0.19:8080/ACae6e420f425248d6a26948c17a9e2acf"); // HTTP POST Geolocation creation with given parameters values and those returned via GMLC stub @@ -231,7 +231,7 @@ public void testCreateNotApiCompliantImmediateGeolocation() // Test create Immediate type of Geolocation via POST with one missing mandatory parameter // Parameter values Assignment, StatusCallback missing - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); Sid rejectedGeolocationSid = null; // HTTP POST Geolocation creation with given parameters values @@ -301,7 +301,7 @@ public void testUpdateImmediateGeolocation() // Create Immediate type of Geolocation via POST // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("StatusCallback", "http://192.1.0.19:8080/ACae6e420f425248d6a26948c17a9e2acf"); // HTTP POST Geolocation creation with given parameters values and those returned via GMLC stub @@ -310,7 +310,7 @@ public void testUpdateImmediateGeolocation() Sid geolocationSid = new Sid(geolocationJson.get("sid").getAsString()); // Define new values to the application attributes (POST test) - MultivaluedMap geolocationParamsUpdate = new MultivaluedMapImpl(); + MultivaluedMap geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParamsUpdate.add("DesiredAccuracy", "Low"); geolocationParamsUpdate.add("StatusCallback", "http://192.1.0.19:8080/ACae6e420f425248d6a26948c17a9e2acf"); @@ -384,7 +384,7 @@ public void testUpdateImmediateGeolocation() assertTrue(geolocationJson.get("api_version").getAsString().equals("2012-04-24")); // Define new values for the Geolocation attributes (PUT test) - geolocationParamsUpdate = new MultivaluedMapImpl(); + geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("DesiredAccuracy", "Average"); geolocationParamsUpdate.add("StatusCallback", "http://192.1.2.19:8080/ACae6e420f425248d6a26948c17a9e2acf"); geolocationParamsUpdate.add("ResponseStatus", responseStatus = "successfull"); @@ -490,7 +490,7 @@ public void testNotApiCompliantUpdateImmediateGeolocation() // Create Immediate type of Geolocation via POST // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("StatusCallback", "http://192.1.0.19:8080/ACae6e420f425248d6a26948c17a9e2acf"); // HTTP POST Geolocation creation with given parameters values and those returned via GMLC stub @@ -504,7 +504,7 @@ public void testNotApiCompliantUpdateImmediateGeolocation() locationTimestamp = df.format(dateTime.toDate()); // Define malformed values for the Geolocation attributes (PUT test to fail) - MultivaluedMap geolocationParamsUpdate = new MultivaluedMapImpl(); + MultivaluedMap geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("DeviceLatitude", deviceLatitude = "North 72.908134"); // WGS84 not compliant geolocationParamsUpdate.add("DeviceLongitude", deviceLongitude = "170.908134"); // Update failed Geolocation via PUT @@ -543,7 +543,7 @@ public void testNotApiCompliantUpdateImmediateGeolocation() assertTrue(geolocationJson.get("api_version").getAsString().equals("2012-04-24")); // Define new values for the Geolocation attributes (PUT test) - geolocationParamsUpdate = new MultivaluedMapImpl(); + geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("DesiredAccuracy", "High"); geolocationParamsUpdate.add("StatusCallback", "http://192.1.2.19:8080/ACae6e420f425248d6a26948c17a9e2acf"); geolocationParamsUpdate.add("ResponseStatus", responseStatus = "successfull"); @@ -646,7 +646,7 @@ public void testDeleteImmediateGeolocation() throws IllegalArgumentException, Cl // Create Immediate type of Geolocation via POST // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("DesiredAccuracy", "High"); geolocationParams.add("StatusCallback", "http://192.1.0.19:8080/ACae6e420f425248d6a26948c17a9e2acf"); @@ -701,7 +701,7 @@ public void testCreateAndGetNotificationGeolocation() // Test create Notification type of Geolocation via POST (only mandatory parameters) // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("EventGeofenceLatitude", eventGeofenceLatitude = "45.426280"); geolocationParams.add("EventGeofenceLongitude", eventGeofenceLongitude = "-80.566560"); @@ -817,7 +817,7 @@ public void testCreateNotApiCompliantNotificationGeolocation() // Test create Notification type of Geolocation via POST with one missing mandatory parameter // Parameter values Assignment, GeofenceEvent missing - MultivaluedMap geolocationNewParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationNewParams = new MultivaluedHashMap(); geolocationNewParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationNewParams.add("EventGeofenceLatitude", eventGeofenceLatitude = "-43.426280"); geolocationNewParams.add("EventGeofenceLongitude", eventGeofenceLongitude = "170.566560"); @@ -871,7 +871,7 @@ public void testUpdateNotificationGeolocation() // Create Notification type of Geolocation via POST // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("EventGeofenceLatitude", "-33.426280"); geolocationParams.add("EventGeofenceLongitude", "-70.566560"); @@ -884,7 +884,7 @@ public void testUpdateNotificationGeolocation() Sid geolocationSid = new Sid(geolocationJson.get("sid").getAsString()); // Define new values to the application attributes (POST test) - MultivaluedMap geolocationParamsUpdate = new MultivaluedMapImpl(); + MultivaluedMap geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParamsUpdate.add("EventGeofenceLatitude", eventGeofenceLatitude = "34\u00b038'19.39''N"); geolocationParamsUpdate.add("EventGeofenceLongitude", eventGeofenceLongitude = "55\u00b028'59.33''E"); @@ -964,7 +964,7 @@ public void testUpdateNotificationGeolocation() assertTrue(geolocationJson.get("api_version").getAsString().equals("2012-04-24")); // Define new values for the Geolocation attributes (PUT test) - geolocationParamsUpdate = new MultivaluedMapImpl(); + geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("EventGeofenceLatitude", eventGeofenceLatitude = "N172 42 62.80"); geolocationParamsUpdate.add("EventGeofenceLongitude", eventGeofenceLongitude = "W170 56 65.60"); geolocationParamsUpdate.add("GeofenceRange", "50"); @@ -1078,7 +1078,7 @@ public void testNotApiCompliantUpdateNotificationGeolocation() // Create Notification type of Geolocation via POST // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("EventGeofenceLatitude", "-33.426280"); geolocationParams.add("EventGeofenceLongitude", "-70.566560"); @@ -1097,7 +1097,7 @@ public void testNotApiCompliantUpdateNotificationGeolocation() // Define malformed values for the Geolocation attributes (PUT test to fail) - MultivaluedMap geolocationParamsUpdate = new MultivaluedMapImpl(); + MultivaluedMap geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("DeviceLatitude", deviceLatitude = "72.908134"); geolocationParamsUpdate.add("DeviceLongitude", deviceLongitude = "South 170.908134"); // WGS84 not compliant // Update failed Geolocation via PUT @@ -1137,7 +1137,7 @@ public void testNotApiCompliantUpdateNotificationGeolocation() assertTrue(geolocationJson.get("api_version").getAsString().equals("2012-04-24")); // Define new values for the Geolocation attributes (PUT test) - geolocationParamsUpdate = new MultivaluedMapImpl(); + geolocationParamsUpdate = new MultivaluedHashMap(); geolocationParamsUpdate.add("EventGeofenceLatitude", eventGeofenceLatitude = "172 42 62.80N"); geolocationParamsUpdate.add("EventGeofenceLongitude", eventGeofenceLongitude = "170 56 65.60E"); geolocationParamsUpdate.add("GeofenceRange", "50"); @@ -1246,7 +1246,7 @@ public void testDeleteNotificationGeolocation() throws IllegalArgumentException, // Create Notification type of Geolocation via POST // Parameter values Assignment - MultivaluedMap geolocationParams = new MultivaluedMapImpl(); + MultivaluedMap geolocationParams = new MultivaluedHashMap(); geolocationParams.add("DeviceIdentifier", deviceIdentifier = msisdn); geolocationParams.add("EventGeofenceLatitude", "-33.426280"); geolocationParams.add("EventGeofenceLongitude", "-70.566560"); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/NotificationEndpointTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/NotificationEndpointTool.java index 8dcb8d1abc..24d66ed02f 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/NotificationEndpointTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/NotificationEndpointTool.java @@ -21,10 +21,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; @@ -57,11 +57,11 @@ private String getAccountsUrl(String deploymentUrl, String username, Boolean jso } public JsonObject getNotificationList (String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget WebTarget = jerseyClient.target(url); + String response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); return jsonObject; @@ -69,24 +69,28 @@ public JsonObject getNotificationList (String deploymentUrl, String username, St public JsonObject getNotificationList (String deploymentUrl, String username, String authToken, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); String response; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webTarget.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); + webTarget.queryParam("PageSize", String.valueOf(pageSize)); + } - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -96,20 +100,20 @@ public JsonObject getNotificationList (String deploymentUrl, String username, St public JsonObject getNotificationListUsingFilter(String deploymentUrl, String username, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webTarget = webTarget.queryParam(filterName, filterData); } - webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OrganizationsEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OrganizationsEndpointTest.java index 190b465e97..a4e0b3f203 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OrganizationsEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OrganizationsEndpointTest.java @@ -22,7 +22,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.jersey.api.client.ClientResponse; +import javax.ws.rs.core.Response; /** * @author maria @@ -88,7 +88,7 @@ public void getOrganizationFromSuperAdminAccount(){ */ @Test public void getOrganizationFromAdministratorAccount(){ - ClientResponse clientResponse = RestcommOrganizationsTool.getInstance().getOrganizationResponse(deploymentUrl.toString(), adminAccountSid, adminAuthToken, org1); + Response clientResponse = RestcommOrganizationsTool.getInstance().getOrganizationResponse(deploymentUrl.toString(), adminAccountSid, adminAuthToken, org1); assertTrue(clientResponse!=null); logger.info("organization: "+clientResponse); assertTrue(clientResponse.getStatus() == 200); @@ -115,7 +115,7 @@ public void getOrganizationFromAdministratorAccount(){ @Test @Category(FeatureExpTests.class) public void getOrganizationFromDeveloperAccount(){ - ClientResponse clientResponse = RestcommOrganizationsTool.getInstance().getOrganizationResponse(deploymentUrl.toString(), devAccountSid, devAuthToken, org1); + Response clientResponse = RestcommOrganizationsTool.getInstance().getOrganizationResponse(deploymentUrl.toString(), devAccountSid, devAuthToken, org1); assertTrue(clientResponse!=null); logger.info("organization: "+clientResponse); assertTrue(clientResponse.getStatus() == 403); @@ -161,7 +161,7 @@ public void getOrganizationListByStatus(){ @Test public void createOrganizationTest(){ //super admin tries to create org - ClientResponse clientResponse = RestcommOrganizationsTool.getInstance().createOrganizationResponse(deploymentUrl.toString(), superAdminAccountSid, superAdminAuthToken, "newdomain"); + Response clientResponse = RestcommOrganizationsTool.getInstance().createOrganizationResponse(deploymentUrl.toString(), superAdminAccountSid, superAdminAuthToken, "newdomain"); logger.info("clientResponse: "+clientResponse); assertTrue(clientResponse.getStatus() == 200); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OutboundProxyTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OutboundProxyTool.java index 161bf6bbed..e109751626 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OutboundProxyTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/OutboundProxyTool.java @@ -4,9 +4,9 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; /** * @author gvagenas @@ -42,16 +42,16 @@ private String getAccountsUrl(String deploymentUrl, String username, Boolean jso public JsonObject getProxies(String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = WebTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); JsonParser parser = new JsonParser(); @@ -61,17 +61,17 @@ public JsonObject getProxies(String deploymentUrl, String username, String authT public JsonObject switchProxy(String deploymentUrl, String username, String authToken) { - - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - - WebResource webResource = jerseyClient.resource(url); + + WebTarget WebTarget = jerseyClient.target(url); String response = null; - response = webResource.path("switchProxy").accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = WebTarget.path("switchProxy").request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); JsonParser parser = new JsonParser(); @@ -81,16 +81,16 @@ public JsonObject switchProxy(String deploymentUrl, String username, String auth public JsonObject getActiveProxy(String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - - WebResource webResource = jerseyClient.resource(url); + + WebTarget WebTarget = jerseyClient.target(url); String response = null; - response = webResource.path("getActiveProxy").accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = WebTarget.path("getActiveProxy").request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); JsonParser parser = new JsonParser(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RecordingEndpointTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RecordingEndpointTool.java index 1ed3629be0..5dda292902 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RecordingEndpointTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RecordingEndpointTool.java @@ -21,10 +21,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; @@ -57,11 +57,11 @@ private String getAccountsUrl(String deploymentUrl, String username, Boolean jso } public JsonObject getRecordingList (String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget WebTarget = jerseyClient.target(url); + String response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); return jsonObject; @@ -69,24 +69,28 @@ public JsonObject getRecordingList (String deploymentUrl, String username, Strin public JsonObject getRecordingList (String deploymentUrl, String username, String authToken, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); String response; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webTarget.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); + webTarget.queryParam("PageSize", String.valueOf(pageSize)); + } - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -96,20 +100,20 @@ public JsonObject getRecordingList (String deploymentUrl, String username, Strin public JsonObject getRecordingListUsingFilter(String deploymentUrl, String username, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webTarget.queryParam(filterName, filterData); } - webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommAccountsTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommAccountsTool.java index b1d16016d0..65f2bc6563 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommAccountsTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommAccountsTool.java @@ -9,12 +9,14 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MultivaluedHashMap; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import org.restcomm.connect.testsuite.WebTargetUtil; /** * @author gvagenas @@ -58,37 +60,37 @@ private String getAccountsUrl (String deploymentUrl, Boolean xml) { } public void removeAccount (String deploymentUrl, String adminUsername, String adminAuthToken, String accountSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getAccountsUrl(deploymentUrl, true) + "/" + accountSid; - WebResource webResource = jerseyClient.resource(url); - webResource.accept(MediaType.APPLICATION_JSON).delete(); + WebTarget WebTarget = jerseyClient.target(url); + WebTarget.request(MediaType.APPLICATION_JSON).delete(); } public JsonObject updateAccount (String deploymentUrl, String adminUsername, String adminAuthToken, String accountSid, String friendlyName, String password, String authToken, String role, String status) { JsonParser parser = new JsonParser(); JsonObject jsonResponse = null; try { - ClientResponse clientResponse = updateAccountResponse(deploymentUrl, adminUsername, adminAuthToken, accountSid, friendlyName, password, authToken, role, status); - jsonResponse = parser.parse(clientResponse.getEntity(String.class)).getAsJsonObject(); + Response clientResponse = updateAccountResponse(deploymentUrl, adminUsername, adminAuthToken, accountSid, friendlyName, password, authToken, role, status); + jsonResponse = parser.parse(clientResponse.readEntity(String.class)).getAsJsonObject(); } catch (Exception e) { logger.info("Exception: " + e); } return jsonResponse; } - public ClientResponse updateAccountResponse (String deploymentUrl, String adminUsername, String adminAuthToken, String accountSid, String friendlyName, String password, String authToken, String role, String status) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + public Response updateAccountResponse (String deploymentUrl, String adminUsername, String adminAuthToken, String accountSid, String friendlyName, String password, String authToken, String role, String status) { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getAccountsUrl(deploymentUrl, false) + "/" + accountSid; - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); // FriendlyName, status, password and auth_token are currently updated in AccountsEndpoint. Role remains to be added - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); if (friendlyName != null) params.add("FriendlyName", friendlyName); if (password != null) @@ -100,7 +102,7 @@ public ClientResponse updateAccountResponse (String deploymentUrl, String adminU if (status != null) params.add("Status", status); - ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + Response response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); return response; } @@ -109,21 +111,21 @@ public JsonObject migrateAccount (String deploymentUrl, String adminUsername, St JsonParser parser = new JsonParser(); JsonObject jsonResponse = null; - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getAccountsUrl(deploymentUrl, false) + "/migrate/" + accountSid; - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); // FriendlyName, status, password and auth_token are currently updated in AccountsEndpoint. Role remains to be added - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); if (newOrganizationSid != null) params.add("Organization", newOrganizationSid); - ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + Response response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); if (response.getStatus() == 200) { - jsonResponse = parser.parse(response.getEntity(String.class)).getAsJsonObject(); + jsonResponse = parser.parse(response.readEntity(String.class)).getAsJsonObject(); } return jsonResponse; @@ -140,29 +142,29 @@ public JsonObject createAccount (String deploymentUrl, String adminUsername, Str JsonParser parser = new JsonParser(); JsonObject jsonResponse = null; try { - ClientResponse clientResponse = createAccountResponse(deploymentUrl, adminUsername, adminAuthToken, emailAddress, password, friendlyName, null); - jsonResponse = parser.parse(clientResponse.getEntity(String.class)).getAsJsonObject(); + Response clientResponse = createAccountResponse(deploymentUrl, adminUsername, adminAuthToken, emailAddress, password, friendlyName, null); + jsonResponse = parser.parse(clientResponse.readEntity(String.class)).getAsJsonObject(); } catch (Exception e) { logger.info("Exception: " + e); } return jsonResponse; } - public ClientResponse createAccountResponse (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String emailAddress, + public Response createAccountResponse (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String emailAddress, String password) { return createAccountResponse(deploymentUrl, operatorUsername, operatorAuthtoken, emailAddress, password, null, null); } - public ClientResponse createAccountResponse (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String emailAddress, + public Response createAccountResponse (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String emailAddress, String password, String friendlyName, String organizationSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(operatorUsername, operatorAuthtoken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(operatorUsername, operatorAuthtoken)); String url = getAccountsUrl(deploymentUrl); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("EmailAddress", emailAddress); params.add("Password", password); params.add("Role", "Administartor"); @@ -171,18 +173,18 @@ public ClientResponse createAccountResponse (String deploymentUrl, String operat if (organizationSid != null) params.add("OrganizationSid", organizationSid); - ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, params); + Response response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params)); return response; } public JsonObject getAccount (String deploymentUrl, String adminUsername, String adminAuthToken, String username) - throws UniformInterfaceException { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); - WebResource webResource = jerseyClient.resource(getAccountsUrl(deploymentUrl)); + WebTarget WebTarget = jerseyClient.target(getAccountsUrl(deploymentUrl)); - String response = webResource.path(username).get(String.class); + String response = WebTarget.path(username).request().get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); @@ -192,27 +194,27 @@ public JsonObject getAccount (String deploymentUrl, String adminUsername, String /* Returns an account response so that the invoker can make decisions on the status code etc. */ - public ClientResponse getAccountResponse (String deploymentUrl, String username, String authtoken, String accountSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authtoken)); - WebResource webResource = jerseyClient.resource(getAccountsUrl(deploymentUrl)); - ClientResponse response = webResource.path(accountSid).get(ClientResponse.class); + public Response getAccountResponse (String deploymentUrl, String username, String authtoken, String accountSid) { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authtoken)); + WebTarget WebTarget = jerseyClient.target(getAccountsUrl(deploymentUrl)); + Response response = WebTarget.path(accountSid).request().get(); return response; } - public ClientResponse getAccountsResponse (String deploymentUrl, String username, String authtoken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authtoken)); - WebResource webResource = jerseyClient.resource(getAccountsUrl(deploymentUrl)); - ClientResponse response = webResource.get(ClientResponse.class); + public Response getAccountsResponse (String deploymentUrl, String username, String authtoken) { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authtoken)); + WebTarget WebTarget = jerseyClient.target(getAccountsUrl(deploymentUrl)); + Response response = WebTarget.request().get(); return response; } - public ClientResponse removeAccountResponse (String deploymentUrl, String operatingUsername, String operatingAuthToken, String removedAccountSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(operatingUsername, operatingAuthToken)); - WebResource webResource = jerseyClient.resource(getAccountsUrl(deploymentUrl)); - ClientResponse response = webResource.path(removedAccountSid).delete(ClientResponse.class); + public Response removeAccountResponse (String deploymentUrl, String operatingUsername, String operatingAuthToken, String removedAccountSid) { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(operatingUsername, operatingAuthToken)); + WebTarget WebTarget = jerseyClient.target(getAccountsUrl(deploymentUrl)); + Response response = WebTarget.path(removedAccountSid).request().delete(Response.class); return response; } @@ -224,12 +226,12 @@ public ClientResponse removeAccountResponse (String deploymentUrl, String operat * @param domainName * @return */ - public ClientResponse getAccountsWithFilterClientResponse (String deploymentUrl, String username, String authtoken, String organizationSid, String domainName) { - WebResource webResource = prepareAccountListWebResource(deploymentUrl, username, authtoken); - - ClientResponse response = webResource.queryParams(prepareAccountListFilter(organizationSid, domainName)) - .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) - .get(ClientResponse.class); + public Response getAccountsWithFilterClientResponse (String deploymentUrl, String username, String authtoken, String organizationSid, String domainName) { + WebTarget webTarget = prepareAccountListWebTarget(deploymentUrl, username, authtoken); + WebTargetUtil.addQueryMap(webTarget, prepareAccountListFilter(organizationSid, domainName)); + Response response = webTarget + .request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + .get(); return response; } @@ -242,10 +244,11 @@ public ClientResponse getAccountsWithFilterClientResponse (String deploymentUrl, * @return JsonArray */ public JsonArray getAccountsWithFilterResponse (String deploymentUrl, String username, String authtoken, String organizationSid, String domainName) { - WebResource webResource = prepareAccountListWebResource(deploymentUrl, username, authtoken); + WebTarget webTarget = prepareAccountListWebTarget(deploymentUrl, username, authtoken); - String response = webResource.queryParams(prepareAccountListFilter(organizationSid, domainName)) - .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + WebTargetUtil.addQueryMap(webTarget, prepareAccountListFilter(organizationSid, domainName)); + String response = webTarget + .request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); JsonElement jsonElement = new JsonParser().parse(response); return jsonElement.getAsJsonArray(); @@ -257,11 +260,11 @@ public JsonArray getAccountsWithFilterResponse (String deploymentUrl, String use * @param authtoken * @return */ - private WebResource prepareAccountListWebResource(String deploymentUrl, String username, String authtoken){ - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authtoken)); - WebResource webResource = jerseyClient.resource(getAccountsUrl(deploymentUrl)); - return webResource; + private WebTarget prepareAccountListWebTarget(String deploymentUrl, String username, String authtoken){ + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authtoken)); + WebTarget WebTarget = jerseyClient.target(getAccountsUrl(deploymentUrl)); + return WebTarget; } /** @@ -270,7 +273,7 @@ private WebResource prepareAccountListWebResource(String deploymentUrl, String u * @return */ private MultivaluedMap prepareAccountListFilter(String organizationSid, String domainName){ - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); if(organizationSid != null && !(organizationSid.trim().isEmpty())) params.add("OrganizationSid", organizationSid); if(domainName != null && !(domainName.trim().isEmpty())) diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommApplicationsTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommApplicationsTool.java index c14e25adae..15f75b3b38 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommApplicationsTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommApplicationsTool.java @@ -29,9 +29,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; /** * @author guilherme.jansen@telestax.com @@ -80,11 +81,11 @@ private String getEndpoint(String deploymentUrl) { public JsonObject createApplication(String deploymentUrl, String adminAccountSid, String adminUsername, String adminAuthToken, MultivaluedMap applicationParams) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getApplicationsUrl(deploymentUrl, adminAccountSid, false); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, applicationParams); + WebTarget WebTarget = jerseyClient.target(url); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(applicationParams), String.class); JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); return jsonResponse; @@ -92,14 +93,14 @@ public JsonObject createApplication(String deploymentUrl, String adminAccountSid public JsonObject getApplication(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, String applicationSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getApplicationUrl(deploymentUrl, adminAccountSid, applicationSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; JsonObject jsonResponse = null; try { - response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); jsonResponse = parser.parse(response).getAsJsonObject(); } catch (Exception e) { @@ -113,13 +114,13 @@ public JsonArray getApplications(String deploymentUrl, String adminUsername, Str } public JsonArray getApplications(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, boolean includeNumbers) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getApplicationsUrl(deploymentUrl, adminAccountSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); if (includeNumbers) - webResource = webResource.queryParam("includeNumbers", "true"); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget = WebTarget.queryParam("includeNumbers", "true"); + String response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); return jsonResponse; @@ -127,15 +128,15 @@ public JsonArray getApplications(String deploymentUrl, String adminUsername, Str public JsonObject updateApplication(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, String applicationSid, MultivaluedMap applicationParams, boolean usePut) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getApplicationUrl(deploymentUrl, adminAccountSid, applicationSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = ""; if (usePut) { - response = webResource.accept(MediaType.APPLICATION_JSON).put(String.class, applicationParams); + response = WebTarget.request(MediaType.APPLICATION_JSON).put(Entity.form(applicationParams), String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, applicationParams); + response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(applicationParams), String.class); } JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); @@ -147,9 +148,9 @@ public void deleteApplication(String deploymentUrl, String adminUsername, String String endpoint = getEndpoint(deploymentUrl).replaceAll("http://", ""); String url = getApplicationUrl("http://" + adminAccountSid + ":" + adminAuthToken + "@" + endpoint, adminAccountSid, applicationSid, false); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAuthToken)); - WebResource webResource = jerseyClient.resource(url); - webResource.accept(MediaType.APPLICATION_JSON).delete(); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAuthToken)); + WebTarget WebTarget = jerseyClient.target(url); + WebTarget.request(MediaType.APPLICATION_JSON).delete(); } } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommCallsTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommCallsTool.java index a1fb24c1a3..d1e7d58e0a 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommCallsTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommCallsTool.java @@ -12,12 +12,13 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import com.thoughtworks.xstream.XStream; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.client.Entity; /** * @author gvagenas @@ -79,15 +80,15 @@ private String getGateWayUrl(String deploymentUrl, String username) { } public JsonArray getRecordings(String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getRecordingsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; - response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); // response = response.replaceAll("\\[", "").replaceAll("]", "").trim(); JsonArray jsonArray = null; try { @@ -108,27 +109,31 @@ public JsonObject getCalls(String deploymentUrl, String username, String authTok public JsonObject getCalls(String deploymentUrl, String username, String authToken, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, json); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); String response = null; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webTarget.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); + webTarget.queryParam("PageSize", String.valueOf(pageSize)); + } - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -181,19 +186,19 @@ public JsonObject getCall(String deploymentUrl, String username, String authToke */ public JsonObject getCall(String deploymentUrl, String username, String authToken, String resourceAccountSid, String sid){ - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, resourceAccountSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; - webResource = webResource.path(String.valueOf(sid)+".json"); - logger.info("The URI to sent: "+webResource.getURI()); + WebTarget = WebTarget.path(String.valueOf(sid)+".json"); + logger.info("The URI to sent: "+WebTarget.getUri()); - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = WebTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); JsonParser parser = new JsonParser(); @@ -205,21 +210,21 @@ public JsonObject getCall(String deploymentUrl, String username, String authToke public JsonObject getCallsUsingFilter(String deploymentUrl, String username, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webTarget.queryParam(filterName, filterData); } - webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); @@ -242,14 +247,14 @@ public JsonElement createCall(String deploymentUrl, String username, String auth public JsonElement createCall(String deploymentUrl, String username, String authToken, String from, String to, String rcmlUrl, final String statusCallback, final String statusCallbackMethod, final String statusCallbackEvent, final String timeout) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("From", from); params.add("To", to); params.add("Url", rcmlUrl); @@ -264,8 +269,8 @@ public JsonElement createCall(String deploymentUrl, String username, String auth if (timeout != null) params.add("Timeout", timeout); - // webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + // WebTarget = WebTarget.queryParams(params); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); if (response.startsWith("[")) { return parser.parse(response).getAsJsonArray(); @@ -322,14 +327,14 @@ public JsonObject modifyCall(String deploymentUrl, String username, String authT public JsonObject modifyCall(String deploymentUrl, String username, String authToken, String callSid, String status, String rcmlUrl, boolean moveConnectedLeg, Boolean mute) throws Exception { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); if (status != null && rcmlUrl != null) { throw new Exception( "You can either redirect a call using the \"url\" attribute or terminate it using the \"status\" attribute!"); @@ -350,12 +355,12 @@ public JsonObject modifyCall(String deploymentUrl, String username, String authT JsonObject jsonObject = null; try { - String response = webResource.path(callSid).accept(MediaType.APPLICATION_JSON).post(String.class, params); + String response = WebTarget.path(callSid).request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); jsonObject = parser.parse(response).getAsJsonObject(); } catch (Exception e) { logger.error("Exception : ", e); - UniformInterfaceException exception = (UniformInterfaceException)e; + WebApplicationException exception = (WebApplicationException)e; jsonObject = new JsonObject(); jsonObject.addProperty("Exception",exception.getResponse().getStatus()); } @@ -363,14 +368,14 @@ public JsonObject modifyCall(String deploymentUrl, String username, String authT } public JsonArray getCallRecordings(String deploymentUrl, String username, String authToken, String callWithRecordingsSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getCallRecordingsUrl(deploymentUrl, username, callWithRecordingsSid, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonArray jsonArray = parser.parse(response).getAsJsonArray(); @@ -380,14 +385,14 @@ public JsonArray getCallRecordings(String deploymentUrl, String username, String public String setGateWay(String deploymentUrl, String username, String authToken, String friend, String uName, String password, String proxy, boolean register, String ttl) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getGateWayUrl(deploymentUrl, username); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Register", String.valueOf(register)); if (friend != null) { params.add("FriendlyName", friend); @@ -407,10 +412,9 @@ public String setGateWay(String deploymentUrl, String username, String authToken String response = null; try { - response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); } catch (Exception e) { logger.error("Exception : ", e); - UniformInterfaceException exception = (UniformInterfaceException)e; } return response; } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceParticipantsTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceParticipantsTool.java index 4fdeef8eec..457a7c1425 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceParticipantsTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceParticipantsTool.java @@ -30,12 +30,13 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import com.thoughtworks.xstream.XStream; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.client.Entity; /** * @author maria @@ -46,7 +47,7 @@ public class RestcommConferenceParticipantsTool { private static RestcommConferenceParticipantsTool instance; private static String accountsUrl; private static Logger logger = Logger.getLogger(RestcommConferenceParticipantsTool.class); - + private RestcommConferenceParticipantsTool() {} public static RestcommConferenceParticipantsTool getInstance() { @@ -73,27 +74,31 @@ public JsonObject getParticipants(String deploymentUrl, String username, String public JsonObject getParticipants(String deploymentUrl, String username, String authToken, String conferenceSid, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, conferenceSid, json); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); String response = null; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webTarget.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); + webTarget.queryParam("PageSize", String.valueOf(pageSize)); + } - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -123,19 +128,19 @@ public JsonObject getParticipants(String deploymentUrl, String username, String public JsonObject getParticipant(String deploymentUrl, String username, String conferenceSid, String authToken, String sid){ - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, conferenceSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; - webResource = webResource.path(String.valueOf(sid)+".json"); - logger.info("The URI to sent: "+webResource.getURI()); - - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + WebTarget = WebTarget.path(String.valueOf(sid)+".json"); + logger.info("The URI to sent: "+WebTarget.getUri()); + + response = WebTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); JsonParser parser = new JsonParser(); @@ -147,21 +152,21 @@ public JsonObject getParticipant(String deploymentUrl, String username, String c public JsonObject getParticipantsUsingFilter(String deploymentUrl, String username, String conferenceSid, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, conferenceSid, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webTarget.queryParam(filterName, filterData); } - webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); @@ -170,14 +175,14 @@ public JsonObject getParticipantsUsingFilter(String deploymentUrl, String userna public JsonObject modifyCall(String deploymentUrl, String username, String conferenceSid, String authToken, String callSid, Boolean muted) throws Exception { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, conferenceSid, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); if (muted != null) params.add("Mute", ""+muted); @@ -185,12 +190,12 @@ public JsonObject modifyCall(String deploymentUrl, String username, String confe JsonObject jsonObject = null; try { - String response = webResource.path(callSid).accept(MediaType.APPLICATION_JSON).post(String.class, params); + String response = WebTarget.path(callSid).request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); jsonObject = parser.parse(response).getAsJsonObject(); } catch (Exception e) { logger.info("Exception e: "+e); - UniformInterfaceException exception = (UniformInterfaceException)e; + WebApplicationException exception = (WebApplicationException)e; jsonObject = new JsonObject(); jsonObject.addProperty("Exception",exception.getResponse().getStatus()); } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceTool.java index ccaa793ab3..c09725b790 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommConferenceTool.java @@ -31,10 +31,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import com.thoughtworks.xstream.XStream; /** @@ -46,7 +46,7 @@ public class RestcommConferenceTool { private static RestcommConferenceTool instance; private static String accountsUrl; private static Logger logger = Logger.getLogger(RestcommConferenceTool.class); - + private RestcommConferenceTool() {} public static RestcommConferenceTool getInstance() { @@ -73,27 +73,31 @@ public JsonObject getConferences(String deploymentUrl, String username, String a public JsonObject getConferences(String deploymentUrl, String username, String authToken, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, json); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); String response = null; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webTarget.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); + webTarget.queryParam("PageSize", String.valueOf(pageSize)); + } - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -123,19 +127,19 @@ public JsonObject getConferences(String deploymentUrl, String username, String a public JsonObject getConference(String deploymentUrl, String username, String authToken, String sid){ - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; - webResource = webResource.path(String.valueOf(sid)+".json"); - logger.info("The URI to sent: "+webResource.getURI()); - - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + WebTarget = WebTarget.path(String.valueOf(sid)+".json"); + logger.info("The URI to sent: "+WebTarget.getUri()); + + response = WebTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); JsonParser parser = new JsonParser(); @@ -147,21 +151,21 @@ public JsonObject getConference(String deploymentUrl, String username, String au public JsonObject getConferencesUsingFilter(String deploymentUrl, String username, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webTarget.queryParam(filterName, filterData); } - webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommExtensionsConfigurationTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommExtensionsConfigurationTool.java index c6b873491e..f17c239097 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommExtensionsConfigurationTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommExtensionsConfigurationTool.java @@ -1,16 +1,16 @@ package org.restcomm.connect.testsuite.http; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import java.util.logging.Logger; +import javax.ws.rs.client.Entity; /** * @author gvagenas @@ -54,15 +54,15 @@ public JsonObject postConfiguration(String deploymentUrl, String adminUsername, JsonParser parser = new JsonParser(); JsonObject jsonResponse = null; - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getUrl(deploymentUrl, xml); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - ClientResponse clientResponse = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, configurationParams); - jsonResponse = parser.parse(clientResponse.getEntity(String.class)).getAsJsonObject(); + Response clientResponse = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(configurationParams)); + jsonResponse = parser.parse(clientResponse.readEntity(String.class)).getAsJsonObject(); return jsonResponse; } @@ -71,12 +71,12 @@ public JsonObject getConfiguration(String deploymentUrl, String adminUsername, S } public JsonObject getConfiguration(String deploymentUrl, String adminUsername, String adminAuthToken, String extensionName, Boolean xml) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); - WebResource webResource = jerseyClient.resource(getUrl(deploymentUrl, xml)); + WebTarget WebTarget = jerseyClient.target(getUrl(deploymentUrl, xml)); - String response = webResource.path(extensionName).get(String.class); + String response = WebTarget.path(extensionName).request().get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); @@ -93,15 +93,15 @@ public JsonObject updateConfiguration(String deploymentUrl, String adminUsername JsonParser parser = new JsonParser(); JsonObject jsonResponse = null; - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getUrl(deploymentUrl, xml)+"/"+extensionSid; - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - ClientResponse clientResponse = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, configurationParams); - jsonResponse = parser.parse(clientResponse.getEntity(String.class)).getAsJsonObject(); + Response clientResponse = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(configurationParams)); + jsonResponse = parser.parse(clientResponse.readEntity(String.class)).getAsJsonObject(); return jsonResponse; } } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommGeolocationsTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommGeolocationsTool.java index 521a62a0e5..ea63ba9393 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommGeolocationsTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommGeolocationsTool.java @@ -32,9 +32,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; /** * @author Fernando Mendioroz @@ -108,11 +109,11 @@ private String getEndpoint(String deploymentUrl) { public JsonObject createImmediateGeolocation(String deploymentUrl, String adminAccountSid, String adminUsername, String adminAuthToken, MultivaluedMap geolocationParams) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getImmediateGeolocationsUrl(deploymentUrl, adminAccountSid, false); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, geolocationParams); + WebTarget WebTarget = jerseyClient.target(url); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post( Entity.form(geolocationParams),String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = null; try { @@ -131,11 +132,11 @@ public JsonObject createImmediateGeolocation(String deploymentUrl, String adminA public JsonObject createNotificationGeolocation(String deploymentUrl, String adminAccountSid, String adminUsername, String adminAuthToken, MultivaluedMap geolocationParams) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getNotificationGeolocationsUrl(deploymentUrl, adminAccountSid, false); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, geolocationParams); + WebTarget WebTarget = jerseyClient.target(url); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(geolocationParams),String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = null; try { @@ -154,14 +155,14 @@ public JsonObject createNotificationGeolocation(String deploymentUrl, String adm public JsonObject getImmediateGeolocation(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, String geolocationSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getImmediateGeolocationUrl(deploymentUrl, adminAccountSid, geolocationSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; JsonObject jsonResponse = null; try { - response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); jsonResponse = parser.parse(response).getAsJsonObject(); } catch (Exception e) { @@ -172,14 +173,14 @@ public JsonObject getImmediateGeolocation(String deploymentUrl, String adminUser public JsonObject getNotificationGeolocation(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, String geolocationSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getNotificationGeolocationUrl(deploymentUrl, adminAccountSid, geolocationSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = null; JsonObject jsonResponse = null; try { - response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); jsonResponse = parser.parse(response).getAsJsonObject(); } catch (Exception e) { @@ -190,11 +191,11 @@ public JsonObject getNotificationGeolocation(String deploymentUrl, String adminU public JsonArray getGeolocations(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getGeolocationsUrl(deploymentUrl, adminAccountSid, false); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget WebTarget = jerseyClient.target(url); + String response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); return jsonResponse; @@ -202,15 +203,15 @@ public JsonArray getGeolocations(String deploymentUrl, String adminUsername, Str public JsonObject updateImmediateGeolocation(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, String geolocationSid, MultivaluedMap geolocationParams, boolean usePut) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getImmediateGeolocationUrl(deploymentUrl, adminAccountSid, geolocationSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = ""; if (usePut) { - response = webResource.accept(MediaType.APPLICATION_JSON).put(String.class, geolocationParams); + response = WebTarget.request(MediaType.APPLICATION_JSON).put(Entity.form(geolocationParams),String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, geolocationParams); + response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(geolocationParams),String.class); } JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); @@ -219,15 +220,15 @@ public JsonObject updateImmediateGeolocation(String deploymentUrl, String adminU public JsonObject updateNotificationGeolocation(String deploymentUrl, String adminUsername, String adminAuthToken, String adminAccountSid, String geolocationSid, MultivaluedMap geolocationParams, boolean usePut) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String url = getNotificationGeolocationUrl(deploymentUrl, adminAccountSid, geolocationSid, false); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); String response = ""; if (usePut) { - response = webResource.accept(MediaType.APPLICATION_JSON).put(String.class, geolocationParams); + response = WebTarget.request(MediaType.APPLICATION_JSON).put(Entity.form(geolocationParams),String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, geolocationParams); + response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(geolocationParams),String.class); } JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); @@ -239,10 +240,10 @@ public void deleteImmediateGeolocation(String deploymentUrl, String adminUsernam String endpoint = getEndpoint(deploymentUrl).replaceAll("http://", ""); String url = getImmediateGeolocationUrl("http://" + adminAccountSid + ":" + adminAuthToken + "@" + endpoint, adminAccountSid, geolocationSid, false); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAuthToken)); - WebResource webResource = jerseyClient.resource(url); - webResource.accept(MediaType.APPLICATION_JSON).delete(); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAuthToken)); + WebTarget WebTarget = jerseyClient.target(url); + WebTarget.request(MediaType.APPLICATION_JSON).delete(); } public void deleteNotificationGeolocation(String deploymentUrl, String adminUsername, String adminAuthToken, @@ -250,10 +251,10 @@ public void deleteNotificationGeolocation(String deploymentUrl, String adminUser String endpoint = getEndpoint(deploymentUrl).replaceAll("http://", ""); String url = getNotificationGeolocationUrl("http://" + adminAccountSid + ":" + adminAuthToken + "@" + endpoint, adminAccountSid, geolocationSid, false); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAuthToken)); - WebResource webResource = jerseyClient.resource(url); - webResource.accept(MediaType.APPLICATION_JSON).delete(); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAuthToken)); + WebTarget WebTarget = jerseyClient.target(url); + WebTarget.request(MediaType.APPLICATION_JSON).delete(); } private String evaluateDeploymentUrl(String deploymentUrl) { diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommOrganizationsTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommOrganizationsTool.java index faf2c04f84..ebec222008 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommOrganizationsTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommOrganizationsTool.java @@ -9,12 +9,12 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; /** * @author maria farooq @@ -54,13 +54,13 @@ private String getOrganizationsUrl (String deploymentUrl, Boolean xml) { } public JsonObject getOrganization (String deploymentUrl, String adminUsername, String adminAuthToken, String username) - throws UniformInterfaceException { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); - WebResource webResource = jerseyClient.resource(getOrganizationsUrl(deploymentUrl)); + WebTarget WebTarget = jerseyClient.target(getOrganizationsUrl(deploymentUrl)); - String response = webResource.path(username).get(String.class); + String response = WebTarget.path(username).request().get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); @@ -68,20 +68,21 @@ public JsonObject getOrganization (String deploymentUrl, String adminUsername, S } public JsonArray getOrganizationList (String deploymentUrl, String adminUsername, String adminAuthToken, String status) - throws UniformInterfaceException { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); - WebResource webResource = jerseyClient.resource(getOrganizationsUrl(deploymentUrl)); + WebTarget webTarget = jerseyClient.target(getOrganizationsUrl(deploymentUrl)); String response; if (status != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("Status", String.valueOf(status)); + webTarget.queryParam("Status", String.valueOf(status)); - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); JsonArray jsonArray = null; @@ -100,19 +101,19 @@ public JsonArray getOrganizationList (String deploymentUrl, String adminUsername return jsonArray; } - public ClientResponse getOrganizationResponse (String deploymentUrl, String username, String authtoken, String organizationSid) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authtoken)); - WebResource webResource = jerseyClient.resource(getOrganizationsUrl(deploymentUrl)); - ClientResponse response = webResource.path(organizationSid).get(ClientResponse.class); + public Response getOrganizationResponse (String deploymentUrl, String username, String authtoken, String organizationSid) { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authtoken)); + WebTarget WebTarget = jerseyClient.target(getOrganizationsUrl(deploymentUrl)); + Response response = WebTarget.path(organizationSid).request().get(); return response; } - public ClientResponse getOrganizationsResponse (String deploymentUrl, String username, String authtoken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authtoken)); - WebResource webResource = jerseyClient.resource(getOrganizationsUrl(deploymentUrl)); - ClientResponse response = webResource.get(ClientResponse.class); + public Response getOrganizationsResponse (String deploymentUrl, String username, String authtoken) { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authtoken)); + WebTarget WebTarget = jerseyClient.target(getOrganizationsUrl(deploymentUrl)); + Response response = WebTarget.request().get(); return response; } @@ -121,23 +122,23 @@ public JsonObject createOrganization (String deploymentUrl, String username, Str JsonParser parser = new JsonParser(); JsonObject jsonResponse = null; try { - ClientResponse clientResponse = createOrganizationResponse(deploymentUrl, username, adminAuthToken, domainName); - jsonResponse = parser.parse(clientResponse.getEntity(String.class)).getAsJsonObject(); + Response clientResponse = createOrganizationResponse(deploymentUrl, username, adminAuthToken, domainName); + jsonResponse = parser.parse(clientResponse.readEntity(String.class)).getAsJsonObject(); } catch (Exception e) { logger.info("Exception: " + e); } return jsonResponse; } - public ClientResponse createOrganizationResponse (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String domainName) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(operatorUsername, operatorAuthtoken)); + public Response createOrganizationResponse (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String domainName) { + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(operatorUsername, operatorAuthtoken)); String url = getOrganizationsUrl(deploymentUrl) + "/" + domainName; - WebResource webResource = jerseyClient.resource(url); - MultivaluedMap params = new MultivaluedMapImpl(); - ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).put(ClientResponse.class, params); + WebTarget WebTarget = jerseyClient.target(url); + MultivaluedMap params = new MultivaluedHashMap(); + Response response = WebTarget.request(MediaType.APPLICATION_JSON).put(Entity.form(params)); return response; } } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUsageRecordsTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUsageRecordsTool.java index 777a2c7f15..6c988c5188 100755 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUsageRecordsTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUsageRecordsTool.java @@ -27,21 +27,12 @@ import org.apache.commons.collections.map.HashedMap; import org.apache.log4j.Logger; -import org.restcomm.connect.dao.entities.CallDetailRecordList; -import org.restcomm.connect.dao.entities.UsageList; - -import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; -import com.thoughtworks.xstream.XStream; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; /** * @author abdulazizali77 @@ -139,22 +130,19 @@ public JsonElement getUsageRecords(String deploymentUrl, String username, String public JsonElement getUsageRecordsUsingFilter(String deploymentUrl, String username, String authToken, String subresource, Map filters, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getUsageRecordsUrl(deploymentUrl, username, subresource, json); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webTarget.queryParam(filterName, filterData); } - if (!params.isEmpty()) { - webResource = webResource.queryParams(params); - } - - String response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + String response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); JsonParser parser = new JsonParser(); JsonElement jsonElement = null; if (json) { diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUssdPushTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUssdPushTool.java index 778bf8e38c..c71a9d05e5 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUssdPushTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RestcommUssdPushTool.java @@ -5,10 +5,11 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; /** * @author gvagenas @@ -44,20 +45,20 @@ private String getAccountsUrl(String deploymentUrl, String username) { public JsonObject createUssdPush(String deploymentUrl, String username, String authToken, String from, String to, String rcmlUrl) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username); - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("From", from); params.add("To", to); params.add("Url", rcmlUrl); - // webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + // WebTarget = WebTarget.queryParams(params); + String response = WebTarget.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RoleSensitiveTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RoleSensitiveTest.java index 7ad702f416..ea5cb572e0 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RoleSensitiveTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/RoleSensitiveTest.java @@ -35,10 +35,10 @@ import org.junit.runner.RunWith; import org.restcomm.connect.commons.annotations.FeatureExpTests; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MultivaluedHashMap; /** * Selective testing (relies on accounts endpoint only) that involves accounts, roles and permissions. @@ -70,14 +70,14 @@ public class RoleSensitiveTest extends EndpointTest { public void testSinglePermissionAccess() { // user can read his account Client jersey = getClient(userUsername, userAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/" + userSid) ); - ClientResponse response = resource.get(ClientResponse.class); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/" + userSid) ); + Response response = resource.request().get(); Assert.assertEquals("user@company.com cannot read his account", 200, response.getStatus()); // user is refused access when missing permission - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts/" + userSid + ".json") ); - MultivaluedMap applicationParams = new MultivaluedMapImpl(); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts/" + userSid + ".json") ); + MultivaluedMap applicationParams = new MultivaluedHashMap(); applicationParams.add("FriendlyName", "Test User UPDATED"); - response = resource.accept(MediaType.APPLICATION_JSON).put(ClientResponse.class, applicationParams); + response = resource.request(MediaType.APPLICATION_JSON).put(Entity.form(applicationParams)); Assert.assertEquals(403, response.getStatus()); } @@ -86,8 +86,8 @@ public void testSinglePermissionAccess() { public void testSiblingAccountPermissionAccess() { // user cannot read sibling account although he has Accounts:Read permission Client jersey = getClient(userUsername, userAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/" + developerSid) ); - ClientResponse response = resource.get(ClientResponse.class); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/" + developerSid) ); + Response response = resource.request().get(); Assert.assertEquals(403, response.getStatus()); } @@ -95,14 +95,14 @@ public void testSiblingAccountPermissionAccess() { public void testStarPermission() { // power user can read his account Client jersey = getClient(powerUserUsername, powerUserAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/" + powerUserSid) ); - ClientResponse response = resource.get(ClientResponse.class); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/" + powerUserSid) ); + Response response = resource.request().get(); Assert.assertEquals(200, response.getStatus()); // power user is refused access when missing permission - resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/" + powerUserSid) ); - MultivaluedMap applicationParams = new MultivaluedMapImpl(); + resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/" + powerUserSid) ); + MultivaluedMap applicationParams = new MultivaluedHashMap(); applicationParams.add("FriendlyName", "Test User UPDATED"); - response = resource.accept(MediaType.APPLICATION_JSON).put(ClientResponse.class, applicationParams); + response = resource.request(MediaType.APPLICATION_JSON).put(Entity.form(applicationParams)); Assert.assertEquals(200, response.getStatus()); } @@ -111,8 +111,8 @@ public void testStarPermission() { public void testNoPermissions() { // guest cannot read his account Client jersey = getClient(guestUsername, guestAuthToken); - WebResource resource = jersey.resource( getResourceUrl("/2012-04-24/Accounts.json/" + guestSid) ); - ClientResponse response = resource.get(ClientResponse.class); + WebTarget resource = jersey.target( getResourceUrl("/2012-04-24/Accounts.json/" + guestSid) ); + Response response = resource.request().get(); Assert.assertEquals(403, response.getStatus()); } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/SupervisorEndpointAccessControlTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/SupervisorEndpointAccessControlTest.java index d179b49a49..ca158b75ec 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/SupervisorEndpointAccessControlTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/SupervisorEndpointAccessControlTest.java @@ -35,10 +35,10 @@ import org.restcomm.connect.testsuite.tools.MonitoringServiceTool; import com.google.gson.JsonObject; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; /** * SupervisorEndpointAccessControlTest Supervisor metrices should be accessible to only Super Admin role. @@ -89,11 +89,11 @@ public void testSuperAdmin2PermissionTest() { @Test @Category(FeatureExpTests.class) public void testAdminPermissionTest() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAccountAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAccountAuthToken)); String url = MonitoringServiceTool.getInstance().getAccountsUrl(deploymentUrl.toString(), adminAccountSid); - WebResource webResource = jerseyClient.resource(url+"/metrics"); - ClientResponse response = webResource.get(ClientResponse.class); + WebTarget WebTarget = jerseyClient.target(url+"/metrics"); + Response response = WebTarget.request().get(); Assert.assertEquals(403, response.getStatus()); } @@ -103,11 +103,11 @@ public void testAdminPermissionTest() { @Test @Category(FeatureExpTests.class) public void testDeveloperPermissionTest() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(developerSid, developerAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(developerSid, developerAuthToken)); String url = MonitoringServiceTool.getInstance().getAccountsUrl(deploymentUrl.toString(), developerSid); - WebResource webResource = jerseyClient.resource(url+"/metrics"); - ClientResponse response = webResource.get(ClientResponse.class); + WebTarget WebTarget = jerseyClient.target(url+"/metrics"); + Response response = WebTarget.request().get(); Assert.assertEquals(403, response.getStatus()); } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/TranscriptionEndpointTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/TranscriptionEndpointTool.java index 4fc1d892ad..aaba642790 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/TranscriptionEndpointTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/TranscriptionEndpointTool.java @@ -21,10 +21,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; @@ -57,11 +57,11 @@ private String getAccountsUrl(String deploymentUrl, String username, Boolean jso } public JsonObject getTranscriptionList (String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget WebTarget = jerseyClient.target(url); + String response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); return jsonObject; @@ -69,24 +69,27 @@ public JsonObject getTranscriptionList (String deploymentUrl, String username, S public JsonObject getTranscriptionList (String deploymentUrl, String username, String authToken, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); String response; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webTarget.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); - - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + webTarget.queryParam("PageSize", String.valueOf(pageSize)); + } + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webTarget.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -96,20 +99,20 @@ public JsonObject getTranscriptionList (String deploymentUrl, String username, S public JsonObject getTranscriptionListUsingFilter(String deploymentUrl, String username, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webTarget = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webTarget.queryParam(filterName, filterData); } - webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/UsageRecordsTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/UsageRecordsTest.java index cdb48292d1..7fb5380961 100755 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/UsageRecordsTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/UsageRecordsTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.*; -import com.sun.jersey.api.client.UniformInterfaceException; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -39,6 +38,7 @@ import org.restcomm.connect.commons.Version; import java.net.URL; +import javax.ws.rs.WebApplicationException; import org.junit.experimental.categories.Category; import org.restcomm.connect.commons.annotations.BrokenTests; import org.restcomm.connect.commons.annotations.UnstableTests; @@ -60,7 +60,7 @@ public class UsageRecordsTest { private String adminAccountSid = "ACae6e420f425248d6a26948c17a9e2acf"; private String adminAuthToken = "77f8c12cc7b8f8423e5c38b035249166"; - @Test(expected = UniformInterfaceException.class) + @Test(expected = WebApplicationException.class) public void getUsageRecordsList() { // NB: currently unimplemented JsonElement firstPage = RestcommUsageRecordsTool.getInstance().getUsageRecords(deploymentUrl.toString(), @@ -68,14 +68,14 @@ public void getUsageRecordsList() { logger.info(firstPage); } - @Test(expected = UniformInterfaceException.class) + @Test(expected = WebApplicationException.class) public void getUsageRecordsListCategoryCalls() { JsonElement firstPage = RestcommUsageRecordsTool.getInstance().getUsageRecordsDaily(deploymentUrl.toString(), adminAccountSid, adminAuthToken, "calls", true); logger.info(firstPage); } - @Test(expected = UniformInterfaceException.class) + @Test(expected = WebApplicationException.class) public void getUsageRecordsListCategorySms() { JsonElement firstPage = RestcommUsageRecordsTool.getInstance().getUsageRecordsDaily(deploymentUrl.toString(), adminAccountSid, adminAuthToken, "sms", true); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/VersionTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/VersionTest.java index 20d4cb8c6d..39aab5c7b3 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/VersionTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/VersionTest.java @@ -41,9 +41,9 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; /** * Created by gvagenas on 1/19/16. @@ -63,14 +63,14 @@ public class VersionTest { @Test public void testVersionJson() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAuthToken)); String url = deploymentUrl + "2012-04-24/Accounts/" + adminAccountSid + "/Version.json"; - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = WebTarget.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject json = parser.parse(response).getAsJsonObject(); assertTrue(version.equals(json.get("Version").getAsString())); @@ -79,14 +79,14 @@ public void testVersionJson() { @Test public void testVersionXml() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAuthToken)); String url = deploymentUrl + "2012-04-24/Accounts/" + adminAccountSid + "/Version"; - WebResource webResource = jerseyClient.resource(url); + WebTarget WebTarget = jerseyClient.target(url); - String response = webResource.accept(MediaType.APPLICATION_XML).get(String.class); + String response = WebTarget.request(MediaType.APPLICATION_XML).get(String.class); assertNotNull(response); assertTrue(response.contains(version)); assertTrue(response.contains(revision)); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthAvailablePhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthAvailablePhoneNumbersEndpointTest.java index a4e42a3bd6..809901fda8 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthAvailablePhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthAvailablePhoneNumbersEndpointTest.java @@ -23,10 +23,10 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.gson.JsonArray; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.apache.log4j.Logger; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; @@ -80,16 +80,16 @@ public void testReturnAreaCodeSearch(){ .withHeader("Content-Type", "text/json") .withBody(BandwidthAvailablePhoneNumbersEndpointTestUtils.areaCode201SearchResult))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("AreaCode","201").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("AreaCode","201").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); JsonParser parser = new JsonParser(); @@ -112,16 +112,16 @@ public void testSearchAreaCode205() { .withHeader("Content-Type", "text/json") .withBody(BandwidthAvailablePhoneNumbersEndpointTestUtils.areaCode205SearchResult))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("AreaCode","201").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("AreaCode","201").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); JsonParser parser = new JsonParser(); @@ -139,16 +139,16 @@ public void testReturnZipCodeSearch(){ .withHeader("Content-Type", "text/json") .withBody(BandwidthAvailablePhoneNumbersEndpointTestUtils.zipCode27601SearchResult))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("AreaCode","201").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("AreaCode","201").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); @@ -166,16 +166,16 @@ public void testReturnEmptyResultsSearch() { .withStatus(200) .withHeader("Content-Type", "text/json") .withBody(BandwidthAvailablePhoneNumbersEndpointTestUtils.emptySearchResult))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); @@ -192,16 +192,16 @@ public void testMalformedSearchResultXml() { .withStatus(200) .withHeader("Content-Type", "text/json") .withBody(BandwidthAvailablePhoneNumbersEndpointTestUtils.emptySearchResult))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); @@ -217,16 +217,16 @@ public void testSearchForTollFreeNumbers() { .withHeader("Content-Type", "text-json") .withBody(BandwidthAvailablePhoneNumbersEndpointTestUtils.validTollFreeSearchResult))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/TollFree.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("RangeSize","2").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("RangeSize","2").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); JsonParser parser = new JsonParser(); @@ -248,16 +248,16 @@ public void testSearchForTollFreeNumbersInvalidPattern() { .withHeader("Content-Type", "text-json") .withBody(BandwidthAvailablePhoneNumbersEndpointTestUtils.invalidTollFreeSearchResult))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/TollFree.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("RangeSize","2").queryParam("Contains", "7**").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("RangeSize","2").queryParam("Contains", "7**").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthIncomingPhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthIncomingPhoneNumbersEndpointTest.java index 185750651f..9640ebd5d0 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthIncomingPhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/bandwidth/BandwidthIncomingPhoneNumbersEndpointTest.java @@ -23,11 +23,11 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import org.apache.log4j.Logger; import org.jboss.arquillian.container.test.api.Deployer; @@ -48,6 +48,7 @@ import java.net.URL; import static com.github.tomakehurst.wiremock.client.WireMock.*; +import javax.ws.rs.client.Entity; import static junit.framework.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.experimental.categories.Category; @@ -88,22 +89,22 @@ public void testBuyNumber() { .withBody(BandwidthIncomingPhoneNumbersEndpointTestUtils.validOrderResponseXml))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; System.out.println(provisioningURL); - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); numberBought = true; - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -132,23 +133,23 @@ public void testCancelNumber() { .withHeader("Content-Type", "application/xml") .withBody(BandwidthIncomingPhoneNumbersEndpointTestUtils.validDisconnectOrderResponseXml))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; System.out.println(provisioningURL); - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); JsonObject jsonResponse; if (clientResponse.getStatus()==200) { assertEquals(200, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -161,8 +162,8 @@ public void testCancelNumber() { String phoneNumberSid = jsonResponse.get("sid").getAsString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(); assertTrue(clientResponse.getStatus() == 204); } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoAvailablePhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoAvailablePhoneNumbersEndpointTest.java index 2aa65efec3..072ac6fb9a 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoAvailablePhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoAvailablePhoneNumbersEndpointTest.java @@ -44,10 +44,10 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.gson.JsonArray; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.restcomm.connect.commons.Version; import org.restcomm.connect.commons.annotations.FeatureAltTests; @@ -72,10 +72,10 @@ public class NexmoAvailablePhoneNumbersEndpointTest { private String adminAccountSid = "ACae6e420f425248d6a26948c17a9e2acf"; private String adminAuthToken = "77f8c12cc7b8f8423e5c38b035249166"; private String baseURL = "2012-04-24/Accounts/" + adminAccountSid + "/AvailablePhoneNumbers/"; - + @Rule public WireMockRule wireMockRule = new WireMockRule(8090); // No-args constructor defaults to port 8080 - + /* * Testing https://docs.nexmo.com/index.php/developer-api/number-search Example 1 */ @@ -87,28 +87,28 @@ public void testSearchESPhoneNumbers700Pattern() { .withHeader("Content-Type", "text/json") .withBody(NexmoAvailablePhoneNumbersEndpointTestUtils.jsonResponseES700))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "ES/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","700").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","700").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 1); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(NexmoAvailablePhoneNumbersEndpointTestUtils.jsonResultES700)); } - + /* * Testing https://docs.nexmo.com/index.php/developer-api/number-search Example 2 */ @@ -120,28 +120,28 @@ public void testSearchUSPhoneNumbersRangeIndexAndSize() { .withHeader("Content-Type", "text/json") .withBody(NexmoAvailablePhoneNumbersEndpointTestUtils.jsonResponseUSRange))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("RangeSize","5").queryParam("RangeIndex","2").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("RangeSize","5").queryParam("RangeIndex","2").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 5); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(NexmoAvailablePhoneNumbersEndpointTestUtils.jsonResultUSRange)); } - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-1 * available local phone numbers in the United States in the 510 area code. @@ -155,28 +155,28 @@ public void testSearchUSLocalPhoneNumbersWith501AreaCode() { .withHeader("Content-Type", "text/json") .withBody(NexmoAvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("AreaCode","501").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("AreaCode","501").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 6); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(NexmoAvailablePhoneNumbersEndpointTestUtils.firstJSonResult501AreaCode)); } - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-1 * available local phone numbers in the United States in the 510 area code. @@ -190,30 +190,30 @@ public void testSearchCALocalPhoneNumbersWith450AreaCode() { .withHeader("Content-Type", "text/json") .withBody(NexmoAvailablePhoneNumbersEndpointTestUtils.bodyCA450AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "CA/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("AreaCode","450").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("AreaCode","450").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 10); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(NexmoAvailablePhoneNumbersEndpointTestUtils.firstJSonResultCA450AreaCode)); } - + /* - * + * */ @Test public void testSearchCALocalPhoneNumbersWithContainsAreaCode() { @@ -223,28 +223,28 @@ public void testSearchCALocalPhoneNumbersWithContainsAreaCode() { .withHeader("Content-Type", "text/json") .withBody(NexmoAvailablePhoneNumbersEndpointTestUtils.bodyCA418AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "CA/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","418").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","418").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 10); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(NexmoAvailablePhoneNumbersEndpointTestUtils.firstJSonResultCA418AreaCode)); } - + // @Test // public void testSearchUSPhoneNumbersSMSOnly() { //// stubFor(get(urlMatching("/nexmo/number/search/.*/.*/US\\?index=2&size=5")) @@ -253,28 +253,28 @@ public void testSearchCALocalPhoneNumbersWithContainsAreaCode() { //// .withHeader("Content-Type", "text/json") //// .withBody(NexmoAvailablePhoneNumbersEndpointTestUtils.jsonResponseUSRange))); // // Get Account using admin email address and user email address -// Client jerseyClient = Client.create(); -// jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); +// Client jerseyClient = ClientBuilder.newClient(); +// jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); // // String provisioningURL = deploymentUrl + baseURL + "SK/Local.json"; -// WebResource webResource = jerseyClient.resource(provisioningURL); +// WebTarget webResource = jerseyClient.target(provisioningURL); // -// ClientResponse clientResponse = webResource.queryParam("SmsEnabled","true").accept("application/json") -// .get(ClientResponse.class); +// Response clientResponse = webResource.queryParam("SmsEnabled","true").request("application/json") +// .request().get(); // assertTrue(clientResponse.getStatus() == 200); -// String response = clientResponse.getEntity(String.class); +// String response = clientResponse.readEntity(String.class); // System.out.println(response); // assertTrue(!response.trim().equalsIgnoreCase("[]")); // JsonParser parser = new JsonParser(); // JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); -// +// // System.out.println(jsonResponse); -// +// // assertTrue(jsonResponse.size() == 5); // System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); // assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(NexmoAvailablePhoneNumbersEndpointTestUtils.jsonResultUSRange)); // } - + @Deployment(name = "NexmoAvailablePhoneNumbersEndpointTest", managed = true, testable = false) public static WebArchive createWebArchiveNoGw() { logger.info("Packaging Test App"); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoIncomingPhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoIncomingPhoneNumbersEndpointTest.java index 63b3c6cd93..699984a516 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoIncomingPhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/nexmo/NexmoIncomingPhoneNumbersEndpointTest.java @@ -50,11 +50,12 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import org.restcomm.connect.commons.Version; import org.restcomm.connect.commons.annotations.FeatureExpTests; @@ -88,15 +89,15 @@ public class NexmoIncomingPhoneNumbersEndpointTest { @Test public void testGetAvailableCountries() { // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/AvailableCountries.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.accept("application/json").get(ClientResponse.class); + Response clientResponse = webResource.request("application/json").get(); Assert.assertEquals(200, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -126,20 +127,20 @@ public void testPurchasePhoneNumberSuccess() { .withBody(NexmoIncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); Assert.assertEquals(200, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -173,20 +174,20 @@ public void testDeletePhoneNumberSuccess() { .withHeader("Content-Type", "application/json") .withBody(NexmoIncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+34911067000"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); Assert.assertEquals(200, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info("testDeletePhoneNumberSuccess response for buyNumber: "+response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -197,8 +198,8 @@ public void testDeletePhoneNumberSuccess() { String phoneNumberSid = jsonResponse.get("sid").getAsString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(); logger.info("testDeletePhoneNumberSuccess delete response: "+clientResponse); assertTrue(clientResponse.getStatus() == 204); } @@ -218,20 +219,20 @@ public void testPurchasePhoneNumberNoPhoneNumberFound() { .withBody(NexmoIncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902860"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertEquals(400, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); // JsonParser parser = new JsonParser(); @@ -265,20 +266,20 @@ public void testUpdatePhoneNumberSuccess() { .withHeader("Content-Type", "application/json") .withBody(NexmoIncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+33911067000"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); Assert.assertEquals(200, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -289,15 +290,15 @@ public void testUpdatePhoneNumberSuccess() { String phoneNumberSid = jsonResponse.get("sid").getAsString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - formData = new MultivaluedMapImpl(); + webResource = jerseyClient.target(provisioningURL); + formData = new MultivaluedHashMap(); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice2.xml"); formData.add("SmsUrl", "http://demo.telestax.com/docs/sms2.xml"); formData.add("VoiceMethod", "POST"); formData.add("SMSMethod", "GET"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - response = clientResponse.getEntity(String.class); + response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); parser = new JsonParser(); @@ -306,8 +307,8 @@ public void testUpdatePhoneNumberSuccess() { assertTrue(NexmoIncomingPhoneNumbersEndpointTestUtils.match(jsonResponse.toString(),NexmoIncomingPhoneNumbersEndpointTestUtils.jSonResultUpdateSuccessPurchaseNumber)); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(); assertTrue(clientResponse.getStatus() == 204); } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/AvailablePhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/AvailablePhoneNumbersEndpointTest.java index b7c6ba8448..f1db8dbf41 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/AvailablePhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/AvailablePhoneNumbersEndpointTest.java @@ -45,10 +45,10 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.gson.JsonArray; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.restcomm.connect.commons.Version; import org.restcomm.connect.commons.annotations.FeatureAltTests; @@ -72,10 +72,10 @@ public class AvailablePhoneNumbersEndpointTest { private String adminAccountSid = "ACae6e420f425248d6a26948c17a9e2acf"; private String adminAuthToken = "77f8c12cc7b8f8423e5c38b035249166"; private String baseURL = "2012-04-24/Accounts/" + adminAccountSid + "/AvailablePhoneNumbers/"; - + @Rule public WireMockRule wireMockRule = new WireMockRule(8090); // No-args constructor defaults to port 8080 - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-1 * available local phone numbers in the United States in the 510 area code. @@ -91,23 +91,23 @@ public void testSearchUSLocalPhoneNumbersWith501AreaCode() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("AreaCode","501").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("AreaCode","501").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 33); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResult501AreaCode)); @@ -128,28 +128,28 @@ public void testSearchUSLocalPhoneNumbersWithPattern() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","501555****").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","501555****").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 2); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResult501ContainsPattern)); } - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-3 * Find local phone numbers that match the pattern 'STORM'. @@ -165,23 +165,23 @@ public void testSearchUSLocalPhoneNumbersWithLetterPattern() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","STORM").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","STORM").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 1); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResult501ContainsLetterPattern)); @@ -201,28 +201,28 @@ public void testSearchUSLocalPhoneNumbersWithInRegionFilter() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("AreaCode","501").queryParam("InRegion","AR").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("AreaCode","501").queryParam("InRegion","AR").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 1); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResult501InRegionPattern)); } - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-5 * Find a phone number in the London prefix (+4420) which is Fax-enabled. @@ -237,28 +237,28 @@ public void testSearchUKFaxEnabledFilter() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "GB/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","4420").queryParam("FaxEnabled","true").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","4420").queryParam("FaxEnabled","true").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 1); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResultUKPattern)); } - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-5 * Find a phone number in the London prefix (+4420) which is Fax-enabled. @@ -273,28 +273,28 @@ public void testSearchAdvancedFilter() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("NearLatLong","37.840699%2C-122.461853").queryParam("Distance","50").queryParam("Contains","501").queryParam("InRegion","CA").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("NearLatLong","37.840699%2C-122.461853").queryParam("Distance","50").queryParam("Contains","501").queryParam("InRegion","CA").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 2); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResultAdvancedPattern)); } - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#toll-free-get-example-3 * Find toll-free phone numbers in the 800 area code that contain the pattern 'STORM'. @@ -310,28 +310,28 @@ public void testSearchUSTollFreePhoneNumbersWithLetterPattern() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/TollFree.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","STORM").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","STORM").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 1); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResult501ContainsLetterPattern)); } - + /* * https://www.twilio.com/docs/api/rest/available-phone-numbers#mobile-get-example-1 * Find a phone number in the London prefix (+4420) which is Fax-enabled. @@ -347,28 +347,28 @@ public void testSearchMobileUKFaxEnabledFilter() { .withHeader("Content-Type", "text/xml") .withBody(AvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "GB/Mobile.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","4420").queryParam("FaxEnabled","true").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","4420").queryParam("FaxEnabled","true").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); - + System.out.println(jsonResponse); - + assertTrue(jsonResponse.size() == 1); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue(jsonResponse.get(0).getAsJsonObject().toString().equalsIgnoreCase(AvailablePhoneNumbersEndpointTestUtils.firstJSonResultUKPattern)); } - + @Deployment(name = "AvailablePhoneNumbersEndpointTest", managed = true, testable = false) public static WebArchive createWebArchiveNoGw() { logger.info("Packaging Test App"); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/IncomingPhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/IncomingPhoneNumbersEndpointTest.java index 6834fa3dc5..76499e69fa 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/IncomingPhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/IncomingPhoneNumbersEndpointTest.java @@ -51,11 +51,12 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import org.junit.experimental.categories.Category; import org.restcomm.connect.commons.Version; import org.restcomm.connect.commons.dao.Sid; @@ -125,16 +126,16 @@ public void testDeletePhoneNumberNotFound() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); String phoneNumberSid = Sid.generate(Sid.Type.PHONE_NUMBER).toString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + Response clientResponse = webResource.request("application/json").delete(); logger.info("clientResponse: "+clientResponse.getStatus()); assertTrue(clientResponse.getStatus() == 404); } @@ -170,22 +171,22 @@ public void testUpdatePhoneNumberNotFound() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); String phoneNumberSid = Sid.generate(Sid.Type.PHONE_NUMBER).toString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - formData = new MultivaluedMapImpl(); + webResource = jerseyClient.target(provisioningURL); + formData = new MultivaluedHashMap(); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice2.xml"); formData.add("SmsUrl", "http://demo.telestax.com/docs/sms2.xml"); formData.add("VoiceMethod", "POST"); formData.add("SMSMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); logger.info("clientResponse.getStatus(): "+clientResponse.getStatus()); assertTrue(clientResponse.getStatus() == 404); } @@ -257,15 +258,15 @@ public void getIncomingPhoneNumbersListUsingPageSize() { @Test public void testGetAvailableCountries() { // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/AvailableCountries.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.accept("application/json").get(ClientResponse.class); + Response clientResponse = webResource.request("application/json").get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -302,20 +303,20 @@ public void testPurchasePhoneNumberSuccess() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -350,22 +351,22 @@ public void testPurchasePhoneNumberNoPhoneNumberFound() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); if(logger.isDebugEnabled()) logger.debug("clientResponse for buying unavailable number: " + clientResponse); assertEquals(400, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -396,20 +397,20 @@ public void testPurchaseLocalPhoneNumberSuccess() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14166902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -444,22 +445,22 @@ public void testPurchaseLocalPhoneNumberNoPhoneNumberFound() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); if(logger.isDebugEnabled()) logger.debug("clientResponse for buying unavailable number: " + clientResponse); assertEquals(400, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -490,20 +491,20 @@ public void testPurchaseTollFreePhoneNumberSuccess() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/TollFree.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14176902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -538,22 +539,22 @@ public void testPurchaseTollFreePhoneNumberNoPhoneNumberFound() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/TollFree.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); if(logger.isDebugEnabled()) logger.debug("clientResponse for buying unavailable number: " + clientResponse); assertEquals(400, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -584,20 +585,20 @@ public void testPurchaseMobilePhoneNumberSuccess() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Mobile.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14186902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -632,22 +633,22 @@ public void testPurchaseMobilePhoneNumberNoPhoneNumberFound() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Mobile.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); if(logger.isDebugEnabled()) logger.debug("clientResponse for buying unavailable number: " + clientResponse); assertEquals(400, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -687,20 +688,20 @@ public void testDeletePhoneNumberSuccess() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14196902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -710,8 +711,8 @@ public void testDeletePhoneNumberSuccess() { String phoneNumberSid = jsonResponse.get("sid").getAsString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(Response.class); assertTrue(clientResponse.getStatus() == 204); } @@ -745,20 +746,20 @@ public void testUpdatePhoneNumberSuccess() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14206902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -768,16 +769,16 @@ public void testUpdatePhoneNumberSuccess() { String phoneNumberSid = jsonResponse.get("sid").getAsString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - formData = new MultivaluedMapImpl(); + webResource = jerseyClient.target(provisioningURL); + formData = new MultivaluedHashMap(); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice2.xml"); formData.add("SmsUrl", "http://demo.telestax.com/docs/sms2.xml"); formData.add("VoiceMethod", "POST"); formData.add("SMSMethod", "GET"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); logger.info(clientResponse); assertTrue(clientResponse.getStatus() == 200); - response = clientResponse.getEntity(String.class); + response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); parser = new JsonParser(); @@ -789,15 +790,15 @@ public void testUpdatePhoneNumberSuccess() { @Test @Category(FeatureAltTests.class) public void testMigratePhoneNumberSuccess() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + migrateURL + "IncomingPhoneNumbers/migrate"; - WebResource webResource = jerseyClient.resource(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); - formData = new MultivaluedMapImpl(); + WebTarget webResource = jerseyClient.target(provisioningURL); + MultivaluedMap formData = new MultivaluedHashMap(); + formData = new MultivaluedHashMap(); formData.add("OrganizationSid", "ORafbe225ad37541eba518a74248f0ac4c"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); logger.info(clientResponse); assertEquals(200, clientResponse.getStatus()); } @@ -805,15 +806,15 @@ public void testMigratePhoneNumberSuccess() { @Test @Category(FeatureExpTests.class) public void testMigratePhoneNumberPermission() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminOrg2AccountSid, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminOrg2AccountSid, adminAuthToken)); String provisioningURL = deploymentUrl + migrateURL + "IncomingPhoneNumbers/migrate"; - WebResource webResource = jerseyClient.resource(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); - formData = new MultivaluedMapImpl(); + WebTarget webResource = jerseyClient.target(provisioningURL); + MultivaluedMap formData = new MultivaluedHashMap(); + formData = new MultivaluedHashMap(); formData.add("OrganizationSid", "ORafbe225ad37541eba518a74248f0ac4c"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); logger.info(clientResponse); assertEquals(403, clientResponse.getStatus()); } @@ -824,15 +825,15 @@ public void testMigratePhoneNumberPermission() { @Test @Category(FeatureExpTests.class) public void testMigratePhoneNumberSuperAdminMigration() { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminAccountSid, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminAccountSid, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/migrate"; - WebResource webResource = jerseyClient.resource(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); - formData = new MultivaluedMapImpl(); + WebTarget webResource = jerseyClient.target(provisioningURL); + MultivaluedMap formData = new MultivaluedHashMap(); + formData = new MultivaluedHashMap(); formData.add("OrganizationSid", "ORafbe225ad37541eba518a74248f0ac4c"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); logger.info(clientResponse); assertEquals(400, clientResponse.getStatus()); } @@ -889,20 +890,20 @@ public void testAccountAssociatedPhoneNumbers() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14216902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -911,21 +912,21 @@ public void testAccountAssociatedPhoneNumbers() { assertTrue(IncomingPhoneNumbersEndpointTestUtils.match(jsonResponse.toString(),IncomingPhoneNumbersEndpointTestUtils.jSonResultAccountAssociatedPurchaseNumber)); String phoneNumberSid = jsonResponse.get("sid").getAsString(); - formData = new MultivaluedMapImpl(); + formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+15216902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My 2nd Company Line"); formData.add("VoiceMethod", "GET"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - response = clientResponse.getEntity(String.class); + response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); parser = new JsonParser(); jsonResponse = parser.parse(response).getAsJsonObject(); String secondPhoneNumberSid = jsonResponse.get("sid").getAsString(); -// formData = new MultivaluedMapImpl(); +// formData = new MultivaluedHashMap(); // formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice2.xml"); Map filters = new HashMap<>(); @@ -942,13 +943,13 @@ public void testAccountAssociatedPhoneNumbers() { assertTrue(IncomingPhoneNumbersEndpointTestUtils.match(jsonArray.get(jsonArray.size()-1).getAsJsonObject().toString(),IncomingPhoneNumbersEndpointTestUtils.jSonResultAccountAssociatedPurchaseNumberResult)); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(Response.class); assertTrue(clientResponse.getStatus() == 204); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + secondPhoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(Response.class); assertTrue(clientResponse.getStatus() == 204); } @@ -1005,20 +1006,20 @@ public void testAccountAssociatedPhoneNumbersFilter() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14216902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -1027,14 +1028,14 @@ public void testAccountAssociatedPhoneNumbersFilter() { assertTrue(IncomingPhoneNumbersEndpointTestUtils.match(jsonResponse.toString(),IncomingPhoneNumbersEndpointTestUtils.jSonResultAccountAssociatedPurchaseNumber)); String phoneNumberSid = jsonResponse.get("sid").getAsString(); - formData = new MultivaluedMapImpl(); + formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+15216902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My 2nd Company Line"); formData.add("VoiceMethod", "GET"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - response = clientResponse.getEntity(String.class); + response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); parser = new JsonParser(); @@ -1054,13 +1055,13 @@ public void testAccountAssociatedPhoneNumbersFilter() { assertTrue(IncomingPhoneNumbersEndpointTestUtils.match(jsonArray.get(0).getAsJsonObject().toString(),IncomingPhoneNumbersEndpointTestUtils.jSonResultAccountAssociatedPurchaseNumberResult)); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(Response.class); assertTrue(clientResponse.getStatus() == 204); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + secondPhoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(Response.class); assertTrue(clientResponse.getStatus() == 204); } @@ -1118,20 +1119,20 @@ public void testAccountAssociatedPhoneNumbersSecondFilter() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14216902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertEquals(200, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -1140,14 +1141,14 @@ public void testAccountAssociatedPhoneNumbersSecondFilter() { assertTrue(IncomingPhoneNumbersEndpointTestUtils.match(jsonResponse.toString(),IncomingPhoneNumbersEndpointTestUtils.jSonResultAccountAssociatedPurchaseNumber)); String phoneNumberSid = jsonResponse.get("sid").getAsString(); - formData = new MultivaluedMapImpl(); + formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+15216902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My 2nd Company Line"); formData.add("VoiceMethod", "GET"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - response = clientResponse.getEntity(String.class); + response = clientResponse.readEntity(String.class); logger.info(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); parser = new JsonParser(); @@ -1158,7 +1159,7 @@ public void testAccountAssociatedPhoneNumbersSecondFilter() { JsonObject jsonObject = RestcommIncomingPhoneNumberTool.getInstance().getIncomingPhoneNumbersUsingFilter(deploymentUrl.toString(), adminAccountSid, adminAuthToken, filters); JsonArray jsonArray = jsonObject.get("incomingPhoneNumbers").getAsJsonArray(); - webResource = jerseyClient.resource(provisioningURL); + webResource = jerseyClient.target(provisioningURL); logger.info(jsonArray + " \n " + jsonArray.size()); @@ -1167,13 +1168,13 @@ public void testAccountAssociatedPhoneNumbersSecondFilter() { assertTrue(IncomingPhoneNumbersEndpointTestUtils.match(jsonArray.get(jsonArray.size() - 1).getAsJsonObject().toString(),IncomingPhoneNumbersEndpointTestUtils.jSonResultAccountAssociatedPurchaseNumberResult)); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(Response.class); assertTrue(clientResponse.getStatus() == 204); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + secondPhoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(Response.class); assertTrue(clientResponse.getStatus() == 204); } @@ -1199,21 +1200,21 @@ public void testCreatePureSipPhoneNumbersForOrganizations() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "11223344"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); formData.add("isSIP", "TRUE"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -1244,17 +1245,17 @@ public void testCreatePureSipPhoneNumbersForOrganizations() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Local.json"; - webResource = jerseyClient.resource(provisioningURL); - formData = new MultivaluedMapImpl(); + webResource = jerseyClient.target(provisioningURL); + formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "11223344"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); formData.add("isSIP", "TRUE"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); logger.info("testCreatePureSipPhoneNumber from default org TWICE clientResponse: " + clientResponse.toString()); assertTrue(clientResponse.getStatus() != 200); @@ -1278,21 +1279,21 @@ public void testCreatePureSipPhoneNumbersForOrganizations() { .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); - jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminOrg2Username, adminOrg2AuthToken)); + jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminOrg2Username, adminOrg2AuthToken)); provisioningURL = deploymentUrl + baseURLOrg2 + "IncomingPhoneNumbers/Local.json"; - webResource = jerseyClient.resource(provisioningURL); + webResource = jerseyClient.target(provisioningURL); - formData = new MultivaluedMapImpl(); + formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "11223344"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); formData.add("isSIP", "TRUE"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - response = clientResponse.getEntity(String.class); + response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); parser = new JsonParser(); @@ -1327,20 +1328,20 @@ public void testCreateNonPureSipPhoneNumbersForOrganizations() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14166902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -1370,16 +1371,16 @@ public void testCreateNonPureSipPhoneNumbersForOrganizations() { .withHeader("Content-Type", "text/xml") .withBody(IncomingPhoneNumbersEndpointTestUtils.purchaseNumberSuccessResponse))); // Get Account using admin email address and user email address - jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/Local.json"; - webResource = jerseyClient.resource(provisioningURL); - formData = new MultivaluedMapImpl(); + webResource = jerseyClient.target(provisioningURL); + formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+4156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); logger.info("testCreatePureSipPhoneNumber from default org TWICE clientResponse: " + clientResponse.toString()); assertEquals(400, clientResponse.getStatus()); @@ -1388,17 +1389,17 @@ public void testCreateNonPureSipPhoneNumbersForOrganizations() { * under different organization/account, * it should not be allowed * */ - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminOrg2Username, adminOrg2AuthToken)); + jerseyClient.register(HttpAuthenticationFeature.basic(adminOrg2Username, adminOrg2AuthToken)); provisioningURL = deploymentUrl + baseURLOrg2 + "IncomingPhoneNumbers/Local.json"; - webResource = jerseyClient.resource(provisioningURL); + webResource = jerseyClient.target(provisioningURL); - formData = new MultivaluedMapImpl(); + formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+4156902867"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertEquals(400, clientResponse.getStatus()); } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/RestcommIncomingPhoneNumberTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/RestcommIncomingPhoneNumberTool.java index c16c151ea1..e69a402c46 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/RestcommIncomingPhoneNumberTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/vi/RestcommIncomingPhoneNumberTool.java @@ -30,17 +30,17 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import com.thoughtworks.xstream.XStream; /** * @author muhammad.bilal19@gmail.com (Muhammad Bilal) */ public class RestcommIncomingPhoneNumberTool { - + private static RestcommIncomingPhoneNumberTool instance; private static String accountsUrl; private static Logger logger = Logger.getLogger(RestcommIncomingPhoneNumberTool.class); @@ -53,7 +53,7 @@ public static RestcommIncomingPhoneNumberTool getInstance() { return instance; } - + private String getAccountsUrl(String deploymentUrl, String username, Boolean json) { if (deploymentUrl.endsWith("/")) { deploymentUrl = deploymentUrl.substring(0, deploymentUrl.length() - 1); @@ -63,35 +63,39 @@ private String getAccountsUrl(String deploymentUrl, String username, Boolean jso return accountsUrl; } - + public JsonObject getIncomingPhoneNumbers(String deploymentUrl, String username, String authToken) { return (JsonObject) getIncomingPhoneNumbers(deploymentUrl, username, authToken, null, null, true); } - + public JsonObject getIncomingPhoneNumbers(String deploymentUrl, String username, String authToken, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, json); - WebResource webResource = jerseyClient.resource(url); + WebTarget webResource = jerseyClient.target(url); String response = null; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webResource.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); + webResource.queryParam("PageSize", String.valueOf(pageSize)); + } - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webResource.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webResource.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -118,8 +122,8 @@ public JsonObject getIncomingPhoneNumbers(String deploymentUrl, String username, } } - - + + /** * @param deploymentUrl * @param username @@ -130,20 +134,21 @@ public JsonObject getIncomingPhoneNumbers(String deploymentUrl, String username, public JsonObject getIncomingPhoneNumbersUsingFilter(String deploymentUrl, String username, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webResource = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webResource.queryParam(filterName, filterData); } - String response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webResource.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = null; try { @@ -160,6 +165,6 @@ public JsonObject getIncomingPhoneNumbersUsingFilter(String deploymentUrl, Strin return jsonObject; } - + } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneAvailablePhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneAvailablePhoneNumbersEndpointTest.java index af329a642e..f622609905 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneAvailablePhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneAvailablePhoneNumbersEndpointTest.java @@ -45,10 +45,10 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.gson.JsonArray; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.restcomm.connect.commons.Version; /** @@ -92,18 +92,18 @@ public void testSearchUSLocalPhoneNumbersWith501AreaCode() { .withHeader("Content-Type", "application/json") .withBody(VoxboneAvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource. + Response clientResponse = webResource. queryParam("AreaCode","501"). - accept("application/json") - .get(ClientResponse.class); + request("application/json") + .get(); Assert.assertEquals(200, clientResponse.getStatus()); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -131,16 +131,16 @@ public void testSearchESPhoneNumbers700Pattern() { .withStatus(200) .withHeader("Content-Type", "application/json") .withBody(VoxboneAvailablePhoneNumbersEndpointTestUtils.jsonResponseES700))); - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "ES/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("Contains","700").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("Contains","700").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -169,16 +169,16 @@ public void testSearchUSPhoneNumbersRangeIndexAndSize() { .withHeader("Content-Type", "application/json") .withBody(VoxboneAvailablePhoneNumbersEndpointTestUtils.jsonResponseUSRange))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.queryParam("RangeSize","5").queryParam("RangeIndex","2").accept("application/json") - .get(ClientResponse.class); + Response clientResponse = webResource.queryParam("RangeSize","5").queryParam("RangeIndex","2").request("application/json") + .get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneIncomingPhoneNumbersEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneIncomingPhoneNumbersEndpointTest.java index d90a654f41..cb5fef5f26 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneIncomingPhoneNumbersEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/provisioning/number/voxbone/VoxboneIncomingPhoneNumbersEndpointTest.java @@ -49,16 +49,16 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import org.junit.experimental.categories.Category; import org.restcomm.connect.commons.Version; import org.restcomm.connect.commons.annotations.BrokenTests; import org.restcomm.connect.commons.annotations.FeatureExpTests; -import org.restcomm.connect.commons.annotations.UnstableTests; /** * @author Jean Deruelle @@ -101,15 +101,15 @@ public void testGetAvailableCountries() { .withHeader("Content-Type", "application/json") .withBody(VoxboneIncomingPhoneNumbersEndpointTestUtils.listCountries))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/AvailableCountries.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - ClientResponse clientResponse = webResource.accept("application/json").get(ClientResponse.class); + Response clientResponse = webResource.request("application/json").get(); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -164,20 +164,20 @@ public void testPurchaseAndDeletePhoneNumberSuccess() { .withBody(VoxboneIncomingPhoneNumbersEndpointTestUtils.cancelDidSuccessResponse))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "22073"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "USA-ACKLEY-641"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 200); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -188,8 +188,8 @@ public void testPurchaseAndDeletePhoneNumberSuccess() { String phoneNumberSid = jsonResponse.get("sid").getAsString(); provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; - webResource = jerseyClient.resource(provisioningURL); - clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); + webResource = jerseyClient.target(provisioningURL); + clientResponse = webResource.request("application/json").delete(); assertTrue(clientResponse.getStatus() == 204); } @@ -215,20 +215,20 @@ public void testPurchaseAndDeletePhoneNumberSuccess() { // .withHeader("Content-Type", "application/json") // .withBody(VoxboneIncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // // Get Account using admin email address and user email address -// Client jerseyClient = Client.create(); -// jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); +// Client jerseyClient = ClientBuilder.newClient(); +// jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); // // String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; -// WebResource webResource = jerseyClient.resource(provisioningURL); +// WebTarget webResource = jerseyClient.target(provisioningURL); // -// MultivaluedMap formData = new MultivaluedMapImpl(); +// MultivaluedMap formData = new MultivaluedHashMap(); // formData.add("PhoneNumber", "+34911067000"); // formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); // formData.add("FriendlyName", "My Company Line"); // formData.add("VoiceMethod", "GET"); -// ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); +// Response clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).request("application/json").post(Response.class, formData); // assertTrue(clientResponse.getStatus() == 200); -// String response = clientResponse.getEntity(String.class); +// String response = clientResponse.readEntity(String.class); // System.out.println(response); // assertTrue(!response.trim().equalsIgnoreCase("[]")); // JsonParser parser = new JsonParser(); @@ -239,8 +239,8 @@ public void testPurchaseAndDeletePhoneNumberSuccess() { // // String phoneNumberSid = jsonResponse.get("sid").getAsString(); // provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; -// webResource = jerseyClient.resource(provisioningURL); -// clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); +// webResource = jerseyClient.target(provisioningURL); +// clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).request("application/json").delete(Response.class); // assertTrue(clientResponse.getStatus() == 204); // } @@ -268,20 +268,20 @@ public void testPurchasePhoneNumberNoPhoneNumberFound() { .withHeader("Content-Type", "application/json"))); // Get Account using admin email address and user email address - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; - WebResource webResource = jerseyClient.resource(provisioningURL); + WebTarget webResource = jerseyClient.target(provisioningURL); - MultivaluedMap formData = new MultivaluedMapImpl(); + MultivaluedMap formData = new MultivaluedHashMap(); formData.add("PhoneNumber", "+14156902860"); formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); formData.add("FriendlyName", "My Company Line"); formData.add("VoiceMethod", "GET"); - ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); + Response clientResponse = webResource.request("application/json").post(Entity.form(formData)); assertTrue(clientResponse.getStatus() == 400); - String response = clientResponse.getEntity(String.class); + String response = clientResponse.readEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); @@ -313,20 +313,20 @@ public void testPurchasePhoneNumberNoPhoneNumberFound() { // .withHeader("Content-Type", "application/json") // .withBody(VoxboneIncomingPhoneNumbersEndpointTestUtils.deleteNumberSuccessResponse))); // // Get Account using admin email address and user email address -// Client jerseyClient = Client.create(); -// jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); +// Client jerseyClient = ClientBuilder.newClient(); +// jerseyClient.register(HttpAuthenticationFeature.basic(adminUsername, adminAuthToken)); // // String provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers.json"; -// WebResource webResource = jerseyClient.resource(provisioningURL); +// WebTarget webResource = jerseyClient.target(provisioningURL); // -// MultivaluedMap formData = new MultivaluedMapImpl(); +// MultivaluedMap formData = new MultivaluedHashMap(); // formData.add("PhoneNumber", "+33911067000"); // formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice.xml"); // formData.add("FriendlyName", "My Company Line"); // formData.add("VoiceMethod", "GET"); -// ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); +// Response clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).request("application/json").post(Response.class, formData); // assertTrue(clientResponse.getStatus() == 200); -// String response = clientResponse.getEntity(String.class); +// String response = clientResponse.readEntity(String.class); // System.out.println(response); // assertTrue(!response.trim().equalsIgnoreCase("[]")); // JsonParser parser = new JsonParser(); @@ -337,15 +337,15 @@ public void testPurchasePhoneNumberNoPhoneNumberFound() { // // String phoneNumberSid = jsonResponse.get("sid").getAsString(); // provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; -// webResource = jerseyClient.resource(provisioningURL); -// formData = new MultivaluedMapImpl(); +// webResource = jerseyClient.target(provisioningURL); +// formData = new MultivaluedHashMap(); // formData.add("VoiceUrl", "http://demo.telestax.com/docs/voice2.xml"); // formData.add("SmsUrl", "http://demo.telestax.com/docs/sms2.xml"); // formData.add("VoiceMethod", "POST"); // formData.add("SMSMethod", "GET"); -// clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").post(ClientResponse.class, formData); +// clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).request("application/json").post(Response.class, formData); // assertTrue(clientResponse.getStatus() == 200); -// response = clientResponse.getEntity(String.class); +// response = clientResponse.readEntity(String.class); // System.out.println(response); // assertTrue(!response.trim().equalsIgnoreCase("[]")); // parser = new JsonParser(); @@ -354,8 +354,8 @@ public void testPurchasePhoneNumberNoPhoneNumberFound() { // assertTrue(VoxboneIncomingPhoneNumbersEndpointTestUtils.match(jsonResponse.toString(),VoxboneIncomingPhoneNumbersEndpointTestUtils.jSonResultUpdateSuccessPurchaseNumber)); // // provisioningURL = deploymentUrl + baseURL + "IncomingPhoneNumbers/" + phoneNumberSid + ".json"; -// webResource = jerseyClient.resource(provisioningURL); -// clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept("application/json").delete(ClientResponse.class); +// webResource = jerseyClient.target(provisioningURL); +// clientResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).request("application/json").delete(Response.class); // assertTrue(clientResponse.getStatus() == 204); // } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsEndpointTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsEndpointTool.java index 5522cabd5b..c00af4a0b2 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsEndpointTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsEndpointTool.java @@ -28,11 +28,12 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.sun.jersey.core.util.MultivaluedMapImpl; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import javax.ws.rs.core.MultivaluedHashMap; import java.util.Map; +import javax.ws.rs.client.Entity; /** * @author gvagenas @@ -64,14 +65,14 @@ private String getAccountsUrl(String deploymentUrl, String username, Boolean jso public JsonObject createSms (String deploymentUrl, String username, String authToken, String from, String to, String body, HashMap additionalHeaders) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webResource = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("From", from); params.add("To", to); params.add("Body", body); @@ -85,7 +86,7 @@ public JsonObject createSms (String deploymentUrl, String username, String authT } // webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + String response = webResource.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); @@ -94,14 +95,14 @@ public JsonObject createSms (String deploymentUrl, String username, String authT public JsonObject createSms (String deploymentUrl, String username, String authToken, String from, String to, String body, HashMap additionalHeaders, String encoding) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webResource = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); params.add("From", from); params.add("To", to); params.add("Encoding", encoding); @@ -116,7 +117,7 @@ public JsonObject createSms (String deploymentUrl, String username, String authT } // webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).post(String.class, params); + String response = webResource.request(MediaType.APPLICATION_JSON).post(Entity.form(params),String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); @@ -124,11 +125,11 @@ public JsonObject createSms (String deploymentUrl, String username, String authT } public JsonArray getSmsList(String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget webResource = jerseyClient.target(url); + String response = webResource.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonArray jsonArray = null; JsonObject jsonObject = parser.parse(response).getAsJsonObject(); @@ -137,11 +138,11 @@ public JsonArray getSmsList(String deploymentUrl, String username, String authTo } public JsonObject getSmsMessageList (String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + WebTarget webResource = jerseyClient.target(url); + String response = webResource.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); return jsonObject; @@ -149,24 +150,28 @@ public JsonObject getSmsMessageList (String deploymentUrl, String username, Stri public JsonObject getSmsMessageList (String deploymentUrl, String username, String authToken, Integer page, Integer pageSize, Boolean json) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webResource = jerseyClient.target(url); String response; if (page != null || pageSize != null) { - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); - if (page != null) + if (page != null) { params.add("Page", String.valueOf(page)); - if (pageSize != null) + webResource.queryParam("Page", String.valueOf(page)); + } + if (pageSize != null) { params.add("PageSize", String.valueOf(pageSize)); + webResource.queryParam("PageSize", String.valueOf(pageSize)); + } - response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) + response = webResource.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML) .get(String.class); } else { - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webResource.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); } JsonParser parser = new JsonParser(); @@ -176,20 +181,20 @@ public JsonObject getSmsMessageList (String deploymentUrl, String username, Stri public JsonObject getSmsMessageListUsingFilter(String deploymentUrl, String username, String authToken, Map filters) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username, true); - WebResource webResource = jerseyClient.resource(url); + WebTarget webResource = jerseyClient.target(url); - MultivaluedMap params = new MultivaluedMapImpl(); + MultivaluedMap params = new MultivaluedHashMap(); for (String filterName : filters.keySet()) { String filterData = filters.get(filterName); params.add(filterName, filterData); + webResource.queryParam(filterName, filterData); } - webResource = webResource.queryParams(params); - String response = webResource.accept(MediaType.APPLICATION_JSON).get(String.class); + String response = webResource.request(MediaType.APPLICATION_JSON).get(String.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(response).getAsJsonObject(); diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java index 8906963d13..994ba3b4b2 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java @@ -4,9 +4,9 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.apache.log4j.Logger; import javax.ws.rs.core.MediaType; @@ -42,13 +42,13 @@ public String getAccountsUrl(String deploymentUrl, String username) { } public JsonObject getLiveCalls(String deploymentUrl, String username, String authToken) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username); - WebResource webResource = jerseyClient.resource(url).path("/livecalls"); + WebTarget webResource = jerseyClient.target(url).path("/livecalls"); String response = null; - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webResource.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); JsonParser parser = new JsonParser(); return parser.parse(response).getAsJsonObject(); } @@ -71,10 +71,10 @@ public JsonObject getMetrics(String deploymentUrl, String username, String authT } public JsonObject getMetrics(String deploymentUrl, String username, String authToken, boolean callDetails, boolean mgcpStats) { - Client jerseyClient = Client.create(); - jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); + Client jerseyClient = ClientBuilder.newClient(); + jerseyClient.register(HttpAuthenticationFeature.basic(username, authToken)); String url = getAccountsUrl(deploymentUrl, username); - WebResource webResource = jerseyClient.resource(url).path("/metrics"); + WebTarget webResource = jerseyClient.target(url).path("/metrics"); if (callDetails) { webResource = webResource.queryParam("LiveCallDetails","true"); @@ -84,7 +84,7 @@ public JsonObject getMetrics(String deploymentUrl, String username, String authT } String response = null; - response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); + response = webResource.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); JsonParser parser = new JsonParser(); return parser.parse(response).getAsJsonObject(); }