本文整理汇总了Java中org.jboss.resteasy.util.HttpResponseCodes.SC_OK属性的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseCodes.SC_OK属性的具体用法?Java HttpResponseCodes.SC_OK怎么用?Java HttpResponseCodes.SC_OK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jboss.resteasy.util.HttpResponseCodes
的用法示例。
在下文中一共展示了HttpResponseCodes.SC_OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessages
public void getMessages()
throws Exception
{
WebTarget target = ClientBuilder.newClient().target(MessageReceiverGetURL);
Invocation.Builder builder = target.request();
builder.header("Authorization", "OpenId " + SubscriberOpenIdIdentifier);
Response response = builder.post(null);
response.close();
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);
}
示例2: registerMessagingServiceCallback
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();
}
}
示例3: produceMessages
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();
}
}
示例4: registerMessagingService
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();
}
}
示例5: registerMessagingServiceScopes
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();
}
}
示例6: registerMessagingServiceCallback
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();
}
}
示例7: produceMessages
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();
}
}
示例8: getMessages
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();
}
}
示例9: getMessagesFromSubscriberReceiver
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();
}
}
示例10: accessEndUserResource
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();
}
}
示例11: getSharedSecret
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;
}
示例12: getRequestToken
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));
}
示例13: getAccessToken
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));
}
示例14: sendMessage
public void sendMessage(String callbackURI, String messageSenderId, String message) {
Response response = null;
try
{
WebTarget target = ClientBuilder.newClient().target(getPushMessageURL(callbackURI, messageSenderId));
response = target.request().post(Entity.entity(message, MediaType.TEXT_PLAIN_TYPE));
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();
}
}
示例15: getResponseContent
public byte[] getResponseContent(HttpResponse httpResponse) throws IOException {
if ((httpResponse == null) || (httpResponse.getStatusLine().getStatusCode() != HttpResponseCodes.SC_OK)) {
return null;
}
HttpEntity entity = httpResponse.getEntity();
byte[] responseBytes = new byte[0];
if (entity != null) {
responseBytes = EntityUtils.toByteArray(entity);
}
// Consume response content
if (entity != null) {
EntityUtils.consume(entity);
}
return responseBytes;
}