com.noelios.restlet.component.ChildClientDispatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.restlet
Show all versions of org.apache.servicemix.bundles.restlet
This OSGi bundle wraps org.restlet, and com.noelios.restlet ${pkgVersion} jar files.
The newest version!
/**
* Copyright 2005-2008 Noelios Technologies.
*
* The contents of this file are subject to the terms of the following open
* source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 (the "Licenses"). You can
* select the license that you prefer but you may not use this file except in
* compliance with one of these Licenses.
*
* You can obtain a copy of the LGPL 3.0 license at
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* You can obtain a copy of the LGPL 2.1 license at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* You can obtain a copy of the CDDL 1.0 license at
* http://www.sun.com/cddl/cddl.html
*
* See the Licenses for the specific language governing permissions and
* limitations under the Licenses.
*
* Alternatively, you can obtain a royaltee free commercial license with less
* limitations, transferable or non-transferable, directly at
* http://www.noelios.com/products/restlet-engine
*
* Restlet is a registered trademark of Noelios Technologies.
*/
package com.noelios.restlet.component;
import org.restlet.Application;
import org.restlet.data.LocalReference;
import org.restlet.data.Protocol;
import org.restlet.data.Request;
import org.restlet.data.Response;
import com.noelios.restlet.TemplateDispatcher;
/**
* Client dispatcher for a component child.
*
* Concurrency note: instances of this class or its subclasses can be invoked by
* several threads at the same time and therefore must be thread-safe. You
* should be especially careful when storing state as member variables.
*
* @author Jerome Louvel
*/
public class ChildClientDispatcher extends TemplateDispatcher {
/**
* Constructor.
*
* @param childContext
* The child context.
*/
public ChildClientDispatcher(ChildContext childContext) {
super(childContext);
}
/**
* Transmits the call to the parent component except if the call is internal
* as denoted by the {@link Protocol#RIAP} protocol and targets this child
* application.
*
*
* @param request
* The request to handle.
* @param response
* The response to update.
*/
@Override
public void doHandle(Request request, Response response) {
super.doHandle(request, response);
final Protocol protocol = request.getProtocol();
if (protocol.equals(Protocol.RIAP)) {
// Let's dispatch it
final LocalReference cr = new LocalReference(request
.getResourceRef());
if (cr.getRiapAuthorityType() == LocalReference.RIAP_APPLICATION) {
if ((getChildContext() != null)
&& (getChildContext().getChild() instanceof Application)) {
Application application = (Application) getChildContext()
.getChild();
request.getResourceRef().setBaseRef(
request.getResourceRef().getHostIdentifier());
application.getRoot().handle(request, response);
}
} else if (cr.getRiapAuthorityType() == LocalReference.RIAP_COMPONENT) {
parentHandle(request, response);
} else if (cr.getRiapAuthorityType() == LocalReference.RIAP_HOST) {
parentHandle(request, response);
} else {
getLogger()
.warning(
"Unknown RIAP authority. Only \"component\", \"host\" and \"application\" are supported.");
}
} else {
if ((getChildContext() != null)
&& (getChildContext().getChild() instanceof Application)) {
Application application = (Application) getChildContext()
.getChild();
if (!application.getConnectorService().getClientProtocols()
.contains(protocol)) {
getLogger()
.fine(
"The protocol used by this request is not declared in the application's connector service. "
+ "Please update the list of client connectors used by your application and restart it.");
}
}
parentHandle(request, response);
}
}
/**
* Returns the child context.
*
* @return The child context.
*/
private ChildContext getChildContext() {
return (ChildContext) getContext();
}
/**
* Asks to the parent component to handle the call.
*
* @param request
* The request to handle.
* @param response
* The response to update.
*/
private void parentHandle(Request request, Response response) {
if (getChildContext() != null) {
if (getChildContext().getParentContext() != null) {
if (getChildContext().getParentContext().getClientDispatcher() != null) {
getChildContext().getParentContext().getClientDispatcher()
.handle(request, response);
} else {
getLogger()
.warning(
"The parent context doesn't have a client dispatcher available. Unable to handle call.");
}
} else {
getLogger()
.warning(
"Your Restlet doesn't have a parent context available.");
}
} else {
getLogger().warning(
"Your Restlet doesn't have a context available.");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy