本文整理汇总了Java中org.jboss.resteasy.util.HttpResponseCodes类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseCodes类的具体用法?Java HttpResponseCodes怎么用?Java HttpResponseCodes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponseCodes类属于org.jboss.resteasy.util包,在下文中一共展示了HttpResponseCodes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRequestAllParams
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
@Test
public void testRequestAllParams() throws Exception
{
Client client = ClientBuilder.newClient();
WebTarget target = client.target(getRequestURL(MyProvider.Consumer1Key, MyProvider.Consumer1Secret));
Invocation.Builder request = target.request();
Response response = request.get();
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
Map<String, String> tokens = getResponse(response.readEntity(String.class));
Assert.assertEquals(tokens.size(), 3);
Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN));
Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN).length() > 0);
Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET));
Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0);
Assert.assertTrue(tokens.containsKey(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM));
Assert.assertEquals(tokens.get(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM), "true");
}
示例2: testAccessAllParams
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
@Test
public void testAccessAllParams() throws Exception
{
Client client = ClientBuilder.newClient();
WebTarget target = client.target(getAccessURL(MyProvider.Consumer1Key, MyProvider.Consumer1Secret, MyProvider.Consumer1Request1Key, MyProvider.Consumer1Request1Secret, MyProvider.Consumer1Request1Verifier));
Invocation.Builder request = target.request();
Response response = request.get();
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
// check that we got all tokens
Map<String, String> tokens = getResponse(response.readEntity(String.class));
Assert.assertEquals(tokens.size(), 2);
Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN));
Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN).length() > 0);
Assert.assertTrue(tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET));
Assert.assertTrue(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0);
}
示例3: sendMessage
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void sendMessage(String callbackURI, String messageSenderId, String message) {
Response response = null;
try {
WebTarget target = ClientBuilder.newClient().target(getPushMessageURL(callbackURI, messageSenderId));
Entity entity = Entity.entity(message, MediaType.TEXT_PLAIN_TYPE);
response = target.request().post(entity);
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Message can not be delivered to subscribers");
}
} catch (Exception ex)
{
throw new RuntimeException("Message can not be delivered to subscribers");
} finally {
response.close();
}
}
示例4: registerMessagingServiceCallback
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void registerMessagingServiceCallback(String consumerKey, String callback)
{
WebTarget target = ClientBuilder.newClient().target(MessagingServiceCallbackRegistrationURL);
Invocation.Builder builder = target.request();
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
builder.header("Authorization", "Basic " + base64Credentials);
Form form = new Form("consumer_id", consumerKey);
form.param("callback_uri", callback);
Response response = null;
try {
response = builder.post(Entity.form(form));
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Callback Registration failed");
}
}
catch (Exception ex) {
throw new RuntimeException("Callback Registration failed");
}
finally {
response.close();
}
}
示例5: produceMessages
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void produceMessages()
{
WebTarget target = ClientBuilder.newClient().target(MessagingServiceMessagesURL);
Invocation.Builder builder = target.request();
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
builder.header("Authorization", "Basic " + base64Credentials);
Response response = null;
try {
response = builder.post(Entity.entity("Hello2 !", MediaType.TEXT_PLAIN_TYPE));
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Messages can not be sent");
}
}
catch (Exception ex) {
throw new RuntimeException("Messages can not be sent");
}
finally {
response.close();
}
}
示例6: registerMessagingService
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public String registerMessagingService(String consumerKey) throws Exception
{
WebTarget target = ClientBuilder.newClient().target(ConsumerRegistrationURL);
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
Invocation.Builder builder = target.request();
builder.header("Authorization", "Basic " + base64Credentials);
Entity<Form> formEntity = Entity.form(new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey));
Response response = null;
try {
response = builder.post(formEntity);
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Registration failed");
}
// check that we got all tokens
Map<String, String> tokens = OAuth.newMap(OAuth.decodeForm(response.readEntity(String.class)));
String secret = tokens.get("xoauth_consumer_secret");
if (secret == null) {
throw new RuntimeException("No secret available");
}
return secret;
} finally {
response.close();
}
}
示例7: registerMessagingServiceScopes
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void registerMessagingServiceScopes(String consumerKey, String scope) throws Exception
{
WebTarget target = ClientBuilder.newClient().target(ConsumerScopesRegistrationURL);
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
Invocation.Builder builder = target.request();
builder.header("Authorization", "Basic " + base64Credentials);
Form form = new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
form.param("xoauth_scope", scope);
form.param("xoauth_permission", "sendMessages");
Response response = null;
try {
response = builder.post(Entity.form(form));
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Scopes can not be registered");
}
} finally {
response.close();
}
}
示例8: registerMessagingServiceCallback
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void registerMessagingServiceCallback(String consumerKey, String consumerSecret, String callback)
throws Exception
{
WebTarget target = ClientBuilder.newClient().target(MessagingServiceCallbackRegistrationURL);
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
Invocation.Builder builder = target.request();
builder.header("Authorization", "Basic " + base64Credentials);
Form form = new Form("consumer_id", consumerKey);
form.param("consumer_secret", consumerSecret);
form.param("callback_uri", callback);
Response response = null;
try {
response = builder.post(Entity.form(form));
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Callback Registration failed");
}
} finally {
response.close();
}
}
示例9: produceMessages
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void produceMessages()
throws Exception
{
WebTarget target = ClientBuilder.newClient().target(MessagingServiceMessagesURL);
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
Invocation.Builder builder = target.request();
builder.header("Authorization", "Basic " + base64Credentials);
Response response = null;
try {
response = builder.post(Entity.entity("Hello", MediaType.TEXT_PLAIN_TYPE));
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Messages can not be sent");
}
} finally {
response.close();
}
}
示例10: getMessages
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void getMessages()
throws Exception
{
WebTarget target = ClientBuilder.newClient().target(MessageReceiverGetURL);
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
Invocation.Builder builder = target.request();
builder.header("Authorization", "Basic " + base64Credentials);
Response response = null;
try {
response = builder.get();
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Messages can not be received");
}
String message = response.readEntity(String.class);
if (!"Hello !".equals(message))
{
throw new RuntimeException("Wrong Message");
}
System.out.println("Success : " + message);
} finally {
response.close();
}
}
示例11: getMessagesFromSubscriberReceiver
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public void getMessagesFromSubscriberReceiver() throws Exception
{
WebTarget target = ClientBuilder.newClient().target(MessageReceiverSubscriberGetURL);
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
Invocation.Builder builder = target.request();
builder.header("Authorization", "Basic " + base64Credentials);
Response response = null;
try {
response = builder.get();
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("Messages can not be received");
}
String message = response.readEntity(String.class);
if (!"Hello2 !".equals(message))
{
throw new RuntimeException("Wrong Message");
}
System.out.println("Message from the subscriber-receiver : " + message);
} finally {
response.close();
}
}
示例12: accessEndUserResource
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
private static void accessEndUserResource(String relativeURI) throws Exception
{
WebTarget target = ClientBuilder.newClient().target(EndUserResourceURL + relativeURI);
String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
target.request().header("Authorization", "Basic " + base64Credentials);
Response response = null;
try
{
response = target.request().get();
if ("/invisible".equals(relativeURI)) {
if (response.getStatus() != 401) {
throw new RuntimeException("End user can access the invisible resource");
} else {
return;
}
}
if (HttpResponseCodes.SC_OK != response.getStatus()) {
throw new RuntimeException("End user can not access its own resources");
}
System.out.println("End user resource : " + response.getEntity());
}
finally
{
response.close();
}
}
示例13: getSharedSecret
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public String getSharedSecret(String consumerKey) throws Exception
{
WebTarget target = ClientBuilder.newClient().target(ConsumerRegistrationURL);
Invocation.Builder builder = target.request();
Form form = new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
Entity<Form> formEntity = Entity.form(form);
Response response = builder.post(formEntity);
if (HttpResponseCodes.SC_OK != response.getStatus()) {
response.close();
throw new RuntimeException("Registration failed");
}
// check that we got all tokens
Map<String, String> tokens = OAuth.newMap(OAuth.decodeForm(response.readEntity(String.class)));
String secret = tokens.get("xoauth_consumer_secret");
if (secret == null) {
throw new RuntimeException("No secret available");
}
return secret;
}
示例14: getRequestToken
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public Token getRequestToken(String consumerKey, String consumerSecret,
String callbackURI, String scope, String permission) throws Exception
{
WebTarget target = ClientBuilder.newClient().target(getRequestURL(consumerKey, consumerSecret, callbackURI, scope, permission));
Response response = target.request().get();
if (HttpResponseCodes.SC_OK != response.getStatus()) {
response.close();
throw new RuntimeException("Request token can not be obtained");
}
// check that we got all tokens
Map<String, String> tokens = getTokens(response.readEntity(String.class));
if (tokens.size() != 3
|| !tokens.containsKey(OAuth.OAUTH_TOKEN)
|| !(tokens.get(OAuth.OAUTH_TOKEN).length() > 0)
|| !tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET)
|| !(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0)
|| !tokens.containsKey(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM)
|| !tokens.get(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM).equals("true")) {
throw new RuntimeException("Wrong request token details");
}
return new Token(tokens.get(OAuth.OAUTH_TOKEN), tokens.get(OAuth.OAUTH_TOKEN_SECRET));
}
示例15: getAccessToken
import org.jboss.resteasy.util.HttpResponseCodes; //导入依赖的package包/类
public Token getAccessToken(String consumerKey, String consumerSecret,
Token requestToken) throws Exception
{
String url = getAccessURL(consumerKey, consumerSecret,
requestToken.getToken(), requestToken.getSecret(),
requestToken.getVerifier());
WebTarget target = ClientBuilder.newClient().target(url);
Response response = target.request().get();
if (HttpResponseCodes.SC_OK != response.getStatus()) {
response.close();
throw new RuntimeException("Request token can not be obtained");
}
// check that we got all tokens
Map<String, String> tokens = getTokens(response.readEntity(String.class));
if (tokens.size() != 2
|| !tokens.containsKey(OAuth.OAUTH_TOKEN)
|| !(tokens.get(OAuth.OAUTH_TOKEN).length() > 0)
|| !tokens.containsKey(OAuth.OAUTH_TOKEN_SECRET)
|| !(tokens.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0)) {
throw new RuntimeException("Wrong access token details");
}
return new Token(tokens.get(OAuth.OAUTH_TOKEN), tokens.get(OAuth.OAUTH_TOKEN_SECRET));
}