本文整理汇总了Java中org.glassfish.jersey.server.mvc.Viewable类的典型用法代码示例。如果您正苦于以下问题:Java Viewable类的具体用法?Java Viewable怎么用?Java Viewable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Viewable类属于org.glassfish.jersey.server.mvc包,在下文中一共展示了Viewable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateSystemOption
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@POST
@Path("/option/{optionName}")
@Consumes("application/x-www-form-urlencoded")
@Produces(MediaType.TEXT_HTML)
public Viewable updateSystemOption(@FormParam("name") String name, @FormParam("value") String value,
@FormParam("kind") String kind) {
try {
work.getContext()
.getOptionManager()
.setOption(OptionValue.createOption(
OptionValue.Kind.valueOf(kind),
OptionValue.OptionType.SYSTEM,
name,
value));
} catch (Exception e) {
logger.debug("Could not update.", e);
}
return getSystemOptions();
}
示例2: defaultPage
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_HTML)
public Response defaultPage(@Context UriInfo ui) throws URISyntaxException {
/*
* This redirect is required due to change of "Jersey" version from "1.17" to "2.13".
* The "1.*" version of jersey has property "FEATURE_REDIRECT".
* For example, when making request "localhost:8888/context/dev", Jersey checks whether "FEATURE_REDIRECT" is set to "true" in ServletContainer and request does not end with '/'.
* If so, trailing slash is added and redirect is occurred to "localhost:8888/context/dev/"
*
* Jersey "2.*" does not contain property "FEATURE_REDIRECT".
* The code that made redirect in "1.*" jersey is commented out in ServletContainer.java:504
* Jersey "2.*" resolves request even if '/' was not present in the end.
* But all links in our *.jsp and *.html to *.js and *.css are relative. So without adding '/' in the end, files can not be opened.
* To solve it, we introduced this redirect
*/
if (!ui.getAbsolutePath().toString().endsWith("/")) {
return Response.temporaryRedirect(new URI(ui.getAbsolutePath().toString() + "/")).build();
} else {
return Response.ok(new Viewable("/index.jsp", new HashMap<String, Object>())).build();
}
}
示例3: writeTo
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@Override
public void writeTo(String templateReference, Viewable viewable, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException {
// 获取 模板引擎
VelocityEngine velocityEngine = getVelocityEngine();
// 实例化一个VelocityContext
VelocityContext context = (VelocityContext) viewable.getModel();
Enumeration<String> enums = request.getParameterNames();
while (enums.hasMoreElements()) {
String key = enums.nextElement();
context.put(key, request.getParameter(key));
}
// 把request放进模板上下文里
context.put("request", request);
// 渲染并输出
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out);
velocityEngine.mergeTemplate(templateReference, "utf8", context, outputStreamWriter);
outputStreamWriter.flush();
outputStreamWriter.close(); // 有必要关闭吗? 关闭了是否对jax-rs拦截器,servlet有影响,需要继续学习,参考jsp模板实现
}
示例4: writeTo
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@Override
public void writeTo(final Template template, final Viewable viewable, final MediaType mediaType,
final MultivaluedMap<String, Object> httpHeaders, final OutputStream out) throws IOException {
try {
Object model = viewable.getModel();
if (!(model instanceof Map)) {
model = new HashMap<String, Object>() {{
put("model", viewable.getModel());
}};
}
Charset encoding = setContentType(mediaType, httpHeaders);
template.process(model, new OutputStreamWriter(out, encoding));
} catch (TemplateException te) {
throw new ContainerException(te);
}
}
示例5: updateSystemOption
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@SuppressWarnings("resource")
@POST
@Path("option/{optionName}")
@RolesAllowed(DrillUserPrincipal.ADMIN_ROLE)
@Consumes("application/x-www-form-urlencoded")
@Produces(MediaType.TEXT_HTML)
public Viewable updateSystemOption(@FormParam("name") String name,
@FormParam("value") String value,
@FormParam("kind") String kind) {
SystemOptionManager optionManager = work.getContext()
.getOptionManager();
try {
optionManager.setLocalOption(OptionValue.Kind.valueOf(kind), name, value);
} catch (Exception e) {
logger.debug("Could not update.", e);
}
if (optionManager.getOptionDefinition(name).getMetaData().isInternal()) {
return getSystemInternalOptions();
} else {
return getSystemPublicOptions();
}
}
示例6: submitQuery
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@POST
@Path("/query")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public Viewable submitQuery(@FormParam("query") String query,
@FormParam("queryType") String queryType) throws Exception {
try {
final String trimmedQueryString = CharMatcher.is(';').trimTrailingFrom(query.trim());
final QueryResult result = submitQueryJSON(new QueryWrapper(trimmedQueryString, queryType));
return ViewableWithPermissions.create(authEnabled.get(), "/rest/query/result.ftl", sc, new TabularResult(result));
} catch (Exception | Error e) {
logger.error("Query from Web UI Failed", e);
return ViewableWithPermissions.create(authEnabled.get(), "/rest/query/errorMessage.ftl", sc, e);
}
}
示例7: getLoginPage
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@GET
@Path(WebServerConstants.FORM_LOGIN_RESOURCE_PATH)
@Produces(MediaType.TEXT_HTML)
public Viewable getLoginPage(@Context HttpServletRequest request, @Context HttpServletResponse response,
@Context SecurityContext sc, @Context UriInfo uriInfo,
@QueryParam(WebServerConstants.REDIRECT_QUERY_PARM) String redirect) throws Exception {
if (AuthDynamicFeature.isUserLoggedIn(sc)) {
// if the user is already login, forward the request to homepage.
request.getRequestDispatcher(WebServerConstants.WEBSERVER_ROOT_PATH).forward(request, response);
return null;
}
updateSessionRedirectInfo(redirect, request);
return ViewableWithPermissions.createLoginPage(null);
}
示例8: getSpnegoLogin
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@GET
@Path(WebServerConstants.SPENGO_LOGIN_RESOURCE_PATH)
@Produces(MediaType.TEXT_HTML)
public Viewable getSpnegoLogin(@Context HttpServletRequest request, @Context HttpServletResponse response,
@Context SecurityContext sc, @Context UriInfo uriInfo,
@QueryParam(WebServerConstants.REDIRECT_QUERY_PARM) String redirect) throws Exception {
if (AuthDynamicFeature.isUserLoggedIn(sc)) {
request.getRequestDispatcher(WebServerConstants.WEBSERVER_ROOT_PATH).forward(request, response);
return null;
}
final String errorString = "Invalid SPNEGO credentials or SPNEGO is not configured";
final DrillConfig drillConfig = workManager.getContext().getConfig();
MainLoginPageModel model = new MainLoginPageModel(errorString, drillConfig);
return ViewableWithPermissions.createMainLoginPage(model);
}
示例9: doLogin
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@GET
public Response doLogin(@PathParam("code") final String code) {
final Validation v = commonValidation(code);
if (v.getError() != null) {
return v.getError();
}
final LoginCode loginCode = v.getLoginCode();
final List<UserClientScope> userClientScopes = getUserClientScopes(loginCode);
if (!loginCode.getClient().isShowPromptNoScopes() &&
(userClientScopes.isEmpty() || userClientScopes.stream().allMatch(ucs -> ucs.getAcceptedScope() != null))) {
return acceptPermissions(code, "ok", new MultivaluedHashMap<>());
}
return Response.ok(
new Viewable("/templates/Permissions.ftl", new PermissionsModel(loginCode, userClientScopes))
).build();
}
示例10: root
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_HTML)
public Response root() {
LOG.info("Mainpage is requested");
List<DeploymentArtifactTopology> dats = new ArrayList<DeploymentArtifactTopology>();
try {
dats.addAll(new DATopologyDataSource().getDATs());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Response.ok(
new Viewable("index", new MainResourceDAO(Configuration
.getInstance(), dats))).build();
}
示例11: index
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@GET
@Path("{userName}")
@Produces(MediaType.TEXT_HTML)
public Viewable index(@PathParam("userName") String userName, @QueryParam("tab") final String tab) {
Account account = userService.findAccount(userName);
MapViewable viewable = new MapViewable("/user/main.ftl").add("account", account).add("tab", tab);
if ("activity".equals(tab)) {
} else {
viewable.add("repositories", repositoryService.getByOwner(userName));
}
return viewable;
}
示例12: writeTo
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
@Override
public void writeTo(JasperReport jr, Viewable vwbl, MediaType mt, MultivaluedMap<String, Object> mm, OutputStream outputStream) throws IOException {
JasperModel jasperModel = null;
try{
jasperModel = findJasperModel(vwbl);
}catch(JRException e){
throw new IllegalStateException("Cannot load jasper model", e);
}
try {
JasperPrint print = getJasperFactory().getJasperProxy().fillReport(jr,
jasperModel.getParameters(),
jasperModel.getListModels());
factory.getJasperProxy().exportReportToPDFStream(print, outputStream);
} catch (JRException jre) {
throw new IOException("Houve um problema ao gerar a ficha do snapshot/processo", jre);
}
}
示例13: writeViewable
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
/**
* <p>writeViewable.</p>
*
* @param viewable a {@link org.glassfish.jersey.server.mvc.Viewable} object.
* @param mediaType a {@link javax.ws.rs.core.MediaType} object.
* @param httpHeaders a {@link javax.ws.rs.core.MultivaluedMap} object.
* @param entityStream a {@link java.io.OutputStream} object.
* @throws java.io.IOException if any.
*/
protected void writeViewable(Viewable viewable,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
MessageBodyWriter<Viewable> writer = workers.get().getMessageBodyWriter(Viewable.class, null,
new Annotation[]{}, null);
if (writer != null) {
writer.writeTo(viewable,
Viewable.class,
Viewable.class,
new Annotation[0],
mediaType,
httpHeaders,
entityStream);
}
}
示例14: resolveRelativeViewable
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
/**
* Resolve given {@link Viewable viewable} with relative template name using {@link MediaType media type},
* {@code resolving class} and {@link TemplateProcessor template processor}.
*
* @param viewable viewable to be resolved.
* @param mediaType media type of te output.
* @param resolvingClass resolving class.
* @param templateProcessor template processor to be used.
* @return resolved viewable or {@code null} if the viewable cannot be resolved.
*/
private ResolvedViewable resolveRelativeViewable(final Viewable viewable,
final Class<?> resolvingClass,
final MediaType mediaType,
final TemplateProcessor templateProcessor) {
final String path = TemplateHelper.getTemplateName(viewable);
ResolvedViewable resolvedViewable = resolveRelativeViewable(Viewables.PROTECTED_DIR + "/" + path,
viewable, resolvingClass, mediaType, templateProcessor);
if (resolvedViewable == null) {
resolvedViewable = resolveRelativeViewable(path,
viewable, resolvingClass, mediaType, templateProcessor);
}
return resolvedViewable;
}
示例15: writeTo
import org.glassfish.jersey.server.mvc.Viewable; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void writeTo(T templateReference, Viewable viewable, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException {
MediaType m = (MediaType) httpHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
if (m == null) m = mediaType;
setContentType(m, httpHeaders);
try {
writeTemplate(templateReference, viewable, mediaType, httpHeaders, out);
} catch (Exception e) {
RuntimeException r;
try {
r = createException(e, templateReference);
} catch (Exception ex) {
if (ex instanceof AmebaException) {
r = (RuntimeException) ex;
} else {
r = new TemplateException("create writeTo Exception error", e, -1);
}
}
throw r;
}
}