本文整理汇总了Java中org.apache.cxf.jaxrs.ext.MessageContext类的典型用法代码示例。如果您正苦于以下问题:Java MessageContext类的具体用法?Java MessageContext怎么用?Java MessageContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageContext类属于org.apache.cxf.jaxrs.ext包,在下文中一共展示了MessageContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUploadExternalProperties
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@Test
public void testUploadExternalProperties() throws IOException {
final MessageContext msgContextMock = mock(MessageContext.class);
final HttpHeaders httpHeadersMock = mock(HttpHeaders.class);
final List<MediaType> mediaTypeList = new ArrayList<>();
final HttpServletRequest httpServletRequestMock = mock(HttpServletRequest.class);
final HttpServletResponse httpServletResponseMock = mock(HttpServletResponse.class);
when(httpHeadersMock.getAcceptableMediaTypes()).thenReturn(mediaTypeList);
when(msgContextMock.getHttpHeaders()).thenReturn(httpHeadersMock);
when(msgContextMock.getHttpServletRequest()).thenReturn(httpServletRequestMock);
when(msgContextMock.getHttpServletResponse()).thenReturn(httpServletResponseMock);
when(httpServletRequestMock.getContentType()).thenReturn("multipart/form-data; boundary=----WebKitFormBoundaryXRxegBGqTe4gApI2");
when(httpServletRequestMock.getInputStream()).thenReturn(new DelegatingServletInputStream());
cut.setMessageContext(msgContextMock);
final SecurityContext securityContextMock = mock(SecurityContext.class);
final AuthenticatedUser authenticatedUser = new AuthenticatedUser(securityContextMock);
final Principal mockPrincipal = mock(Principal.class);
when(mockPrincipal.getName()).thenReturn("user");
when(securityContextMock.getUserPrincipal()).thenReturn(mockPrincipal);
cut.uploadExternalProperties(authenticatedUser);
verify(impl).createResource(any(ResourceIdentifier.class), any(ResourceTemplateMetaData.class), any(InputStream.class));
}
示例2: getSelf
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@GET
@Path("/self")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml"})
public <T extends ObjectType> Response getSelf(@Context MessageContext mc){
LOGGER.debug("model rest service for get operation start");
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SELF);
Response response;
try {
UserType loggedInUser = SecurityUtil.getPrincipal().getUser();
PrismObject<UserType> user = model.getObject(UserType.class, loggedInUser.getOid(), null, task, parentResult);
response = RestServiceUtil.createResponse(Response.Status.OK, user, parentResult, true);
// ResponseBuilder builder = Response.ok();
// builder.entity(user);
// response = builder.build();
parentResult.recordSuccessIfUnknown();
} catch (SecurityViolationException | ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
response = RestServiceUtil.handleException(parentResult, e);
}
finishRequest(task);
return response;
}
示例3: findShadowOwner
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@GET
@Path("/shadows/{oid}/owner")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml"})
public Response findShadowOwner(@PathParam("oid") String shadowOid, @Context MessageContext mc){
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_FIND_SHADOW_OWNER);
Response response;
try {
PrismObject<UserType> user = model.findShadowOwner(shadowOid, task, parentResult);
// response = Response.ok().entity(user).build();
response = RestServiceUtil.createResponse(Response.Status.NO_CONTENT, user, parentResult);
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
parentResult.computeStatus();
finishRequest(task);
return response;
}
示例4: importFromResource
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@POST
@Path("/resources/{resourceOid}/import/{objectClass}")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml"})
public Response importFromResource(@PathParam("resourceOid") String resourceOid, @PathParam("objectClass") String objectClass,
@Context MessageContext mc, @Context UriInfo uriInfo) {
LOGGER.debug("model rest service for import from resource operation start");
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_IMPORT_FROM_RESOURCE);
QName objClass = new QName(MidPointConstants.NS_RI, objectClass);
Response response;
try {
model.importFromResource(resourceOid, objClass, task, parentResult);
response = RestServiceUtil.createResponse(Response.Status.SEE_OTHER, (uriInfo.getBaseUriBuilder().path(this.getClass(), "getObject")
.build(ObjectTypes.TASK.getRestType(), task.getOid())), parentResult);
// response = Response.seeOther((uriInfo.getBaseUriBuilder().path(this.getClass(), "getObject")
// .build(ObjectTypes.TASK.getRestType(), task.getOid()))).build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
parentResult.computeStatus();
finishRequest(task);
return response;
}
示例5: testResource
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@POST
@Path("/resources/{resourceOid}/test")
// @Produces({"text/html", "application/xml"})
public Response testResource(@PathParam("resourceOid") String resourceOid, @Context MessageContext mc) {
LOGGER.debug("model rest service for test resource operation start");
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_TEST_RESOURCE);
Response response;
OperationResult testResult = null;
try {
testResult = model.testResource(resourceOid, task);
response = RestServiceUtil.createResponse(Response.Status.OK, testResult, parentResult);
// response = Response.ok(testResult).build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
if (testResult != null) {
parentResult.getSubresults().add(testResult);
}
finishRequest(task);
return response;
}
示例6: suspendTasks
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@POST
@Path("/tasks/{oid}/suspend")
public Response suspendTasks(@PathParam("oid") String taskOid, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SUSPEND_TASKS);
Response response;
Collection<String> taskOids = MiscUtil.createCollection(taskOid);
try {
model.suspendTasks(taskOids, WAIT_FOR_TASK_STOP, parentResult);
parentResult.computeStatus();
response = RestServiceUtil.createResponse(Response.Status.NO_CONTENT, parentResult);
// if (parentResult.isSuccess()){
// response = Response.noContent().build();
// } else {
// response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(parentResult.getMessage()).build();
// }
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
finishRequest(task);
return response;
}
示例7: resumeTasks
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@POST
@Path("/tasks/{oid}/resume")
public Response resumeTasks(@PathParam("oid") String taskOid, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_RESUME_TASKS);
Response response;
Collection<String> taskOids = MiscUtil.createCollection(taskOid);
try {
model.resumeTasks(taskOids, parentResult);
parentResult.computeStatus();
response = RestServiceUtil.createResponse(Response.Status.ACCEPTED, parentResult);
// if (parentResult.isSuccess()) {
// response = Response.accepted().build();
// } else {
// response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(parentResult.getMessage()).build();
// }
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
finishRequest(task);
return response;
}
示例8: getLogFileSize
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@GET
@Path("/log/size")
@Produces({"text/plain"})
public Response getLogFileSize(@Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult result = task.getResult().createSubresult(OPERATION_GET_LOG_FILE_SIZE);
Response response;
try {
long size = modelDiagnosticService.getLogFileSize(task, result);
response = RestServiceUtil.createResponse(Response.Status.OK, String.valueOf(size), result);
// ResponseBuilder builder = Response.ok();
// builder.entity(String.valueOf(size));
// response = builder.build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(result, ex);
}
result.computeStatus();
finishRequest(task);
return response;
}
示例9: execute
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
private Response execute(CloseableHttpClient http, ServerInfo serverInfo, HttpRequestBase request, MessageContext context) throws IOException
{
ensureCertsAreLoaded(context);
CloseableHttpResponse response = http.execute(request, serverInfo.httpContext);
if (response == null)
{
return Response.status(Response.Status.BAD_GATEWAY).build();
}
Header[] responseHeaders = response.getAllHeaders();
ResponseBuilder builder = Response.status(response.getStatusLine().getStatusCode());
for (Header header : responseHeaders)
{
builder.header(header.getName(), header.getValue());
}
String strReply = new String(EntityUtils.toByteArray(response.getEntity()));
HttpServletRequest servletRequest = context.getHttpServletRequest();
StringBuffer entireRequestUrl = servletRequest.getRequestURL();
builder.entity(strReply.replaceAll(serverInfo.url.toExternalForm(), entireRequestUrl.substring(0, entireRequestUrl.indexOf(servletRequest.getPathInfo()))+"/"+serverInfo.name+"/"));
return builder.build();
}
示例10: testProxyCreation
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@Test
public void testProxyCreation() throws Exception
{
MessageContext msgContext = mock(MessageContext.class);
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
ServletContext servletContext = mock(ServletContext.class);
when(msgContext.getHttpServletRequest()).thenReturn(servletRequest);
when(msgContext.getServletContext()).thenReturn(servletContext);
when(servletContext.getRealPath("/WEB-INF/classes/certificates")).thenReturn("target/classes/certificates");
when(servletRequest.getQueryString()).thenReturn("f=pjson&token=shouldBeReplaced");
GeoEventDataStoreProxy proxy = new GeoEventDataStoreProxy();
//Response response = proxy.proxyGet("javidel", "arcgis/rest/info", msgContext);
//byte[] entity = (byte[])response.getEntity();
//System.out.println(new String(entity));
//response = proxy.proxyGet("portalhostqa", "gis/sharing/rest/info", msgContext);
//entity = (byte[])response.getEntity();
//System.out.println(new String(entity));
}
示例11: getOpenGridDatasetList
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@Override
public String getOpenGridDatasetList(MessageContext mc) throws JsonParseException, JsonMappingException, ServiceException, IOException {
String key = ServiceProperties.getProperties().getStringProperty("auth.key");
tokenAuthService.setKey(key);
String token = tokenAuthService.getToken(mc.getHttpServletRequest());
TokenHandler h = new TokenHandler();
h.setSecret(key);
Claims c = h.getClaims(token);
String descriptors = "";
List<String> ds = omniDataProvider.getAllDatasetIds(
ServiceProperties.getProperties().getStringProperty("mongo.metaCollectionName")
);
for (String s: ds) {
if (roleAccessValidator.lookupAccessMap("/rest/datasets/" + s, "GET", (String) c.get("resources"))) {
if (!descriptors.isEmpty())
descriptors += ", ";
descriptors += this.getOpenGridDataset(s);
}
}
return "[" + descriptors + "]";
}
示例12: validateValue
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@POST
@Path("/{type}/{oid}/validate")
@Consumes({"application/xml", "application/json", "application/yaml"})
@Produces({"application/xml", "application/json", "application/yaml"})
public <O extends ObjectType> Response validateValue(@PathParam("type") String type, @PathParam("oid") String oid, PolicyItemsDefinitionType policyItemsDefinition, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_VALIDATE_VALUE);
Class<O> clazz = ObjectTypes.getClassFromRestType(type);
Response response = null;
try {
PrismObject<O> object = model.getObject(clazz, oid, null, task, parentResult);
response = validateValue(object, policyItemsDefinition, task, parentResult);
} catch (Exception ex) {
parentResult.computeStatus();
response = RestServiceUtil.handleException(parentResult, ex);
}
finishRequest(task);
return response;
}
示例13: suspendTasks
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@POST
@Path("/tasks/{oid}/suspend")
public Response suspendTasks(@PathParam("oid") String taskOid, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SUSPEND_TASKS);
Response response;
Collection<String> taskOids = MiscUtil.createCollection(taskOid);
try {
model.suspendTasks(taskOids, WAIT_FOR_TASK_STOP, task, parentResult);
parentResult.computeStatus();
response = RestServiceUtil.createResponse(Response.Status.NO_CONTENT, task, parentResult);
// if (parentResult.isSuccess()){
// response = Response.noContent().build();
// } else {
// response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(parentResult.getMessage()).build();
// }
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
finishRequest(task);
return response;
}
示例14: resumeTasks
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
@POST
@Path("/tasks/{oid}/resume")
public Response resumeTasks(@PathParam("oid") String taskOid, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_RESUME_TASKS);
Response response;
Collection<String> taskOids = MiscUtil.createCollection(taskOid);
try {
model.resumeTasks(taskOids, task, parentResult);
parentResult.computeStatus();
response = RestServiceUtil.createResponse(Response.Status.ACCEPTED, parentResult);
// if (parentResult.isSuccess()) {
// response = Response.accepted().build();
// } else {
// response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(parentResult.getMessage()).build();
// }
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
finishRequest(task);
return response;
}
示例15: contextClasses
import org.apache.cxf.jaxrs.ext.MessageContext; //导入依赖的package包/类
private static Set<Class<?>> contextClasses() {
final Set<Class<?>> classes = new HashSet<>(); classes.add(UriInfo.class);
classes.add(SecurityContext.class);
classes.add(HttpHeaders.class);
classes.add(ContextResolver.class);
classes.add(Providers.class);
classes.add(Request.class);
/* TODO: when we have jaxrs 2
classes.add(ResourceInfo.class);
classes.add(ResourceContext.class);
*/
classes.add(Application.class);
classes.add(HttpServletRequest.class);
classes.add(HttpServletResponse.class);
classes.add(ServletConfig.class);
classes.add(ServletContext.class);
classes.add(MessageContext.class);
return classes;
}