當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpStatus.SC_BAD_REQUEST屬性代碼示例

本文整理匯總了Java中org.apache.http.HttpStatus.SC_BAD_REQUEST屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.SC_BAD_REQUEST屬性的具體用法?Java HttpStatus.SC_BAD_REQUEST怎麽用?Java HttpStatus.SC_BAD_REQUEST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.http.HttpStatus的用法示例。


在下文中一共展示了HttpStatus.SC_BAD_REQUEST屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isVersioningEnabled

@Override
public boolean isVersioningEnabled() throws StorageAdapterException {
    // Try to get the versions of a random (made up) file.
    // There are 3 possible scenarios:
    // a) versioning is enabled, and the file exsists, so the call will succeed without error
    // b) versioning is enabled and the file does NOT exist. We'll get a 404 NOT FOUND returned
    // c) versioning is not enabled, regardless whether the file exists or not, we'll get a 400
    // BAD REQUEST
    try {
        ArcMoverDirectory dir = getVersions("/HCP_dummy_filename_used_by_Data_Migrator_may_or_may_not_exist");
        dir.getFileListIterator(true, true);
        return true;
    } catch (StorageAdapterException e) {
        Integer statusCode = e.getStatusCode();
        if (statusCode != null && statusCode == HttpStatus.SC_BAD_REQUEST) { // 400
            return false;
        } else if (statusCode != null && statusCode == HttpStatus.SC_NOT_FOUND) { // 404
            return true;
        } else {
            throw e;
        }
    }
}
 
開發者ID:Hitachi-Data-Systems,項目名稱:Open-DM,代碼行數:23,代碼來源:Hcp5AuthNamespaceAdapter.java

示例2: testBadRequestFailure

