本文整理汇总了Java中com.sun.jersey.api.representation.Form.add方法的典型用法代码示例。如果您正苦于以下问题:Java Form.add方法的具体用法?Java Form.add怎么用?Java Form.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.api.representation.Form
的用法示例。
在下文中一共展示了Form.add方法的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: 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);
}
}
示例3: 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);
}
示例4: insertRoute
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
/**
* Call a rest service to insert a Route
*
* @param route
* @return true if the environment has been created
*/
public String insertRoute(Route route) {
String response = null;
try {
LOGGER.info("Calling insert Route Table service");
String url = getURL("vrf/staticrouting/route");
Form fm = new Form();
fm.add("ipSource", route.getSourceAddress());
fm.add("ipDest", route.getDestinationAddress());
fm.add("switchDPID", route.getSwitchInfo().getMacAddress());
fm.add("inputPort", route.getSwitchInfo().getInputPort());
fm.add("outputPort", route.getSwitchInfo().getOutputPort());
Client client = Client.create();
addHTTPBasicAuthentication(client);
WebResource webResource = client.resource(url);
response = webResource.accept(MediaType.TEXT_PLAIN).put(String.class, fm);
LOGGER.info("Route table: " + response);
} catch (ClientHandlerException e) {
LOGGER.error(e.getMessage());
throw e;
}
return response;
}
示例5: insertRoute
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
/**
* Call a rest service to insert a Route
*
* @param request
* @return true if the environment has been created
* @throws RestServiceException
*/
public String insertRoute(String resourceName, Route route) {
String response = null;
try {
LOGGER.info("Calling insert Route Table service");
String url = getURL(resourceType+"/" + resourceName + "/"+capabilityName+"/route");
Form fm = new Form();
fm.add("ipSource", route.getSourceAddress());
fm.add("ipDest", route.getDestinationAddress());
fm.add("switchDPID", route.getSwitchInfo().getMacAddress());
fm.add("inputPort", route.getSwitchInfo().getInputPort());
fm.add("outputPort", route.getSwitchInfo().getOutputPort());
Client client = Client.create();
WebResource webResource = client.resource(url);
response = webResource.accept(MediaType.TEXT_PLAIN).put(String.class, fm);
LOGGER.info("Route table: " + response);
} catch (ClientHandlerException e) {
LOGGER.error(e.getMessage());
throw e;
}
return response;
}
示例6: insertControllerInfo
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
public String insertControllerInfo(String resourceName, ControllerInfo ctrl) {
String response = null;
try {
LOGGER.info("Calling insert controller service");
String url = getURL(resourceType+"/" + resourceName + "/"+capabilityName+"/putSwitchController");
Form fm = new Form();
fm.add("ipController", ctrl.getControllerIp());
fm.add("portController", ctrl.getControllerPort());
fm.add("switchDPID", ctrl.getMacAddress());
Client client = Client.create();
WebResource webResource = client.resource(url);
response = webResource.accept(MediaType.TEXT_PLAIN).put(String.class, fm);
LOGGER.info("Route table: " + response);
} catch (ClientHandlerException e) {
LOGGER.error(e.getMessage());
throw e;
}
return response;
}
示例7: queryPostEncoded
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@Test
public void queryPostEncoded() throws IOException {
Form f = new Form();
f.add("query", getQueryAsString("/q1.sparql"));
ClientResponse res = request("rdf/query")
.accept(RDFMediaType.SPARQL_RESULTS_JSON)
.type(MediaType.APPLICATION_FORM_URLENCODED)
.entity(f)
.post(ClientResponse.class);
String yr = getJsonValue(res, "$.results.bindings[0].yr.value", String.class);
assertEquals("Should return 200 response code", 200, res.getStatus());
assertEquals("Should return 1940", "1940", yr);
}
示例8: ContextChangesPending
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@Override
public Form ContextChangesPending(final long agentCoupon, final String contextManager, final String itemNames,
final String itemValues, final long contextCoupon, final String managerSignature) {
final String[] names = itemNames.split("\\|");
final String[] values = itemValues.split("\\|");
systemCall(names, values);
final Form form = new Form();
// 17.3.3.2.2 Outputs
// final String[]itemNames
// final String[] itemValues
form.add("itemNames", "");
form.add("itemValues", "");
form.add("agentCoupon", agentCoupon);
form.add("contextCoupon", contextCoupon);
form.add("agentSignature", "");
// The interface MappingAgent, deprecated in CMA 1.4, has been removed
// altogether.
// 17.3.3.2.3 Outputs for Mapping Agents
form.add("decision", "");
form.add("reason", "");
return form;
}
示例9: GetItemNames
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@Override
@GET
@Path("GetItemNames")
public Form GetItemNames(@QueryParam("contextCoupon") long contextCoupon) {
List<String> list = FluentIterable.from(internalContextSession.getState(contextCoupon).keySet()).toList();
String value = Joiner.on("|").join(list);
Form f = new Form();
f.add("itemNames", value);
return f;
}
示例10: GetItemValues
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@Override
@GET
@Path("GetItemValues")
public Form GetItemValues(@QueryParam("itemNames") String itemNames,
@DefaultValue("false") @QueryParam("onlyChanges") boolean onlyChanges,
@QueryParam("contextCoupon") long contextCoupon) {
if (onlyChanges)
throw new RuntimeException("onlyChanges is currently not handled");
Map<String, String> stateMap = internalContextSession.getState(contextCoupon);
List<String> collectedItemNamesResult = Lists.newArrayList();
List<String> collectedItemValuesResult = Lists.newArrayList();
for (Entry<String, String> e : stateMap.entrySet()) {
String name = e.getKey();
String value = e.getValue();
// erasing number postfix on patient ID's
// or handle a specific query from client
if (itemNames.contains(name.replaceAll("\\d+(\\.\\d+)?", "*")) || itemNames.contains(name)) {
collectedItemNamesResult.add(name);
collectedItemValuesResult.add(value);
}
}
String itemNamesResult = "";
String itemValuesResult = "";
if (!collectedItemNamesResult.isEmpty()) {
itemNamesResult = Joiner.on("|").join(collectedItemNamesResult);
itemValuesResult = Joiner.on("|").join(collectedItemValuesResult);
}
Form f = new Form();
f.add("itemNames", itemNamesResult);
f.add("itemValues", itemValuesResult);
return f;
}
示例11: Perform
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@GET
@Path("Perform")
@Override
public Form Perform(@QueryParam("cpCallBackURL") final String cpCallBackURL,
@QueryParam("cpErrorURL") final String cpErrorURL,
@QueryParam("participantCoupon") final long participantCoupon,
@QueryParam("inputNames") final String inputNames, @QueryParam("inputValues") final String inputValues,
@QueryParam("appSignature") final String appSignature) {
final String[] names = inputNames.split("\\|");
final String[] values = inputValues.split("\\|");
final IQualifiedContextAgent assignedContextAgent = repository.findContextAgent(names, values);
// 1.4.5 Context Actions
final long contextCoupon = contextState.startSessionChanges(assignedContextAgent.getAgentCoupon());
final Form caForm = assignedContextAgent.ContextChangesPending(assignedContextAgent.getAgentCoupon(), uriInfo.getBaseUri().toString() + "/ContextManager", inputNames, inputValues, contextCoupon, "");
contextState.endSession();
final Form f = new Form();
f.add("actionCoupon", caForm.getFirst("actionCoupon"));
f.add("outputNames", caForm.getFirst("itemNames"));
f.add("outputValues", caForm.getFirst("itemValues"));
// Secure not supported
f.add("managerSignature", "");
return f;
}
示例12: GetMostRecentContextCoupon
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@Override
@Path("GetMostRecentContextCoupon")
@GET
public Form GetMostRecentContextCoupon() {
final long contextCoupon = internalContextSession.getLatestContextCoupon();
final Form f = new Form();
f.add("contextCoupon", contextCoupon + "");
return f;
}
示例13: StartContextChanges
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@Override
@Path("StartContextChanges")
@GET
public Form StartContextChanges(@QueryParam("participantCoupon") final long participantCoupon) {
final long contextCoupon = internalContextSession.startSessionChanges(participantCoupon);
final Form f = new Form();
f.add("contextCoupon", contextCoupon + "");
return f;
}
示例14: ContextChangesPending
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
@Override
@Path("ContextChangesPending")
@GET
public Form ContextChangesPending(@QueryParam("contextCoupon") final long contextCoupon) throws Exception {
final Form form = new Form();
form.add("decision", "valid");
form.add("reason", "");
return form;
}
示例15: getLoginForm
import com.sun.jersey.api.representation.Form; //导入方法依赖的package包/类
private static Form getLoginForm(String email, String password, Cookie csrfCookie, String chToken) {
Form form = new Form();
form.add(LOGIN_FORM_EMAIL_FIELD, email);
form.add(LOGIN_FORM_PASSWORD_FIELD, password);
form.add(LOGIN_FORM_CSRF_FIELD, csrfCookie.getValue());
form.add("_ch", chToken);
return form;
}