当前位置: 首页>>代码示例>>Java>>正文


Java RestfulServerUtils类代码示例

本文整理汇总了Java中ca.uhn.fhir.rest.server.RestfulServerUtils的典型用法代码示例。如果您正苦于以下问题:Java RestfulServerUtils类的具体用法?Java RestfulServerUtils怎么用?Java RestfulServerUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RestfulServerUtils类属于ca.uhn.fhir.rest.server包,在下文中一共展示了RestfulServerUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReturnResponse

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testReturnResponse() throws IOException {
	IdType theId = new IdType(15L);
	int operationStatus = 200;
	boolean allowPrefer = true;
	String resourceName = "Patient";
	MethodOutcome methodOutcome = new MethodOutcome(theId);
	boolean addContentLocationHeader = true;
	boolean respondGzip = true;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals(Constants.CT_FHIR_JSON_NEW+"; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	assertTrue(result.getEntity().toString().contains("resourceType\": \"Patient"));
	assertTrue(result.getEntity().toString().contains("15"));
	
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:17,代码来源:JaxRsResponseDstu3Test.java

示例2: testReturnResponseAsXml

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testReturnResponseAsXml() throws IOException {
	IdType theId = new IdType(15L);
	int operationStatus = 200;
	boolean allowPrefer = true;
	String resourceName = "Patient";
	MethodOutcome methodOutcome = new MethodOutcome(theId);
	response.getRequestDetails().addParameter(Constants.PARAM_FORMAT, new String[]{Constants.CT_XML});
	boolean addContentLocationHeader = true;
	boolean respondGzip = true;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals("application/fhir+xml; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	assertTrue(result.getEntity().toString().contains("<Patient"));
	assertTrue(result.getEntity().toString().contains("15"));
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:17,代码来源:JaxRsResponseDstu3Test.java

示例3: incomingRequestPostProcessed

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Override
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
	EncodingEnum encoding = RestfulServerUtils.determineRequestEncodingNoDefault(theRequestDetails);
	if (encoding == null) {
		ourLog.trace("Incoming request does not appear to be FHIR, not going to validate");
		return true;
	}

	Charset charset = ResourceParameter.determineRequestCharset(theRequestDetails);
	String requestText = new String(theRequestDetails.loadRequestContents(), charset);

	if (isBlank(requestText)) {
		ourLog.trace("Incoming request does not have a body");
		return true;
	}

	ValidationResult validationResult = validate(requestText, theRequestDetails);

	// The JPA server will use this
	theRequestDetails.getUserData().put(REQUEST_VALIDATION_RESULT, validationResult);

	return true;
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:24,代码来源:RequestValidatingInterceptor.java

示例4: streamResponseHeaders

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
private void streamResponseHeaders(RequestDetails theRequestDetails, HttpServletResponse theServletResponse, StringBuilder b) {
	if (theServletResponse.getHeaderNames().isEmpty() == false) {
		b.append("<h1>Response Headers</h1>");

		b.append("<div class=\"headersDiv\">");
		for (String nextHeaderName : theServletResponse.getHeaderNames()) {
			for (String nextHeaderValue : theServletResponse.getHeaders(nextHeaderName)) {
				/*
				 * Let's pretend we're returning a FHIR content type even though we're
				 * actually returning an HTML one
				 */
				if (nextHeaderName.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE)) {
					ResponseEncoding responseEncoding = RestfulServerUtils.determineResponseEncodingNoDefault(theRequestDetails, theRequestDetails.getServer().getDefaultResponseEncoding());
					if (responseEncoding != null && isNotBlank(responseEncoding.getResourceContentType())) {
						nextHeaderValue = responseEncoding.getResourceContentType() + ";charset=utf-8";
					}
				}
				b.append("<div class=\"headersRow\">");
				b.append("<span class=\"headerName\">").append(nextHeaderName).append(": ").append("</span>");
				b.append("<span class=\"headerValue\">").append(nextHeaderValue).append("</span>");
				b.append("</div>");
			}
		}
		b.append("</div>");
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:27,代码来源:ResponseHighlighterInterceptor.java

示例5: translateQueryParametersIntoServerArgument

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Override
public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException {
	switch (myMode) {
	case BODY:
		try {
			return IOUtils.toString(createRequestReader(theRequest));
		} catch (IOException e) {
			// Shouldn't happen since we're reading from a byte array
			throw new InternalErrorException("Failed to load request", e);
		}
	case BODY_BYTE_ARRAY:
		return theRequest.loadRequestContents();
	case ENCODING:
		return RestfulServerUtils.determineRequestEncodingNoDefault(theRequest);
	case RESOURCE:
	default:
		return parseResourceFromRequest(theRequest, theMethodBinding, myResourceType);
	}
	// }
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:21,代码来源:ResourceParameter.java

示例6: invokeServer

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Override
public void invokeServer(RestfulServer theServer, Request theRequest) throws BaseServerResponseException, IOException {
	Object[] params = createParametersForServerRequest(theRequest, null);

	if (myIdParamIndex != null) {
		params[myIdParamIndex] = theRequest.getId();
	}
	if (myVersionIdParamIndex != null) {
		params[myVersionIdParamIndex] = theRequest.getId();
	}

	TagList resp = (TagList) invokeServerMethod(params);

	for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
		IServerInterceptor next = theServer.getInterceptors().get(i);
		boolean continueProcessing = next.outgoingResponse(theRequest, resp, theRequest.getServletRequest(), theRequest.getServletResponse());
		if (!continueProcessing) {
			return;
		}
	}
	
	EncodingEnum responseEncoding = RestfulServerUtils.determineResponseEncodingWithDefault(theServer, theRequest.getServletRequest());

	HttpServletResponse response = theRequest.getServletResponse();
	response.setContentType(responseEncoding.getResourceContentType());
	response.setStatus(Constants.STATUS_HTTP_200_OK);
	response.setCharacterEncoding(Constants.CHARSETNAME_UTF_8);

	theServer.addHeadersToResponse(response);

	IParser parser = responseEncoding.newParser(getContext());
	parser.setPrettyPrint(RestfulServerUtils.prettyPrintResponse(theServer, theRequest));
	PrintWriter writer = response.getWriter();
	try {
		parser.encodeTagListToWriter(resp, writer);
	} finally {
		writer.close();
	}
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:40,代码来源:GetTagsMethodBinding.java

示例7: parseRequestObject

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Override
protected Object parseRequestObject(Request theRequest) throws IOException {
	EncodingEnum encoding = RestfulServerUtils.determineRequestEncoding(theRequest);
	IParser parser = encoding.newParser(getContext());
	BufferedReader requestReader = theRequest.getServletRequest().getReader();

	if (theRequest.getRequestType() == RequestTypeEnum.GET) {
		return null;
	}

	Class<? extends IBaseResource> wantedResourceType = getContext().getResourceDefinition("Parameters").getImplementingClass();
	return parser.parseResource(wantedResourceType, requestReader);
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:14,代码来源:OperationMethodBinding.java

示例8: returnResponse

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Override
public Response returnResponse(ParseAction<?> outcome, int operationStatus, boolean allowPrefer,
		MethodOutcome response, String resourceName) throws IOException {
	StringWriter writer = new StringWriter();
	if (outcome != null) {
		FhirContext fhirContext = getRequestDetails().getServer().getFhirContext();
		IParser parser = RestfulServerUtils.getNewParser(fhirContext, fhirContext.getVersion().getVersion(), getRequestDetails());
		outcome.execute(parser, writer);
	}
	return sendWriterResponse(operationStatus, getParserType(), null, writer);
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:12,代码来源:JaxRsResponse.java

示例9: testSendAttachmentResponse

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testSendAttachmentResponse() throws IOException {
	boolean respondGzip = true;
	IBaseBinary binary = new Binary();
	String contentType = "foo";
	byte[] content = new byte[] { 1, 2, 3, 4 };
	binary.setContentType(contentType);
	binary.setContent(content);
	boolean theAddContentLocationHeader = false;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals(contentType, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	assertEquals(content, result.getEntity());
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:15,代码来源:JaxRsResponseTest.java

示例10: testSendAttachmentResponseNoContent

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testSendAttachmentResponseNoContent() throws IOException {
	boolean respondGzip = true;
	IBaseBinary binary = new Binary();
	binary.setContent(new byte[] {});
	boolean theAddContentLocationHeader = false;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals(null, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	assertEquals(null, result.getEntity());
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:12,代码来源:JaxRsResponseTest.java

示例11: testSendAttachmentResponseEmptyContent

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testSendAttachmentResponseEmptyContent() throws IOException {
	boolean respondGzip = true;
	IBaseBinary binary = new Binary();
	boolean theAddContentLocationHeader = false;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals(null, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	assertEquals(null, result.getEntity());
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:11,代码来源:JaxRsResponseTest.java

示例12: testReturnResponse

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testReturnResponse() throws IOException {
	boolean addContentLocationHeader = true;
	boolean respondGzip = true;
	// Response result = response.returnResponse(outcome, operationStatus, allowPrefer, methodOutcome, resourceName);
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	System.out.println(result.getEntity().toString());
	assertTrue(result.getEntity().toString().contains("resourceType\": \"Patient"));
	assertTrue(result.getEntity().toString().contains("15"));

}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:14,代码来源:JaxRsResponseTest.java

示例13: testReturnResponseAsXml

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testReturnResponseAsXml() throws IOException {
	response.getRequestDetails().addParameter(Constants.PARAM_FORMAT, new String[] { Constants.CT_XML });
	boolean addContentLocationHeader = true;
	boolean respondGzip = true;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals("application/xml+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	assertTrue(result.getEntity().toString().contains("<Patient"));
	assertTrue(result.getEntity().toString().contains("15"));
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:12,代码来源:JaxRsResponseTest.java

示例14: testNoOutcomeXml

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testNoOutcomeXml() throws IOException {
	response.getRequestDetails().addParameter(Constants.PARAM_FORMAT, new String[] { Constants.CT_XML });
	boolean addContentLocationHeader = true;
	boolean respondGzip = true;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
	assertEquals(200, result.getStatus());
	assertEquals("application/xml+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:10,代码来源:JaxRsResponseTest.java

示例15: testGetResponseWriterNoZipNoBrowser

import ca.uhn.fhir.rest.server.RestfulServerUtils; //导入依赖的package包/类
@Test
public void testGetResponseWriterNoZipNoBrowser() throws IOException {
	boolean theRequestIsBrowser = false;
	boolean respondGzip = false;
	Set<SummaryEnum> theSummaryMode = Collections.<SummaryEnum>emptySet();
       boolean theAddContentLocationHeader = false;
	Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), bundle, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, request);
	assertEquals(200, result.getStatus());
	assertEquals(Constants.CT_FHIR_JSON_NEW+Constants.CHARSET_UTF8_CTSUFFIX, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
	assertTrue(result.getEntity().toString().contains("Patient"));
	assertTrue(result.getEntity().toString().contains("15"));
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:13,代码来源:JaxRsResponseDstu3Test.java


注:本文中的ca.uhn.fhir.rest.server.RestfulServerUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。