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

The following examples show how to use javax.ws.rs.core.Response.Status#NO_CONTENT . 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: MockContext.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public CartridgeBean getAvailableSingleTenantCartridgeInfo(String cartridgeType) throws RestAPIException {
    int tenantId = getTenantId();
    if (!availableSingleTenantCartridges.containsKey(tenantId)) {
        if (!availableSingleTenantCartridges.containsKey(PUBLIC_DEFINITION)) {
            throw new RestAPIException(Status.NO_CONTENT, "No cartridges defined for current tenant");
        }
        if (!(availableSingleTenantCartridges.get(PUBLIC_DEFINITION)).containsKey(cartridgeType))
            throw new RestAPIException(Status.NO_CONTENT, "Cartridge is not available.");

        return (availableSingleTenantCartridges.get(PUBLIC_DEFINITION)).get(cartridgeType);
    }
    if (!(availableSingleTenantCartridges.get(tenantId)).containsKey(cartridgeType))
        throw new RestAPIException(Status.NO_CONTENT, "Cartridge is not available.");

    return (availableSingleTenantCartridges.get(tenantId)).get(cartridgeType);
}
 
Example 2
Source File: MockContext.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public CartridgeBean getAvailableMultiTenantCartridgeInfo(String cartridgeType) throws RestAPIException {
    int tenantId = getTenantId();
    if (!availableMultiTenantCartridges.containsKey(tenantId)) {
        if (!availableMultiTenantCartridges.containsKey(PUBLIC_DEFINITION)) {
            throw new RestAPIException(Status.NO_CONTENT, "No cartridges defined for current tenant");
        }
        if (!(availableMultiTenantCartridges.get(PUBLIC_DEFINITION)).containsKey(cartridgeType))
            throw new RestAPIException(Status.NO_CONTENT, "Cartridge is not available.");

        return (availableMultiTenantCartridges.get(PUBLIC_DEFINITION)).get(cartridgeType);
    }
    if (!(availableMultiTenantCartridges.get(tenantId)).containsKey(cartridgeType))
        throw new RestAPIException(Status.NO_CONTENT, "Cartridge is not available.");

    return (availableMultiTenantCartridges.get(tenantId)).get(cartridgeType);
}
 
Example 3
Source File: MockContext.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public PartitionBean getPartition(String partitionId) throws RestAPIException {
    int tenantId = getTenantId();
    if (!partitionMap.containsKey(tenantId)) {
        if (!partitionMap.containsKey(PUBLIC_DEFINITION)) {
            throw new RestAPIException(Status.NO_CONTENT, "No partitions have been defined for the tenant");
        }
        if (!(partitionMap.get(PUBLIC_DEFINITION)).containsKey(partitionId)) {
            throw new RestAPIException("There is no partition with the id: " + partitionId);
        }
        return (partitionMap.get(PUBLIC_DEFINITION)).get(partitionId);
    } else {
        if (!(partitionMap.get(tenantId)).containsKey(partitionId)) {
            throw new RestAPIException("There is no partition with the id: " + partitionId);
        }
        return (partitionMap.get(tenantId)).get(partitionId);
    }
}
 
Example 4
Source File: MockContext.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public AutoscalePolicyBean getAutoscalePolicies(String autoscalePolicyId) throws RestAPIException {
    int tenantId = getTenantId();
    if (!autoscalePolicyMap.containsKey(tenantId)) {
        if (!autoscalePolicyMap.containsKey(PUBLIC_DEFINITION)) {
            throw new RestAPIException(Status.NO_CONTENT, "No autoscaling policies have been defined for tenant");
        }
        if (!(autoscalePolicyMap.get(PUBLIC_DEFINITION)).containsKey(autoscalePolicyId)) {
            throw new RestAPIException("There is no auto scale policy with id: " + autoscalePolicyId);
        }
        return (autoscalePolicyMap.get(PUBLIC_DEFINITION)).get(autoscalePolicyId);
    } else {
        if (!(autoscalePolicyMap.get(tenantId)).containsKey(autoscalePolicyId)) {
            throw new RestAPIException("There is no auto scale policy with id: " + autoscalePolicyId);
        }
        return (autoscalePolicyMap.get(tenantId)).get(autoscalePolicyId);
    }
}
 
Example 5
Source File: BulkDataClient.java    From FHIR with Apache License 2.0 5 votes vote down vote up
/**
 * @param job
 * @return status code
 * @throws Exception
 */
