小编spe*_*0ne的帖子

使用restTemplate发送带有身份验证标头的GET请求

我需要通过使用RestTemplate发送带有一些Authorization标头的GET请求来从我的服务器检索资源.

在浏览了文档之后,我注意到没有一个GET方法接受头作为参数,并且发送Headers(如accept和Authorization)的唯一方法是使用exchange方法.

由于这是一个非常基本的行动,我想知道我是否遗漏了一些东西,还有另一种更简单的方法吗?

java spring spring-mvc resttemplate

71
推荐指数
5
解决办法
15万
查看次数

如何在HttpClient 4.1中处理会话

我正在使用HttpClient 4.1.1来测试我的服务器的REST API.

我可以设法登录似乎工作正常,但当我尝试做任何其他事情我失败了.

我很可能在下一个请求中设置cookie时遇到问题.

这是我目前的代码:

HttpGet httpGet = new HttpGet(<my server login URL>);
httpResponse = httpClient.execute(httpGet)
sessionID = httpResponse.getFirstHeader("Set-Cookie").getValue();
httpGet.addHeader("Cookie", sessionID);
httpClient.execute(httpGet);
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来管理HttpClient包中的会话/ cookie设置?

java cookies session httpclient

38
推荐指数
1
解决办法
4万
查看次数

错误:src refspec master与any不匹配

我试图按照这篇文章中提出的解决方案,但它没有工作,我仍然得到:src refspec master不匹配任何.

这就是我所做的:遵循这个解决方案

// adding the file I created
$ git add .
$ git commit -m 'initial commit'
$ git push origin master
error: src refspec master does not match any.
Run Code Online (Sandbox Code Playgroud)

做的时候:

$ git push origin HEAD:master
b40ffdf..a0d1423  HEAD -> master // looks promising

// adding a remote
$ git remote add devstage -f <another git>
$ git merge devstage/master -s recursive -X ours
$ git push -u devstage master
error: src refspec master …
Run Code Online (Sandbox Code Playgroud)

git git-push git-remote

30
推荐指数
9
解决办法
20万
查看次数

在openshift上被允许拒绝(publickey,gssapi-keyex,gssapi-with-mic)

我在修改我的装备时遇到问题.我试图运行rhc设置,我也删除了我的.ssh文件夹并再次执行rhc设置,但这也没有用.

不知道发生了什么变化,但它在几个小时前工作了.

>git push -u <GEAR_NAME> master
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

>git remote add devstage3 -f ssh://<GEAR_ID>@<GEAR_NAME>-<GEAR-DOMAIN>.rhcloud.com/~/git/<GEAR_DOMAIN>.git/ 
Run Code Online (Sandbox Code Playgroud)

此外,我试图启动一个不同的齿轮并承诺,但我得到同样的错误:

