Java Code Examples for javax.ws.rs.core.Response.Status.Family#SUCCESSFUL

The following examples show how to use javax.ws.rs.core.Response.Status.Family#SUCCESSFUL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendFormData.java    From raml-java-client-generator with Apache License 2.0 6 votes vote down vote up
public TestsendformdataResponse<Void> post(SendFormDataPOSTBody body) {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE);
    MultivaluedMap multiValuedMap = new MultivaluedHashMap();
    if (body.getParam1()!= null) {
        multiValuedMap.add("param1", body.getParam1().toString());
    }
    if (body.getParam2()!= null) {
        multiValuedMap.add("param2", body.getParam2().toString());
    }
    Response response = invocationBuilder.post(Entity.entity(multiValuedMap, javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED_TYPE));
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new TestsendformdataException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    TestsendformdataResponse<Void> apiResponse = new TestsendformdataResponse<Void>(null, response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 2
Source File: ManagementWsDelegate.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an application from a template.
 * @param applicationName the application name
 * @param templateName the template's name
 * @param templateQualifier the template's qualifier
 * @return the created application
 * @throws ManagementWsException if a problem occurred with the applications management
 */
public Application createApplication( String applicationName, String templateName, String templateQualifier )
throws ManagementWsException {

	this.logger.finer( "Creating application " + applicationName + " from " + templateName + " - " + templateQualifier + "..." );
	ApplicationTemplate tpl = new ApplicationTemplate( templateName ).version( templateQualifier );
	Application app = new Application( applicationName, tpl );

	WebResource path = this.resource.path( UrlConstants.APPLICATIONS );
	ClientResponse response = this.wsClient.createBuilder( path )
			.type( MediaType.APPLICATION_JSON )
			.post( ClientResponse.class, app );

	if( Family.SUCCESSFUL != response.getStatusInfo().getFamily())
		throw new ManagementWsException( response.getStatusInfo().getStatusCode(), "" );

	Application result = response.getEntity( Application.class );
	return result;
}
 
Example 3
Source File: FileName.java    From raml-java-client-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Creates or updates the given file
 * 
 */
public SimpleApiResponse<Void> put(Object body, FileNamePUTHeader headers) {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    if (headers.getXBaseCommitId()!= null) {
        invocationBuilder.header("x-base-commit-id", headers.getXBaseCommitId());
    }
    if (headers.getXCommitMessage()!= null) {
        invocationBuilder.header("x-commit-message", headers.getXCommitMessage());
    }
    Response response = invocationBuilder.put(Entity.entity(body, "*/*"));
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new SimpleApiException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    SimpleApiResponse<Void> apiResponse = new SimpleApiResponse<Void>(null, response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 4
Source File: Exec.java    From raml-java-client-generator with Apache License 2.0 6 votes vote down vote up
public DataWeaveAPIResponse<Void> post(ExecPOSTBody body) {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    FormDataMultiPart multiPart = new FormDataMultiPart();
    if (body.getFile()!= null) {
        multiPart.bodyPart(new FileDataBodyPart("file", body.getFile()));
    }
    if (body.getFrom()!= null) {
        multiPart.field("From", body.getFrom().toString());
    }
    Response response = invocationBuilder.post(Entity.entity(multiPart, multiPart.getMediaType()));
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new DataWeaveAPIException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    DataWeaveAPIResponse<Void> apiResponse = new DataWeaveAPIResponse<Void>(null, response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 5
Source File: AzureInteractiveLoginStatusCheckerTask.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private String createResourceToken(String refreshToken, String tenantId, String resource) throws InteractiveLoginException {
    Form resourceTokenForm = createResourceTokenForm(refreshToken, resource);
    WebTarget webTarget = ClientBuilder.newClient().target(LOGIN_MICROSOFTONLINE);
    Builder request = webTarget.path(tenantId + "/oauth2/token").queryParam("api-version", "1.0").request();
    request.accept(MediaType.APPLICATION_JSON);
    try (Response response = request.post(Entity.entity(resourceTokenForm, MediaType.APPLICATION_FORM_URLENCODED_TYPE))) {
        if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
            throw new InteractiveLoginException("Obtain access token for " + resource + " failed "
                    + "with tenant ID: " + tenantId + ", status code " + response.getStatus()
                    + ", error message: " + response.readEntity(String.class));
        }
        String responseString = response.readEntity(String.class);
        try {
            return new ObjectMapper().readTree(responseString).get("access_token").asText();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}
 
Example 6
Source File: Id.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public FooResponse<Void> get() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.get();
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    FooResponse<Void> apiResponse = new FooResponse<Void>(null, response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 7
Source File: ApplicationWsDelegate.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
private void handleResponse( ClientResponse response ) throws ApplicationWsException {

		if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) {
			String value = response.getEntity( String.class );
			this.logger.finer( response.getStatusInfo() + ": " + value );
			throw new ApplicationWsException( response.getStatusInfo().getStatusCode(), value );
		}
	}
 
Example 8
Source File: SubscriptionChecker.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void checkSubscription(String subscriptionId, String accessToken) throws InteractiveLoginException {
    if (subscriptionId == null) {
        throw new InteractiveLoginException("Parameter subscriptionId is required and cannot be null.");
    }
    Client client = ClientBuilder.newClient();
    WebTarget resource = client.target(AZURE_MANAGEMENT);
    Builder request = resource.path("/subscriptions/" + subscriptionId)
            .queryParam("api-version", "2016-06-01")
            .request();
    request.accept(MediaType.APPLICATION_JSON);

    request.header("Authorization", "Bearer " + accessToken);
    try (Response response = request.get()) {
        if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
            AzureSubscription subscription = response.readEntity(AzureSubscription.class);
            if (!subscription.getState().equals(SubscriptionState.ENABLED)) {
                throw new InteractiveLoginException("Subscription is in incorrect state:" + "" + subscription.getState());
            }
            LOGGER.debug("Subscription definitions successfully retrieved:" + subscription.getDisplayName());
        } else {
            String errorResponse = response.readEntity(String.class);
            try {
                String errorMessage = new ObjectMapper().readTree(errorResponse).get("error").get("message").asText();
                LOGGER.info("Subscription retrieve error:" + errorMessage);
                throw new InteractiveLoginException("Error with the subscription id: " + subscriptionId + " message: " + errorMessage);
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}
 
Example 9
Source File: AuthenticationWsDelegate.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Logs in with a user name and a password.
 * @param username a user name
 * @param password a password
 * @return a session ID, or null if login failed
 * @throws DebugWsException
 */
public String login( String username, String password ) throws DebugWsException {

	this.logger.finer( "Logging in as " + username );
	WebResource path = this.resource.path( UrlConstants.AUTHENTICATION ).path( "e" );
	ClientResponse response = path
					.header( "u", username )
					.header( "p", password )
					.post( ClientResponse.class );

	if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) {
		String value = response.getEntity( String.class );
		this.logger.finer( response.getStatusInfo() + ": " + value );
		throw new DebugWsException( response.getStatusInfo().getStatusCode(), value );
	}

	// Get the session ID from the cookie that should have been returned
	String sessionId = null;
	List<NewCookie> cookies = response.getCookies();
	if( cookies != null ) {
		for( NewCookie cookie : cookies ) {
			if( UrlConstants.SESSION_ID.equals( cookie.getName())) {
				sessionId = cookie.getValue();
				break;
			}
		}
	}

	// Set the session ID
	this.wsClient.setSessionId( sessionId );
	this.logger.finer( "Session ID: " + sessionId );

	return sessionId;
}
 
Example 10
Source File: Login.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public FooResponse<String> post() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.post(null);
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    FooResponse<String> apiResponse = new FooResponse<String>(((String) response.readEntity(Object.class)), response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 11
Source File: Bar.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
/**
 * SomeDescriptionValue
 * 
 */
public recursive_type.model.Foo get() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.get();
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new LocationsException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    return response.readEntity(recursive_type.model.Foo.class);
}
 
Example 12
Source File: Bar.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public void post() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.post(null);
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
}
 
Example 13
Source File: ManagementWsDelegate.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Shutdowns an application.
 * @param applicationName the application name
 * @throws ManagementWsException if a problem occurred with the applications management
 */
public void shutdownApplication( String applicationName ) throws ManagementWsException {
	this.logger.finer( "Removing application " + applicationName + "..." );

	WebResource path = this.resource
				.path( UrlConstants.APPLICATIONS )
				.path( applicationName )
				.path( "shutdown" );

	ClientResponse response = this.wsClient.createBuilder( path ).post( ClientResponse.class );
	String text = response.getEntity( String.class );
	this.logger.finer( text );
	if( Family.SUCCESSFUL != response.getStatusInfo().getFamily())
		throw new ManagementWsException( response.getStatusInfo().getStatusCode(), text );
}
 
Example 14
Source File: Test.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public MyapiResponse<type_decl.model.MyType> get() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.get();
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new MyapiException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    MyapiResponse<type_decl.model.MyType> apiResponse = new MyapiResponse<type_decl.model.MyType>(response.readEntity(type_decl.model.MyType.class), response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 15
Source File: Rename.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Rename a project
 * 
 */
public DesignCenterProjectsServicewithsubresourceonsamelineResponse<Void> put(Object body) {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.put(Entity.json(body));
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new DesignCenterProjectsServicewithsubresourceonsamelineException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    DesignCenterProjectsServicewithsubresourceonsamelineResponse<Void> apiResponse = new DesignCenterProjectsServicewithsubresourceonsamelineResponse<Void>(null, response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 16
Source File: Login.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public FooResponse<String> post() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.post(null);
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    FooResponse<String> apiResponse = new FooResponse<String>(((String) response.readEntity(Object.class)), response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 17
Source File: Login.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public CoreServicesAPIReferenceResponse<Void> get() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.get();
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new CoreServicesAPIReferenceException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    CoreServicesAPIReferenceResponse<Void> apiResponse = new CoreServicesAPIReferenceResponse<Void>(null, response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 18
Source File: Login.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public List<AuthorizationJson> post() {
        WebTarget target = this._client.target(getBaseUri());
        final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
        Response response = invocationBuilder.post(null);
        if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
            Response.StatusType statusInfo = response.getStatusInfo();
            throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
        }
        return response.readEntity((
new javax.ws.rs.core.GenericType<java.util.List<include_schema.resource.cs.login.model.AuthorizationJson>>() {}));
    }
 
Example 19
Source File: B.java    From raml-java-client-generator with Apache License 2.0 5 votes vote down vote up
public FooResponse<same_path_multiple_times.resource.foo.b.model.BGETResponseBody> get() {
    WebTarget target = this._client.target(getBaseUri());
    final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.get();
    if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
        Response.StatusType statusInfo = response.getStatusInfo();
        throw new FooException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
    }
    FooResponse<same_path_multiple_times.resource.foo.b.model.BGETResponseBody> apiResponse = new FooResponse<same_path_multiple_times.resource.foo.b.model.BGETResponseBody>(response.readEntity(same_path_multiple_times.resource.foo.b.model.BGETResponseBody.class), response.getStringHeaders(), response);
    return apiResponse;
}
 
Example 20
Source File: SnomedClientRest.java    From SNOMED-in-5-minutes with Apache License 2.0 4 votes vote down vote up
/**
 * Returns description matches for the specified parameters.
 *
 * @param query the query
 * @param limit the limit
 * @param searchMode the search mode
 * @param lang the lang
 * @param statusFilter the status filter
 * @param skipTo the skip to
 * @param returnLimit the return limit
 * @param normalize the normalize
 * @param semanticFilter the semantic filter
 * @return the matches for query
 * @throws Exception the exception
 */
public MatchResults findByQuery(String query, Long limit, String searchMode,
  String lang, String statusFilter, Long skipTo, Long returnLimit,
  Boolean normalize, String semanticFilter) throws Exception {
  Logger.getLogger(getClass()).debug(
      "Snomed Client - get description matches by query " + query);

  validateNotEmpty(query, "query");

  // Use defaults if null is passed
  final long localLimit = limit == null ? 50L : limit;
  final String localSearchMode =
      searchMode == null ? "partialMatching" : searchMode;
  final String localLang = lang == null ? "english" : lang;
  final String localStatusFilter =
      statusFilter == null ? "activeOnly" : statusFilter;
  final long localSkipTo = skipTo == null ? 0L : skipTo;
  final long localReturnLimit = returnLimit == null ? 100L : returnLimit;
  final boolean localNormalize = normalize == null ? true : normalize;
  final String localSemanticFilter =
      semanticFilter == null ? "" : "&semanticFilter=" + semanticFilter;

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(getUrl()
          + "/descriptions?query="
          + URLEncoder.encode(query == null ? "" : query, "UTF-8")
              .replaceAll("\\+", "%20") + "&limit=" + localLimit
          + "&searchMode=" + localSearchMode + "&lang=" + localLang
          + "&statusFilter=" + localStatusFilter + "&skipTo=" + localSkipTo
          + "&returnLimit=" + localReturnLimit + "&normalize="
          + localNormalize + localSemanticFilter);

  final Response response = target.request(MediaType.APPLICATION_JSON).get();
  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  return Utility.getGraphForJson(resultString, MatchResults.class);
}