Search in sources :

Example 1 with Resource

use of org.apache.wink.client.Resource in project ppm-octane-connector by MicroFocus.

the class UsernamePasswordClient method oneResource.

private Resource oneResource(String url, String[] fields, FieldQuery... queries) {
    // Only allowing secure protocols to connect
    System.setProperty("https.protocols", "TLSv1.2,SSLv3");
    Resource rsc = new RestClient(this.config).resource(baseURL + url);
    if (fields != null && fields.length > 0) {
        rsc.queryParam(getURLParamNameForVisibleFields(), StringUtils.join(fields, ','));
    }
    if (queries.length > 0) {
        StringBuffer sb = new StringBuffer();
        sb.append("%7B");
        boolean isFirst = true;
        for (FieldQuery q : queries) {
            if (isFirst) {
                isFirst = false;
            } else {
                sb.append(';');
            }
            sb.append(q.toQueryString());
        }
        sb.append("%7D");
        rsc.queryParam(getURLParamNameForFieldQuery(), sb.toString());
    }
    return rsc;
}
Also used : Resource(org.apache.wink.client.Resource) RestClient(org.apache.wink.client.RestClient)

Example 2 with Resource

use of org.apache.wink.client.Resource in project ppm-octane-connector by MicroFocus.

the class UsernamePasswordClient method auth.

public UsernamePasswordClient auth(String username, String password, boolean enable_csrf) {
    JSONObject json = enable_csrf ? CredentialJson.toJSONObject(username, password, enable_csrf) : CredentialJson.toJSONObject(username, password);
    ClientResponse resp;
    Resource rsc = this.oneResource(AUTHORIZATION_SIGN_IN_URL);
    resp = rsc.post(json.toString());
    if (resp.getStatusCode() != 200) {
        throw new OctaneClientException("AGM_API", "ERROR_AUTHENTICATION_FAILED");
    }
    this.cookie = resp.getHeaders().get("Set-Cookie");
    return this;
}
Also used : ClientResponse(org.apache.wink.client.ClientResponse) JSONObject(net.sf.json.JSONObject) Resource(org.apache.wink.client.Resource)

Example 3 with Resource

use of org.apache.wink.client.Resource in project product-is by wso2.

the class ConsentMgtTestCase method addReceipt.

private JSONObject addReceipt(String piiPrincipalId, String service, String serviceDisplayName, String serviceDescription, String consentType, String collectionMethod, String jurisdiction, String language, String policyURL) {
    RestClient restClient = new RestClient();
    Resource piiCatResource = restClient.resource(consentEndpoint);
    String addReceiptString = "{" + "  \"services\": [" + "    {" + "      \"service\": \"" + service + "\"," + "      \"serviceDisplayName\": \"" + serviceDisplayName + "\"," + "      \"serviceDescription\": \"" + serviceDescription + "\"," + "      \"purposes\": [" + "        {" + "          \"purposeId\": 1," + "          \"purposeCategoryId\": [" + "            1" + "          ]," + "          \"consentType\": \"" + consentType + "\"," + "          \"piiCategory\": [" + "            {" + "              \"piiCategoryId\": 1," + "              \"validity\": \"3\"" + "            }" + "          ]," + "          \"primaryPurpose\": true," + "          \"termination\": \"string\"," + "          \"thirdPartyDisclosure\": true," + "          \"thirdPartyName\": \"string\"" + "        }" + "      ]" + "    }" + "  ]," + "  \"collectionMethod\": \"" + collectionMethod + "\"," + "  \"jurisdiction\": \"" + jurisdiction + "\"," + "  \"language\": \"" + language + "\"," + "  \"policyURL\": \"" + policyURL + "\"" + "}";
    String response = piiCatResource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(userInfo)).post(String.class, addReceiptString);
    return (JSONObject) JSONValue.parse(response);
}
Also used : JSONObject(org.json.simple.JSONObject) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource)

Example 4 with Resource

use of org.apache.wink.client.Resource in project product-is by wso2.

the class ConsentMgtTestCase method addPurpose.

private JSONObject addPurpose(String name, String description, String group, String groupType) {
    RestClient restClient = new RestClient();
    Resource piiCatResource = restClient.resource(consentEndpoint + "/" + "purposes");
    String addPurposeString = "{" + "  \"purpose\": \"" + name + "\"," + "  \"description\": \"" + description + "\"," + "  \"group\": \"" + group + "\"," + "  \"groupType\": \"" + groupType + "\"," + "  \"piiCategories\": [" + "    {" + "      \"piiCategoryId\": 1," + "      \"mandatory\": true" + "    }" + "  ]" + "}";
    String response = piiCatResource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(userInfo)).post(String.class, addPurposeString);
    return (JSONObject) JSONValue.parse(response);
}
Also used : JSONObject(org.json.simple.JSONObject) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource)

Example 5 with Resource

use of org.apache.wink.client.Resource in project product-is by wso2.

the class ProvisioningTestCase method createUserForSecondServer.

@Test(alwaysRun = true, description = "Add SCIM provisioning user on second server", dependsOnMethods = "createUser")
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void createUserForSecondServer() throws Exception {
    buildSCIMProvisioningConnector(PORT_OFFSET_1);
    addSP(PORT_OFFSET_1);
    scimClient = new SCIMClient();
    String encodedUser = getScimUser(2);
    // create a apache wink ClientHandler to intercept and identify response messages
    Resource userResource = getResource(scimClient, scim_url_1);
    BasicAuthInfo encodedBasicAuthInfo = getBasicAuthInfo(automationContextMap.get(PORT_OFFSET_0));
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedUser);
    Assert.assertTrue(response.contains(userName2));
}
Also used : Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Aggregations

Resource (org.apache.wink.client.Resource)43 RestClient (org.apache.wink.client.RestClient)28 Test (org.testng.annotations.Test)19 BasicAuthInfo (org.wso2.identity.integration.test.utils.BasicAuthInfo)18 ClientConfig (org.apache.wink.client.ClientConfig)16 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)16 JSONObject (org.json.simple.JSONObject)15 SCIMResponseHandler (org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler)13 User (org.wso2.carbon.automation.engine.context.beans.User)7 ClientResponse (org.apache.wink.client.ClientResponse)5 SCIMClient (org.wso2.charon.core.client.SCIMClient)5 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)4 BasicAuthSecurityHandler (org.apache.wink.client.handlers.BasicAuthSecurityHandler)3 Group (org.wso2.charon.core.objects.Group)3 JSONObject (org.json.JSONObject)2 JSONArray (org.json.simple.JSONArray)2 RestRequestException (com.ppm.integration.agilesdk.connector.jira.rest.util.exception.RestRequestException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 RemoteException (java.rmi.RemoteException)1 JSONObject (net.sf.json.JSONObject)1