Add extendible methods to RestfulServer
This commit is contained in:
parent
d9296b8e42
commit
20b1f883ba
|
@ -316,15 +316,11 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
if (isBlank(requestPath)) {
|
||||
throw new InvalidRequestException(myFhirContext.getLocalizer().getMessage(RestfulServer.class, "rootRequest"));
|
||||
}
|
||||
throw new InvalidRequestException(myFhirContext.getLocalizer().getMessage(RestfulServer.class, "unknownMethod", requestType.name(), requestPath, requestDetails.getParameters().keySet()));
|
||||
throwUnknownFhirOperationException(requestDetails, requestPath, requestType);
|
||||
}
|
||||
return resourceMethod;
|
||||
}
|
||||
|
||||
protected void throwUnknownResourceTypeException(String theResourceName) {
|
||||
throw new ResourceNotFoundException("Unknown resource type '" + theResourceName + "' - Server knows how to handle: " + myResourceNameToBinding.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
handleRequest(RequestTypeEnum.DELETE, request, response);
|
||||
|
@ -573,10 +569,10 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
*
|
||||
* @param theList The list of interceptors (may be null)
|
||||
*/
|
||||
public void setInterceptors(IServerInterceptor... theList) {
|
||||
public void setInterceptors(List<IServerInterceptor> theList) {
|
||||
myInterceptors.clear();
|
||||
if (theList != null) {
|
||||
myInterceptors.addAll(Arrays.asList(theList));
|
||||
myInterceptors.addAll(theList);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -606,11 +602,8 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
*
|
||||
* @see #setResourceProviders(Collection)
|
||||
*/
|
||||
public void setPlainProviders(Collection<Object> theProviders) {
|
||||
myPlainProviders.clear();
|
||||
if (theProviders != null) {
|
||||
myPlainProviders.addAll(theProviders);
|
||||
}
|
||||
public void setPlainProviders(Object... theProv) {
|
||||
setPlainProviders(Arrays.asList(theProv));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -640,10 +633,10 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
/**
|
||||
* Sets the resource providers for this server
|
||||
*/
|
||||
public void setResourceProviders(Collection<IResourceProvider> theResourceProviders) {
|
||||
public void setResourceProviders(IResourceProvider... theResourceProviders) {
|
||||
myResourceProviders.clear();
|
||||
if (theResourceProviders != null) {
|
||||
myResourceProviders.addAll(theResourceProviders);
|
||||
myResourceProviders.addAll(Arrays.asList(theResourceProviders));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1516,10 +1509,10 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
*
|
||||
* @param theList The list of interceptors (may be null)
|
||||
*/
|
||||
public void setInterceptors(List<IServerInterceptor> theList) {
|
||||
public void setInterceptors(IServerInterceptor... theList) {
|
||||
myInterceptors.clear();
|
||||
if (theList != null) {
|
||||
myInterceptors.addAll(theList);
|
||||
myInterceptors.addAll(Arrays.asList(theList));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1528,8 +1521,11 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
*
|
||||
* @see #setResourceProviders(Collection)
|
||||
*/
|
||||
public void setPlainProviders(Object... theProv) {
|
||||
setPlainProviders(Arrays.asList(theProv));
|
||||
public void setPlainProviders(Collection<Object> theProviders) {
|
||||
myPlainProviders.clear();
|
||||
if (theProviders != null) {
|
||||
myPlainProviders.addAll(theProviders);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1547,10 +1543,10 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
/**
|
||||
* Sets the resource providers for this server
|
||||
*/
|
||||
public void setResourceProviders(IResourceProvider... theResourceProviders) {
|
||||
public void setResourceProviders(Collection<IResourceProvider> theResourceProviders) {
|
||||
myResourceProviders.clear();
|
||||
if (theResourceProviders != null) {
|
||||
myResourceProviders.addAll(Arrays.asList(theResourceProviders));
|
||||
myResourceProviders.addAll(theResourceProviders);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1563,6 +1559,14 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
myTenantIdentificationStrategy = theTenantIdentificationStrategy;
|
||||
}
|
||||
|
||||
protected void throwUnknownFhirOperationException(RequestDetails requestDetails, String requestPath, RequestTypeEnum theRequestType) {
|
||||
throw new InvalidRequestException(myFhirContext.getLocalizer().getMessage(RestfulServer.class, "unknownMethod", theRequestType.name(), requestPath, requestDetails.getParameters().keySet()));
|
||||
}
|
||||
|
||||
protected void throwUnknownResourceTypeException(String theResourceName) {
|
||||
throw new ResourceNotFoundException("Unknown resource type '" + theResourceName + "' - Server knows how to handle: " + myResourceNameToBinding.keySet());
|
||||
}
|
||||
|
||||
public void unregisterInterceptor(IServerInterceptor theInterceptor) {
|
||||
Validate.notNull(theInterceptor, "Interceptor can not be null");
|
||||
myInterceptors.remove(theInterceptor);
|
||||
|
|
|
@ -9,9 +9,9 @@ package ca.uhn.fhir.rest.server.provider;
|
|||
* 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.
|
||||
|
|
Loading…
Reference in New Issue