Updating <GEAR_NAME>
The authenticity of host '<GEAR_NAME>-<GEAR-DOMAIN>.rhcloud.com (<GEAR_IP>)' can't be established.
RSA key fingerprint is <KEY_FINGERPRINT>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '<GEAR_NAME>-<GEAR-DOMAIN>.rhcloud.com,<GEAR_IP>' (RSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not …
Run Code Online (Sandbox Code Playgroud)

git git-push public-key openshift

24
推荐指数
4
解决办法
7万
查看次数

尝试使用intellij进行部署时,服务器未连接

我正在尝试在intellij中构建,部署和调试我的webapp.

我使用这个答案设置了我的tomcat ,我能够让服务器运行.问题是我的webapp没有被部署,尽管它在deployment选项卡中定义.

我收到以下错误: 服务器未连接.部署不可用

如果我复制战争并启动服务器,一切正常.端口8080和8000.

我究竟做错了什么?

为了防止它以某种方式相关,该项目是使用Maven和Spring构建的

我添加了服务器的运行/调试配置:

服务器标签 服务器标签

部署选项卡 部署选项卡

调试控制台输出:

D:\development\infra\appServers\apache-tomcat-7.0.47\bin\catalina.bat run
[2014-08-05 01:23:11,413] Artifact devstage:war exploded: Server is not connected. Deploy is not available.
Using CATALINA_BASE:   "C:\Users\chaim\.IntelliJIdea13\system\tomcat\Unnamed_devstage_4"
Using CATALINA_HOME:   "D:\development\infra\appServers\apache-tomcat-7.0.47"
Using CATALINA_TMPDIR: "D:\development\infra\appServers\apache-tomcat-7.0.47\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.7.0_45"
Using CLASSPATH:       "D:\development\infra\appServers\apache-tomcat-7.0.47\bin\bootstrap.jar;D:\development\infra\appServers\apache-tomcat-7.0.47\bin\tomcat-juli.jar"
Aug 05, 2014 1:23:12 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.4.8.
Aug 05, 2014 1:23:12 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile …
Run Code Online (Sandbox Code Playgroud)

tomcat war intellij-idea auto-update

21
推荐指数
1
解决办法
3万
查看次数

如何将JSONObject转换为gson.JsonObject?

我有一个org.json.JSONObject对象.

从中创建gson.JsonObject对象的最简单方法是什么?

谢谢

java serialization json gson

19
推荐指数
1
解决办法
2万
查看次数

如何设置intellij以在日志选项卡而不是输出选项卡中显示日志

当我使用intellijs'(12.1.4)内置的tomcat时,日志被写入调试面板的输出选项卡而不是正常的localhost日志选项卡.

我按照这个文档添加了我的log4j.properties,它在输出选项卡中正常工作,但它仍然将日志写入右侧选项卡.

当我打包项目并将其部署在独立的tomcat上时,我可以看到日志.

通常我不在乎,但输出选项卡的问题是你无法搜索它.

这是我的log4j,我已经厌倦了ConsoleAppender和RollingFileAppender.

log4j.rootLogger=TRACE, A1

log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=${catalina.home}/logs/algo_js.log
log4j.appender.A1.MaxFileSize=500KB
log4j.appender.A1.MaxBackupIndex=5
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
Run Code Online (Sandbox Code Playgroud)

我缺少什么想法?

只是说明我添加了一张照片. 顶部面板是显示日志的位置,底部面板是我希望显示的位置...搜索的位置

spring tomcat log4j intellij-idea

14
推荐指数
1
解决办法
1万
查看次数

如何在Spring Security 3.2中设置Access-Control-Allow-Origin过滤器

我正在尝试使用Spring Security 3.2设置我的Spring服务器,以便能够执行ajax登录请求.

我关注了Spring Security 3.2视频和几个帖子,但问题是我得到了

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:9000' is therefore not allowed access. 
Run Code Online (Sandbox Code Playgroud)

对于登录请求(见下文).

我创建了一个CORSFilter设置,我可以访问系统中未受保护的资源,并在响应中添加相应的标头.

我的猜测是我没有添加CORSFilter到安全过滤器链,或者它可能在链中太晚了.任何想法将不胜感激.

WebAppInitializer

public class WebAppInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) {
        WebApplicationContext rootContext = createRootContext(servletContext);

        configureSpringMvc(servletContext, rootContext);

        FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", CORSFilter.class);
        corsFilter.addMappingForUrlPatterns(null, false, "/*");
    }

    private WebApplicationContext createRootContext(ServletContext servletContext) {
        AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();

        rootContext.register(SecurityConfig.class, PersistenceConfig.class, CoreConfig.class);

        servletContext.addListener(new ContextLoaderListener(rootContext));
        servletContext.setInitParameter("defaultHtmlEscape", "true");

        return rootContext;
    }


    private void configureSpringMvc(ServletContext …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-security http-headers servlet-filters

13
推荐指数
1
解决办法
2万
查看次数

为rhino构建java脚本调试器

我正在使用tomcat服务器,我已经添加了一个rhino引擎,以便能够为我的用户提供一些脚本功能.第二阶段是提供一些调试环境.

我知道rhino有一个调试API,但我找不到任何关于如何使用它的文档/代码示例,并围绕它构建一个调试器

有谁知道?

javascript java debugging open-source rhino

9
推荐指数
1
解决办法
7460
查看次数

如何在没有XML文件的情况下配置Spring ACL

我正在尝试将ACL功能添加到我的服务器.我已经使用java文件配置了spring security,并希望以相同的方式添加ACL.我该怎么办?我发现的所有教程都使用了XML文件.

SecurityInit:

@Order(1)
public class SecurityInitializer extends AbstractSecurityWebApplicationInitializer {
}
Run Code Online (Sandbox Code Playgroud)

SecurityConfig

@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
@Component
@ComponentScan(basePackages = {"test.package"})
public class SecurityConfig extends 

WebSecurityConfigurerAdapter {

...
    @Autowired
    protected void registerAuthentication(UserDetailsService userDetailsService, AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }

//  http://stackoverflow.com/a/21100458/162345
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .headers().disable()
                .addFilterBefore(...)
                .addFilterBefore(...)

//                TODO: create a better way to differentiate login to signup
                .exceptionHandling()
                    .authenticationEntryPoint(noRedirectForAnonymous)
                    .and()

                .formLogin()
                    .successHandler(restAuthenticationSuccessHandler)
                    .failureHandler(restAuthenticationFailureHandler)
                    .and()

                .logout()
                    .logoutSuccessHandler(noRedirectLogoutSuccessHandler)
                    .and()

                .authorizeRequests()
                    .antMatchers("/api/keywords/**").permitAll()
                    .antMatchers("/api/**").authenticated();
    }
}
Run Code Online (Sandbox Code Playgroud)

configuration spring acl spring-mvc spring-security

8
推荐指数
2
解决办法
3856
查看次数