将文件从SFTP直接下载到HTTP响应,而不使用中间文件

我正在尝试使用Java JSsch库通过SFTP下载文件。 我成功地将文件下载到本地目录。 **但是,我只需要将文件直接下载到浏览器而不提供任何本地目标路径(例如如何在Chrome中下载文件)。 我使用Spring控制器AngularJS Promise来捕获响应。 以下是我的代码。 @RequestMapping(value = “/downloadAttachment”, method = RequestMethod.POST, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public void downloadAttachment( @RequestParam(value = “fileName”) String fileName, @RequestParam(value = “filePath”) String filePath, @RequestParam(value = “fileId”) String fileId, HttpServletResponse response, Locale locale) throws Exception { InputStream is = null; if(!fileName.isEmpty() && !filePath.isEmpty() && !fileId.isEmpty()){ String directory = filePath; java.util.Properties […]

无法使用M2Eclipse(0.10.0,使用Maven 3)下载jar

我在项目中使用M2Eclipse(0.10.0,Maven 3)。 我可以使用m2eclipse添加Maven依赖。 但无法下载依赖jar。 相反,它在名为[JAR_Name] .jar.lastupdate的每个本地repo文件夹中创建了一个文件。 这个文件的内容是这样的:http:// [REPO_URL] / central / = 1276221188566 甚至使用Maven 3命令行。 无法下载jar子。 关于这怎么可能发生的任何想法?

是否需要在直通方法中使用有界通配符generics?

我知道在Collection中的以下方法中: public void addAll(Collection subcollection); 我们用Collection Collection允许一个仅存在子元素的集合,例如: List drivables = new ArrayList(); List cars = new ArrayList(); //we need the wildcard here, because of the following line: drivables.addAll(cars); 但是,我的以下方法需要这样的有界通配符吗? public static Collection requireNonEmpty(final Collection collection) throws NoSuchElementException { if (collection.isEmpty()) { throw new NoSuchElementException(“collection must be non-empty”); } return collection; } 它使用与Objects.requireNonNull(T object)类似的习惯用法,它实际上返回T object 。 […]

Spring Oauth2:在SecurityContext中找不到身份validation对象

我有一个项目,我实现了Spring安全性和Spring OAuth2 Security。当我请求访问令牌时,它运行良好但是当我使用访问令牌请求资源时,我得到了“在SecurityContext中找不到身份validation对象”。 我的项目的SecurityContext是: <!– –> <!– –> <!– –> <!– –> <!– –> <!– –> <!– –> 我使用http:// localhost:8060 / oauth / token请求令牌?grant_type =密码&client_id = nokia3320&client_secret = 0987654321&username = subash&password = 123456我得到了以下回复 { “access_token”: “9f5a89ce-a0d9-4d65-8e83-5d3b16d8c025”, “token_type”: “bearer”, “refresh_token”: “c2ac82ec-9f41-46dd-b7c2-4772c018505c”, “expires_in”: 499, “scope”: “read trust write” } 当我尝试使用http:// localhost:8060 / Api / currencyList在authorizatioin错误中使用访问令牌访问资源时,我得到了以下响应 { “error”: […]

Spark – 可以在JAVA中将MultiMap转换为DataFrame

我正在尝试将数十亿数据值的MultiMap转换为Spark DataFrame以运行计算,然后将结果写入cassandra表。 我从以下cassandra查询和循环生成多图。 我很乐意接受建议,如果有更好的方法来获取和操纵数据到DataFrame,就像我在循环中一样。 代码更新了答案: //Build ResultSet from cassandra query for data manipulation. Statement stmt = new SimpleStatement(“SELECT \”Power\”,\”Bandwidth\”,\”Start_Frequency\” FROM \”SB1000_49552019\”.\”Measured_Value\”;”); //Statement stmt = new SimpleStatement(“SELECT power, bandwidth, start_frequency FROM model.reports;”); stmt.setFetchSize(1000); ResultSet results = session.execute(stmt); // Get the Variables from each Row of Cassandra Data Multimap data = LinkedListMultimap.create(); for (Row row : results){ […]

Java无法使用带图像的html发送电子邮件

我正在尝试使用带有两个图像的html发送电子邮件。 这两个图像从AngularJS客户端发送为base64字符串,如下所示: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+gAAALuCAYAAAA9jTxNAAAgAElEQ 请注意,我已将base64字符串截断为太长。 String temp = baseString.split(“,”)[1]; byte[] tile = DatatypeConverter.parseBase64Binary(temp); BodyPart messageBodyPart = new MimeBodyPart(); InputStream inputStream = new ByteArrayInputStream(tile); DataHandler dataHandler = new DataHandler(new InputStreamDataSource(inputStream)); messageBodyPart.setDataHandler(dataHandler); messageBodyPart.setHeader(“Content-ID”, “”); multipart.addBodyPart(messageBodyPart); InputStreamDataSource: public class InputStreamDataSource implements DataSource { private InputStream inputStream; public InputStreamDataSource(InputStream inputStream) { this.inputStream = inputStream; } public InputStream getInputStream() { return […]

对Jenkins的Selenium webDriver / Maven java测试无法与firefox通信

我正在尝试使用jenkins为Web应用程序创建自动回归测试。 Jenkins基本上从git中获取我的maven项目并读取pom.xml。 然后启动测试套件。 问题是我的测试是使用selenium web驱动程序与gekodriver结合使用以启动firefox并在网站上导航。 但每次我启动测试时都会遇到这些错误: 控制台日志 我正在运行Jenkins作为服务(安装后它是如何启动的)并且我在通过eclipse或java运行时测试工作正常。 所以我认为问题来自jenkins如何处理selenium webdriver。 您可能已经看到,我使用的是Windows 7专业许可证。 Firefox和gekowebdriver已更新到最新版本。

jackson – 结合@JsonValue和@JsonSerialize

我正在尝试@JsonValue和@JsonSerialize的组合。 让我们从我当前的容器类开始: public class Container { private final Map data; @JsonValue @JsonSerialize(keyUsing = SomeKeySerializer.class) public Map data() { return data; } } 在这种情况下,不使用自定义序列化程序SomeKeySerializer 。 如果我按如下方式更改容器,则会调用序列化程序: public class Container { @JsonSerialize(keyUsing = SomeKeySerializer.class) private final Map data; } 但是,这不是我想要的,因为这会在输出JSON中引入另一个“数据”级别。 是否有可能以某种方式组合@JsonValue和@JsonSerialize ? 我总是可以为Container编写另一个自定义序列化程序,它或多或少与@JsonValue背后的function相同。 在我看来,这或多或少都是黑客攻击。 jackson版本:2.6.2

使用Bonjour获取设备IP

我正在使用Java 6更新14进行开发和NetBeans 6.7。 我正在创建一个示例客户端,以使用Bonjour检测特定类型的服务。 我面临一个特殊的挑战,我想获得设备的IP地址。 但是ResolveListener.serviceResolved(…)函数只提供Hostname和Port。 FullName也不包含设备的IP信息。 是否可以使用Bonjour SDK获取设备的IP地址? 如果有,怎么样? 谢谢。

在Android中使用MultipartEntityBuilder时,HttpPost返回错误

我正在尝试查询“ http://www.idmypill.com/api/id/”api ,我收到的JSON字符串是{“results”:[],”success”:false,”errors”:null}这是我的服务处理程序类: public String makeServiceCall(String url, int method, String api, byte[] pillImage) { try { // http client DefaultHttpClient httpClient = new DefaultHttpClient(); HttpEntity httpEntity = null; HttpResponse httpResponse = null; // Checking http request method type if (method == POST) { android.os.Debug.waitForDebugger(); HttpPost httpPost = new HttpPost(url); httpPost.setHeader(“data = api_key”, api); MultipartEntityBuilder builder […]