mirror of https://github.com/apache/jclouds.git
Using an RFC 2068-compliant header for 'trusted' requestors and integration-test-specific settings for the local RunAtCloudServer
This commit is contained in:
parent
0448fcaa9f
commit
d8443bec4d
|
@ -3,6 +3,7 @@ package org.jclouds.demo.tweetstore.config.utils;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.inject.name.Names.bindProperties;
|
import static com.google.inject.name.Names.bindProperties;
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
|
import static org.jclouds.demo.tweetstore.controller.StoreTweetsController.AUTHORIZED_REQUEST_ORIGINATOR_HEADER;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -31,8 +32,6 @@ public class HttpRequestTask implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Factory {
|
public static class Factory {
|
||||||
private static final String HTTP_REQUEST_ORIGINATOR_HEADER = "X-RUN@cloud-Originator";
|
|
||||||
|
|
||||||
protected final HttpCommandExecutorService httpClient;
|
protected final HttpCommandExecutorService httpClient;
|
||||||
protected final String originator;
|
protected final String originator;
|
||||||
|
|
||||||
|
@ -56,7 +55,7 @@ public class HttpRequestTask implements Runnable {
|
||||||
public HttpRequestTask create(HttpRequest request) {
|
public HttpRequestTask create(HttpRequest request) {
|
||||||
HttpRequest requestWithSubmitter = request.toBuilder().headers(
|
HttpRequest requestWithSubmitter = request.toBuilder().headers(
|
||||||
copyOfWithEntry(request.getHeaders(),
|
copyOfWithEntry(request.getHeaders(),
|
||||||
HTTP_REQUEST_ORIGINATOR_HEADER, originator)).build();
|
AUTHORIZED_REQUEST_ORIGINATOR_HEADER, originator)).build();
|
||||||
return new HttpRequestTask(httpClient, requestWithSubmitter);
|
return new HttpRequestTask(httpClient, requestWithSubmitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,8 @@ import com.google.common.base.Function;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class StoreTweetsController extends HttpServlet {
|
public class StoreTweetsController extends HttpServlet {
|
||||||
|
public static final String AUTHORIZED_REQUEST_ORIGINATOR_HEADER = "X-RUNatcloud-Originator";
|
||||||
|
|
||||||
private static final class StatusToBlob implements Function<Status, Blob> {
|
private static final class StatusToBlob implements Function<Status, Blob> {
|
||||||
private final BlobMap map;
|
private final BlobMap map;
|
||||||
|
|
||||||
|
@ -109,8 +110,8 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
if (request.getHeader("X-RUN@cloud-Submitter") != null
|
if (request.getHeader(AUTHORIZED_REQUEST_ORIGINATOR_HEADER) != null
|
||||||
&& request.getHeader("X-RUN@cloud-Submitter").equals("twitter")) {
|
&& request.getHeader(AUTHORIZED_REQUEST_ORIGINATOR_HEADER).equals("twitter")) {
|
||||||
try {
|
try {
|
||||||
String contextName = checkNotNull(request.getHeader("context"), "missing header context");
|
String contextName = checkNotNull(request.getHeader("context"), "missing header context");
|
||||||
logger.info("retrieving tweets");
|
logger.info("retrieving tweets");
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.demo.tweetstore.integration;
|
package org.jclouds.demo.tweetstore.integration;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.demo.tweetstore.controller.StoreTweetsController.AUTHORIZED_REQUEST_ORIGINATOR_HEADER;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||||
|
@ -173,13 +174,13 @@ public class TweetStoreLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeTest(dependsOnMethods = "clearAndCreateContainers")
|
@BeforeTest(dependsOnMethods = "clearAndCreateContainers")
|
||||||
@Parameters({ "warfile", "bees.address", "bees.port", "bees.environment", "bees.basedir" })
|
@Parameters({ "warfile", "bees.address", "bees.port", "bees.basedir" })
|
||||||
public void startDevAppServer(final String warfile, final String address, final String port,
|
public void startDevAppServer(final String warfile, final String address, final String port,
|
||||||
String environments, String serverBaseDirectory) throws Exception {
|
String serverBaseDirectory) throws Exception {
|
||||||
url = new URL(String.format("http://%s:%s", address, port));
|
url = new URL(String.format("http://%s:%s", address, port));
|
||||||
|
|
||||||
server = new RunAtCloudServer();
|
server = new RunAtCloudServer();
|
||||||
server.writePropertiesAndStartServer(address, port, warfile, environments,
|
server.writePropertiesAndStartServer(address, port, warfile, "itest",
|
||||||
serverBaseDirectory, props);
|
serverBaseDirectory, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +203,7 @@ public class TweetStoreLiveTest {
|
||||||
for (String context : blobstores) {
|
for (String context : blobstores) {
|
||||||
System.out.println("storing at context: " + context);
|
System.out.println("storing at context: " + context);
|
||||||
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection();
|
||||||
connection.addRequestProperty("X-RUN@cloud-Submitter", "twitter");
|
connection.addRequestProperty(AUTHORIZED_REQUEST_ORIGINATOR_HEADER, "twitter");
|
||||||
connection.addRequestProperty("context", context);
|
connection.addRequestProperty("context", context);
|
||||||
InputStream i = connection.getInputStream();
|
InputStream i = connection.getInputStream();
|
||||||
String string = Strings2.toStringAndClose(i);
|
String string = Strings2.toStringAndClose(i);
|
||||||
|
|
Loading…
Reference in New Issue