List of usage examples for org.springframework.web.context.request ServletWebRequest ServletWebRequest
public ServletWebRequest(HttpServletRequest request)
From source file:ch.ralscha.extdirectspring.util.ParametersResolver.java
@SuppressWarnings("unchecked") public Object[] resolveParameters(HttpServletRequest request, HttpServletResponse response, Locale locale, ExtDirectRequest directRequest, MethodInfo methodInfo) throws Exception { int jsonParamIndex = 0; Map<String, Object> remainingParameters = null; ExtDirectStoreReadRequest extDirectStoreReadRequest = null; List<Object> directStoreModifyRecords = null; Class<?> directStoreEntryClass; if (methodInfo.isType(ExtDirectMethodType.STORE_READ) || methodInfo.isType(ExtDirectMethodType.FORM_LOAD) || methodInfo.isType(ExtDirectMethodType.TREE_LOAD)) { List<Object> data = (List<Object>) directRequest.getData(); if (data != null && data.size() > 0) { if (methodInfo.isType(ExtDirectMethodType.STORE_READ)) { extDirectStoreReadRequest = new ExtDirectStoreReadRequest(); remainingParameters = fillReadRequestFromMap(extDirectStoreReadRequest, (Map<String, Object>) data.get(0)); } else { remainingParameters = (Map<String, Object>) data.get(0); }//www .ja v a 2s .c o m jsonParamIndex = 1; } } else if (methodInfo.isType(ExtDirectMethodType.STORE_MODIFY)) { directStoreEntryClass = methodInfo.getCollectionType(); List<Object> data = (List<Object>) directRequest.getData(); if (directStoreEntryClass != null && data != null && data.size() > 0) { Object obj = data.get(0); if (obj instanceof List) { directStoreModifyRecords = convertObjectEntriesToType((List<Object>) obj, directStoreEntryClass); } else { Map<String, Object> jsonData = (Map<String, Object>) obj; Object records = jsonData.get("records"); if (records != null) { if (records instanceof List) { directStoreModifyRecords = convertObjectEntriesToType((List<Object>) records, directStoreEntryClass); } else { directStoreModifyRecords = new ArrayList<Object>(); directStoreModifyRecords .add(this.jsonHandler.convertValue(records, directStoreEntryClass)); } remainingParameters = new HashMap<String, Object>(jsonData); remainingParameters.remove("records"); } else { directStoreModifyRecords = new ArrayList<Object>(); directStoreModifyRecords .add(this.jsonHandler.convertValue(jsonData, directStoreEntryClass)); } } jsonParamIndex = 1; } else if (data != null && data.size() > 0) { Object obj = data.get(0); if (obj instanceof Map) { remainingParameters = new HashMap<String, Object>((Map<String, Object>) obj); remainingParameters.remove("records"); } } } else if (methodInfo.isType(ExtDirectMethodType.SIMPLE_NAMED)) { Map<String, Object> data = (Map<String, Object>) directRequest.getData(); if (data != null && data.size() > 0) { remainingParameters = new HashMap<String, Object>(data); } } else if (methodInfo.isType(ExtDirectMethodType.POLL)) { throw new IllegalStateException("this controller does not handle poll calls"); } else if (methodInfo.isType(ExtDirectMethodType.FORM_POST)) { throw new IllegalStateException("this controller does not handle form posts"); } else if (methodInfo.isType(ExtDirectMethodType.FORM_POST_JSON)) { List<Object> data = (List<Object>) directRequest.getData(); if (data != null && data.size() > 0) { Object obj = data.get(0); if (obj instanceof Map) { remainingParameters = new HashMap<String, Object>((Map<String, Object>) obj); remainingParameters.remove("records"); } } } List<ParameterInfo> methodParameters = methodInfo.getParameters(); Object[] parameters = null; if (!methodParameters.isEmpty()) { parameters = new Object[methodParameters.size()]; for (int paramIndex = 0; paramIndex < methodParameters.size(); paramIndex++) { ParameterInfo methodParameter = methodParameters.get(paramIndex); if (methodParameter.isSupportedParameter()) { parameters[paramIndex] = SupportedParameters.resolveParameter(methodParameter.getType(), request, response, locale, directRequest); } else if (ExtDirectStoreReadRequest.class.isAssignableFrom(methodParameter.getType())) { parameters[paramIndex] = extDirectStoreReadRequest; } else if (directStoreModifyRecords != null && methodParameter.getCollectionType() != null) { parameters[paramIndex] = directStoreModifyRecords; } else if (methodParameter.hasRequestParamAnnotation()) { parameters[paramIndex] = resolveRequestParam(null, remainingParameters, methodParameter); } else if (methodParameter.hasMetadataParamAnnotation()) { parameters[paramIndex] = resolveRequestParam(null, directRequest.getMetadata(), methodParameter); } else if (methodParameter.hasRequestHeaderAnnotation()) { parameters[paramIndex] = resolveRequestHeader(request, methodParameter); } else if (methodParameter.hasCookieValueAnnotation()) { parameters[paramIndex] = resolveCookieValue(request, methodParameter); } else if (methodParameter.hasAuthenticationPrincipalAnnotation()) { parameters[paramIndex] = resolveAuthenticationPrincipal(methodParameter); } else if (remainingParameters != null && remainingParameters.containsKey(methodParameter.getName())) { Object jsonValue = remainingParameters.get(methodParameter.getName()); parameters[paramIndex] = convertValue(jsonValue, methodParameter); } else if (directRequest.getData() != null && directRequest.getData() instanceof List && ((List<Object>) directRequest.getData()).size() > jsonParamIndex) { Object jsonValue = ((List<Object>) directRequest.getData()).get(jsonParamIndex); parameters[paramIndex] = convertValue(jsonValue, methodParameter); jsonParamIndex++; } else { if (methodInfo.isType(ExtDirectMethodType.SIMPLE_NAMED)) { if (Map.class.isAssignableFrom(methodParameter.getType())) { parameters[paramIndex] = remainingParameters; continue; } else if (methodParameter.isJavaUtilOptional()) { parameters[paramIndex] = javaUtilOptionalEmpty; continue; } } log.info("WebResolvers size:" + this.webArgumentResolvers.size()); log.info("ParamIndex:" + paramIndex); log.info("Request params size:" + request.getParameterMap().isEmpty()); log.info("Request params names:" + request.getParameterMap().keySet()); log.info("Direct Request:" + directRequest.toString()); MethodParameter p = new MethodParameter(methodInfo.getMethod(), paramIndex); request.setAttribute("directRequest", directRequest); request.setAttribute("extDirectStoreReadRequest", extDirectStoreReadRequest); ServletWebRequest r = new ServletWebRequest(request); Object result = WebArgumentResolver.UNRESOLVED; for (WebArgumentResolver resolver : this.webArgumentResolvers) { log.info("Resolving with:" + resolver.getClass().getCanonicalName()); result = resolver.resolveArgument(p, r); if (result != WebArgumentResolver.UNRESOLVED) { log.info("Resolved by:" + resolver.getClass().getCanonicalName()); parameters[paramIndex] = result; break; } } if (result == WebArgumentResolver.UNRESOLVED) { throw new IllegalArgumentException( "Error, parameter mismatch. Please check your remoting method signature to ensure all supported parameters types are used."); } } } } return parameters; }
From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java
/** * @see ShortPatientFormController#saveShortPatient(WebRequest,PersonName,ShortPatientModel,Map,BindingResult, SessionStatus) *//*from w ww.j a v a 2 s . c o m*/ @Test @Verifies(value = "should add a new address if the person had none", method = "saveShortPatient(WebRequest,PersonName,ShortPatientModel,BindingResult,SessionStatus)") public void saveShortPatient_shouldAddANewAddressIfThePersonHadNone() throws Exception { Patient p = Context.getPatientService().getPatient(2); p.getPersonAddress().setVoided(true); Context.getPatientService().savePatient(p); Assert.assertNull(p.getPersonAddress());// make sure all addresses are // voided // add a name that will used as a duplicate for testing purposes PersonAddress newAddress = new PersonAddress(); newAddress.setAddress1("Kampala"); newAddress.setDateCreated(new Date()); ShortPatientModel patientModel = new ShortPatientModel(p); patientModel.setPersonAddress(newAddress); BindException errors = new BindException(patientModel, "patientModel"); ServletWebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest()); ShortPatientFormController controller = (ShortPatientFormController) applicationContext .getBean("shortPatientFormController"); String redirectUrl = controller.saveShortPatient(mockWebRequest, (PersonName) BeanUtils.cloneBean(p.getPersonName()), new PersonAddress(), null, patientModel, errors); Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors()); Assert.assertEquals("redirect:/patientDashboard.form?patientId=" + p.getPatientId(), redirectUrl); Assert.assertNotNull(newAddress.getId());// name should have been added // to DB }
From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java
/** * @see ShortPatientFormController#saveShortPatient(WebRequest,PersonName,PersonAddress,ShortPatientModel,BindingResult,SessionStatus) *///from w w w . ja v a 2 s. c o m @Test @Verifies(value = "should ignore a new address that was added and voided at same time", method = "saveShortPatient(WebRequest,PersonName,PersonAddress,ShortPatientModel,BindingResult,SessionStatus)") public void saveShortPatient_shouldIgnoreANewAddressThatWasAddedAndVoidedAtSameTime() throws Exception { Patient p = Context.getPatientService().getPatient(2); p.getPersonAddress().setVoided(true); Context.getPatientService().savePatient(p); // make sure all addresses are voided so that whatever is entered a new // address Assert.assertNull(p.getPersonAddress()); // add the new address PersonAddress newAddress = new PersonAddress(); newAddress.setAddress1("Kampala"); newAddress.setDateCreated(new Date()); newAddress.setVoided(true); ShortPatientModel patientModel = new ShortPatientModel(p); patientModel.setPersonAddress(newAddress); BindException errors = new BindException(patientModel, "patientModel"); ServletWebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest()); ShortPatientFormController controller = (ShortPatientFormController) applicationContext .getBean("shortPatientFormController"); String redirectUrl = controller.saveShortPatient(mockWebRequest, (PersonName) BeanUtils.cloneBean(p.getPersonName()), new PersonAddress(), null, patientModel, errors); Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors()); Assert.assertEquals("redirect:/patientDashboard.form?patientId=" + p.getPatientId(), redirectUrl); // address should have been ignored Assert.assertNull(p.getPersonAddress()); }
From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java
/** * @see ShortPatientFormController#saveShortPatient(WebRequest,PersonName,PersonAddress,Map,ShortPatientModel, BindingResult) *///w w w. ja v a 2 s. c o m @Test @Verifies(value = "should add a new person attribute with a non empty value", method = "saveShortPatient(WebRequest,PersonName,PersonAddress,ShortPatientModel,BindingResult)") public void saveShortPatient_shouldAddANewPersonAttributeWithANonEmptyValue() throws Exception { Patient p = Context.getPatientService().getPatient(2); int originalAttributeCount = p.getAttributes().size(); ShortPatientModel patientModel = new ShortPatientModel(p); int attributeTypeId = 2; String birthPlace = "Kampala"; PersonAttribute newPersonAttribute = new PersonAttribute( Context.getPersonService().getPersonAttributeType(attributeTypeId), birthPlace); newPersonAttribute.setDateCreated(new Date()); newPersonAttribute.setCreator(Context.getAuthenticatedUser()); patientModel.getPersonAttributes().add(newPersonAttribute); WebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest()); BindException errors = new BindException(patientModel, "patientModel"); mockWebRequest.setAttribute("personNameCache", p.getPersonName(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("personAddressCache", p.getPersonAddress(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("patientModel", patientModel, WebRequest.SCOPE_SESSION); ShortPatientFormController controller = (ShortPatientFormController) applicationContext .getBean("shortPatientFormController"); String redirectUrl = controller.saveShortPatient(mockWebRequest, (PersonName) mockWebRequest.getAttribute("personNameCache", WebRequest.SCOPE_SESSION), (PersonAddress) mockWebRequest.getAttribute("personAddressCache", WebRequest.SCOPE_SESSION), null, (ShortPatientModel) mockWebRequest.getAttribute("patientModel", WebRequest.SCOPE_SESSION), errors); Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors()); Assert.assertEquals("Patient.saved", mockWebRequest.getAttribute(WebConstants.OPENMRS_MSG_ATTR, WebRequest.SCOPE_SESSION)); Assert.assertEquals("redirect:/patientDashboard.form?patientId=" + p.getPatientId(), redirectUrl); //The new person attribute should have been added and saved Assert.assertNotNull(p.getAttribute(2).getPersonAttributeId()); Assert.assertEquals(birthPlace, p.getAttribute(2).getValue()); Assert.assertEquals(originalAttributeCount + 1, p.getAttributes().size()); }
From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java
/** * @see ShortPatientFormController#saveShortPatient(WebRequest,PersonName,PersonAddress,Map,ShortPatientModel, BindingResult) *///from ww w .jav a 2s .c o m @Test @Verifies(value = "should not add a new person attribute with an empty value", method = "saveShortPatient(WebRequest,PersonName,PersonAddress,ShortPatientModel,BindingResult)") public void saveShortPatient_shouldNotAddANewPersonAttributeWithAnEmptyValue() throws Exception { Patient p = Context.getPatientService().getPatient(2); int originalAttributeCount = p.getAttributes().size(); ShortPatientModel patientModel = new ShortPatientModel(p); //add a new person Attribute with no value patientModel.getPersonAttributes() .add(new PersonAttribute(Context.getPersonService().getPersonAttributeType(2), null)); WebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest()); BindException errors = new BindException(patientModel, "patientModel"); mockWebRequest.setAttribute("personNameCache", p.getPersonName(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("personAddressCache", p.getPersonAddress(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("patientModel", patientModel, WebRequest.SCOPE_SESSION); ShortPatientFormController controller = (ShortPatientFormController) applicationContext .getBean("shortPatientFormController"); String redirectUrl = controller.saveShortPatient(mockWebRequest, (PersonName) mockWebRequest.getAttribute("personNameCache", WebRequest.SCOPE_SESSION), (PersonAddress) mockWebRequest.getAttribute("personAddressCache", WebRequest.SCOPE_SESSION), null, (ShortPatientModel) mockWebRequest.getAttribute("patientModel", WebRequest.SCOPE_SESSION), errors); Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors()); Assert.assertEquals("Patient.saved", mockWebRequest.getAttribute(WebConstants.OPENMRS_MSG_ATTR, WebRequest.SCOPE_SESSION)); Assert.assertEquals("redirect:/patientDashboard.form?patientId=" + p.getPatientId(), redirectUrl); //The new blank person attribute should have been ignored Assert.assertEquals(originalAttributeCount, p.getAttributes().size()); }
From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java
/** * @see ShortPatientFormController#saveShortPatient(WebRequest,PersonName,PersonAddress,Map,ShortPatientModel, BindingResult) *//*w w w . ja va 2s . com*/ @Test @Verifies(value = "should void an existing person attribute with an empty value", method = "saveShortPatient(WebRequest,PersonName,PersonAddress,ShortPatientModel,BindingResult)") public void saveShortPatient_shouldVoidAnExistingPersonAttributeWithAnEmptyValue() throws Exception { int attributeTypeId = 8; PersonAttributeType pat = Context.getPersonService().getPersonAttributeType(attributeTypeId); //For this test to pass we need to have some viewable attributes to be displayed on the form for editing AdministrationService as = Context.getAdministrationService(); GlobalProperty gp = as.getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_VIEWING_ATTRIBUTES); if (gp == null) gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_VIEWING_ATTRIBUTES); gp.setPropertyValue(pat.getName()); as.saveGlobalProperty(gp); Patient p = Context.getPatientService().getPatient(2); int originalActiveAttributeCount = p.getActiveAttributes().size(); ShortPatientModel patientModel = new ShortPatientModel(p); PersonAttribute attributeToEdit = null; String oldValue = null; String newValue = ""; //assuming we are in the webapp on the form, find the attribute with the matching // attribute type and change its value to an empty string for (PersonAttribute at : patientModel.getPersonAttributes()) { if (at.getAttributeType().equals(pat)) { oldValue = at.getValue(); at.setValue(newValue); attributeToEdit = at; break; } } //ensure we found and edited it Assert.assertNotNull(attributeToEdit); Assert.assertNotNull(oldValue); WebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest()); BindException errors = new BindException(patientModel, "patientModel"); mockWebRequest.setAttribute("personNameCache", p.getPersonName(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("personAddressCache", p.getPersonAddress(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("patientModel", patientModel, WebRequest.SCOPE_SESSION); ShortPatientFormController controller = (ShortPatientFormController) applicationContext .getBean("shortPatientFormController"); controller.saveShortPatient(mockWebRequest, (PersonName) mockWebRequest.getAttribute("personNameCache", WebRequest.SCOPE_SESSION), (PersonAddress) mockWebRequest.getAttribute("personAddressCache", WebRequest.SCOPE_SESSION), null, (ShortPatientModel) mockWebRequest.getAttribute("patientModel", WebRequest.SCOPE_SESSION), errors); Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors()); Assert.assertEquals("Patient.saved", mockWebRequest.getAttribute(WebConstants.OPENMRS_MSG_ATTR, WebRequest.SCOPE_SESSION)); //the attribute should have been voided Assert.assertEquals(originalActiveAttributeCount - 1, p.getActiveAttributes().size()); }
From source file:alfio.controller.ReservationFlowIntegrationTest.java
private String reserveTicket(String eventName) { ReservationForm reservationForm = new ReservationForm(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); ServletWebRequest servletWebRequest = new ServletWebRequest(request); BindingResult bindingResult = new BeanPropertyBindingResult(reservationForm, "reservation"); Model model = new BindingAwareModelMap(); RedirectAttributes redirectAttributes = new RedirectAttributesModelMap(); TicketReservationModification ticketReservation = new TicketReservationModification(); ticketReservation.setAmount(1);/* w w w . ja v a2 s . com*/ ticketReservation.setTicketCategoryId(ticketCategoryRepository.findByEventId(event.getId()).stream() .findFirst().map(TicketCategory::getId).orElseThrow(IllegalStateException::new)); reservationForm.setReservation(Collections.singletonList(ticketReservation)); return eventController.reserveTicket(eventName, reservationForm, bindingResult, model, servletWebRequest, redirectAttributes, Locale.ENGLISH); }
From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java
/** * @see ShortPatientFormController#saveShortPatient(WebRequest,PersonName,PersonAddress,Map,ShortPatientModel, BindingResult) */// w w w. ja v a 2 s . c om @Test @Verifies(value = "should should replace an existing attribute with a new one when edited", method = "saveShortPatient(WebRequest,PersonName,PersonAddress,ShortPatientModel,BindingResult)") public void saveShortPatient_shouldShouldReplaceAnExistingAttributeWithANewOneWhenEdited() throws Exception { int attributeTypeId = 2; PersonAttributeType pat = Context.getPersonService().getPersonAttributeType(attributeTypeId); //For this test to pass we need to have some viewable attributes to be displayed on the form for editing AdministrationService as = Context.getAdministrationService(); GlobalProperty gp = as.getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_VIEWING_ATTRIBUTES); if (gp == null) gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_VIEWING_ATTRIBUTES); gp.setPropertyValue(pat.getName()); as.saveGlobalProperty(gp); Patient p = Context.getPatientService().getPatient(2); int originalAttributeCount = p.getAttributes().size(); ShortPatientModel patientModel = new ShortPatientModel(p); PersonAttribute attributeToEdit = null; String oldValue = null; String newValue = "New"; //assuming we are in the webapp on the form, find the attribute with the matching // attribute type and change its value for (PersonAttribute at : patientModel.getPersonAttributes()) { if (at.getAttributeType().equals(pat)) { oldValue = at.getValue(); at.setValue(newValue); attributeToEdit = at; break; } } //ensure we found and edited it Assert.assertNotNull(attributeToEdit); Assert.assertNotNull(oldValue); WebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest()); BindException errors = new BindException(patientModel, "patientModel"); mockWebRequest.setAttribute("personNameCache", p.getPersonName(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("personAddressCache", p.getPersonAddress(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("patientModel", patientModel, WebRequest.SCOPE_SESSION); ShortPatientFormController controller = (ShortPatientFormController) applicationContext .getBean("shortPatientFormController"); controller.saveShortPatient(mockWebRequest, (PersonName) mockWebRequest.getAttribute("personNameCache", WebRequest.SCOPE_SESSION), (PersonAddress) mockWebRequest.getAttribute("personAddressCache", WebRequest.SCOPE_SESSION), null, (ShortPatientModel) mockWebRequest.getAttribute("patientModel", WebRequest.SCOPE_SESSION), errors); Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors()); Assert.assertEquals("Patient.saved", mockWebRequest.getAttribute(WebConstants.OPENMRS_MSG_ATTR, WebRequest.SCOPE_SESSION)); //a new replacement attribute should have been created with the new value PersonAttribute newAttribute = p.getAttribute(attributeTypeId); Assert.assertEquals(originalAttributeCount + 1, p.getAttributes().size()); Assert.assertEquals(newValue, newAttribute.getValue()); PersonAttribute oldAttribute = null; //find the voided attribute for (PersonAttribute at : p.getAttributes()) { //skip past the new one since it will be having a matching attribute type //and find exactly the attribute with the expected void reason if (at.getAttributeType().equals(pat) && OpenmrsUtil.nullSafeEquals("New value: " + newValue, at.getVoidReason())) { oldAttribute = at; break; } } //The old attribute should have been voided and maintained its old value Assert.assertNotNull(oldAttribute); Assert.assertEquals(oldValue, oldAttribute.getValue()); Assert.assertTrue(oldAttribute.isVoided()); }
From source file:org.beadle.framework.view.ReturnTypeViewResolver.java
/** * Determines the list of {@link MediaType} for the given {@link HttpServletRequest}. * @param request the current servlet request * @return the list of media types requested, if any *//*from w ww .j a v a 2 s .co m*/ protected List<MediaType> getMediaTypes(HttpServletRequest request) { try { ServletWebRequest webRequest = new ServletWebRequest(request); List<MediaType> acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest); acceptableMediaTypes = acceptableMediaTypes.isEmpty() ? Collections.singletonList(MediaType.ALL) : acceptableMediaTypes; List<MediaType> producibleMediaTypes = getProducibleMediaTypes(request); Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>(); for (MediaType acceptable : acceptableMediaTypes) { for (MediaType producible : producibleMediaTypes) { if (acceptable.isCompatibleWith(producible)) { compatibleMediaTypes.add(getMostSpecificMediaType(acceptable, producible)); } } } List<MediaType> selectedMediaTypes = new ArrayList<MediaType>(compatibleMediaTypes); MediaType.sortBySpecificityAndQuality(selectedMediaTypes); if (logger.isDebugEnabled()) { logger.debug("Requested media types are " + selectedMediaTypes + " based on Accept header types " + "and producible media types " + producibleMediaTypes + ")"); } return selectedMediaTypes; } catch (HttpMediaTypeNotAcceptableException ex) { return null; } }