本文整理汇总了Java中net.oauth.OAuth.FORM_ENCODED属性的典型用法代码示例。如果您正苦于以下问题:Java OAuth.FORM_ENCODED属性的具体用法?Java OAuth.FORM_ENCODED怎么用?Java OAuth.FORM_ENCODED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.oauth.OAuth
的用法示例。
在下文中一共展示了OAuth.FORM_ENCODED属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendPostData
private String sendPostData(HttpMethod method) throws IOException {
String form;
if (useAuthHeader) {
form = OAuth.formEncode(nonOAuthParams);
} else {
form = OAuth.formEncode(message.getParameters());
}
method.addRequestHeader(HEADER_CONTENT_TYPE, OAuth.FORM_ENCODED);
method.addRequestHeader(HEADER_CONTENT_LENGTH, form.length() + ""); //$NON-NLS-1$
if (method instanceof PostMethod || method instanceof PutMethod) {
StringRequestEntity requestEntity = new StringRequestEntity(
form, OAuth.FORM_ENCODED, OAuth.ENCODING);
((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
} else {
log.error("Logic error, method must be POST or PUT to send body"); //$NON-NLS-1$
}
return form;
}
示例2: testConsumerFailBodyHashSigningWithFormEncoding
@Test
public void testConsumerFailBodyHashSigningWithFormEncoding() throws Exception {
replay();
FakeOAuthRequest bodyHashPost =
new FakeOAuthRequest("POST", TEST_URL, "a=b&c=d&oauth_body_hash=hash",
OAuth.FORM_ENCODED);
FakeHttpServletRequest request = bodyHashPost
.sign(null, FakeOAuthRequest.OAuthParamLocation.URI_QUERY,
FakeOAuthRequest.BodySigning.NONE);
try {
reqHandler.getSecurityTokenFromRequest(request);
fail("Cant have body signing with form-encoded post bodies");
} catch (AuthenticationHandler.InvalidAuthenticationException iae) {
// Pass
}
}
示例3: setUp
@Override
protected void setUp() throws Exception {
reqHandler = new OAuthAuthenticationHandler(mockStore, true);
formEncodedPost = new FakeOAuthRequest("POST", TEST_URL, "a=b&c=d",
OAuth.FORM_ENCODED);
nonFormEncodedPost = new FakeOAuthRequest("POST", TEST_URL, "BODY",
"text/plain");
}
示例4: testInvokeMessage
public void testInvokeMessage() throws Exception {
final String echo = "http://localhost:" + port + "/Echo";
final String data = new String(new char[] { 0, 1, ' ', 'a', 127, 128,
0xFF, 0x3000, 0x4E00 });
final byte[] utf8 = data.getBytes("UTF-8");
List<OAuth.Parameter> parameters = OAuth.newList("x", "y",
"oauth_token", "t");
String parametersForm = "oauth_token=t&x=y";
final Object[][] messages = new Object[][] {
{ new OAuthMessage("GET", echo, parameters),
"GET\n" + parametersForm + "\n" + "null\n", null },
{
new OAuthMessage("POST", echo, parameters),
"POST\n" + parametersForm + "\n"
+ parametersForm.length() + "\n",
OAuth.FORM_ENCODED },
{
new MessageWithBody("PUT", echo, parameters,
"text/OAuthClientTest; charset=\"UTF-8\"", utf8),
"PUT\n" + parametersForm + "\n"
+ utf8.length + "\n" + data,
"text/OAuthClientTest; charset=UTF-8" },
{
new MessageWithBody("PUT", echo, parameters,
"application/octet-stream", utf8),
"PUT\n" + parametersForm + "\n"
+ utf8.length + "\n"
+ new String(utf8, "ISO-8859-1"),
"application/octet-stream" },
{ new OAuthMessage("DELETE", echo, parameters),
"DELETE\n" + parametersForm + "\n" + "null\n", null } };
final ParameterStyle[] styles = new ParameterStyle[] {
ParameterStyle.BODY, ParameterStyle.AUTHORIZATION_HEADER };
final long startTime = System.nanoTime();
for (OAuthClient client : clients) {
for (Object[] testCase : messages) {
for (ParameterStyle style : styles) {
OAuthMessage request = (OAuthMessage) testCase[0];
final String id = client + " " + request.method + " " + style;
OAuthMessage response = null;
// System.out.println(id + " ...");
try {
response = client.invoke(request, style);
} catch (Exception e) {
AssertionError failure = new AssertionError(id);
failure.initCause(e);
throw failure;
}
// System.out.println(response.getDump()
// .get(OAuthMessage.HTTP_REQUEST));
String expectedBody = (String) testCase[1];
if ("POST".equalsIgnoreCase(request.method)
&& style == ParameterStyle.AUTHORIZATION_HEADER) {
// Only the non-oauth parameters went in the body.
expectedBody = expectedBody.replace("\n" + parametersForm.length()
+ "\n", "\n3\n");
}
String body = response.readBodyAsString();
assertEquals(id, expectedBody, body);
assertEquals(id, testCase[2], response.getHeader(HttpMessage.CONTENT_TYPE));
}
}
}
final long endTime = System.nanoTime();
final float elapsedSec = ((float) (endTime - startTime)) / 1000000000L;
if (elapsedSec > 10) {
fail("elapsed time = " + elapsedSec + " sec");
// This often means the client isn't re-using TCP connections,
// and consequently all the Jetty server threads are occupied
// waiting for data on the wasted connections.
}
}