Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Early pieces of JAX-RS ctx broker frontend.
Browse files Browse the repository at this point in the history
  • Loading branch information
labisso committed Aug 13, 2010
1 parent 8fe5c30 commit 801f020
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 1 deletion.
53 changes: 53 additions & 0 deletions ctx-broker/src/org/nimbustools/ctxbroker/rest/BrokerContact.java
@@ -0,0 +1,53 @@
/*
* Copyright 1999-2009 University of Chicago
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.nimbustools.ctxbroker.rest;

public class BrokerContact {

private final String brokerUri;
private final String contextId;
private final String secret;

public BrokerContact(String brokerUri, String contextId, String secret) {
if (brokerUri == null) {
throw new IllegalArgumentException("brokerUri may not be null");
}

if (contextId == null) {
throw new IllegalArgumentException("contextId may not be null");
}

if (secret == null) {
throw new IllegalArgumentException("secret may not be null");
}

this.brokerUri = brokerUri;
this.contextId = contextId;
this.secret = secret;
}

public String getBrokerUri() {
return brokerUri;
}

public String getContextId() {
return contextId;
}

public String getSecret() {
return secret;
}
}
111 changes: 111 additions & 0 deletions ctx-broker/src/org/nimbustools/ctxbroker/rest/BrokerResource.java
@@ -0,0 +1,111 @@
/*
* Copyright 1999-2009 University of Chicago
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.nimbustools.ctxbroker.rest;

import com.google.gson.Gson;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.globus.wsrf.Resource;
import org.globus.wsrf.ResourceException;
import org.globus.wsrf.ResourceKey;
import org.nimbustools.ctxbroker.ContextBrokerException;
import org.nimbustools.ctxbroker.blackboard.CtxStatus;
import org.nimbustools.ctxbroker.service.ContextBrokerHomeImpl;
import org.nimbustools.ctxbroker.service.ContextBrokerResourceImpl;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import java.net.URI;

@Path("/ctx")
public class BrokerResource {

private static final Log logger =
LogFactory.getLog(BrokerResource.class.getName());

private ContextBrokerHomeImpl home; //TODO this has to come from somewhere

private final Gson gson = new Gson();

@POST
@Path("/")
public Response createContext(@Context UriInfo uriInfo) {

final String callerDn = null; //TODO get dn from security
final boolean expectInjections = false;

final String rawId;
final BrokerContact contact;
try {
final EndpointReferenceType epr =
this.home.createNewResource(callerDn, expectInjections);

final ResourceKey resourceKey = this.home.getResourceKey(epr);
final String contextId = resourceKey.toString();

rawId = (String) resourceKey.getValue();


contact = new BrokerContact(this.home.getBrokerURL(),
contextId, this.home.getContextSecret(epr));
} catch (ContextBrokerException e) {
logger.error("Problem creating a context: "+e.getMessage(), e);
return Response.serverError().build();
}

final UriBuilder uriBuilder =
uriInfo.getAbsolutePathBuilder().
path(this.getClass(), "checkContext");

final URI uri = uriBuilder.build(rawId);

return Response.created(uri)
.entity(gson.toJson(contact))
.build();
}

@GET
@Path("/{id}")
public Response checkContext(@PathParam("id") String id) {

final Resource resource;
try {
final ResourceKey resourceKey = this.home.getResourceKey(id);
resource = this.home.find(resourceKey);
} catch (ResourceException e) {
logger.error("Problem retrieving ctx resource with id '"+id+"': "
+e.getMessage(), e);
return Response.status(Response.Status.NOT_FOUND).build();
}

ContextBrokerResourceImpl brokerResource = (ContextBrokerResourceImpl) resource;
try {
final CtxStatus status = brokerResource.getBlackboard().getStatus();

return Response.ok(gson.toJson(status)).build();
} catch (ContextBrokerException e) {
logger.error("Problem checking a context status: "+e.getMessage(), e);
return Response.serverError().build();
}
}
}
Expand Up @@ -143,7 +143,7 @@ public void setBootstrap(BootstrapInformation bootstrap) {

// always access it this way internally in the class or there may
// be a check then act on the cache set
private synchronized Blackboard getBlackboard()
public synchronized Blackboard getBlackboard()
throws ContextBrokerException {
if (this.resourceID == null) {
throw new ContextBrokerException("no resource id yet (?)");
Expand Down

0 comments on commit 801f020

Please sign in to comment.