本文整理匯總了Java中javax.ws.rs.core.MultivaluedMap類的典型用法代碼示例。如果您正苦於以下問題:Java MultivaluedMap類的具體用法?Java MultivaluedMap怎麽用?Java MultivaluedMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MultivaluedMap類屬於javax.ws.rs.core包,在下文中一共展示了MultivaluedMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createInstance
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
/**
* Create a broker Instance
*
* @param brokerName
* @return
* @throws CloudKarafkaServiceException
*/
public CloudKarafkaCreateInstanceResponse createInstance(final String brokerName,
final String plan) throws CloudKarafkaServiceException {
// build input form
final MultivaluedMap<String, String> form = new MultivaluedHashMap<>();
form.add("name", brokerName);
form.add("plan", plan);
form.add("region", brokerConfig.getCloudKarafkaRegion());
//build post request
final String target = String.format("%s/%s", brokerConfig.getCloudkarafkaApiUrl(), "instances");
final WebTarget webTarget = client.target(target);
// call create broker instances API
return webTarget.request(MediaType.APPLICATION_JSON)
.post(Entity.form(form), CloudKarafkaCreateInstanceResponse.class);
}
示例2: readFrom
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Override
public Representation readFrom(Class<Representation> type,
Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try (InputStreamReader reader = new InputStreamReader(entityStream,
CommonParams.CHARSET)) {
Gson gson = new GsonBuilder().setDateFormat(
CommonParams.FORMAT_DATE).create();
return gson.fromJson(reader, genericType);
} catch (JsonSyntaxException e) {
throw WebException.badRequest()
.message(CommonParams.ERROR_JSON_FORMAT)
.moreInfo(e.getMessage()).build();
}
}
示例3: writeTo
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Override public void writeTo(
Object object, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException, WebApplicationException {
try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8)) {
Type jsonType;
if (type.equals(genericType)) {
jsonType = type;
} else {
jsonType = genericType;
}
Globals.newGson().toJson(object, jsonType, writer);
}
}
示例4: map_ReturnsOptionalParameter_WithValidData
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Test
public void map_ReturnsOptionalParameter_WithValidData() {
// Arrange
MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>();
// Note there are multiple values for this parameter, to test that the first value is used only
queryParameters.put(optionalParameter.getName(), ImmutableList.of("value", "valueB"));
when(uriInfoMock.getQueryParameters()).thenReturn(queryParameters);
// Act
Map<String, String> result = representationRequestParameterMapper.map(product, contextMock);
// Assert
assertThat(result.size(), is(1));
assertThat(result, hasEntry(optionalParameter.getName(), "value"));
}
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:18,代碼來源:RepresentationRequestParameterMapperTest.java
示例5: writeTo
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Override
public void writeTo(CharmAttachmentPost attachment, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmAttachmentPost.class);
Marshaller taskMarshaller = context.createMarshaller();
taskMarshaller.marshal(attachment, entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error serializing Attachment to output stream");
}
}
示例6: readFrom
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Override
public Object readFrom(
final Class<Object> type,
final Type genericType,
final Annotation[] annotations,
final MediaType mediaType,
final MultivaluedMap<String, String> httpHeaders,
final InputStream entityStream)
throws IOException {
try {
return objectMapper.readValue(entityStream, type);
} catch (final JsonProcessingException ex) {
throw new BadRequestException(ex.getMessage(), ex);
}
}
示例7: map_ReturnsRequiredParameter_WithValidData
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Test
public void map_ReturnsRequiredParameter_WithValidData() {
// Arrange
MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>();
// Note there are multiple values for this parameter, to test that the first value is used only
queryParameters.put(requiredParameter.getName(), ImmutableList.of("value", "valueB"));
when(uriInfoMock.getQueryParameters()).thenReturn(queryParameters);
// Act
Map<String, String> result = representationRequestParameterMapper.map(product, contextMock);
// Assert
assertThat(result.size(), is(1));
assertThat(result, hasEntry(requiredParameter.getName(), "value"));
}
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:18,代碼來源:RepresentationRequestParameterMapperTest.java
示例8: map_ReturnsCorrectParameterName_ForQueryParameter
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Test
public void map_ReturnsCorrectParameterName_ForQueryParameter() {
// Arrange
QueryParameter queryParameter = new QueryParameter();
queryParameter.setName("param1");
queryParameter.setIn("query");
queryParameter.setVendorExtension(OpenApiSpecificationExtensions.PARAMETER,
parameter.getIdentifier().stringValue());
Operation operation = new Operation();
operation.addParameter(queryParameter);
MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>();
queryParameters.put(queryParameter.getName(), ImmutableList.of("value", "valueB"));
// Act
Map<String, String> result = mapper.map(operation, product, requestParameters);
// Assert
assertThat(result.size(), is(1));
assertThat(result, hasEntry(parameter.getName(), "value"));
}
示例9: testGet
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Test
public void testGet() throws Exception {
MockRequestParameters params = new MockRequestParameters();
params.setId(1L);
UriInfo uriinfo = mock(UriInfo.class);
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle(CommonParams.PARAM_VERSION, "v" + Integer.valueOf(CommonParams.VERSION_1).toString());
Mockito.when(uriinfo.getPathParameters()).thenReturn(map);
Response response = get(uriinfo, backendGet, params, true);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertNotNull(response.getEntity());
assertThat(response.getEntity(), instanceOf(MockRepresentation.class));
}
示例10: testVersionFilter
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@SuppressWarnings("boxing")
private MultivaluedMap<String, String> testVersionFilter(String version) throws WebApplicationException, NoSuchMethodException {
ResourceInfo resourceInfo = mock(ResourceInfo.class);
ContainerRequestContext request = mock(ContainerRequestContext.class);
UriInfo uriInfo = mock(UriInfo.class);
when(request.getUriInfo()).thenReturn(uriInfo);
Method method = SinceClass.class.getMethod("dummy");
MultivaluedMap<String, String> prop = new MultivaluedHashMap<>();
prop.putSingle(CommonParams.PARAM_VERSION, version);
when(uriInfo.getPathParameters()).thenReturn(prop);
VersionFilter filter = spy(new VersionFilter());
when(filter.getResourceInfo()).thenReturn(resourceInfo);
when(resourceInfo.getResourceMethod()).thenReturn(method);
filter.filter(request);
return prop;
}
示例11: extAuthnHandlerSetsErrorAttributeWhenIdentificationFails
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Test
public void extAuthnHandlerSetsErrorAttributeWhenIdentificationFails() throws Exception {
when(mockAuthenticationHandlerService.buildSession(any()))
.thenReturn(null);
when(mockAuthenticationHandlerService.purgeSession(any()))
.thenReturn(mock(MultivaluedMap.class));
ProfileRequestContext profileRequestContext = new ProfileRequestContext();
profileRequestContext.addSubcontext(new AuthenticationContext());
MockHttpServletRequest request = getQueryParamRequest(getValidTupasResponseParams());
MockHttpServletResponse response = new MockHttpServletResponse();
when(ExternalAuthentication.getProfileRequestContext("e1s1", request)).thenReturn(profileRequestContext);
extAuthnHandler.doGet(request, response);
AuthenticationContext authenticationContext = profileRequestContext.getSubcontext(AuthenticationContext.class);
assertNotNull(authenticationContext);
TupasContext tupasContext = authenticationContext.getSubcontext(TupasContext.class);
assertNull(tupasContext);
assertNotNull(response.getRedirectedUrl());
}
開發者ID:vrk-kpa,項目名稱:e-identification-tupas-idp-public,代碼行數:23,代碼來源:ShibbolethExtAuthnHandlerTest.java
示例12: parseSessionDataFailsIfStampIsExpired
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Test
public void parseSessionDataFailsIfStampIsExpired() throws Exception {
ReflectionTestUtils.setField(parser, "clock", expired);
MultivaluedMap<String,String> initParams = getValidInitParams();
initParams.putSingle("sessionId", "1234567890");
when(authenticationHandlerUtils.popFromCache(any())).thenReturn(initParams);
Map<String,String> attributeNameMap = mock(Map.class);
when(attributeNameMap.get("B02K_CUSTID")).thenReturn("ATTRNAME_CUSTID");
when(attributeNameMap.get("B02K_CUSTNAME")).thenReturn("ATTRNAME_CUSTNAME");
MultivaluedMap<String,String> sessionParams = getValidSessionParamsWithHetu();
sessionParams.putSingle("sessionId", "1234567890");
assertNull(parser.parseSessionData(sessionParams));
}
開發者ID:vrk-kpa,項目名稱:e-identification-tupas-idp-public,代碼行數:18,代碼來源:SessionParserServiceSessionTest.java
示例13: writeTo
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Override
public void writeTo(User t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
t.setPassword(null);
JsonbConfig config = new JsonbConfig().withNullValues(false);
JsonbBuilder.create(config)
.toJson(t, entityStream);
}
示例14: logHttpHeaders
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
protected void logHttpHeaders(MultivaluedMap<String, String> headers) {
StringBuilder msg = new StringBuilder("The HTTP headers are: \n");
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
msg.append(entry.getKey()).append(": ");
for (int i = 0; i < entry.getValue().size(); i++) {
msg.append(entry.getValue().get(i));
if (i < entry.getValue().size() - 1) {
msg.append(", ");
}
}
msg.append("\n");
}
logger.info(msg.toString());
}
示例15: writeTo
import javax.ws.rs.core.MultivaluedMap; //導入依賴的package包/類
@Override
public void writeTo(ApplicationResponse t, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException {
ByteArrayOutputStream boss = new ByteArrayOutputStream();
ObjectMapper om = jsonProvider.locateMapper(type, MediaType.APPLICATION_JSON_TYPE);
if(om != null) {
jsonProvider.writeTo(t, type, genericType, annotations, MediaType.APPLICATION_JSON_TYPE, httpHeaders, boss);
boss.flush();
}
Writer osWriter = new OutputStreamWriter(entityStream);
String code, text, prefix;
if(StringUtils.hasText(t.getMsgCode())) {
code = "400"; prefix = t.getMsgCode();
} else {
code = "200"; prefix = "";
}
if(StringUtils.hasText(t.getMessage())) {
text = prefix + " " + t.getMessage();
} else {
text = "ok";
}
osWriter.write("<html><body status='"+code+"' statusText='" + text + "'>");
osWriter.flush();
entityStream.write(boss.toByteArray());
boss.close();
osWriter.write("</body></html>");
osWriter.close();
}