小编use*_*005的帖子

Joda String DateTime to DateTime

我试图转换像下面传递的DateTime字符串

"2013-08-14T12:54:57.908+05:30"
Run Code Online (Sandbox Code Playgroud)

我的转换器功能看起来像这样

public static DateTime stringDateToJodaDateTime(String strDate){
        DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss Z");
        DateTime jodaDateTime = formatter.parseDateTime(strDate);
        return jodaDateTime;
    }
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
    ... 88 more
Caused by: java.lang.IllegalArgumentException: Invalid format: "2013-08-14T12:54:57.908+05:30"
    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899)
    at com.kpowd.utility.UserUtility.stringDateToJodaDateTime(UserUtility.java:65)
    at com.kpowd.controller.CommonChartController.init(CommonChartController.java:51)
    ... 93 more
Run Code Online (Sandbox Code Playgroud)

我认为因为错误的"forPattern",我无法更改传递的字符串DateTime Pattern.我所能做的就是改变"DateTimeFormat.forPattern",帮助我

java datetime jodatime

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

如何使用Post方法获取OAuth2访问令牌

我试图用Spring安全配置oauth2,我举了一个例子

https://github.com/neel4software/SpringSecurityOAuth2
Run Code Online (Sandbox Code Playgroud)

现在我的问题是我需要使用post方法而不是get获取oauth2访问令牌,下面是如何在spring security xml中配置令牌端点

这是正在运行的GET方法URL端点

http://localhost:8080/SpringRestSecurityOauth/oauth/token?grant_type=password&client_id=restapp&client_secret=restapp&username=beingjavaguys&password=spring@java 
Run Code Online (Sandbox Code Playgroud)

这就是spring security xml中完成端点配置的方式

<http pattern="/oauth/token" create-session="stateless"
        authentication-manager-ref="clientAuthenticationManager"
        xmlns="http://www.springframework.org/schema/security">
        <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
        <anonymous enabled="false" />
        <http-basic entry-point-ref="clientAuthenticationEntryPoint" />
        <!-- include this only if you need to authenticate clients via request 
            parameters -->
        <custom-filter ref="clientCredentialsTokenEndpointFilter"
            after="BASIC_AUTH_FILTER" />
        <access-denied-handler ref="oauthAccessDeniedHandler" />
    </http>
Run Code Online (Sandbox Code Playgroud)

为了使用POST方法访问它,我试图使用以下端点访问它

http://localhost:8080/SpringRestSecurityOauth/oauth/token
Run Code Online (Sandbox Code Playgroud)

将给定参数作为休息客户端中的有效负载(我也尝试将这些参数作为标头参数提供)

grant_type: password
client_id: restapp
client_secret: restapp
username: beingjavaguys
password: spring@java
Run Code Online (Sandbox Code Playgroud)

但每次我尝试使用rest客户端访问它时,总是提示我输入我不知道的用户名和密码.我给用户名为"beingjavaguys",密码为"spring @ java",但没有用.我是第一次使用Oauth2

authentication cxf spring-security java-ee oauth-2.0

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

bash 命令等待 TCP 端口打开

我希望我的微服务在一个新的命令行中打开,并从那里一个接一个地运行它。下面是我的 bash 脚本

################ first SERVER #####################
gnome-terminal -x sh -c 'java -jar server/target/first-server.jar; exec bash'

################ second SERVER #####################
export service_port=8771
export host_name=firstdomain
gnome-terminal -x sh -c 'java -Dservice.port="${service_port}" -Dhost.name="${host_name}" -jar eureka/target/second-server.jar; exec bash'
Run Code Online (Sandbox Code Playgroud)

问题是我想在成功启动“first-server.jar”后启动“second-server.jar”。我可以通过检查服务是否正在侦听网络端口来检测这一点。有什么办法可以存档这个吗?sleep bash 命令不适合我。

java linux bash microservices

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