Start working on server interceptors
This commit is contained in:
parent
ab17c9f3d1
commit
3808f95f6a
|
@ -97,6 +97,9 @@
|
|||
<action type="fix">
|
||||
Rename NotImpementedException to NotImplementedException (to correct typo)
|
||||
</action>
|
||||
<action type="fix">
|
||||
Server setUseBrowserFriendlyContentType setting also respected for errors (e.g. OperationOutcome with 4xx/5xx status)
|
||||
</action>
|
||||
</release>
|
||||
<release version="0.5" date="2014-Jul-30">
|
||||
<action type="add">
|
||||
|
|
|
@ -162,7 +162,7 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding<Void>
|
|||
params[myIdParamIndex] = theRequest.getId();
|
||||
|
||||
if (myVersionIdParamIndex != null) {
|
||||
params[myVersionIdParamIndex] = theRequest.getVersionId();
|
||||
params[myVersionIdParamIndex] = theRequest.getId();
|
||||
}
|
||||
|
||||
IParser parser = createAppropriateParserForParsingServerRequest(theRequest);
|
||||
|
@ -204,7 +204,7 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding<Void>
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((myVersionIdParamIndex != null) != (theRequest.getVersionId() != null)) {
|
||||
if ((myVersionIdParamIndex != null) != (theRequest.getId() != null && theRequest.getId().hasVersionIdPart())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
|
|||
throw new IllegalStateException("Should not get here!");
|
||||
}
|
||||
|
||||
public abstract IBundleProvider invokeServer(Request theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException;
|
||||
public abstract IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException;
|
||||
|
||||
@Override
|
||||
public void invokeServer(RestfulServer theServer, Request theRequest, HttpServletResponse theResponse) throws BaseServerResponseException, IOException {
|
||||
|
|
|
@ -65,7 +65,7 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding
|
|||
}
|
||||
|
||||
@Override
|
||||
public IBundleProvider invokeServer(Request theRequest, Object[] theMethodParams) throws BaseServerResponseException {
|
||||
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException {
|
||||
IResource conf = (IResource) invokeServerMethod(theMethodParams);
|
||||
return new SimpleBundleProvider(conf);
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ public class GetTagsMethodBinding extends BaseMethodBinding<TagList> {
|
|||
params[myIdParamIndex] = theRequest.getId();
|
||||
}
|
||||
if (myVersionIdParamIndex != null) {
|
||||
params[myVersionIdParamIndex] = theRequest.getVersionId();
|
||||
params[myVersionIdParamIndex] = theRequest.getId();
|
||||
}
|
||||
|
||||
TagList resp = (TagList) invokeServerMethod(params);
|
||||
|
|
|
@ -154,7 +154,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IBundleProvider invokeServer(Request theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
if (myIdParamIndex != null) {
|
||||
theMethodParams[myIdParamIndex] = theRequest.getId();
|
||||
}
|
||||
|
@ -220,7 +220,9 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (theRequest.getVersionId() != null && !theRequest.getVersionId().isEmpty()) {
|
||||
if (theRequest.getId() == null) {
|
||||
return myResourceOperationType == RestfulOperationTypeEnum.HISTORY_TYPE;
|
||||
} else if (theRequest.getId().hasVersionIdPart()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,14 +91,14 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (mySupportsVersion == false) {
|
||||
if ((theRequest.getVersionId() == null) != (myVersionIdIndex == null)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (theRequest.getId() == null) {
|
||||
return false;
|
||||
}
|
||||
if (mySupportsVersion == false) {
|
||||
if (theRequest.getId().hasVersionIdPart()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (theRequest.getRequestType() != RequestType.GET) {
|
||||
ourLog.trace("Method {} doesn't match because request type is not GET: {}", theRequest.getId(), theRequest.getRequestType());
|
||||
return false;
|
||||
|
@ -107,7 +107,7 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem
|
|||
if (mySupportsVersion == false && myVersionIdIndex == null) {
|
||||
return false;
|
||||
}
|
||||
if (theRequest.getVersionId() == null) {
|
||||
if (theRequest.getId().hasVersionIdPart()==false) {
|
||||
return false;
|
||||
}
|
||||
} else if (!StringUtils.isBlank(theRequest.getOperation())) {
|
||||
|
@ -122,10 +122,10 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public IBundleProvider invokeServer(Request theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
theMethodParams[myIdIndex] = theRequest.getId();
|
||||
if (myVersionIdIndex != null) {
|
||||
theMethodParams[myVersionIdIndex] = new IdDt(theRequest.getVersionId().getVersionIdPart());
|
||||
theMethodParams[myVersionIdIndex] = new IdDt(theRequest.getId().getVersionIdPart());
|
||||
}
|
||||
|
||||
Object response = invokeServerMethod(theMethodParams);
|
||||
|
|
|
@ -30,24 +30,23 @@ import java.util.Set;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
|
||||
|
||||
public class Request {
|
||||
/**
|
||||
* This class is internal to HAPI - Use with caution as methods may change in future versions of the library
|
||||
*/
|
||||
public class Request extends RequestDetails {
|
||||
|
||||
private String myCompleteUrl;
|
||||
private String myFhirServerBase;
|
||||
private IdDt myId;
|
||||
private String myOperation;
|
||||
private Map<String, String[]> myParameters;
|
||||
private RequestType myRequestType;
|
||||
private String myResourceName;
|
||||
private boolean myRespondGzip;
|
||||
private String mySecondaryOperation;
|
||||
private HttpServletRequest myServletRequest;
|
||||
private HttpServletResponse myServletResponse;
|
||||
private IdDt myVersion;
|
||||
private Map<String,List<String>> myUnqualifiedToQualifiedNames;
|
||||
private boolean myRespondGzip;
|
||||
private Map<String, List<String>> myUnqualifiedToQualifiedNames;
|
||||
|
||||
public String getCompleteUrl() {
|
||||
return myCompleteUrl;
|
||||
|
@ -57,19 +56,10 @@ public class Request {
|
|||
return myFhirServerBase;
|
||||
}
|
||||
|
||||
public IdDt getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
public String getOperation() {
|
||||
return myOperation;
|
||||
}
|
||||
|
||||
public Map<String, String[]> getParameters() {
|
||||
return myParameters;
|
||||
}
|
||||
|
||||
|
||||
public RequestType getRequestType() {
|
||||
return myRequestType;
|
||||
}
|
||||
|
@ -90,8 +80,12 @@ public class Request {
|
|||
return myServletResponse;
|
||||
}
|
||||
|
||||
public IdDt getVersionId() {
|
||||
return myVersion;
|
||||
public Map<String, List<String>> getUnqualifiedToQualifiedNames() {
|
||||
return myUnqualifiedToQualifiedNames;
|
||||
}
|
||||
|
||||
public boolean isRespondGzip() {
|
||||
return myRespondGzip;
|
||||
}
|
||||
|
||||
public void setCompleteUrl(String theCompleteUrl) {
|
||||
|
@ -102,28 +96,25 @@ public class Request {
|
|||
myFhirServerBase = theFhirServerBase;
|
||||
}
|
||||
|
||||
public void setId(IdDt theId) {
|
||||
myId = theId;
|
||||
}
|
||||
|
||||
public void setOperation(String theOperation) {
|
||||
myOperation = theOperation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameters(Map<String, String[]> theParams) {
|
||||
myParameters = theParams;
|
||||
|
||||
for (String next : myParameters.keySet()) {
|
||||
for (int i = 0; i < next.length();i++) {
|
||||
super.setParameters(theParams);
|
||||
|
||||
for (String next : theParams.keySet()) {
|
||||
for (int i = 0; i < next.length(); i++) {
|
||||
char nextChar = next.charAt(i);
|
||||
if(nextChar == ':' || nextChar == '.') {
|
||||
if (myUnqualifiedToQualifiedNames==null) {
|
||||
if (nextChar == ':' || nextChar == '.') {
|
||||
if (myUnqualifiedToQualifiedNames == null) {
|
||||
myUnqualifiedToQualifiedNames = new HashMap<String, List<String>>();
|
||||
}
|
||||
String unqualified = next.substring(0,i);
|
||||
String unqualified = next.substring(0, i);
|
||||
List<String> list = myUnqualifiedToQualifiedNames.get(unqualified);
|
||||
if (list==null) {
|
||||
list=new ArrayList<String>(4);
|
||||
if (list == null) {
|
||||
list = new ArrayList<String>(4);
|
||||
myUnqualifiedToQualifiedNames.put(unqualified, list);
|
||||
}
|
||||
list.add(next);
|
||||
|
@ -132,13 +123,10 @@ public class Request {
|
|||
}
|
||||
}
|
||||
|
||||
if (myUnqualifiedToQualifiedNames==null) {
|
||||
myUnqualifiedToQualifiedNames=Collections.emptyMap();
|
||||
if (myUnqualifiedToQualifiedNames == null) {
|
||||
myUnqualifiedToQualifiedNames = Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getUnqualifiedToQualifiedNames() {
|
||||
return myUnqualifiedToQualifiedNames;
|
||||
}
|
||||
|
||||
public void setRequestType(RequestType theRequestType) {
|
||||
|
@ -149,6 +137,10 @@ public class Request {
|
|||
myResourceName = theResourceName;
|
||||
}
|
||||
|
||||
public void setRespondGzip(boolean theRespondGzip) {
|
||||
myRespondGzip = theRespondGzip;
|
||||
}
|
||||
|
||||
public void setSecondaryOperation(String theSecondaryOperation) {
|
||||
mySecondaryOperation = theSecondaryOperation;
|
||||
}
|
||||
|
@ -161,10 +153,6 @@ public class Request {
|
|||
myServletResponse = theServletResponse;
|
||||
}
|
||||
|
||||
public void setVersion(IdDt theVersion) {
|
||||
myVersion = theVersion;
|
||||
}
|
||||
|
||||
public static Request withResourceAndParams(String theResourceName, RequestType theRequestType, Set<String> theParamNames) {
|
||||
Request retVal = new Request();
|
||||
retVal.setResourceName(theResourceName);
|
||||
|
@ -177,12 +165,4 @@ public class Request {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
public void setRespondGzip(boolean theRespondGzip) {
|
||||
myRespondGzip=theRespondGzip;
|
||||
}
|
||||
|
||||
public boolean isRespondGzip() {
|
||||
return myRespondGzip;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package ca.uhn.fhir.rest.method;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
|
||||
public class RequestDetails {
|
||||
|
||||
private IdDt myId;
|
||||
private Map<String, String[]> myParameters;
|
||||
private RestfulOperationTypeEnum myResourceOperationType;
|
||||
private RestfulOperationSystemEnum mySystemOperationType;
|
||||
|
||||
public IdDt getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
public Map<String, String[]> getParameters() {
|
||||
return myParameters;
|
||||
}
|
||||
|
||||
|
||||
public RestfulOperationTypeEnum getResourceOperationType() {
|
||||
return myResourceOperationType;
|
||||
}
|
||||
|
||||
public RestfulOperationSystemEnum getSystemOperationType() {
|
||||
return mySystemOperationType;
|
||||
}
|
||||
|
||||
public void setId(IdDt theId) {
|
||||
myId = theId;
|
||||
}
|
||||
|
||||
public void setParameters(Map<String, String[]> theParams) {
|
||||
myParameters = theParams;
|
||||
}
|
||||
|
||||
|
||||
public void setResourceOperationType(RestfulOperationTypeEnum theResourceOperationType) {
|
||||
myResourceOperationType = theResourceOperationType;
|
||||
}
|
||||
|
||||
public void setSystemOperationType(RestfulOperationSystemEnum theSystemOperationType) {
|
||||
mySystemOperationType = theSystemOperationType;
|
||||
}
|
||||
|
||||
}
|
|
@ -122,9 +122,8 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IBundleProvider invokeServer(Request theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
assert theRequest.getId() == null;
|
||||
assert theRequest.getVersionId() == null;
|
||||
|
||||
Object response = invokeServerMethod(theMethodParams);
|
||||
|
||||
|
@ -138,8 +137,8 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
ourLog.trace("Method {} doesn't match because resource name {} != {}", getMethod().getName(), theRequest.getResourceName(), getResourceName());
|
||||
return false;
|
||||
}
|
||||
if (theRequest.getId() != null || theRequest.getVersionId() != null) {
|
||||
ourLog.trace("Method {} doesn't match because ID or Version are not null: {} - {}", theRequest.getId(), theRequest.getVersionId());
|
||||
if (theRequest.getId() != null) {
|
||||
ourLog.trace("Method {} doesn't match because IDis not null: {}", theRequest.getId());
|
||||
return false;
|
||||
}
|
||||
if (theRequest.getRequestType() == RequestType.GET && theRequest.getOperation() != null && !Constants.PARAM_SEARCH.equals(theRequest.getOperation())) {
|
||||
|
|
|
@ -93,7 +93,7 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public IBundleProvider invokeServer(Request theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
// Grab the IDs of all of the resources in the transaction
|
||||
List<IResource> resources;
|
||||
if (theMethodParams[myTransactionParamIndex] instanceof Bundle) {
|
||||
|
|
|
@ -91,14 +91,11 @@ class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithResourceP
|
|||
if (mo.getId() == null || mo.getId().isEmpty()) {
|
||||
throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader);
|
||||
}
|
||||
if (mo.getVersionId() != null && mo.getVersionId().isEmpty() == false) {
|
||||
theRequest.setVersion(mo.getVersionId());
|
||||
}
|
||||
}
|
||||
|
||||
theParams[myIdParameterIndex] = theRequest.getId();
|
||||
if (myVersionIdParameterIndex != null) {
|
||||
theParams[myVersionIdParameterIndex] = theRequest.getVersionId();
|
||||
theParams[myVersionIdParameterIndex] = theRequest.getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
|
|||
import ca.uhn.fhir.rest.method.IParameter;
|
||||
import ca.uhn.fhir.rest.method.QualifiedParamList;
|
||||
import ca.uhn.fhir.rest.method.Request;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
||||
|
@ -111,7 +112,7 @@ public abstract class BaseQueryParameter implements IParameter {
|
|||
|
||||
}
|
||||
|
||||
private void parseParams(Request theRequest, List<QualifiedParamList> paramList, String theQualifiedParamName, String theQualifier) {
|
||||
private void parseParams(RequestDetails theRequest, List<QualifiedParamList> paramList, String theQualifiedParamName, String theQualifier) {
|
||||
String[] value = theRequest.getParameters().get(theQualifiedParamName);
|
||||
if (value != null) {
|
||||
for (String nextParam : value) {
|
||||
|
|
|
@ -70,12 +70,14 @@ import ca.uhn.fhir.parser.IParser;
|
|||
import ca.uhn.fhir.rest.method.BaseMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.ConformanceMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.Request;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
|
||||
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
|
||||
import ca.uhn.fhir.util.VersionUtil;
|
||||
|
@ -605,11 +607,23 @@ public class RestfulServer extends HttpServlet {
|
|||
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
handleRequest(SearchMethodBinding.RequestType.PUT, request, response);
|
||||
}
|
||||
|
||||
|
||||
private List<IServerInterceptor> myInterceptors = new ArrayList<IServerInterceptor>();
|
||||
|
||||
|
||||
protected void handleRequest(SearchMethodBinding.RequestType theRequestType, HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException {
|
||||
for(IServerInterceptor next : myInterceptors) {
|
||||
boolean continueProcessing = next.incomingRequest(theRequest, theResponse);
|
||||
if (!continueProcessing) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String fhirServerBase = null;
|
||||
boolean requestIsBrowser = requestIsBrowser(theRequest);
|
||||
try {
|
||||
|
||||
|
||||
if (null != mySecurityManager) {
|
||||
mySecurityManager.authenticate(theRequest);
|
||||
}
|
||||
|
@ -633,7 +647,6 @@ public class RestfulServer extends HttpServlet {
|
|||
}
|
||||
|
||||
IdDt id = null;
|
||||
IdDt versionId = null;
|
||||
String operation = null;
|
||||
|
||||
String requestPath = requestFullPath.substring(escapedLength(servletContextPath) + escapedLength(servletPath));
|
||||
|
@ -691,7 +704,6 @@ public class RestfulServer extends HttpServlet {
|
|||
throw new InvalidRequestException("Don't know how to handle request path: " + requestPath);
|
||||
}
|
||||
id = new IdDt(resourceName + "/" + id.getIdPart() + "/_history/" + versionString);
|
||||
versionId = id;
|
||||
} else {
|
||||
operation = Constants.PARAM_HISTORY;
|
||||
}
|
||||
|
@ -717,10 +729,10 @@ public class RestfulServer extends HttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
if (theRequestType == RequestType.PUT && versionId == null) {
|
||||
if (theRequestType == RequestType.PUT) {
|
||||
String contentLocation = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION);
|
||||
if (contentLocation != null) {
|
||||
versionId = new IdDt(contentLocation);
|
||||
id = new IdDt(contentLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -740,7 +752,6 @@ public class RestfulServer extends HttpServlet {
|
|||
Request r = new Request();
|
||||
r.setResourceName(resourceName);
|
||||
r.setId(id);
|
||||
r.setVersion(versionId);
|
||||
r.setOperation(operation);
|
||||
r.setSecondaryOperation(secondaryOperation);
|
||||
r.setParameters(params);
|
||||
|
@ -760,7 +771,7 @@ public class RestfulServer extends HttpServlet {
|
|||
if (resourceMethod == null && resourceBinding != null) {
|
||||
resourceMethod = resourceBinding.getMethod(r);
|
||||
}
|
||||
if (null == resourceMethod) {
|
||||
if (resourceMethod == null) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("No resource method available for ");
|
||||
b.append(theRequestType.name());
|
||||
|
@ -772,10 +783,21 @@ public class RestfulServer extends HttpServlet {
|
|||
throw new InvalidRequestException(b.toString());
|
||||
}
|
||||
|
||||
RequestDetails requestDetails = r;
|
||||
requestDetails.setResourceOperationType(resourceMethod.getResourceOperationType());
|
||||
requestDetails.setSystemOperationType(resourceMethod.getSystemOperationType());
|
||||
|
||||
for (IServerInterceptor next : myInterceptors) {
|
||||
boolean continueProcessing = next.incomingRequest(requestDetails, theRequest, theResponse);
|
||||
if (!continueProcessing) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
resourceMethod.invokeServer(this, r, theResponse);
|
||||
|
||||
} catch (AuthenticationException e) {
|
||||
if (requestIsBrowser(theRequest)) {
|
||||
if (requestIsBrowser) {
|
||||
// if request is coming from a browser, prompt the user to enter login credentials
|
||||
theResponse.setHeader("WWW-Authenticate", "BASIC realm=\"FHIR\"");
|
||||
}
|
||||
|
@ -812,7 +834,7 @@ public class RestfulServer extends HttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
streamResponseAsResource(this, theResponse, oo, determineResponseEncoding(theRequest), true, false, NarrativeModeEnum.NORMAL, statusCode, false, fhirServerBase);
|
||||
streamResponseAsResource(this, theResponse, oo, determineResponseEncoding(theRequest), true, requestIsBrowser, NarrativeModeEnum.NORMAL, statusCode, false, fhirServerBase);
|
||||
|
||||
theResponse.setStatus(statusCode);
|
||||
addHeadersToResponse(theResponse);
|
||||
|
@ -938,7 +960,7 @@ public class RestfulServer extends HttpServlet {
|
|||
return b.toString();
|
||||
}
|
||||
|
||||
public static NarrativeModeEnum determineNarrativeMode(Request theRequest) {
|
||||
public static NarrativeModeEnum determineNarrativeMode(RequestDetails theRequest) {
|
||||
Map<String, String[]> requestParams = theRequest.getParameters();
|
||||
String[] narrative = requestParams.remove(Constants.PARAM_NARRATIVE);
|
||||
NarrativeModeEnum narrativeMode = null;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.rest.server.security;
|
||||
package ca.uhn.fhir.rest.server.interceptor;
|
||||
|
||||
/*
|
||||
* #%L
|
|
@ -0,0 +1,68 @@
|
|||
package ca.uhn.fhir.rest.server.interceptor;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 University Health Network
|
||||
* %%
|
||||
* 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.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
|
||||
/**
|
||||
* Provides methods to intercept requests and responses
|
||||
*/
|
||||
public interface IServerInterceptor {
|
||||
|
||||
/**
|
||||
* This method is called before any other processing takes place for each incoming request. It may be used to provide alternate handling for some requests, or to screen requests before they are
|
||||
* handled, etc.
|
||||
* <p>
|
||||
* Note that any exceptions thrown by this method will not be trapped by HAPI (they will be passed up to the server)
|
||||
* </p>
|
||||
*
|
||||
* @param theRequest
|
||||
* The incoming request
|
||||
* @param theResponse
|
||||
* The response. Note that interceptors may choose to provide a response (i.e. by calling {@link HttpServletResponse#getWriter()}) but in that case it is important to return
|
||||
* <code>true</code>
|
||||
* @return Return <code>true</code> if processing should continue normally. This is generally the right thing to do. If your interceptor is providing a response rather than letting HAPI handle the
|
||||
* response normally, you must return <code>false</code>. In this case, no further processing will occur and no further interceptors will be called.
|
||||
*/
|
||||
public boolean incomingRequest(HttpServletRequest theRequest, HttpServletResponse theResponse);
|
||||
|
||||
/**
|
||||
* This method is called just before the actual implementing server method is invoked
|
||||
*
|
||||
* @param theRequestDetails
|
||||
* A bean containing details about the request that is about to be processed, including
|
||||
* @param theRequest
|
||||
* The incoming request
|
||||
* @param theResponse
|
||||
* The response. Note that interceptors may choose to provide a response (i.e. by calling {@link HttpServletResponse#getWriter()}) but in that case it is important to return
|
||||
* <code>true</code>
|
||||
* @return Return <code>true</code> if processing should continue normally. This is generally the right thing to do. If your interceptor is providing a response rather than letting HAPI handle the
|
||||
* response normally, you must return <code>false</code>. In this case, no further processing will occur and no further interceptors will be called.
|
||||
* @throws AuthenticationException
|
||||
* This exception may be thrown to indicate that the interceptor has detected an unauthorized access attempt
|
||||
*/
|
||||
public boolean incomingRequest(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException;
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package ca.uhn.fhir.rest.server.security;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 University Health Network
|
||||
* %%
|
||||
* 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.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
|
||||
/**
|
||||
* Implementations of this interface provide authorization to incoming service calls
|
||||
*
|
||||
*/
|
||||
public interface IResourceSecurity {
|
||||
|
||||
public ISecurityOutcome authenticate(HttpServletRequest request) throws AuthenticationException;
|
||||
|
||||
}
|
|
@ -1300,16 +1300,16 @@ public class ResfulServerMethodTest {
|
|||
* @return The resource
|
||||
*/
|
||||
@Read()
|
||||
public Patient getResourceById(@IdParam IdDt theId) {
|
||||
public Patient read(@IdParam IdDt theId) {
|
||||
return getIdToPatient().get(theId.getIdPart());
|
||||
}
|
||||
|
||||
@Read()
|
||||
public Patient getResourceById(@IdParam IdDt theId, @VersionIdParam IdDt theVersionId) {
|
||||
@Read(version=true)
|
||||
public Patient vread(@IdParam IdDt theId) {
|
||||
Patient retVal = getIdToPatient().get(theId.getIdPart());
|
||||
List<HumanNameDt> name = retVal.getName();
|
||||
HumanNameDt nameDt = name.get(0);
|
||||
String value = theVersionId.getValue();
|
||||
String value = theId.getVersionIdPart();
|
||||
nameDt.setText(value);
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<dependent-module archiveName="hapi-fhir-base-0.6-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/hapi-fhir-base/hapi-fhir-base">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module deploy-path="/" handle="module:/overlay/var/M2_REPO/ca/uhn/hapi/fhir/hapi-fhir-testpage-overlay/0.6-SNAPSHOT/hapi-fhir-testpage-overlay-0.6-SNAPSHOT.war?unpackFolder=target/m2e-wtp/overlays&includes=**/**&excludes=META-INF/MANIFEST.MF">
|
||||
<dependent-module deploy-path="/" handle="module:/overlay/prj/hapi-fhir-testpage-overlay?includes=**/**&excludes=META-INF/MANIFEST.MF">
|
||||
<dependency-type>consumes</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module deploy-path="/" handle="module:/overlay/slf/?includes=**/**&excludes=META-INF/MANIFEST.MF">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<dependent-module archiveName="hapi-fhir-base-0.6-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/hapi-fhir-base/hapi-fhir-base">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module deploy-path="/" handle="module:/overlay/var/M2_REPO/ca/uhn/hapi/fhir/hapi-fhir-testpage-overlay/0.6-SNAPSHOT/hapi-fhir-testpage-overlay-0.6-SNAPSHOT.war?unpackFolder=target/m2e-wtp/overlays&includes=**/**&excludes=META-INF/MANIFEST.MF">
|
||||
<dependent-module deploy-path="/" handle="module:/overlay/prj/hapi-fhir-testpage-overlay?includes=**/**&excludes=META-INF/MANIFEST.MF">
|
||||
<dependency-type>consumes</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module deploy-path="/" handle="module:/overlay/slf/?includes=**/**&excludes=META-INF/MANIFEST.MF">
|
||||
|
|
Loading…
Reference in New Issue