使用Java发送HTTP请求GET / POST以形成?

所以我有这段代码,我得到它的工作,现在它基本上允许我发送httppost并获取几乎任何我想要的外部网站的请求除非元素不包含name属性。 这是一个例子: 这是Java代码: public static String sendPostRequest(String url) { StringBuffer sb = null; try { String data = URLEncoder.encode(“user”, “UTF-8”) + “=” + URLEncoder.encode(“myUserName”, “UTF-8”) + “&” + URLEncoder.encode(“submit”, “UTF-8”) + “=” + URLEncoder.encode(“Submit”, “UTF-8”); URL requestUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) requestUrl .openConnection(); conn.setDoOutput(true); conn.setRequestMethod(“GET”); OutputStreamWriter osw = new OutputStreamWriter( conn.getOutputStream()); osw.write(data); […]

Spring Boot – RestController反序列化YAML上传?

如何配置Spring Boot RestController以接受YAML上传? 以下结果为415.我可以从调试中看到,我的Spring上下文中的MappingJackson2HttpMessageConverter实例仅支持[application/json;charset=UTF-8, application/*+json;charset=UTF-8] 。 我不能成为唯一一个尝试这样做的Spring Boot用户,我很惊讶它不仅仅起作用 – 大多数事情都是在Spring Boot中完成的! 我的POM中有YAML数据格式: com.fasterxml.jackson.dataformat jackson-dataformat-yaml 我的RestController有一个方法: @RequestMapping(method=RequestMethod.POST, value=”/”, consumes=”application/yaml”) public String upload(@RequestBody Declaration declaration) { //Do stuff } 我的测试: @Test public void triggersConvergence() throws Exception { ClassPathResource fixture = new ClassPathResource(“declaration.yml”); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.add(“Content-Type”, “application/yaml”); requestHeaders.add(“Accept”, “application/json”); URI uri = new URI(“http://127.0.0.1:”+port); byte[] […]

我可以在一个类中使用多个ActionListener吗?

考虑下面过于简化的例子; 其中一些用伪代码编写,以简洁起见。 当我尝试按原样运行时,我收到编译器错误,指出已在我的main方法中找到actionPerformed 。 但是,如果我重命名它,对actionPerformed2说,它不再被ActionListener识别。 我是否需要将foo和foo2方法的侦听器组合到一个ActionListener方法中? 在具有多个按钮对象的单个类中使用多个侦听器时,如何正确区分侦听器? 我刚刚开始玩摆动组件,所以我怀疑我可能不会问正确的问题……但是我可以随时编辑。 🙂 public class foo { declare button1, button2, button3 and panel1 public foo() { show panel1 with button1 and button2; } public foo2() { show panel1 with button3; } public void actionPerformed(ActionEvent e) { Object source1 = e.getSource(); do some stuff when button1 is clicked } public […]

容器管理的交易

只是澄清我对容器管理事务(CMT)如何在JPA中工作的理解 – CMT使应用程序能够明确地开始和提交事务吗? CMT只能应用于会话和消息驱动的bean而不是pojos? 我对上述问题的理由是 – 我想知道如何从java-se应用程序以及java-ee访问实体。 我需要两个独立的持久性单元吗?

在java中获取csv文件维度的最快方法是什么

我在获取csv文件的维度任务时的常规过程如下: 获取它有多少行: 我使用while循环读取每一行,并通过每次成功读取计数。 缺点是读取整个文件需要花费时间来计算它有多少行。 然后得到它有多少列:我使用String[] temp = lineOfText.split(“,”); 然后采取临时的大小。 有更聪明的方法吗? 喜欢: file1 = read.csv; xDimention = file1.xDimention; yDimention = file1.yDimention;

Spring Security sec:使用Java Config授权标记

我目前正在开发一个用例,我需要使用以下Spring Security taglib来显示(或不显示)基于用户权限的链接。 在查看日志时,我发现在谈到日志时没有任何反应 无论我的角色如何,我总是看到按钮。 当我使用hasRole时,它可以工作,所以我肯定错过了的工作。 在阅读Spring Security参考的以下部分时: 要使用此标记,还必须在应用程序上下文中有一个WebInvocationPrivilegeEvaluator实例。 如果您使用命名空间,将自动注册。 …问题是该引用不包括Java Config。 所以我想我只需要在SecurityConfig类中定义一个@Bean ,就像这样: @Bean public WebInvocationPrivilegeEvaluator webInvocationPrivilegeEvaluator() { return new DefaultWebInvocationPrivilegeEvaluator(); } …但是,它需要一个FilterSecurityInterceptor实例,我已经在日志中看到了它。 事实上,它已经是我的filter链的一部分,所以我想知道如何在上面的DefaultWebInvocationPrivilegeEvaluator构造函数中引用它? Spring Security 3.2.4.RELEASE参考: http ://docs.spring.io/spring-security/site/docs/3.2.4.RELEASE/reference/htmlsingle/#the-authorize-tag 谢谢

使用JSch使用密码进行身份validation时获取“Auth取消”

我正在尝试从Java执行Unix命令。 我正在使用JSch库。 这是我的代码: try{ Session session = new JSch().getSession(“*****”, “****”, 22); session.setPassword(“****”); java.util.Properties config = new java.util.Properties(); config.put(“StrictHostKeyChecking”, “no”); session.setConfig(config); session.connect(); Channel channel=session.openChannel(“exec”); ((ChannelExec)channel).setCommand(“pwd”); InputStream in=channel.getInputStream(); byte[] tmp=new byte[1024]; while(in.available()>0){ int i=in.read(tmp, 0, 1024); System.out.print(new String(tmp, 0, i)); } channel.disconnect(); session.disconnect(); }catch(Exception e){ System.out.println(org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e)); } 我一直收到“validation取消”错误。 在我可以执行任何操作之前,我无法登录。 这是所要求的日志: INFO: Connecting to ***** port 22 INFO: […]

SignalR Java客户端仅支持1.3

是否有理由为SignalR的Java客户端仅支持1.3版? https://github.com/SignalR/java-client/blob/f226631da562cfaacbe8b16d5a9ecbf8205e7c99/signalr-client-sdk/src/microsoft/aspnet/signalr/client/Connection.java#L597 所有客户都不应该向后兼容吗? 是否有任何损害并更改verifyProtocolVersion方法以validation协议是否小于或等于1.3? 出于测试目的,我只是返回true,跳过整个方法体,看它是否适用于我的1.2.1服务器,它确实如此。 也许这应该被视为一个错误?

Selenium Web驱动程序填充字段可保存输出

我绝对是selenium的新人,所以对于noob问题感到抱歉。 但我无法在谷歌找到它。 所以,我有一个简单的javacode: public static void main(String[] args) throws Exception { // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); // Go to the Google Suggest home page driver.get(“http://tudakozo.telekom.hu/main?xml=main&xsl=main”); // Enter the query string “Cheese” WebElement query = driver.findElement(By.xpath(“id(‘searchByName’)/x:input[2]”)); 网页顺便说一句:[link] [1]我想填写左框。 为此,我想要一些selenium命令:s.fill(这里是xpath,“填充文本”) 对于xpath,我使用firefox插件并找到xpath:我无法发布图片,因此有一个链接: http ://tinypic.com/view.php?pic = 5poglt&s = 8#.U_sw-vl_tVY 然后我将得到somecapthca破坏它在当地的未来,但如果oyu有建议我接受:)无论如何,我需要下载图片并手动填写它。 然后点击“ keresés ”按钮xpoath:id(’searchByName’)/ […]

SwingWorker在multilpe面板中更新多个combobox

我有一个小的gui程序,在启动时从Excel文件中读取数据,其中一些数据需要转到相关的combobox。 我知道如何通过为每个combobox使用单独的SwingWorker来做到这一点: public class ExcelReader extends SwingWorker { private final DefaultComboBoxModel model; // Constructor called from a panel that has a combobox public ExcelReader(DefaultComboBoxModel model) { this.model = model; } @Override protected DefaultComboBoxModel doInBackground() throws Exception { ///// code to read data from Excel file ///// publish(someString) used here return model; } @Override protected void […]