private HttpURLConnection getConnection(String pformat, boolean geojsCase) throws ActionException { try { if (geojsCase) // Test service for print + geojs print return IOHelper.getConnection(getPrintGeojsUrl(pformat)); else // Normal print without geojs data return IOHelper.getConnection(getPrintUrl(pformat)); } catch (Exception e) { throw new ActionException("Couldnt get connection to print service", e); } }
public void handleAction(ActionParameters params) throws ActionException { final HttpServletResponse response = params.getResponse(); final HttpServletRequest httpRequest = params.getRequest(); // default print format is application/pdf final String pformat = params.getHttpParam(PARM_FORMAT, "application/pdf"); final JSONObject jsonprint = getPrintJSON(params); String file_save = params.getHttpParam(PARM_SAVE, ""); boolean geojsCase = false; if (!params.getHttpParam(PARM_GEOJSON, "").isEmpty()) geojsCase = true; final HttpURLConnection con = getConnection(pformat, geojsCase); for (Enumeration<String> e = httpRequest.getHeaderNames(); e.hasMoreElements(); ) { final String key = e.nextElement(); final String value = httpRequest.getHeader(key); con.setRequestProperty(key, value); } try { con.setRequestMethod("POST"); con.setDoOutput(true); con.setDoInput(true); HttpURLConnection.setFollowRedirects(false); con.setUseCaches(false); con.setRequestProperty(HEADER_CONTENT_TYPE, "application/json"); con.connect(); if (log.isDebugEnabled()) { log.debug(jsonprint.toString(2)); } IOHelper.writeToConnection(con, jsonprint.toString()); final byte[] presponse = IOHelper.readBytes(con.getInputStream()); // Save plot for future use if (!file_save.isEmpty()) savePdfPng(presponse, file_save, pformat); final String contentType = con.getHeaderField(HEADER_CONTENT_TYPE); response.addHeader(HEADER_CONTENT_TYPE, contentType); response.getOutputStream().write(presponse, 0, presponse.length); response.getOutputStream().flush(); response.getOutputStream().close(); } catch (Exception e) { throw new ActionException("Couldn't proxy request to print server", e); } finally { con.disconnect(); } }
public static String getTableTemplate(final String tableLayout) { try { final String resource = IOHelper.readString(OskariLayoutWorker.class.getResourceAsStream(tableLayout + ".json")); return resource; } catch (Exception ex) { log.warn(ex, "Error loading table layout template for tableLayout:", tableLayout); } return null; }
/** * Creates default highlight sld style by replacing geomtype * * @return sld */ public Style createDefaultHighlightSLDStyle(String geom_type) { log.debug("Creating default highlight SLD for:", geom_type); InputStream resource = WFSImage.class.getResourceAsStream(HIGHLIGHT_SLD); try { String xml = IOHelper.readString(resource, "ISO-8859-1"); xml = xml.replaceAll(GEOM_TYPE_PLACEHOLDER, geom_type); return createSLDStyle(xml); } catch (Exception e) { log.error(e, "Failed to get Default highlight SLD Style - geom type ", geom_type); log.error(resource); } return null; }
/** * Creates own sld style by replacing * * @return sld */ public Style createCustomSLDStyle() { InputStream resource = WFSImage.class.getResourceAsStream(OSKARI_CUSTOM_SLD); try { String xml = IOHelper.readString(resource, "ISO-8859-1"); customStyle.replaceValues(xml, isHighlight); xml = customStyle.getSld(); return createSLDStyle(xml); } catch (Exception e) { log.error(e, "Failed to get Own SLD Style"); log.error(resource); } return null; }
public JSONObject getWMSFeatureInfo(final GFIRequestParams params) { final Map<String, String> headers = new HashMap<String, String>(); headers.put( "User-Agent", "Mozilla/5.0 " + "(Windows; U; Windows NT 6.0; pl; rv:1.9.1.2) " + "Gecko/20090729 Firefox/3.5.2"); headers.put("Referer", "/"); headers.put("Cookie", "_ptifiut_"); String gfiResponse; try { final String url = params.getGFIUrl(); log.debug("Calling GFI url:", url); gfiResponse = IOHelper.getURL(url, headers); log.debug("Got GFI response:", gfiResponse); } catch (IOException e) { log.error(e, "Couldn't call GFI URL with params:", params); return null; } if (gfiResponse != null && !gfiResponse.isEmpty()) { final JSONObject response = new JSONObject(); try { response.put(GetGeoPointDataService.TYPE, params.getLayer().getType()); response.put(GetGeoPointDataService.LAYER_ID, params.getLayer().getId()); final String xslt = params.getLayer().getXslt(); if (xslt == null || xslt.isEmpty()) { response.put( GetGeoPointDataService.PRESENTATION_TYPE, GetGeoPointDataService.PRESENTATION_TYPE_TEXT); response.put(GetGeoPointDataService.CONTENT, gfiResponse); } else { final String transformedResult = transformResponse(xslt, gfiResponse); JSONObject respObj = new JSONObject(transformedResult); response.put( GetGeoPointDataService.PRESENTATION_TYPE, GetGeoPointDataService.PRESENTATION_TYPE_JSON); response.put(GetGeoPointDataService.CONTENT, respObj); } } catch (JSONException je) { log.error(je, "Couldn't construct GFI response from:", gfiResponse, "- params:", params); return null; } return response; } return null; }