public Response.Status delete(String job) throws Exception {
    // <b>Code Flow</b>
    // 1 - Check if the Job Exists and is Valid
    // 2 - Check if the Tenant is expected
    // 3 - Try to immediately DELETE (Optimistic)
    //      A - SC_NO_CONTENT = SUCCESS GO_TO End
    //      B - !SC_INTERNAL_ERROR GO_TO STOP
    //      C - ERROR GO_TO Error
    // 4 - Try to stop the PUT /ibm/api/batch/jobinstances/<job>?action=stop
    //     A - SC_CONTENT_REDIRECT (302) GO_TO Location to PUT
    //       - Stop requests sent to the batch REST API must be sent directly to the executor where the job is running.
    //       - Link - https://www.ibm.com/support/knowledgecenter/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/rwlp_batch_rest_api.html#rwlp_batch_rest_api__STOP_requests
    //     B - SC_ACCEPTED (202) GO_TO ACCEPTED
    // RETURN - ACCEPTED: SC_ACCEPTED - STILL PROCESSING
    // RETURN - DONE: SC_OK - DONE DELETING

    // 1 and 2 (We know it exists)
    runVerificationOfTenantForJob(job);

    // 3 optimistic delete (empty)
    Response.Status status = runDeleteJobForTenant(job);

    // Check 3 (B), else fall through (A).
    // Default Response is Accepted (202)
    // The Alternative Response is 200

    // Check for a server-side error
    if (Status.INTERNAL_SERVER_ERROR == status) {
        // 3.C - ERROR Condition
        // The Server hit an error
        throw BulkDataExportUtil.buildOperationException(
                "Deleting the job has failed; the content is not abandonded", IssueType.EXCEPTION);
    } else if (Status.NO_CONTENT != status) {
        // The Delete was unsuccessful
        // 3.B - STOP Condition and now step 4 in the flow.
        status = runStopOfTenantJob(job);
    }
    return status;
}
 
Example 6
Source File: MockContext.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public ResponseMessageBean unsubscribe(String alias) throws RestAPIException {
    int tenantId = getTenantId();
    if (subscribedCartridges.containsKey(tenantId)) {
        if ((subscribedCartridges.get(tenantId)).containsKey(alias)) {
            (subscribedCartridges.get(tenantId)).remove(alias);
        }
    } else {
        throw new RestAPIException(Status.NO_CONTENT, "Unable to un-subscribe");
    }
    ResponseMessageBean stratosApiResponse = new ResponseMessageBean();
    stratosApiResponse.setMessage("Successfully un-subscribed");
    return stratosApiResponse;
}
 
Example 7
Source File: MockContext.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public CartridgeBean getCartridgeInfo(String alias) throws RestAPIException {
    int tenantId = getTenantId();
    if (!subscribedCartridges.containsKey(tenantId))
        throw new RestAPIException(Status.NO_CONTENT, "No cartridges subscribed for current tenant.");

    if (!(subscribedCartridges.get(tenantId)).containsKey(alias))
        throw new RestAPIException(Status.NO_CONTENT, "Cartridge information is not available.");

    return (subscribedCartridges.get(tenantId)).get(alias);
}
 
Example 8
Source File: MockContext.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public ResponseMessageBean deleteCartridgeDefinition(String cartridgeType) throws RestAPIException {
    if (!deleteFromAvailableSingleTenantCartridgeDefinitions(cartridgeType) && !deleteFromAvailableMultiTenantCartridgeDefinitions(cartridgeType)) {
        throw new RestAPIException(Status.NO_CONTENT, "No cartridges defined for tenant");
    }
    ResponseMessageBean stratosApiResponse = new ResponseMessageBean();
    stratosApiResponse.setMessage("Successfully delete cartridge definition");
    return stratosApiResponse;
}
 
Example 9
Source File: MockContext.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public PartitionBean[] getPartitions(String deploymentPolicyId, String partitionGroupId) throws RestAPIException {
    int tenantId = getTenantId();
    DeploymentPolicyBean deploymentPolicy;

    if (!deploymentPolicyMap.containsKey(tenantId)) {
        if (!deploymentPolicyMap.containsKey(PUBLIC_DEFINITION)) {
            throw new RestAPIException(Status.NO_CONTENT, "No deployment policies have been defined for tenant");
        } else {
            if (!(deploymentPolicyMap.get(PUBLIC_DEFINITION)).containsKey(deploymentPolicyId)) {
                throw new RestAPIException(Status.NO_CONTENT, "There is no deployment policy with id: " + deploymentPolicyId);
            } else {
                deploymentPolicy = (deploymentPolicyMap.get(PUBLIC_DEFINITION)).get(deploymentPolicyId);
            }
        }
    } else {
        if (!(deploymentPolicyMap.get(tenantId)).containsKey(deploymentPolicyId)) {
            throw new RestAPIException(Status.NO_CONTENT, "There is no deployment policy with id: " + deploymentPolicyId);
        } else {
            deploymentPolicy = (deploymentPolicyMap.get(tenantId)).get(deploymentPolicyId);
        }
    }

    PartitionBean[] partitionsArray = null;
    for (NetworkPartitionReferenceBean networkPartition : deploymentPolicy.getNetworkPartitions()) {
        if (networkPartition.getId().equals(partitionGroupId)) {
            List<PartitionReferenceBean> partitions = networkPartition.getPartitions();
            partitionsArray = partitions.toArray(new PartitionBean[partitions.size()]);
        }
    }
    if (partitionsArray == null) {
        throw new RestAPIException(Status.NO_CONTENT, "Partition not found");
    }
    return partitionsArray;
}
 
