当前位置: 首页>>代码示例>>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;未经允许,请勿转载。