本文整理汇总了Java中com.sun.jersey.api.representation.Form类的典型用法代码示例。如果您正苦于以下问题:Java Form类的具体用法?Java Form怎么用?Java Form使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Form类属于com.sun.jersey.api.representation包,在下文中一共展示了Form类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: empty
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
@Test
public void empty() {
ClientResponse res;
res = request("rdf/update")
.get(ClientResponse.class);
assertEquals("Should return 405 response code", 405, res.getStatus());
Form f = new Form();
f.add("update", "");
res = request("rdf/update")
.type(MediaType.APPLICATION_FORM_URLENCODED)
.entity(f)
.post(ClientResponse.class);
assertEquals("Should return 400 response code", 400, res.getStatus());
res = request("rdf/update")
.type(RDFMediaType.SPARQL_UPDATE)
.post(ClientResponse.class);
assertEquals("Should return 200 response code", 400, res.getStatus());
}
示例2: Create
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
@Override
public Form Create() {
if (activated == true)
throw new RuntimeException("Only one active session at a time is allowed");
participants.clear();
transactionIDcalledContextCoupon = null;
owner = null;
activated = false;
state = Maps.newHashMap();
cxContainer = null;
sessionName = UUID.randomUUID().toString();
final Form f = new Form();
f.addFirst("sessionName", sessionName);
f.addFirst("newContextManager", "someUrl");
return f;
}
示例3: toForm
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public static Form toForm(final InputStream inputStream) throws Exception {
final String encoded = ReaderWriter.readFromAsString(new InputStreamReader(inputStream));
// com.sun.jersey.core.impl.provider.entity.BaseFormProvider
final Form map = new Form();
final String charsetName = "UTF-8";
final StringTokenizer tokenizer = new StringTokenizer(encoded, "&");
String token;
try {
while (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
final int idx = token.indexOf('=');
if (idx < 0) {
map.add(URLDecoder.decode(token, charsetName), null);
} else if (idx > 0) {
map.add(URLDecoder.decode(token.substring(0, idx), charsetName),
URLDecoder.decode(token.substring(idx + 1), charsetName));
}
}
return map;
} catch (final IllegalArgumentException ex) {
throw new WebApplicationException(ex, Status.BAD_REQUEST);
}
}
示例4: ContextChangesPending
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
@Override
public Form ContextChangesPending(final long contextCoupon) throws Exception {
final JSONRPC2Request request = new JSONRPC2Request("ContextParticipant.ContextChangesPending", UUID.randomUUID().toString());
final SettableFuture<JSONRPC2Response> future = SettableFuture.create();
cache.put(request.getID().toString(), future);
session.getBasicRemote().sendObject(request);
final JSONRPC2Response response = future.get(3000, TimeUnit.MILLISECONDS);
if(!response.indicatesSuccess())
throw new RuntimeException("Error processing request: " + response.toJSONString());
final Form form = new Form();
final JSONObject r = (JSONObject) response.getResult();
r.forEach((k,v)->form.add(k, v));
return form;
}
示例5: responseToEntity
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public static BasicHttpEntity responseToEntity(final Response jerseyResponse) throws UnsupportedEncodingException {
final BasicHttpEntity entity = new BasicHttpEntity();
if (jerseyResponse.getEntity() != null) {
// com.sun.jersey.core.impl.provider.entity.BaseFormProvider
final String charsetName = "UTF-8";
final Form t = (Form) jerseyResponse.getEntity();
final StringBuilder sb = new StringBuilder();
for (final Map.Entry<String, List<String>> e : t.entrySet()) {
for (final String value : e.getValue()) {
if (sb.length() > 0)
sb.append('&');
sb.append(URLEncoder.encode(e.getKey(), charsetName));
if (value != null) {
sb.append('=');
sb.append(URLEncoder.encode(value, charsetName));
}
}
}
entity.setContent(new ByteArrayInputStream(sb.toString().getBytes()));
entity.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
}
return entity;
}
示例6: toResponse
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
private Form toResponse(final URI uri, final MultivaluedMap<String, String> queryParameters) {
final String method = queryParameters.getFirst("method");
String _interface = queryParameters.getFirst("interface");
if (_interface == null)
_interface = "";
final Method methodToInvoke = getMethod(_interface, method);
final List<Object> args = prepareParameters(uri, queryParameters, methodToInvoke);
try {
final Object[] argsAsArray = args.toArray();
final Object object = methodToInvoke.invoke(servletsToObjects.get(methodToInvoke.getDeclaringClass()),
argsAsArray);
return (Form) object;
} catch (final Exception e) {
throw new RuntimeException("Bad stuff happened", e);
}
}
示例7: participantSetsContextValuesAndEndsContext
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
@Test
public void participantSetsContextValuesAndEndsContext() throws Exception {
system2.startContextChanges();
system2.setItemValues(itemNames, itemValues);
final Form form = system2.endContextChanges();
final boolean _continue = !Boolean.getBoolean(form.getFirst("noContinue"));
final String stringResponses = form.getFirst("responses");
final List<String> reasons;
if (Strings.isNullOrEmpty(stringResponses))
reasons = Lists.newArrayList();
else
reasons = Lists.newArrayList(Splitter.on("|").split(stringResponses));
assertEquals(true, _continue);
assertEquals(true, reasons.isEmpty());
}
示例8: goThroughContextChangeAndVerifyWithWSClient
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
@Test
public void goThroughContextChangeAndVerifyWithWSClient() throws Exception {
final WSContextParticipantImpl wsClient = new WSContextParticipantImpl(host, serverPort);
wsClient.joinCommonContext();
system1.startContextChanges();
system1.setItemValues(itemNames, itemValues);
final Form form = system1.endContextChanges();
final boolean _continue = !Boolean.getBoolean(form.getFirst("noContinue"));
final String stringResponses = form.getFirst("responses");
final List<String> reasons;
if (Strings.isNullOrEmpty(stringResponses))
reasons = Lists.newArrayList();
else
reasons = Lists.newArrayList(Splitter.on("|").split(stringResponses));
assertEquals(true, _continue);
assertEquals(true, reasons.isEmpty());
assertEquals(true, wsClient.getConnection().getLatestMessage() != null);
wsClient.close();
}
示例9: check_token
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public boolean check_token(String token) throws Exception {
String authorization_endpoint = this.getUAAendpoint();
logger.info(">>>" + authorization_endpoint);
WebResource webResource = restClient.resource(authorization_endpoint + "/check_token");
String authString = cfClientId + ":" + cfSecretKey;
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
Form form = new Form();
form.add("token", token);
String authStringEnc = new String(authEncBytes);
ClientResponse cr = webResource
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_FORM_URLENCODED)
.header("charset", "utf-8")
.header("authorization", "Basic " + authStringEnc)
.post(ClientResponse.class, form);
String response = cr.getEntity(String.class);
logger.info(">>>" + response);
int status_code = cr.getStatus();
return (status_code == 200);
}
示例10: test_filter_noActionOnPostFormPut
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public void test_filter_noActionOnPostFormPut() {
ContainerRequest mock = Mockito.mock(ContainerRequest.class);
when(mock.getMethod()).thenReturn("POST");
Form form = new Form();
form.put("method", Arrays.asList("PUT"));
when(mock.getFormParameters()).thenReturn(form);
HttpMethodFilter test = new HttpMethodFilter();
ContainerRequest result = test.filter(mock);
assertSame(mock, result);
verify(mock).getMethod();
verify(mock).getFormParameters();
verify(mock).setMethod("PUT");
verifyNoMoreInteractions(mock);
}
示例11: test_filter_noActionOnPostFormDelete
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public void test_filter_noActionOnPostFormDelete() {
ContainerRequest mock = Mockito.mock(ContainerRequest.class);
when(mock.getMethod()).thenReturn("POST");
Form form = new Form();
form.put("method", Arrays.asList("DELETE"));
when(mock.getFormParameters()).thenReturn(form);
HttpMethodFilter test = new HttpMethodFilter();
ContainerRequest result = test.filter(mock);
assertSame(mock, result);
verify(mock).getMethod();
verify(mock).getFormParameters();
verify(mock).setMethod("DELETE");
verifyNoMoreInteractions(mock);
}
示例12: test_filter_noActionOnPostFormOptions
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public void test_filter_noActionOnPostFormOptions() {
ContainerRequest mock = Mockito.mock(ContainerRequest.class);
when(mock.getMethod()).thenReturn("POST");
Form form = new Form();
form.put("method", Arrays.asList("OPTIONS"));
when(mock.getFormParameters()).thenReturn(form);
HttpMethodFilter test = new HttpMethodFilter();
ContainerRequest result = test.filter(mock);
assertSame(mock, result);
verify(mock).getMethod();
verify(mock).getFormParameters();
verify(mock).setMethod("OPTIONS");
verifyNoMoreInteractions(mock);
}
示例13: test_filter_noActionOnPostFormHead
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public void test_filter_noActionOnPostFormHead() {
ContainerRequest mock = Mockito.mock(ContainerRequest.class);
when(mock.getMethod()).thenReturn("POST");
Form form = new Form();
form.put("method", Arrays.asList("HEAD"));
when(mock.getFormParameters()).thenReturn(form);
HttpMethodFilter test = new HttpMethodFilter();
ContainerRequest result = test.filter(mock);
assertSame(mock, result);
verify(mock).getMethod();
verify(mock).getFormParameters();
verify(mock).setMethod("HEAD");
verifyNoMoreInteractions(mock);
}
示例14: test_filter_noActionOnPostFormPost
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public void test_filter_noActionOnPostFormPost() {
ContainerRequest mock = Mockito.mock(ContainerRequest.class);
when(mock.getMethod()).thenReturn("POST");
Form form = new Form();
form.put("method", Arrays.asList("POST"));
when(mock.getFormParameters()).thenReturn(form);
HttpMethodFilter test = new HttpMethodFilter();
ContainerRequest result = test.filter(mock);
assertSame(mock, result);
verify(mock).getMethod();
verify(mock).getFormParameters();
verify(mock).setMethod("POST");
verifyNoMoreInteractions(mock);
}
示例15: test_filter_noActionOnPostFormGet
import com.sun.jersey.api.representation.Form; //导入依赖的package包/类
public void test_filter_noActionOnPostFormGet() {
ContainerRequest mock = Mockito.mock(ContainerRequest.class);
when(mock.getMethod()).thenReturn("POST");
Form form = new Form();
form.put("method", Arrays.asList("GET"));
when(mock.getFormParameters()).thenReturn(form);
HttpMethodFilter test = new HttpMethodFilter();
ContainerRequest result = test.filter(mock);
assertSame(mock, result);
verify(mock).getMethod();
verify(mock).getFormParameters();
verify(mock).setMethod("GET");
verifyNoMoreInteractions(mock);
}