本文整理匯總了Java中org.restlet.data.Reference類的典型用法代碼示例。如果您正苦於以下問題:Java Reference類的具體用法?Java Reference怎麽用?Java Reference使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Reference類屬於org.restlet.data包,在下文中一共展示了Reference類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createInboundRoot
import org.restlet.data.Reference; //導入依賴的package包/類
@Override
public Restlet createInboundRoot() {
Router baseRouter = new Router(context);
baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
for (RestletRoutable rr : restlets) {
baseRouter.attach(rr.basePath(), rr.getRestlet(context));
}
Filter slashFilter = new Filter() {
@Override
protected int beforeHandle(Request request, Response response) {
Reference ref = request.getResourceRef();
String originalPath = ref.getPath();
if (originalPath.contains("//"))
{
String newPath = originalPath.replaceAll("/+", "/");
ref.setPath(newPath);
}
return Filter.CONTINUE;
}
};
slashFilter.setNext(baseRouter);
return slashFilter;
}
示例2: sendToProvider
import org.restlet.data.Reference; //導入依賴的package包/類
protected Representation sendToProvider(String provider)
{
String id = openIDState.start();
Reference openidRef = new Reference(provider);
openidRef.addQueryParameter("openid.ns", "http://specs.openid.net/auth/2.0");
openidRef.addQueryParameter("openid.return_to", getRequest().getResourceRef().toString()+"/"+id);
openidRef.addQueryParameter("openid.realm", getRequest().getHostRef().toString());
openidRef.addQueryParameter("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select");
openidRef.addQueryParameter("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select");
openidRef.addQueryParameter("openid.mode", "checkid_setup");
openidRef.addQueryParameter("openid.ns.ui", "http://specs.openid.net/extensions/ui/1.0");
openidRef.addQueryParameter("openid.ui.icon", "true");
openidRef.addQueryParameter("openid.ui.mode", "x-has-session");
openidRef.addQueryParameter("openid.ns.ax", "http://openid.net/srv/ax/1.0");
openidRef.addQueryParameter("openid.ax.mode", "fetch_request");
openidRef.addQueryParameter("openid.ax.required", "email,firstname,lastname");
openidRef.addQueryParameter("openid.ax.type.email", "http://axschema.org/contact/email");
openidRef.addQueryParameter("openid.ax.type.firstname", "http://axschema.org/namePerson/first");
openidRef.addQueryParameter("openid.ax.type.lastname", "http://axschema.org/namePerson/last");
getResponse().redirectSeeOther(openidRef);
//response.setEntity(new StringRepresentation(openidRef.toString(),MediaType.TEXT_PLAIN));
return null;
}
示例3: authenticate
import org.restlet.data.Reference; //導入依賴的package包/類
@Get
public void authenticate() {
// Use state if provided
final String next = getRequest().getResourceRef().getQueryAsForm(true).getFirstValue("next");
final StateUrlProcessor state = new StateUrlProcessor(getQueryValue("state"));
if (state.getReturnUrl().isPresent() && next != null) {
state.setReturnUrl(next);
} else if (getRequest().getReferrerRef() != null) {
state.setReturnUrl(getRequest().getReferrerRef().toString());
}
final ExtensionTokenManager tokenManager = getTokenManager();
if (tokenManager != null) {
logger.info("Authenticate method called to obtain authorization url");
final Reference authUrl = new Reference(tokenManager.getOAuthAuthorizationUrl(Optional.of(state)));
getResponse().redirectSeeOther(authUrl);
} else {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
}
}
示例4: getOAuthAuthorizationUrl
import org.restlet.data.Reference; //導入依賴的package包/類
public String getOAuthAuthorizationUrl(final ExtensionOAuthConfiguration config, final Optional<StateUrlProcessor> state) {
final Reference reference = new Reference(config.authorizeUri);
final OAuthParameters parameters = new OAuthParameters();
parameters.responseType(ResponseType.code);
parameters.add(OAuthParameters.CLIENT_ID, config.clientId);
parameters.redirectURI(config.callbackUrl);
parameters.scope(new String[] { "read" });
if (state.isPresent()) {
final Optional<String> stateUrlValue = state.get().encode();
if (stateUrlValue.isPresent()) {
parameters.state(stateUrlValue.get());
}
}
return parameters.toReference(reference.toString()).toString();
}
示例5: createInboundRoot
import org.restlet.data.Reference; //導入依賴的package包/類
@Override
public Restlet createInboundRoot() {
Router baseRouter = new Router(context);
baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
for (RestletRoutable rr : restlets) {
baseRouter.attach(rr.basePath(), rr.getRestlet(context));
}
Filter slashFilter = new Filter() {
@Override
protected int beforeHandle(Request request, Response response) {
Reference ref = request.getResourceRef();
String originalPath = ref.getPath();
if (originalPath.contains("//"))
{
String newPath = originalPath.replaceAll("/+", "/");
ref.setPath(newPath);
}
return Filter.CONTINUE;
}
};
slashFilter.setNext(baseRouter);
return slashFilter;
}
示例6: command
import org.restlet.data.Reference; //導入依賴的package包/類
HandlerCommand command( Link link, Object commandRequest, ResponseHandler handler, ResponseHandler processingErrorHandler )
{
if (handler == null)
handler = commandHandlers.get( link.rel().get() );
if (processingErrorHandler == null)
processingErrorHandler = processingErrorHandlers.get( link.rel().get() );
// Check if we should do POST or PUT
Method method;
if( LinksUtil.withClass( "idempotent" ).test( link ) )
{
method = Method.PUT;
}
else
{
method = Method.POST;
}
Reference ref = new Reference( reference.toUri().toString() + link.href().get() );
return invokeCommand( ref, method, commandRequest, handler, processingErrorHandler );
}
示例7: newClient
import org.restlet.data.Reference; //導入依賴的package包/類
public synchronized ContextResourceClient newClient( String relativePath )
{
if( relativePath.startsWith( "http://" ) )
{
return contextResourceFactory.newClient( new Reference( relativePath ) );
}
Reference reference = this.reference.clone();
if( relativePath.startsWith( "/" ) )
{
reference.setPath( relativePath );
}
else
{
reference.setPath( reference.getPath() + relativePath );
reference = reference.normalize();
}
return contextResourceFactory.newClient( reference );
}
示例8: getTargetRef
import org.restlet.data.Reference; //導入依賴的package包/類
@Override
protected Reference getTargetRef( Request request, Response response )
{
// This is essentially the original Restlet code modified to use
// ResolvingTemplate.
// Create the template
Template rt = new ResolvingTemplate( this.targetTemplate );
rt.setLogger( getLogger() );
// Return the formatted target URI
if( new Reference( this.targetTemplate ).isRelative() )
// Be sure to keep the resource's base reference.
return new Reference( request.getResourceRef(), rt.format( request, response ) );
return new Reference( rt.format( request, response ) );
}
示例9: validateNotRecursiveServerRedirect
import org.restlet.data.Reference; //導入依賴的package包/類
/**
* Throw an exception if there is a recursive server-side redirect.
*
* @param targetRef
* The target reference
* @param request
* The request
* @param response
* The response
*/
private void validateNotRecursiveServerRedirect( Reference targetRef, Request request, Response response )
{
@SuppressWarnings("unchecked")
Set<String> serverRedirectHistory = (Set<String>) request.getAttributes().get( SERVER_REDIRECT_HISTORY_ATTRIBUTE );
if( serverRedirectHistory == null )
{
serverRedirectHistory = new HashSet<String>();
@SuppressWarnings("unchecked")
Set<String> existing = (Set<String>) request.getAttributes().putIfAbsent( SERVER_REDIRECT_HISTORY_ATTRIBUTE, serverRedirectHistory );
if( existing != null )
serverRedirectHistory = existing;
}
String targetRefString = targetRef.toString();
if( serverRedirectHistory.contains( targetRefString ) )
{
String message = "Recursive server redirection to " + targetRef;
getLogger().warning( message );
throw new ResourceException( Status.SERVER_ERROR_INTERNAL, message );
}
serverRedirectHistory.add( targetRefString );
}
示例10: getAccessToken
import org.restlet.data.Reference; //導入依賴的package包/類
/**
* Exchange and authorization code for an auth token from ORCID
*
* @see <a href='http://support.orcid.org/knowledgebase/articles/120107'>GET oauth/authorize</a>
* @see
* <a href='http://support.orcid.org/knowledgebase/articles/179969-methods-to-generate-an-access-token-for-testing'>
* Methods to Generate an Access Token for Testing</a>
*
* @param authorizationCode
* The authorization code returned from a request built with
* {@link #getAuthzCodeRequest(String, OrcidAuthScope)}
*
* @return the parsed response
* @throws IOException
* if result unparsable or network unreachable.
* @throws ResourceException
* if there's a http problem (e.g. 404, 400)
*/
public OrcidAccessToken getAccessToken(String authorizationCode) throws IOException {
Reference ref = new Reference(apiUriToken + TOKEN_ENDPOINT);
if (Context.getCurrent() == null) {
Context.setCurrent(new Context());
}
ClientResource client = new ClientResource(ref);
Form f = new Form();
f.add("client_id", clientID);
f.add("client_secret", clientSecret);
f.add("grant_type", "authorization_code");
f.add("code", authorizationCode);
f.add("redirect_uri", redirectUri);
client.getContext().getParameters().add("followRedirects", "true");
log.fine(f.toString());
log.fine(client.toString());
Representation rep = client.post(f, MediaType.APPLICATION_JSON);
String json = rep.getText();
return new ObjectMapper().reader(OrcidAccessToken.class).readValue(json);
}
示例11: appendWork
import org.restlet.data.Reference; //導入依賴的package包/類
/**
* Adds a research activity to the ORCID Record. Requires
* OrcidAuthScope.CREATE_WORKS scope
*
* @see <a href='http://support.orcid.org/knowledgebase/articles/177528-add-works-technical-developer'>
* Add Information: Technical Developer</a>
* @see <a href='http://support.orcid.org/knowledgebase/articles/171893-tutorial-add-works -with-curl'>
* Tutorial: Add Works with cURL</a>
* @param token
* containing a valid auth token and orcid
* @throws IOException
* if result unparsable or network unreachable.
* @throws ResourceException
* if there's a http problem (e.g. 404, 400)
*/
public void appendWork(OrcidAccessToken token, OrcidWork work) throws ResourceException, IOException {
Reference ref = new Reference(apiUriV12 + "/" + token.getOrcid() + WORK_CREATE_ENDPOINT);
ClientResource client = new ClientResource(ref);
// OAUTH bearer is a pain via restlet ChallengeScheme on GAE
addRestletHeader(client, "Authorization", "Bearer " + token.getAccess_token());
log.info(token.getAccess_token());
try {
StringWriter sw = new StringWriter();
orcidMessageContext.createMarshaller().marshal(wrapWork(work), sw);
log.fine(sw.toString());
StringRepresentation rep = new StringRepresentation(sw.toString(), OrcidConstants.APPLICATION_ORCID_XML);
client.post(rep);
} catch (JAXBException e) {
log.fine("problem marshalling response "+e.getMessage());
throw new IOException(e);
}
//TODO: catch the 500 and extract the following! {"message-version":"1.2_rc3","error-desc":{"value":"Invalid authorization code: Me82Dc"}}
}
示例12: get
import org.restlet.data.Reference; //導入依賴的package包/類
public static ZNRecord get(Client client, String url) throws IOException {
Reference resourceRef = new Reference(url);
Request request = new Request(Method.GET, resourceRef);
Response response = client.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
result.write(sw);
String responseStr = sw.toString();
Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
ObjectMapper mapper = new ObjectMapper();
ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
return record;
}
示例13: post
import org.restlet.data.Reference; //導入依賴的package包/類
public static ZNRecord post(Client client, String url, String body)
throws IOException {
Reference resourceRef = new Reference(url);
Request request = new Request(Method.POST, resourceRef);
request.setEntity(body, MediaType.APPLICATION_ALL);
Response response = client.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
if (result != null) {
result.write(sw);
}
String responseStr = sw.toString();
Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
ObjectMapper mapper = new ObjectMapper();
ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
return record;
}
示例14: postConfig
import org.restlet.data.Reference; //導入依賴的package包/類
private void postConfig(Client client, String url, ObjectMapper mapper, String command,
String configs) throws Exception {
Map<String, String> params = new HashMap<String, String>();
params.put(JsonParameters.MANAGEMENT_COMMAND, command);
params.put(JsonParameters.CONFIGS, configs);
Request request = new Request(Method.POST, new Reference(url));
request.setEntity(
JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(params),
MediaType.APPLICATION_ALL);
Response response = client.handle(request);
Representation result = response.getEntity();
StringWriter sw = new StringWriter();
result.write(sw);
String responseStr = sw.toString();
Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
}
示例15: getRequestValue
import org.restlet.data.Reference; //導入依賴的package包/類
protected String getRequestValue(Request request, String facetName)
{
if ("path".equals(facetName)) {
return request.getResourceRef().getPath();
} else if ("uri".equals(facetName)) {
return request.getResourceRef().toString();
} else if ("remaining".equals(facetName)) {
String remaining = request.getResourceRef().getRemainingPart();
int q = remaining.indexOf('?');
return q<0 ? remaining : remaining.substring(0,q);
} else if ("query".equals(facetName)) {
return request.getResourceRef().getQuery();
} else if ("base".equals(facetName)) {
Reference baseRef = request.getResourceRef().getBaseRef();
if (baseRef!=null) {
return baseRef.toString();
}
}
return null;
}