Example 10
Source File: ServiceSimple.java    From jqm with Apache License 2.0 5 votes vote down vote up
public InputStream getFile(String path)
{
    try
    {
        log.debug("file retrieval service called by user " + getUserName() + " for file " + path);
        return new FileInputStream(path);
    }
    catch (FileNotFoundException e)
    {
        throw new ErrorDto("Could not find the desired file", 8, e, Status.NO_CONTENT);
    }
}
 
Example 11
Source File: ServiceSimple.java    From jqm with Apache License 2.0 5 votes vote down vote up
@GET
@Path("enginelog")
@Produces(MediaType.TEXT_PLAIN)
public String getEngineLog(@QueryParam("latest") int latest)
{
    if (n == null)
    {
        throw new ErrorDto("can only retrieve a file when the web app runs on top of JQM", "", 7, Status.BAD_REQUEST);
    }

    // Failsafe
    if (latest > 10000)
    {
        latest = 10000;
    }

    File f = new File(FilenameUtils.concat("./logs/", "jqm-" + context.getInitParameter("jqmnode") + ".log"));
    try(ReversedLinesFileReader r =  new ReversedLinesFileReader(f, Charset.defaultCharset()))
    {
        StringBuilder sb = new StringBuilder(latest);
        String buf = r.readLine();
        int i = 1;
        while (buf != null && i <= latest)
        {
            sb.append(buf);
            sb.append(System.getProperty("line.separator"));
            i++;
            buf = r.readLine();
        }
        return sb.toString();
    }
    catch (Exception e)
    {
        throw new ErrorDto("Could not return the desired file", 8, e, Status.NO_CONTENT);
    }
}
 
Example 12
Source File: BackchannelAuthenticationCompleteHandlerSpiImpl.java    From java-oauth-server with Apache License 2.0 4 votes vote down vote up
@Override
public void sendNotification(BackchannelAuthenticationCompleteResponse info)
{
    // The URL of the consumption device's notification endpoint.
    URI clientNotificationEndpointUri = info.getClientNotificationEndpoint();

    // The token that is needed for client authentication at the consumption
    // device's notification endpoint.
    String notificationToken = info.getClientNotificationToken();

    // The notification content (JSON) to send to the consumption device.
    String notificationContent = info.getResponseContent();

    // Send the notification to the consumption device's notification endpoint.
    Response response =
            doSendNotification(clientNotificationEndpointUri, notificationToken, notificationContent);

    // The status of the response from the consumption device.
    Status status = Status.fromStatusCode(response.getStatusInfo().getStatusCode());

    // TODO: CIBA specification does not specify how to deal with responses
    // returned from the consumption device in case of error push notification.
    // Then, even in case of error push notification, the current implementation
    // treats the responses as in the case of successful push notification.

    // Check if the "HTTP 200 OK" or "HTTP 204 No Content".
    if (status == Status.OK || status == Status.NO_CONTENT)
    {
        // In this case, the request was successfully processed by the consumption
        // device since the specification says as follows.
        //
        //   CIBA Core spec, 10.2. Ping Callback and 10.3. Push Callback
        //     For valid requests, the Client Notification Endpoint SHOULD
        //     respond with an HTTP 204 No Content.  The OP SHOULD also accept
        //     HTTP 200 OK and any body in the response SHOULD be ignored.
        //
        return;
    }

    if (status.getFamily() == Status.Family.REDIRECTION)
    {
        // HTTP 3xx code. This case must be ignored since the specification
        // says as follows.
        //
        //   CIBA Core spec, 10.2. Ping Callback, 10.3. Push Callback
        //     The Client MUST NOT return an HTTP 3xx code.  The OP MUST
        //     NOT follow redirects.
        //
        return;
    }
}
 
Example 13
Source File: MockContext.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public TenantInfoBean getTenant(String tenantDomain) throws RestAPIException {
    if (!tenantMap.containsKey(tenantDomain)) {
        throw new RestAPIException(Status.NO_CONTENT, "Information for tenant: " + tenantDomain + " is not available");
    }
    return tenantMap.get(tenantDomain);
}