本文整理汇总了Java中net.oauth.OAuthMessage.readBodyAsString方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthMessage.readBodyAsString方法的具体用法?Java OAuthMessage.readBodyAsString怎么用?Java OAuthMessage.readBodyAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.oauth.OAuthMessage
的用法示例。
在下文中一共展示了OAuthMessage.readBodyAsString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
OAuthConsumer consumer = null;
try {
consumer = CookieConsumer.getConsumer(CONSUMER_NAME,
getServletContext());
OAuthAccessor accessor = CookieConsumer.getAccessor(request,
response, consumer);
OAuthMessage result = CookieConsumer.CLIENT.invoke(accessor,
"http://ma.gnolia.com/api/rest/2/tags_find", OAuth.newList(
"person", System.getProperty("user.name")));
String responseBody = result.readBodyAsString();
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(CONSUMER_NAME + " said:");
out.print(responseBody);
} catch (Exception e) {
CookieConsumer.handleException(e, request, response, consumer);
}
}
示例2: testAccess
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public void testAccess() throws Exception {
final String echo = "http://localhost:" + port + "/Echo";
final List<OAuth.Parameter> parameters = OAuth.newList("n", "v");
final String contentType = "text/fred; charset=" + OAuth.ENCODING;
final byte[] content = "1234".getBytes(OAuth.ENCODING);
for (OAuthClient client : clients) {
String id = client.getHttpClient().toString();
OAuthMessage request = new OAuthMessage(OAuthMessage.POST, echo, parameters, new ByteArrayInputStream(content));
request.getHeaders().add(new OAuth.Parameter("Content-Type", contentType));
OAuthMessage response = client.access(request, ParameterStyle.QUERY_STRING);
String expectedBody = (client.getHttpClient() instanceof HttpClient4) //
? "POST\nn=v\nnull\n1234" // no Content-Length
: "POST\nn=v\n4\n1234";
String body = response.readBodyAsString();
assertEquals(id, contentType, response.getHeader(HttpMessage.CONTENT_TYPE));
assertEquals(id, expectedBody, body);
}
}
示例3: makeAuthenticatedRequest
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
/**
* Makes an authenticated request to the JIRA API
*
* @param urlEndpoint
* @param parameters
* @param requestType
* @return Response as String
*/
public String makeAuthenticatedRequest(String urlEndpoint, String parameters,
String requestType) {
try {
String url;
if (parameters == null) {
url = urlEndpoint;
} else {
url = urlEndpoint + parameters;
}
LOG.debug("Making request to " + url);
OAuthClient client = new OAuthClient(new HttpClient4());
this.accessor.accessToken = configurationProvider.getJiraAccessToken();
OAuthMessage response =
client.invoke(this.accessor, requestType, url, Collections.<Map.Entry<?, ?>>emptySet());
return response.readBodyAsString();
} catch (IOException ioException) {
LOG.error("Unable to make authenticated request", ioException);
throw new RuntimeException("Unable to make authenticated request", ioException);
} catch (URISyntaxException syntaxException) {
LOG.error("Unable to make authenticated request", syntaxException);
throw new RuntimeException("Unable to make authenticated request", syntaxException);
} catch (OAuthException oauthException) {
LOG.warn("OAuthException in makeAuthenticatedRequest; attempting to reauthenticate",
oauthException);
this.authenticate();
return this.makeAuthenticatedRequest(urlEndpoint, parameters, requestType);
}
}
示例4: invoke
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private String invoke(OAuthAccessor accessor,
Collection<? extends Map.Entry> parameters)
throws OAuthException, IOException, URISyntaxException {
URL baseURL = (URL) accessor.consumer
.getProperty("serviceProvider.baseURL");
if (baseURL == null) {
baseURL = new URL("http://localhost/oauth-provider/");
}
OAuthMessage request = accessor.newRequestMessage("POST", (new URL(
baseURL, "echo")).toExternalForm(), parameters);
OAuthMessage response = CookieConsumer.CLIENT.invoke(request,
ParameterStyle.AUTHORIZATION_HEADER);
String responseBody = response.readBodyAsString();
return responseBody;
}
示例5: echo
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private static String echo(OAuthAccessor accessor, List<OAuth.Parameter> parameters)
throws OAuthException, IOException, URISyntaxException {
OAuthMessage result = CookieConsumer.CLIENT.invoke(accessor,
"http://term.ie/oauth/example/echo_api.php", parameters);
String responseBody = result.readBodyAsString();
return responseBody;
}
示例6: testInvokeMessage
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
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.
}
}
示例7: processRequest
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean ok;
this.b2Context = new B2Context(request);
this.response = new Response();
this.response.setProviderRef("");
this.response.setConsumerRef(String.valueOf(System.currentTimeMillis()));
String description = "ext.codeminor.request";
OAuthMessage message = OAuthServlet.getMessage(request, null);
Map<String,String> authHeaders = Utils.getAuthorizationHeaders(message);
String consumerKey = authHeaders.get("oauth_consumer_key");
String signatureMethod = authHeaders.get("oauth_signature_method");
String xml = message.readBodyAsString();
String actionName = null;
Document xmlDoc;
Element xmlBody = null;
xmlDoc = Utils.getXMLDoc(xml);
ok = xmlDoc != null;
if (ok) {
Element el = Utils.getXmlChild(xmlDoc.getRootElement(), "imsx_POXBody");
xmlBody = Utils.getXmlChild(el, null);
ok = xmlBody != null;
}
if (ok) {
actionName = xmlBody.getName();
if (actionName.endsWith("Request")) {
actionName = actionName.substring(0, actionName.length() - 7);
}
this.response.setProviderRef(Utils.getXmlChildValue(xmlDoc.getRootElement(), "imsx_messageIdentifier"));
} else if (actionName == null) {
actionName = "";
}
this.response.setAction(actionName);
Action action = null;
String paramName = null;
if (ok) {
if (actionName.equals(Constants.SVC_OUTCOME_READ) ||
actionName.equals(Constants.SVC_OUTCOME_WRITE) ||
actionName.equals(Constants.SVC_OUTCOME_DELETE)) {
action = new Outcome();
paramName = "sourcedId";
}
ok = (action != null);
if (!ok) {
this.response.setCodeMajor("unsupported");
description = "ext.codeminor.action";
}
}
if (ok) {
ok = getServicesData(consumerKey, Utils.getXmlChildValue(xmlBody, paramName));
if (!ok) {
description = "ext.codeminor.security";
}
}
if (ok) {
ok = checkSignature(message);
if (!ok) {
description = "ext.codeminor.signature";
}
}
if (ok) {
ok = Utils.checkBodyHash(message.getAuthorizationHeader(null), signatureMethod, xml);
if (!ok) {
description = "svc.codeminor.bodyhash";
}
}
this.response.setDescription(this.b2Context.getResourceString(description));
if (ok) {
ok = action.execute(actionName, this.b2Context, this.tool, xmlBody, this.servicesData, this.response);
}
this.response.setOk(ok);
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(this.response.toXML());
}