@Test(expectedExceptions = DatarouterHttpResponseException.class)
public void testBadRequestFailure() throws DatarouterHttpException{
	try{
		int status = HttpStatus.SC_BAD_REQUEST;
		String expectedResponse = UUID.randomUUID().toString();
		server.setResponse(status, expectedResponse);
		DatarouterHttpClient client = new DatarouterHttpClientBuilder().build();
		DatarouterHttpRequest request = new DatarouterHttpRequest(HttpRequestMethod.GET, URL, false);
		client.executeChecked(request);
	}catch(DatarouterHttpResponseException e){
		Assert.assertTrue(e.isClientError());
		DatarouterHttpResponse response = e.getResponse();
		Assert.assertNotNull(response);
		Assert.assertEquals(response.getStatusCode(), HttpStatus.SC_BAD_REQUEST);
		throw e;
	}
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:17,代碼來源:DatarouterHttpClientIntegrationTests.java

示例3: fromAuthorizationHeader

@Override
public AuthorizationToken fromAuthorizationHeader(String authenticationValue) {
    Matcher matcher = TOKEN_MATCHER.matcher(authenticationValue);

    if (matcher.find()) {
        String prefix = matcher.group(1);
        String value = matcher.group(2);

        AuthorizationToken token = new AuthorizationToken();
        token.setType(AuthorizationTokenType.fromPrefix(prefix));
        token.setValue(value);

        return token;
    }

    throw new ServiceException(HttpStatus.SC_BAD_REQUEST, "Could not parse Authentication header");
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:17,代碼來源:AuthorizationTokenFactoryImpl.java

示例4: generateSessionToken

@Override
public Single<AuthorizationToken> generateSessionToken(PasswordCredentials credentials) {
    if (credentials.getEmailAddress() == null) {
        throw new ServiceException(HttpStatus.SC_BAD_REQUEST, "Email Address is required to login");
    }

    return FacadePolicies.singleOrException(saltCache.get(credentials.getEmailAddress()), HttpStatus.SC_UNAUTHORIZED, "Invalid credentials")
            .map((salt) -> cryptFacade.encrypt(salt, credentials.getPassword()))
            .map((encryptedPassword) -> {
                    credentials.setPassword(encryptedPassword);
                    return authenticationFacade.authenticate(credentials);
                }
            )
            .flatMap((authenticatedEntity) -> {
                    AuthorizationToken token = authorizationTokenFactory.generateExpiringToken(authenticatedEntity.getAuthenticatable(), ADMIN_TOKEN_LIFESPAN);
                    return authenticationFacade.createCredentials(token);
            });
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:18,代碼來源:PasswordCredentialsFacadeImpl.java

示例5: failed

@Override
public void failed(HttpClientCallbackResult result) {

    String reStr = result.getReplyDataAsString();
    if (result.getRetCode() == HttpStatus.SC_BAD_REQUEST) {
        /**
         * Confusing.......
         */
        logger.err(this,
                "get query result failed -returnCode[" + result.getRetCode() + "] and retMsg[" + reStr + "]",
                result.getException());
        response.resume(reStr);
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:14,代碼來源:GodEyeRestService.java

示例6: resolveOauth

private Observable<IdentityProvider> resolveOauth(OauthEntity oauthEntity) {
    if (oauthEntity.getProvider() == null) {
        throw new ServiceException(HttpStatus.SC_BAD_REQUEST, "In order to resolve an OAUTH Entity, 'provider' is required");
    }

    IdentityProviderQuery query = new IdentityProviderQuery()
            .setType(IdentityProviderType.OAUTH)
            .setProvider(oauthEntity.getProvider());

    return filter(query);
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:11,代碼來源:IdentityProviderFacadeImpl.java

示例7: deliverResponse

@Override
protected void deliverResponse(String response) {
    if (isCanceled()) {
        return;
    }
    if (mResponse != null) {
        int statusCode = 0;
        Map<String, String> headers = null;
        String body = null;
        try {
            JSONObject responseJson = new JSONObject(response);
            if (!responseJson.isNull(RESPONSE_STATUS_CODE)) {
                statusCode = responseJson.getInt(RESPONSE_STATUS_CODE);
            }
            if (!responseJson.isNull(RESPONSE_HEADERS)) {
                headers = toMap(responseJson);
            }
            if (!responseJson.isNull(RESPONSE_BODY)) {
                body = responseJson.getString(RESPONSE_BODY);
            }
            if (statusCode < HttpStatus.SC_BAD_REQUEST) {
                mResponse.onSuccess(new AbstractResponse.Response(statusCode, headers, body));
            } else {
                mResponse.onFailure(new AbstractResponse.Response(statusCode, headers, body));
            }
        } catch (JSONException e) {
            e.printStackTrace();
            mResponse.onError(new AbstractResponse.Response(statusCode, headers, new VolleyError(e)));
        }
    }
}
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:31,代碼來源:BaseRequest.java

示例8: map

public BackgroundException map(final Throwable failure, final StringBuilder buffer, final int statusCode) {
    switch(statusCode) {
        case HttpStatus.SC_UNAUTHORIZED:
            return new LoginFailureException(buffer.toString(), failure);
        case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
            return new ProxyLoginFailureException(buffer.toString(), failure);
        case HttpStatus.SC_FORBIDDEN:
        case HttpStatus.SC_NOT_ACCEPTABLE:
            return new AccessDeniedException(buffer.toString(), failure);
        case HttpStatus.SC_CONFLICT:
            return new ConflictException(buffer.toString(), failure);
        case HttpStatus.SC_NOT_FOUND:
        case HttpStatus.SC_GONE:
        case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
            return new NotfoundException(buffer.toString(), failure);
        case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE:
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
        case HttpStatus.SC_PAYMENT_REQUIRED:
            return new QuotaException(buffer.toString(), failure);
        case HttpStatus.SC_UNPROCESSABLE_ENTITY:
        case HttpStatus.SC_BAD_REQUEST:
        case HttpStatus.SC_REQUEST_URI_TOO_LONG:
        case HttpStatus.SC_METHOD_NOT_ALLOWED:
        case HttpStatus.SC_NOT_IMPLEMENTED:
            return new InteroperabilityException(buffer.toString(), failure);
        case HttpStatus.SC_REQUEST_TIMEOUT:
        case HttpStatus.SC_GATEWAY_TIMEOUT:
        case HttpStatus.SC_BAD_GATEWAY:
            return new ConnectionTimeoutException(buffer.toString(), failure);
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        case HttpStatus.SC_SERVICE_UNAVAILABLE:
        case 429:
            // Too Many Requests. Rate limiting
        case 509:
            // Bandwidth Limit Exceeded
            return new RetriableAccessDeniedException(buffer.toString(), failure);
        default:
            return new InteroperabilityException(buffer.toString(), failure);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:40,代碼來源:HttpResponseExceptionMappingService.java

示例9: handleRequest

public Integer handleRequest(SNSEvent event, Context context) {
    try {
        // SNS Events could be possible more than one even if this looks a bit unusual for the deploy case.
        for (SNSEvent.SNSRecord record : event.getRecords()) {
            SNSEvent.SNS sns = record.getSNS();
            // Check SNS header for event type.
            SNSEvent.MessageAttribute attr = sns.getMessageAttributes().get(X_GITHUB_EVENT);
            // Only watch pushes to master.
            if (EVENT_PUSH.equalsIgnoreCase(attr.getValue())) {
                PushPayload value = MAPPER.readValue(sns.getMessage(), PushPayload.class);
                if (config.isWatchedBranch(new Branch(value.getRef()))) {
                    LOG.info(format("Processing '%s' on '%s': '%s'", attr.getValue(), value.getRef(), value.getHeadCommit().getId()));
                    switch (worker.call()) {
                        case SUCCESS:
                            return HttpStatus.SC_OK;
                        case FAILED:
                            return HttpStatus.SC_BAD_REQUEST;
                    }
                }
                // Different branch was found.
                else {
                    LOG.info(format("Push received for: '%s'", value.getRef()));
                }
            }
            // Different event was found.
            else {
                LOG.info(format("Event was: '%s'", attr.getValue()));
            }
        }
    }
    catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }
    return HttpStatus.SC_BAD_REQUEST;
}
 
開發者ID:berlam,項目名稱:github-bucket,代碼行數:36,代碼來源:Lambda.java

示例10: decideSeverity

/**
 * レスポンスコードからログレベルの判定.
 * @param statusCode ステータスコード
 * @return ステータスコードから判定されたログレベル
 */
static Severity decideSeverity(int statusCode) {
    // 設定が省略されている場合はエラーコードからログレベルを取得
    if (statusCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        // 500係の場合はウォーニング(500以上はまとめてウォーニング)
        return Severity.WARN;
    } else if (statusCode >= HttpStatus.SC_BAD_REQUEST) {
        // 400係の場合はインフォ
        return Severity.INFO;
    } else {
        // それ以外の場合は考えられないのでウォーニング.
        // 200係とか300係をPersoniumCoreExceptionで処理する場合はログレベル設定をちゃんと書きましょう.
        return Severity.WARN;
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:19,代碼來源:PersoniumCoreException.java

示例11: create

@Override
public Single<IdentityProvider> create(IdentityProvider identityProvider) {
    IdentityProviderDao dao = daosByType.get(identityProvider.getType());

    if (dao == null) {
        throw new ServiceException(HttpStatus.SC_BAD_REQUEST, "IdentityProvider of type [" + identityProvider.getType() + "] not supported");
    }

    return dao.create(identityProvider);
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:10,代碼來源:IdentityProviderFacadeImpl.java

示例12: BadRequestException

public BadRequestException(final String message, final Throwable cause) {       
    super(HttpStatus.SC_BAD_REQUEST, message, cause);
}
 
開發者ID:tdsis,項目名稱:lambda-forest,代碼行數:3,代碼來源:BadRequestException.java

示例13: getAllModules

public void getAllModules() {
    SugarRestClient client = new SugarRestClient(TestAccount.Url, TestAccount.Username, TestAccount.Password);
    SugarRestRequest request = new SugarRestRequest(RequestType.AllModulesRead);

    SugarRestResponse response = client.execute(request);
    List<String> allAvailableModules = (List<String>)response.getData();

    assertNotNull(response);
    assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
    assertTrue(allAvailableModules.size() > 0);

    // Get all mapped modules
    List<String> allMappedModules = ModuleMapper.getInstance().getAllModules();

    int count = 0;
    for (String module : allMappedModules) {
        // Do a bulk read module test
        response = bulkReadModule(client, module);
        // assertNotNull(response);
        // assertEquals(response.getStatusCode(), HttpStatus.SC_OK);

        int statusOk = (int)HttpStatus.SC_OK;
        int statusBadRequest = (int)HttpStatus.SC_BAD_REQUEST;
        int statusOInternalError = (int)HttpStatus.SC_INTERNAL_SERVER_ERROR;

        if (response.getStatusCode() == statusOk) {
            System.out.println("Module name:" + module + ":::: Status" + response.getStatusCode());
            System.out.println(response.getJsonRawResponse());
            System.out.println(response.getError().getTrace());
            count = count + 1;
        }
    }

    System.out.println("Total Count::::" + allMappedModules.size());
    System.out.println("Count::::" + count);

    /*
    for (String module : allAvailableModules) {
        if (!allMappedModules.contains(module) ) {
            // Do a bulk read module test
            response = bulkReadModule(client, module);
           // assertNotNull(response);
           // assertEquals(response.getStatusCode(), HttpStatus.SC_OK);

            if (response.getStatusCode() == (int)HttpStatus.SC_BAD_REQUEST) {
                System.out.println("Module name:" + module + ":::: Status" + response.getStatusCode());
                System.out.println(response.getJsonRawResponse());
                System.out.println(response.getError().getTrace());
            }
        }
    }
    */
}
 
開發者ID:mattkol,項目名稱:SugarOnRest,代碼行數:53,代碼來源:AvailableModulesTests.java

示例14: process

public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    // Always drop connection after certain type of responses
    int status = response.getStatusLine().getStatusCode();
    if (status == HttpStatus.SC_BAD_REQUEST ||
            status == HttpStatus.SC_REQUEST_TIMEOUT ||
            status == HttpStatus.SC_LENGTH_REQUIRED ||
            status == HttpStatus.SC_REQUEST_TOO_LONG ||
            status == HttpStatus.SC_REQUEST_URI_TOO_LONG ||
            status == HttpStatus.SC_SERVICE_UNAVAILABLE ||
            status == HttpStatus.SC_NOT_IMPLEMENTED) {
        response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        return;
    }
    Header explicit = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
    if (explicit != null && HTTP.CONN_CLOSE.equalsIgnoreCase(explicit.getValue())) {
        // Connection persistence explicitly disabled
        return;
    }
    // Always drop connection for HTTP/1.0 responses and below
    // if the content body cannot be correctly delimited
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
        if (entity.getContentLength() < 0 &&
                (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0))) {
            response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
            return;
        }
    }
    // Drop connection if requested by the client or request was <= 1.0
    HttpRequest request = (HttpRequest)
        context.getAttribute(ExecutionContext.HTTP_REQUEST);
    if (request != null) {
        Header header = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
        if (header != null) {
            response.setHeader(HTTP.CONN_DIRECTIVE, header.getValue());
        } else if (request.getProtocolVersion().lessEquals(HttpVersion.HTTP_1_0)) {
            response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:48,代碼來源:ResponseConnControl.java


注:本文中的org.apache.http.HttpStatus.SC_BAD_REQUEST屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。