List of usage examples for javax.servlet.http HttpServletResponse SC_NOT_ACCEPTABLE
int SC_NOT_ACCEPTABLE
To view the source code for javax.servlet.http HttpServletResponse SC_NOT_ACCEPTABLE.
Click Source Link
From source file:com.meltmedia.cadmium.servlets.BasicFileServlet.java
/** * Sends an error on the response for status code 406 NOT ACCEPTABLE. * @param context/*from w w w .j a va 2s.c om*/ * @throws IOException */ public static void notAcceptable(FileRequestContext context) throws IOException { context.response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE); }
From source file:org.clothocad.phagebook.controllers.OrdersController.java
@RequestMapping(value = "/markOrderAsReceived", method = RequestMethod.POST) public void markOrderAsReceived(@RequestParam Map<String, String> params, HttpServletResponse response) throws ServletException, IOException { Object pOrderId = params.get("orderId"); String orderId = pOrderId != null ? (String) pOrderId : ""; Object pUserId = params.get("userId"); String userId = pUserId != null ? (String) pUserId : ""; //for error checking later boolean isValid = false; if (!orderId.equals("") && !userId.equals("")) { isValid = true;//from w ww . j ava 2 s .c om } if (isValid) { //login ClothoConnection conn = new ClothoConnection(Args.clothoLocation); Clotho clothoObject = new Clotho(conn); String username = this.backendPhagebookUser; String password = this.backendPhagebookPassword; /* DIRECT ASSUMPTION THAT USER: phagebook exists and their PASSWORD: backend */ Map loginMap = new HashMap(); loginMap.put("username", username); loginMap.put("credentials", password); clothoObject.login(loginMap); Person user = ClothoAdapter.getPerson(userId, clothoObject); clothoObject.logout(); Map loginMap2 = new HashMap(); loginMap2.put("username", user.getEmailId()); loginMap2.put("credentials", user.getPassword()); clothoObject.login(loginMap2); Order order = ClothoAdapter.getOrder(orderId, clothoObject); /*TODO CHECK IF THE ORDER's RECEIVED BY IDS MATCHES THE USER ID PASSED IN*/ List<String> receivedBys = order.getReceivedByIds(); for (String receiver : receivedBys) { if (receiver.equals(userId)) // CHECK IF THE ID'S MATCH WITH THE ONE SUBMITTED. { order.setStatus(OrderStatus.RECEIVED); } } ClothoAdapter.setOrder(order, clothoObject); response.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = response.getWriter(); response.setContentType("application/JSON"); JSONObject responseJSON = new JSONObject(); responseJSON.put("message", "missing required parameters for marking an order"); writer.println(responseJSON.toString()); writer.flush(); writer.close(); conn.closeConnection(); } else { response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); PrintWriter writer = response.getWriter(); response.setContentType("application/JSON"); JSONObject responseJSON = new JSONObject(); responseJSON.put("message", "missing required parameters for marking an order"); writer.println(responseJSON.toString()); writer.flush(); writer.close(); } }
From source file:com.vmware.identity.proxyservice.LogonProcessorImpl.java
/** * Validate principal being asserted by IDP. Provision and update JIT user as needed. * 1. Validate external token from the response. * 2. Provision JIT user if the feature is on and the subject not found. * 3. Update JIT user attributes if it is existing JIT user. * * @param tenant//from ww w . j a v a 2s . com * @param arg0 * @return PrincipalId or null if not able to link account to the incoming token * @throws InvalidSignatureException * @throws InvalidTokenException * @throws SystemException */ private PrincipalId validateExternalUser(IdmAccessor idmAccessor, Message arg0) throws InvalidSignatureException, InvalidTokenException, SystemException { Validate.notNull(idmAccessor, "idmAccessor"); Validate.notNull(arg0, "Message"); String tenant = idmAccessor.getTenant(); Validate.notNull(tenant, "tenant"); AuthnData authnData = (AuthnData) arg0.getMessageData(); Validate.notNull(authnData, "authnData"); Element tokenEle = (Element) authnData.getToken() .getElementsByTagNameNS(SAMLNames.NS_VAL_SAML_SAML, SAMLNames.ASSERTION).item(0); ServerValidatableSamlToken servToken = tokenFactory.parseToken(tokenEle); final TokenValidator authnOnlyTokenValidator = samlAuthFactory.createAuthnOnlyTokenValidator(tenant); final ServerValidatableSamlToken validatedToken = authnOnlyTokenValidator.validate(servToken); Validate.isTrue(validatedToken.isExternal()); IDPConfig extIdp = getIssuerIDPConfig(arg0, idmAccessor); boolean isJitEnabled = extIdp.getJitAttribute(); PrincipalId subjectUpn = validatedToken.getSubject().subjectUpn(); boolean isSubjectValidated = subjectUpn != null && validatedToken.getSubject().subjectValidation() != SubjectValidation.None; if (!isJitEnabled && !isSubjectValidated) { log.error("Not able to validate the subject in external token "); // Failed in creating our own token. Report authentication error com.vmware.identity.websso.client.ValidationResult extResponseVr = new com.vmware.identity.websso.client.ValidationResult( HttpServletResponse.SC_NOT_ACCEPTABLE, OasisNames.REQUEST_DENIED, "Subject validation of external token." + " Unable to validate the subject."); arg0.setValidationResult(extResponseVr); return null; } if (isJitEnabled && !isSubjectValidated) { try { subjectUpn = idmAccessor.createUserAccountJustInTime(servToken.getSubject(), tenant, extIdp); } catch (Exception e) { log.error("Failure to create a temporary user.", e); com.vmware.identity.websso.client.ValidationResult extResponseVr = new com.vmware.identity.websso.client.ValidationResult( HttpServletResponse.SC_UNAUTHORIZED, OasisNames.RESPONDER, null); arg0.setValidationResult(extResponseVr); return null; } } if (isJitEnabled) { // update or add group information based on attribute info in new token try { idmAccessor.updateJitUserGroups(subjectUpn, tenant, extIdp.getTokenClaimGroupMappings(), authnData.getAttributes()); } catch (Exception e) { log.error("Encountered an error while updating Jit user groups", e); com.vmware.identity.websso.client.ValidationResult extResponseVr = new com.vmware.identity.websso.client.ValidationResult( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, OasisNames.RESPONDER, null); arg0.setValidationResult(extResponseVr); return null; } } return subjectUpn; }
From source file:org.jitsi.videobridge.rest.HandlerImpl.java
/** * Creates a new <tt>Conference</tt> in (the associated) * <tt>Videobridge</tt>.//from w w w.ja v a 2 s . c om * * @param baseRequest the original unwrapped {@link Request} object * @param request the request either as the {@code Request} object or a * wrapper of that request * @param response the response either as the {@code Response} object or a * wrapper of that response * @throws IOException * @throws ServletException */ private void doPostConferencesJSON(Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Videobridge videobridge = getVideobridge(); if (videobridge == null) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else if (RESTUtil.isJSONContentType(request.getContentType())) { Object requestJSONObject = null; int status = 0; try { requestJSONObject = new JSONParser().parse(request.getReader()); if ((requestJSONObject == null) || !(requestJSONObject instanceof JSONObject)) { status = HttpServletResponse.SC_BAD_REQUEST; } } catch (ParseException pe) { status = HttpServletResponse.SC_BAD_REQUEST; } if (status == 0) { ColibriConferenceIQ requestConferenceIQ = JSONDeserializer .deserializeConference((JSONObject) requestJSONObject); if ((requestConferenceIQ == null) || (requestConferenceIQ.getID() != null)) { status = HttpServletResponse.SC_BAD_REQUEST; } else { ColibriConferenceIQ responseConferenceIQ = null; try { IQ responseIQ = videobridge.handleColibriConferenceIQ(requestConferenceIQ, Videobridge.OPTION_ALLOW_NO_FOCUS); if (responseIQ instanceof ColibriConferenceIQ) { responseConferenceIQ = (ColibriConferenceIQ) responseIQ; } else { status = getHttpStatusCodeForResultIq(responseIQ); } } catch (Exception e) { status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } if (status == 0 && responseConferenceIQ != null) { JSONObject responseJSONObject = JSONSerializer.serializeConference(responseConferenceIQ); if (responseJSONObject == null) responseJSONObject = new JSONObject(); response.setStatus(HttpServletResponse.SC_OK); responseJSONObject.writeJSONString(response.getWriter()); } } } if (status != 0) response.setStatus(status); } else { response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); } }
From source file:org.jitsi.videobridge.rest.HandlerImpl.java
private void doPostShutdownJSON(Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { Videobridge videobridge = getVideobridge(); if (videobridge == null) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return;/*w w w .jav a 2s . c om*/ } if (!RESTUtil.isJSONContentType(request.getContentType())) { response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); return; } Object requestJSONObject; int status; try { requestJSONObject = new JSONParser().parse(request.getReader()); if ((requestJSONObject == null) || !(requestJSONObject instanceof JSONObject)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } catch (ParseException pe) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } ShutdownIQ requestShutdownIQ = JSONDeserializer.deserializeShutdownIQ((JSONObject) requestJSONObject); if ((requestShutdownIQ == null)) { status = HttpServletResponse.SC_BAD_REQUEST; } else { // Fill source address String ipAddress = request.getHeader("X-FORWARDED-FOR"); if (ipAddress == null) { ipAddress = request.getRemoteAddr(); } requestShutdownIQ.setFrom(ipAddress); try { IQ responseIQ = videobridge.handleShutdownIQ(requestShutdownIQ); if (IQ.Type.RESULT.equals(responseIQ.getType())) { status = HttpServletResponse.SC_OK; } else { status = getHttpStatusCodeForResultIq(responseIQ); } } catch (Exception e) { logger.error("Error while trying to handle shutdown request", e); status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } response.setStatus(status); }
From source file:com.liferay.petra.json.web.service.client.BaseJSONWebServiceClientImpl.java
protected String execute(HttpRequestBase httpRequestBase) throws JSONWebServiceInvocationException, JSONWebServiceTransportException { signRequest(httpRequestBase);//w w w .j a v a2 s . c o m HttpHost httpHost = new HttpHost(_hostName, _hostPort, _protocol); try { if (_closeableHttpAsyncClient == null) { afterPropertiesSet(); } Future<HttpResponse> future = null; if (!isNull(_login) && !isNull(_password)) { HttpClientContext httpClientContext = HttpClientContext.create(); AuthCache authCache = new BasicAuthCache(); AuthScheme authScheme = null; if (!isNull(_proxyHostName)) { authScheme = new BasicScheme(ChallengeState.PROXY); } else { authScheme = new BasicScheme(ChallengeState.TARGET); } authCache.put(httpHost, authScheme); httpClientContext.setAttribute(ClientContext.AUTH_CACHE, authCache); future = _closeableHttpAsyncClient.execute(httpHost, httpRequestBase, httpClientContext, null); } else { future = _closeableHttpAsyncClient.execute(httpHost, httpRequestBase, null); } HttpResponse httpResponse = future.get(); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (_logger.isTraceEnabled()) { _logger.trace("Server returned status " + statusCode); } HttpEntity httpEntity = httpResponse.getEntity(); if ((statusCode == HttpServletResponse.SC_NO_CONTENT) || (((httpEntity == null) || (httpEntity.getContentLength() == 0)) && _isStatus2XX(statusCode))) { return null; } String content = EntityUtils.toString(httpEntity, _CHARSET); if ((httpEntity.getContentType() != null) && _isApplicationJSONContentType(httpEntity)) { content = updateJSON(content); } if (_isStatus2XX(statusCode)) { return content; } else if ((statusCode == HttpServletResponse.SC_BAD_REQUEST) || (statusCode == HttpServletResponse.SC_FORBIDDEN) || (statusCode == HttpServletResponse.SC_METHOD_NOT_ALLOWED) || (statusCode == HttpServletResponse.SC_NOT_ACCEPTABLE) || (statusCode == HttpServletResponse.SC_NOT_FOUND)) { throw new JSONWebServiceInvocationException(content, statusCode); } else if (statusCode == HttpServletResponse.SC_UNAUTHORIZED) { throw new JSONWebServiceTransportException.AuthenticationFailure( "Not authorized to access JSON web service"); } throw new JSONWebServiceTransportException.CommunicationFailure("Server returned status " + statusCode, statusCode); } catch (ExecutionException ee) { throw new JSONWebServiceTransportException.CommunicationFailure("Unable to transmit request", ee); } catch (InterruptedException ie) { throw new JSONWebServiceTransportException.CommunicationFailure("Unable to transmit request", ie); } catch (IOException ioe) { throw new JSONWebServiceTransportException.CommunicationFailure("Unable to transmit request", ioe); } finally { httpRequestBase.releaseConnection(); } }
From source file:byps.http.HHttpServlet.java
private void doPutStream(final long messageId, final long streamId, HttpServletRequest request, HttpServletResponse response) throws IOException { if (log.isDebugEnabled()) log.debug("doPutStream("); try {//from ww w . ja v a 2s. co m // NDC.push(hsess.getId()); if (log.isDebugEnabled()) log.debug("start async, timeout=" + HConstants.REQUEST_TIMEOUT_MILLIS); final HRequestContext rctxt = createRequestContext(request, response, HConstants.PROCESS_PUT_STREAM_ASYNC); rctxt.setTimeout(HConstants.REQUEST_TIMEOUT_MILLIS); try { final BTargetId targetId = new BTargetId(getConfig().getMyServerId(), messageId, streamId); final HActiveMessage msg = getActiveMessages().addIncomingStream(targetId, rctxt); // Session verlngern. Wichtig fr den Upload sehr groer Dateien. final String sessionId = msg.getSessionId(); final HSession sess = sessionId != null ? HSessionListener.getAllSessions().get(sessionId) : null; if (sess != null) { sess.touch(); } } catch (BException e) { int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; if (e.code == BExceptionC.CANCELLED) { status = HttpServletResponse.SC_NOT_ACCEPTABLE; } ((HttpServletResponse) rctxt.getResponse()).setStatus(status); rctxt.complete(); } } finally { // NDC.pop(); } if (log.isDebugEnabled()) log.debug(")doPutStream"); }