本文整理汇总了Java中org.springframework.extensions.webscripts.WebScriptResponse.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java WebScriptResponse.setContentType方法的具体用法?Java WebScriptResponse.setContentType怎么用?Java WebScriptResponse.setContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.extensions.webscripts.WebScriptResponse
的用法示例。
在下文中一共展示了WebScriptResponse.setContentType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: streamContentImpl
import org.springframework.extensions.webscripts.WebScriptResponse; //导入方法依赖的package包/类
protected void streamContentImpl(WebScriptRequest req, WebScriptResponse res,
ContentReader reader, NodeRef nodeRef, QName propertyQName,
boolean attach, Date modified, String eTag, String attachFileName)
throws IOException
{
delegate.setAttachment(req, res, attach, attachFileName);
// establish mimetype
String mimetype = reader.getMimetype();
String extensionPath = req.getExtensionPath();
if (mimetype == null || mimetype.length() == 0)
{
mimetype = MimetypeMap.MIMETYPE_BINARY;
int extIndex = extensionPath.lastIndexOf('.');
if (extIndex != -1)
{
String ext = extensionPath.substring(extIndex + 1);
mimetype = mimetypeService.getMimetype(ext);
}
}
// set mimetype for the content and the character encoding + length for the stream
res.setContentType(mimetype);
res.setContentEncoding(reader.getEncoding());
res.setHeader("Content-Length", Long.toString(reader.getSize()));
// set caching
Cache cache = new Cache();
cache.setNeverCache(false);
cache.setMustRevalidate(true);
cache.setMaxAge(0L);
cache.setLastModified(modified);
cache.setETag(eTag);
res.setCache(cache);
}
示例2: process
import org.springframework.extensions.webscripts.WebScriptResponse; //导入方法依赖的package包/类
public int process(WebScriptRequest req, WebScriptResponse resp)
{
String transferRecordId = null;
try
{
// return the unique transfer id (the lock id)
StringWriter stringWriter = new StringWriter(300);
JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.startValue("data");
jsonWriter.startArray();
jsonWriter.startObject();
//TODO - clearly a dummy message for now.
jsonWriter.writeValue("message", "hello world");
jsonWriter.endObject();
jsonWriter.startObject();
//TODO - clearly a dummy message for now.
jsonWriter.writeValue("message", "message2");
jsonWriter.endObject();
jsonWriter.endArray();
jsonWriter.endValue();
String response = stringWriter.toString();
resp.setContentType("application/json");
resp.setContentEncoding("UTF-8");
int length = response.getBytes("UTF-8").length;
resp.addHeader("Content-Length", "" + length);
resp.setStatus(Status.STATUS_OK);
resp.getWriter().write(response);
return Status.STATUS_OK;
} catch (Exception ex)
{
receiver.end(transferRecordId);
if (ex instanceof TransferException)
{
throw (TransferException) ex;
}
throw new TransferException(MSG_CAUGHT_UNEXPECTED_EXCEPTION, ex);
}
}
示例3: execute
import org.springframework.extensions.webscripts.WebScriptResponse; //导入方法依赖的package包/类
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
if (!subscriptionService.isActive())
{
res.setStatus(404);
return;
}
try
{
String userId = req.getServiceMatch().getTemplateVars().get("userid");
Object obj = executeImpl(userId, req, res);
if (obj instanceof JSONObject || obj instanceof JSONArray)
{
res.setContentEncoding(Charset.defaultCharset().displayName());
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
Writer writer = res.getWriter();
if (obj instanceof JSONObject)
{
((JSONObject) obj).writeJSONString(writer);
} else
{
((JSONArray) obj).writeJSONString(writer);
}
writer.flush();
} else
{
res.setStatus(204);
}
} catch (SubscriptionsDisabledException sde)
{
throw new WebScriptException(404, "Subscription service is disabled!", sde);
} catch (NoSuchPersonException nspe)
{
throw new WebScriptException(404, "Unknown user '" + nspe.getUserName() + "'!", nspe);
} catch (PrivateSubscriptionListException psle)
{
throw new WebScriptException(403, "Subscription list is private!", psle);
} catch (ParseException pe)
{
throw new WebScriptException(400, "Unable to parse JSON!", pe);
} catch (ClassCastException cce)
{
throw new WebScriptException(400, "Unable to parse JSON!", cce);
} catch (IOException ioe)
{
throw new WebScriptException(500, "Unable to serialize JSON!", ioe);
}
}