public InputStream invokeClientInbound(HttpURLConnection httpConnection) throws IOException { // XXX fill this in... Map<String, DataHandler> attachments = new HashMap<String, DataHandler>(); Map<String, Object> httpProperties = new HashMap<String, Object>(); httpProperties.put(HTTP_RESPONSE_CODE, Integer.valueOf(httpConnection.getResponseCode())); httpProperties.put(HTTP_RESPONSE_HEADERS, httpConnection.getHeaderFields()); prepare(httpProperties, /*request=*/ false); if (!invokeInbound(httpConnection.getInputStream(), attachments)) { if (getProtocolException() != null) { reverseDirection(); invokeInboundFaultHandlers(); if (getRuntimeException() != null) throw getRuntimeException(); } else if (getRuntimeException() != null) { closeClient(); throw getRuntimeException(); } } // XXX closeClient(); return finish(); }
public void invokeServerOutbound(Source source, OutputStream os) { Map<String, DataHandler> attachments = new HashMap<String, DataHandler>(); Map<String, Object> httpProperties = new HashMap<String, Object>(); httpProperties.put(HTTP_RESPONSE_CODE, Integer.valueOf(200)); httpProperties.put(HTTP_RESPONSE_HEADERS, new HashMap<String, List<String>>()); prepare(httpProperties, /*request=*/ false); if (!invokeOutbound(source, attachments)) { if (getProtocolException() != null) { reverseDirection(); invokeOutboundFaultHandlers(); } /* else if (getRuntimeException() != null) { closeServer(); finish(response.getOutputStream()); throw getRuntimeException(); }*/ } // XXX closeServer(); finish(os); }
public InputStream invokeServerInbound(HttpServletRequest request, OutputStream os) throws IOException { Map<String, DataHandler> attachments = new HashMap<String, DataHandler>(); Map<String, Object> httpProperties = new HashMap<String, Object>(); httpProperties.put(HTTP_REQUEST_METHOD, request.getMethod()); Map<String, List<String>> headers = new HashMap<String, List<String>>(); Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); List<String> values = new ArrayList<String>(); Enumeration headerValues = request.getHeaders(name); while (headerValues.hasMoreElements()) { String value = (String) headerValues.nextElement(); values.add(value); } headers.put(name, values); } httpProperties.put(HTTP_REQUEST_HEADERS, headers); prepare(httpProperties, /*request=*/ true); if (!invokeInbound(request.getInputStream(), attachments)) { if (getProtocolException() != null) { reverseDirection(); invokeInboundFaultHandlers(); } else if (getRuntimeException() == null) uninvokeInbound(); closeServer(); finish(os); return null; } return finish(); }
public boolean invokeClientOutbound(Source source, OutputStream out) throws ProtocolException { // XXX fill this in... Map<String, DataHandler> attachments = new HashMap<String, DataHandler>(); Map<String, Object> httpProperties = new HashMap<String, Object>(); httpProperties.put(HTTP_REQUEST_METHOD, "POST"); httpProperties.put(HTTP_REQUEST_HEADERS, new HashMap<String, List<String>>()); prepare(httpProperties, /*request=*/ true); if (!invokeOutbound(source, attachments)) { // XXX handle Oneway if (getProtocolException() != null) { reverseDirection(); invokeOutboundFaultHandlers(); closeClient(); if (getRuntimeException() != null) throw getRuntimeException(); if (getProtocolException() != null) throw getProtocolException(); return false; } else if (getRuntimeException() != null) { closeClient(); throw getRuntimeException(); } else { uninvokeOutbound(); closeClient(); if (getRuntimeException() != null) throw getRuntimeException(); if (getProtocolException() != null) throw getProtocolException(); return false; } } finish(out); return true; }
protected Object exec(Object[] args, Context context) { int nargs = args.length; Object schema = null; Map properties = null; Object errorHandler; Object input; switch (nargs) { case 4: schema = args[3]; case 3: properties = (Map) args[2]; case 2: errorHandler = args[1]; break; case 1: errorHandler = Util.getDefaultErrorHandler(context); break; default: undefined(args, context); return null; } input = args[0]; if (properties == null) { properties = new LinkedHashMap(); } if (schema != null) { properties.put(Util.KEY_SCHEMA, schema); } DocumentBuilder builder = Util.getDocumentBuilder(properties, context); if (errorHandler != null) { builder.setErrorHandler((ErrorHandler) Util.contentHandler(errorHandler, context)); } try { return builder.parse(Util.inputSource(input, context)); } catch (IOException e1) { throw new PnutsException(e1, context); } catch (SAXException e2) { throw new PnutsException(e2, context); } }
private void processTxt(Node operation) { List<Node> targets = getChildNodes(operation, "target"); List<Node> optionNodes = getChildNodes(operation, "opt"); List<Node> separatorNode = getChildNodes(operation, "separator"); if (targets.isEmpty() || optionNodes.isEmpty()) { return; } String defaultSeparator = "="; String globalSeparator = defaultSeparator; if (!separatorNode.isEmpty()) { globalSeparator = separatorNode.get(0).getTextContent(); if (globalSeparator.length() != 1) { globalSeparator = defaultSeparator; } } Map<String, String> options = new HashMap<String, String>(); Map<String, String> processedOptions = new HashMap<String, String>(); for (int i = 0; i < optionNodes.size(); i++) { Node option = optionNodes.get(i); String name = option.getAttributes().getNamedItem("name").getNodeValue(); String value = option.getTextContent(); if (options.containsKey(name)) { options.remove(name); } options.put(name, value); } for (int t = 0; t < targets.size(); t++) { File target = new File(absolutePath(targets.get(t).getTextContent())); File tmpFile = new File(Utils.timestamp()); BufferedWriter bw = null; BufferedReader br = null; try { Node separatorAttr = targets.get(t).getAttributes().getNamedItem("separator"); String separator = (separatorAttr == null) ? globalSeparator : separatorAttr.getNodeValue(); if (separator.length() != 1) { separator = globalSeparator; } bw = new BufferedWriter(new FileWriter(tmpFile)); if (target.exists()) { br = new BufferedReader(new FileReader(target)); for (String line; (line = br.readLine()) != null; ) { String[] parts = line.split(separator); if (parts.length < 2) { bw.write(line); bw.newLine(); continue; } String optName = parts[0].trim(); if (options.containsKey(optName)) { String optValue = options.get(optName); bw.write(optName + " " + separator + " " + optValue); bw.newLine(); processedOptions.put(optName, optValue); options.remove(optName); } else if (processedOptions.containsKey(optName)) { bw.write(optName + " " + separator + " " + processedOptions.get(optName)); bw.newLine(); } else { bw.write(line); bw.newLine(); } } br.close(); } for (Map.Entry<String, String> entry : options.entrySet()) { bw.write(entry.getKey() + " " + separator + " " + entry.getValue()); bw.newLine(); } bw.close(); FileUtils.copyFile(tmpFile, target); FileUtils.forceDelete(tmpFile); } catch (IOException ex) { Utils.onError(new Error.WriteTxtConfig(target.getPath())); } } }