List of usage examples for javax.servlet ServletResponse getContentType
public String getContentType();
From source file:edu.cornell.mannlib.vitro.webapp.filters.CharsetEncodingFilter.java
private void setContentTypeOnResponse(HttpServletRequest req, ServletResponse servletResponse) { if (servletResponse.getContentType() != null) { return;/*from w w w . j a v a2 s .c o m*/ } String uri = req.getRequestURI(); if (!hasExtension(uri)) { servletResponse.setContentType("text/html;charset=UTF-8"); return; } String typeFromContext = req.getSession().getServletContext().getMimeType(uri); if (typeFromContext == null) { servletResponse.setContentType("text/html;charset=UTF-8"); return; } servletResponse.setContentType(typeFromContext); servletResponse.setCharacterEncoding("UTF-8"); }
From source file:org.geoserver.wcs.GetCoverageTest.java
@Test public void testLayerQualified() throws Exception { String queryString = "&request=getcoverage&service=wcs&version=1.1.1&&format=image/geotiff" + "&BoundingBox=-45,146,-42,147,urn:ogc:def:crs:EPSG:6.6:4326"; ServletResponse r = getAsServletResponse("wcs/BlueMarble/wcs?identifier=BlueMarble" + queryString); assertTrue(r.getContentType().startsWith("multipart/related")); Document dom = getAsDOM("wcs/DEM/wcs?identifier=BlueMarble" + queryString); assertEquals("ows:ExceptionReport", dom.getDocumentElement().getNodeName()); }
From source file:org.geoserver.wcs.GetCoverageTest.java
@Test public void testWorkspaceQualified() throws Exception { String queryString = "&request=getcoverage&service=wcs&version=1.1.1&&format=image/geotiff" + "&BoundingBox=-45,146,-42,147,urn:ogc:def:crs:EPSG:6.6:4326"; ServletResponse r = getAsServletResponse("wcs?identifier=" + TASMANIA_BM.getLocalPart() + queryString); assertTrue(r.getContentType().startsWith("multipart/related")); Document dom = getAsDOM("cdf/wcs?identifier=" + TASMANIA_BM.getLocalPart() + queryString); assertEquals("ows:ExceptionReport", dom.getDocumentElement().getNodeName()); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testGroupWorkspaceQualified() throws Exception { // check the group works without workspace qualification String url = "wms?request=getmap&service=wms" + "&layers=nature&width=100&height=100&format=image/png" + "&srs=epsg:4326&bbox=-0.002,-0.003,0.005,0.002"; ServletResponse response = getAsServletResponse(url); assertEquals("image/png", response.getContentType()); // see that it works also with workspace qualification response = getAsServletResponse("cite/" + url); assertEquals("image/png", response.getContentType()); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testWorkspaceQualified() throws Exception { Document doc = getAsDOM("cite/wms?request=getmap&service=wms" + "&layers=PrimitiveGeoFeature&width=100&height=100&format=image/png" + "&srs=epsg:4326&bbox=-180,-90,180,90", true); assertEquals("ServiceExceptionReport", doc.getDocumentElement().getNodeName()); ServletResponse response = getAsServletResponse("cite/wms?request=getmap&service=wms" + "&layers=Lakes&width=100&height=100&format=image/png" + "&srs=epsg:4326&bbox=-180,-90,180,90"); assertEquals("image/png", response.getContentType()); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testLayerQualified() throws Exception { Document doc = getAsDOM("cite/Ponds/wms?request=getmap&service=wms" + "&layers=Forests&width=100&height=100&format=image/png" + "&srs=epsg:4326&bbox=-180,-90,180,90", true);/*from ww w.jav a2s. c om*/ assertEquals("ServiceExceptionReport", doc.getDocumentElement().getNodeName()); ServletResponse response = getAsServletResponse("cite/Ponds/wms?request=getmap&service=wms" + "&layers=Ponds&width=100&height=100&format=image/png" + "&srs=epsg:4326&bbox=-180,-90,180,90"); assertEquals("image/png", response.getContentType()); }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testRemoteOWSUserStyleGet() throws Exception { if (!RemoteOWSTestSupport.isRemoteWFSStatesAvailable(LOGGER)) { return;//from w w w.jav a2s . com } URL url = GetMapIntegrationTest.class.getResource("remoteOws.sld"); ServletResponse response = getAsServletResponse( "wms?request=getmap&service=wms&version=1.1.1" + "&format=image/png" + "&sld=" + url.toString() + "&height=1024&width=1024&bbox=-180,-90,180,90&srs=EPSG:4326"); assertEquals("image/png", response.getContentType()); }
From source file:org.picketbox.jaxrs.filters.JWEInterceptor.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String clientId = null;//from w w w.j ava 2 s .com ServletResponse wrappedResponse = response; if (request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; clientId = httpRequest.getHeader(CLIENT_ID); } try { if (request instanceof HttpServletRequest) { wrappedResponse = new ResponseWrapper((HttpServletResponse) response); } chain.doFilter(request, wrappedResponse); } finally { if (wrappedResponse instanceof ResponseWrapper) { ResponseWrapper wrapper = (ResponseWrapper) wrappedResponse; PrintWriter writer = wrapper.getWriter(); ByteArrayOutputStream baos = (ByteArrayOutputStream) wrapper.getByteArrayOutputStream(); String contentType = response.getContentType(); if (contentType != null && contentType.contains("application/json")) { JSONWebToken webToken = new JSONWebToken(); try { webToken.setData(new JSONObject(new String(baos.toByteArray()))); webToken.setHeader(new JSONObject(HEADER)); } catch (JSONException e) { throw PicketBoxJAXRSMessages.MESSAGES.servletException(e); } webToken.setPublicKey(getPublicKey(clientId)); try { String encodedString = webToken.encode(); writer.write(encodedString); writer.flush(); writer.close(); } catch (ProcessingException e) { throw PicketBoxJAXRSMessages.MESSAGES.servletException(e); } } else { writer.write(new String(baos.toByteArray())); } } } }
From source file:org.geoserver.wms.wms_1_1_1.GetMapIntegrationTest.java
@Test public void testRemoteOWSGet() throws Exception { if (!RemoteOWSTestSupport.isRemoteWFSStatesAvailable(LOGGER)) return;//from w w w .jav a 2 s. c o m ServletResponse response = getAsServletResponse("wms?request=getmap&service=wms&version=1.1.1" + "&format=image/png" + "&layers=" + RemoteOWSTestSupport.TOPP_STATES + "," + MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart() + "&styles=Population," + MockData.BASIC_POLYGONS.getLocalPart() + "&remote_ows_type=WFS" + "&remote_ows_url=" + RemoteOWSTestSupport.WFS_SERVER_URL + "&height=1024&width=1024&bbox=-180,-90,180,90&srs=EPSG:4326"); assertEquals("image/png", response.getContentType()); }