List of usage examples for org.springframework.http MediaType APPLICATION_XML_VALUE
String APPLICATION_XML_VALUE
To view the source code for org.springframework.http MediaType APPLICATION_XML_VALUE.
Click Source Link
From source file:org.opentestsystem.authoring.testspecbank.rest.TestSpecificationController.java
private static HttpHeaders buildResponseHeaders(final int contentLength, final String filename) { final HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.clear();//from w ww .j a v a2 s. c o m responseHeaders.add(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE); responseHeaders.setPragma("public"); responseHeaders.setCacheControl("no-store, must-revalidate"); responseHeaders.setExpires(Long.valueOf("-1")); responseHeaders.setContentDispositionFormData("inline", filename); responseHeaders.setContentLength(contentLength); responseHeaders.add(org.apache.http.HttpHeaders.ACCEPT_RANGES, "bytes"); return responseHeaders; }
From source file:org.opentestsystem.delivery.testreg.rest.StudentPackageController.java
@ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/studentpackage", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE) @Secured({ "ROLE_Entity Read" }) @ResponseBody/*from w w w. jav a 2 s. co m*/ public void extractStudentPackage(@RequestParam(value = "ssid", required = false) final String studentId, @RequestParam(value = "externalId", required = false) final String externalSsid, @RequestParam("stateabbreviation") final String stateAbbreviation, final HttpServletResponse response) throws IOException { StopWatch sw = new StopWatch(); sw.start(); Student student = null; if (hasText(studentId) && hasText(externalSsid)) { response.setStatus(HttpServletResponse.SC_CONFLICT); } else if (hasText(studentId)) { student = studentService.findByStudentIdAndStateAbbreviation(studentId, stateAbbreviation); } else if (hasText(externalSsid)) { student = studentService.findByExternalSsidAndStateAbbreviation(externalSsid, stateAbbreviation); } if (student != null) { String studentPackage = studentPackageService.exportStudentPackage(student); response.setContentType(MediaType.APPLICATION_XML_VALUE); ServletOutputStream out = response.getOutputStream(); IOUtils.copy(new ByteArrayInputStream(studentPackage.getBytes()), out); out.flush(); } else { response.setStatus(HttpServletResponse.SC_NO_CONTENT); } sw.stop(); this.metricClient.sendPerformanceMetricToMna("StudentPackage for " + externalSsid + " (ms) ", sw.getTime()); }
From source file:org.opentestsystem.delivery.testreg.rest.UserController.java
/** * SSO Callback//from ww w . jav a 2s. co m */ @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/users/extract", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE) public void ssoUsersExtractCallback(@RequestBody final String xml) throws Exception { userChangeEventCallbackService.processCallback(xml); }
From source file:org.owasp.webgoat.plugin.ContentTypeAssignment.java
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody//from w w w . jav a 2s. c om public AttackResult createNewUser(@RequestBody String commentStr, @RequestHeader("Content-Type") String contentType) throws Exception { AttackResult attackResult = failed().build(); if (APPLICATION_JSON_VALUE.equals(contentType)) { comments.parseJson(commentStr).ifPresent(c -> comments.addComment(c, true)); attackResult = failed().feedback("xxe.content.type.feedback.json").build(); } if (MediaType.APPLICATION_XML_VALUE.equals(contentType)) { String error = ""; try { Comment comment = comments.parseXml(commentStr); comments.addComment(comment, false); if (checkSolution(comment)) { attackResult = success().build(); } } catch (Exception e) { error = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e); attackResult = failed().feedback("xxe.content.type.feedback.xml").output(error).build(); } } return trackProgress(attackResult); }
From source file:org.springframework.xd.dirt.rest.ModulesController.java
/** * Retrieve the configuration file for the provided module information. * /*from ww w. j a va 2 s.c om*/ * @param name the name of an existing resource (required) * @param type the type of the module (required) */ @RequestMapping(value = "/{type}/{name}/definition", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE) @ResponseStatus(HttpStatus.OK) @ResponseBody public Resource downloadDefinition(@PathVariable("type") ModuleType type, @PathVariable("name") String name) { final ModuleDefinition definition = this.compositeModuleDefinitionService.getModuleDefinitionRepository() .findByNameAndType(name, type); if (definition == null) { throw new NoSuchModuleException(name, type); } final Resource resource = definition.getResource(); try { if (logger.isWarnEnabled() && resource.getFile().length() == 0) { logger.warn(String.format("The length of the file '%s' for module '%s' (%s) is zero.", resource.getFilename(), definition.getName(), definition.getType().name())); } } catch (IOException e) { throw new IllegalStateException( "Unable to return the file for the provided resource: " + resource.getFilename(), e); } return resource; }
From source file:org.yes.cart.web.service.rest.AuthenticationController.java
/** * Interface: GET /yes-api/rest/auth/check * <p>// w w w. j a v a2s .co m * <p> * Check interface that allows to check authentication state of user. The token for the authenticated cart is * returned back as response header and also as a cookie. * <p> * <p> * <h3>Headers for operation</h3><p> * <table border="1"> * <tr><td>Accept</td><td>application/json or application/xml</td></tr> * <tr><td>yc</td><td>token uuid</td></tr> * </table> * <p> * <p> * <h3>Parameters for operation</h3><p> * NONE * <p> * <p> * <h3>Output</h3><p> * * <table border="1"> * <tr><td>JSON example</td><td> * <pre><code> * { * "success" : true, * "greeting" : "Bob Doe", * "token" : { * "uuid" : "1db8def2-21e0-44d2-aeb0-56baae761129" * }, * "error" : null * } * </code></pre> * </td></tr> * <tr><td>XML example</td><td> * <pre><code> * <authentication-result> * <greeting>Bob Doe</greeting> * <success>true</success> * <token> * <uuid>1db8def2-21e0-44d2-aeb0-56baae761129</uuid> * </token> * </authentication-result> * </code></pre> * </td></tr> * </table> * <p> * <p> * <h3>Error codes</h3><p> * <table border="1"> * <tr><td>SESSION_EXPIRED</td><td>user session expired</td></tr> * <tr><td>INACTIVE_FOR_SHOP</td><td>user is inactive for shop</td></tr> * <tr><td>AUTH_FAILED</td><td>user exists but credentials are not valid</td></tr> * </table> * * * @param request request * @param response response * * @return authentication result */ @RequestMapping(value = "/check", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) public @ResponseBody AuthenticationResultRO check(final HttpServletRequest request, final HttpServletResponse response) { final ShoppingCart cart = cartMixin.getCurrentCart(); cartMixin.persistShoppingCart(request, response); switch (cart.getLogonState()) { case ShoppingCart.LOGGED_IN: return new AuthenticationResultRO(cart.getCustomerName(), new TokenRO(cart.getGuid())); case ShoppingCart.SESSION_EXPIRED: final AuthenticationResultRO authExpired = new AuthenticationResultRO(cart.getCustomerName(), new TokenRO(cart.getGuid())); authExpired.setAuthenticated(false); authExpired.setCode("SESSION_EXPIRED"); return authExpired; case ShoppingCart.INACTIVE_FOR_SHOP: final AuthenticationResultRO authInactive = new AuthenticationResultRO(cart.getCustomerName(), new TokenRO(cart.getGuid())); authInactive.setAuthenticated(false); authInactive.setCode("INACTIVE_FOR_SHOP"); return authInactive; case ShoppingCart.NOT_LOGGED: default: return new AuthenticationResultRO("AUTH_FAILED"); } }
From source file:org.yes.cart.web.service.rest.AuthenticationController.java
/** * Interface: PUT /yes-api/rest/auth/login * <p>//www . j a va2 s . c o m * <p> * Login interface that allows to authenticate user cart. The token for the authenticated cart is * returned back as response header and also as a cookie. * <p> * <p> * <h3>Headers for operation</h3><p> * <table border="1"> * <tr><td>Content-Type</td><td>application/json or application/xml</td></tr> * <tr><td>Accept</td><td>application/json or application/xml</td></tr> * <tr><td>yc</td><td>token uuid (optional)</td></tr> * </table> * <p> * <p> * <h3>Parameters for login PUT operation</h3><p> * <table border="1"> * <tr><td>JSON example</td><td> * <pre><code> * { * "username": "bob11@bob.com", * "password": "bBuyM-6-", * "activate": true * } * </code></pre> * </td></tr> * <tr><td>XML example</td><td> * <pre><code> * <login> * <username>bob11@bob.com</username> * <password>bBuyM-6-</password> * <activate>true</activate> * </login> * </code></pre> * </td></tr> * </table> * <p> * <p> * <h3>Output</h3><p> * * <table border="1"> * <tr><td>JSON example</td><td> * <pre><code> * { * "success" : true, * "greeting" : "Bob Doe", * "token" : { * "uuid" : "1db8def2-21e0-44d2-aeb0-56baae761129" * }, * "error" : null * } * </code></pre> * </td></tr> * <tr><td>XML example</td><td> * <pre><code> * <authentication-result> * <greeting>Bob Doe</greeting> * <success>true</success> * <token> * <uuid>1db8def2-21e0-44d2-aeb0-56baae761129</uuid> * </token> * </authentication-result> * </code></pre> * </td></tr> * </table> * <p> * <p> * <h3>Error codes</h3><p> * <table border="1"> * <tr><td>USER_FAILED</td><td>user does not exist</td></tr> * <tr><td>AUTH_FAILED</td><td>user exists but credentials are not valid</td></tr> * <tr><td>INACTIVE_FOR_SHOP</td><td>user exists but profile is active for given shop, use activate=true to force activation on login</td></tr> * </table> * * * @param loginRO login parameters (see examples above) * @param request request * @param response response * * @return authentication result */ @RequestMapping(value = "/login", method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) public @ResponseBody AuthenticationResultRO login(final @RequestBody LoginRO loginRO, final HttpServletRequest request, final HttpServletResponse response) { final Customer customer = customerServiceFacade.getCustomerByEmail(loginRO.getUsername()); if (customer != null) { do { executeLoginCommand(loginRO.getUsername(), loginRO.getPassword()); final TokenRO token = cartMixin.persistShoppingCart(request, response); ShoppingCart cart = cartMixin.getCurrentCart(); final int logOnState = cart.getLogonState(); if (logOnState == ShoppingCart.LOGGED_IN) { return new AuthenticationResultRO(cart.getCustomerName(), token); } else if (logOnState == ShoppingCart.INACTIVE_FOR_SHOP) { if (loginRO.isActivate()) { // Login again with inactive state adds customer to shop continue; } return new AuthenticationResultRO("INACTIVE_FOR_SHOP"); } else { // any other state should break to AUTH_FAILED break; } } while (true); return new AuthenticationResultRO("AUTH_FAILED"); } return new AuthenticationResultRO("USER_FAILED"); }
From source file:org.yes.cart.web.service.rest.AuthenticationController.java
/** * Interface: GET /yes-api/rest/auth/logout * <p>/*w ww. j a v a 2 s. c o m*/ * <p> * Logout interface that allows to de-authenticate user cart. The token for the authenticated cart is * returned back as response header and also as a cookie. * <p> * <p> * <h3>Headers for operation</h3><p> * <table border="1"> * <tr><td>Accept</td><td>application/json or application/xml</td></tr> * <tr><td>yc</td><td>token uuid</td></tr> * </table> * <p> * <p> * <h3>Parameters for logout operation</h3><p> * NONE * <p> * <p> * <h3>Output</h3><p> * * <table border="1"> * <tr><td>JSON example</td><td> * <pre><code> * { * "success" : true, * "greeting" : null, * "tokenRO" : null, * "error" : 'LOGOUT_SUCCESS' * } * </code></pre> * </td></tr> * <tr><td>XML example</td><td> * <pre><code> * <authentication-result> * <greeting>Bob Doe</greeting> * <success>true</success> * <token> * <uuid>1db8def2-21e0-44d2-aeb0-56baae761129</uuid> * </token> * </authentication-result> * </code></pre> * </td></tr> * </table> * <p> * <p> * <h3>Error codes</h3><p> * <table border="1"> * <tr><td>LOGOUT_SUCCESS</td><td>if logout was successful</td></tr> * </table> * * * @param request request * @param response response * * @return authentication result */ @RequestMapping(value = "/logout", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) public @ResponseBody AuthenticationResultRO logout(final HttpServletRequest request, final HttpServletResponse response) { final ShoppingCart cart = cartMixin.getCurrentCart(); if (cart.getLogonState() == ShoppingCart.LOGGED_IN) { executeLogoutCommand(); cartMixin.persistShoppingCart(request, response); } return new AuthenticationResultRO("LOGOUT_SUCCESS"); }
From source file:org.yes.cart.web.service.rest.AuthenticationController.java
/** * Interface: GET /yes-api/rest/auth/register * <p>/* w w w . j av a 2 s.com*/ * <p> * Interface to list all attributes required for registration * <p> * <p> * <h3>Headers for operation</h3><p> * <table border="1"> * <tr><td>Content-Type</td><td>application/json or application/xml</td></tr> * <tr><td>Accept</td><td>application/json or application/xml</td></tr> * <tr><td>yc</td><td>token uuid (optional)</td></tr> * </table> * <p> * <p> * <h3>Parameters for register GET operation</h3><p> * <p> * NONE * <p> * <h3>Output</h3><p> * <table border="1"> * <tr><td>JSON example</td><td> * <pre><code> * { * "phone" : null, * "custom" : [ * { * "attrvalueId" : 0, * "val" : null, * "displayVals" : null, * "attributeName" : "Marketing Opt in", * "attributeId" : 11051, * "attributeDisplayNames" : {}, * "attributeDisplayChoices" : {}, * "customerId" : 0 * }, * { * "attrvalueId" : 0, * "val" : null, * "displayVals" : null, * "attributeName" : "Customer Type", * "attributeId" : 1611, * "attributeDisplayNames" : { * "uk" : " ?", * "en" : "Customer Type" * }, * "attributeDisplayChoices" : { * "uk" : "B-,S-", * "ru" : "B-,S-", * "en" : "B-Buyer,S-Seller" * }, * "customerId" : 0 * } * ], * "lastname" : null, * "firstname" : null, * "email" : null * } * </code></pre> * </td></tr> * <tr><td>XML example</td><td> * <pre><code> * <register-form> * <custom> * <attribute attribute-id="11051" attrvalue-id="0" customer-id="0"> * <attribute-display-choices/> * <attribute-display-names/> * <attribute-name>Marketing Opt in</attribute-name> * </attribute> * <attribute attribute-id="1611" attrvalue-id="0" customer-id="0"> * <attribute-display-choices> * <entry lang="uk">B-,S-</entry> * <entry lang="en">B-Buyer,S-Seller</entry> * <entry lang="ru">B-,S-</entry> * </attribute-display-choices> * <attribute-display-names> * <entry lang="uk"> ?</entry> * <entry lang="en">Customer Type</entry> * </attribute-display-names> * <attribute-name>Customer Type</attribute-name> * </attribute> * </custom> * </register-form> * </code></pre> * </td></tr> * </table> * <p> * <p> * * @param request request * @param response response * * @return registration data */ @RequestMapping(value = "/register", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) public @ResponseBody RegisterFormRO register(final HttpServletRequest request, final HttpServletResponse response) { cartMixin.persistShoppingCart(request, response); final Shop shop = cartMixin.getCurrentShop(); final List<AttrValueCustomer> avs = customerServiceFacade.getShopRegistrationAttributes(shop); final RegisterFormRO formRO = new RegisterFormRO(); formRO.setCustom(mappingMixin.map(avs, AttrValueCustomerRO.class, AttrValueCustomer.class)); return formRO; }
From source file:org.yes.cart.web.service.rest.AuthenticationController.java
/** * Interface: PUT /yes-api/rest/auth/register * <p>//from w w w . jav a 2 s . c o m * <p> * Register interface that allows to register user. The token for the authenticated cart is * returned back as response header and also as a cookie. * <p> * <p> * <h3>Headers for operation</h3><p> * <table border="1"> * <tr><td>Content-Type</td><td>application/json or application/xml</td></tr> * <tr><td>Accept</td><td>application/json or application/xml</td></tr> * <tr><td>yc</td><td>token uuid (optional)</td></tr> * </table> * <p> * <p> * <h3>Parameters for register PUT operation</h3><p> * <p> * <p> * <table border="1"> * <tr><td>JSON example:</td><td> * <pre><code> * { * "email" : "bobdoe@yes-cart.org", * "firstname" : "Bob", * "lastname" : "Doe", * "phone" : "123123123123", * "custom" : { * "attr1": "value1", * "attr2": "value2", * ... * "attrN": "valueN" * } * } * </code></pre> * </td></tr> * <tr><td>XML example:</td><td> * <pre><code> * <login> * <email>bobdoe@yes-cart.org</email> * <firstname>Bob</firstname> * <lastname>Doe</lastname> * <phone>123123123123</phone> * <custom> * <entry key="attr1">value1</entry> * <entry key="attr2">value2</entry> * ... * <entry key="attrN">valueN</entry> * </custom> * </login> * </code></pre> * </td></tr> * </table> * <p> * <p> * <h3>Output</h3><p> * <table border="1"> * <tr><td>JSON example</td><td> * <pre><code> * { * "success" : true, * "greeting" : "Bob Doe", * "token" : { * "uuid" : "1db8def2-21e0-44d2-aeb0-56baae761129" * }, * "error" : null * } * </code></pre> * </td></tr> * <tr><td>XML example</td><td> * <pre><code> * <authentication-result> * <greeting>Bob Doe</greeting> * <success>true</success> * <token> * <uuid>1db8def2-21e0-44d2-aeb0-56baae761129</uuid> * </token> * </authentication-result> * </code></pre> * </td></tr> * </table> * <p> * <p> * <h3>Error codes</h3><p> * <table border="1"> * <tr><td>EMAIL_FAILED</td><td>email must be more than 6 and less than 256 chars (^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*((\.[A-Za-z]{2,}){1}$)) </td></tr> * <tr><td>FIRSTNAME_FAILED</td><td>must be not blank</td></tr> * <tr><td>LASTNAME_FAILED</td><td>must be not blank</td></tr> * <tr><td>PHONE_FAILED</td><td>phone must be more than 4 and less than 13 chars</td></tr> * <tr><td>[ATTRIBUTE CODE]:FAILED</td><td> * E.g. CUSTOMERTYPE_FAILED denoting that mandatory value was missing (could also happen if regex fails but there is no * validation message specified on the {@link org.yes.cart.domain.entity.Attribute#getValidationFailedMessage()}) * </td></tr> * <tr><td>[ATTRIBUTE CODE]:FAILED:[Message]</td><td> * E.g. "CUSTOMERTYPE:FAILED:Please choose either Buyer or Seller (UK)" denoting that regex test failed. * RegEx and Message come from {@link org.yes.cart.domain.entity.Attribute#getRegexp()} and * {@link org.yes.cart.domain.entity.Attribute#getValidationFailedMessage()} respectively * </td></tr> * <tr><td>USER_FAILED</td><td>email must not be already registered</td></tr> * </table> * * * @param registerRO register parameters (see examples above) * @param request request * @param response response * * @return authentication result */ @RequestMapping(value = "/register", method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }, consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) public @ResponseBody AuthenticationResultRO register(final @RequestBody RegisterRO registerRO, final HttpServletRequest request, final HttpServletResponse response) { if (StringUtils.isBlank(registerRO.getEmail()) || registerRO.getEmail().length() < 6 || registerRO.getEmail().length() > 256 || !EMAIL.matcher(registerRO.getEmail()).matches()) { return new AuthenticationResultRO("EMAIL_FAILED"); } if (StringUtils.isBlank(registerRO.getFirstname())) { return new AuthenticationResultRO("FIRSTNAME_FAILED"); } if (StringUtils.isBlank(registerRO.getLastname())) { return new AuthenticationResultRO("LASTNAME_FAILED"); } if (StringUtils.isBlank(registerRO.getPhone()) || registerRO.getPhone().length() < 4 || registerRO.getPhone().length() > 13) { return new AuthenticationResultRO("PHONE_FAILED"); } if (customerServiceFacade.isCustomerRegistered(registerRO.getEmail())) { return new AuthenticationResultRO("USER_FAILED"); } final ShoppingCart cart = cartMixin.getCurrentCart(); final Shop shop = cartMixin.getCurrentShop(); final Map<String, Object> data = new HashMap<String, Object>(); if (registerRO.getCustom() != null) { for (final AttrValueCustomer av : customerServiceFacade.getShopRegistrationAttributes(shop)) { final Attribute attr = av.getAttribute(); final String value = registerRO.getCustom().get(attr.getCode()); if (attr.isMandatory() && StringUtils.isBlank(value)) { return new AuthenticationResultRO(attr.getCode() + ":FAILED"); } else if (StringUtils.isNotBlank(attr.getRegexp()) && !Pattern.compile(attr.getRegexp()).matcher(value).matches()) { final String regexError = new FailoverStringI18NModel(attr.getValidationFailedMessage(), null) .getValue(cart.getCurrentLocale()); if (StringUtils.isBlank(regexError)) { return new AuthenticationResultRO(attr.getCode() + ":FAILED"); } return new AuthenticationResultRO(attr.getCode() + ":FAILED:" + regexError); } else { data.put(attr.getCode(), value); } } } data.put("firstname", registerRO.getFirstname()); data.put("lastname", registerRO.getLastname()); data.put("phone", registerRO.getPhone()); final String password = customerServiceFacade.registerCustomer(shop, registerRO.getEmail(), data); final LoginRO loginRO = new LoginRO(); loginRO.setUsername(registerRO.getEmail()); loginRO.setPassword(password); return login(loginRO, request, response); }