我正在尝试确定字符串数组中的特定项是否为整数.
我是表单中.split(" ")'ing
的中缀表达式String
,然后尝试将结果数组拆分为两个数组; 一个用于整数,一个用于操作符,一个用于丢弃括号和其他杂项.实现这一目标的最佳方法是什么?
我以为我可以找到一种Integer.isInteger(String arg)
方法或东西,但没有这样的运气.
我有这段小代码
String[] words = {"{apf","hum_","dkoe","12f"};
for(String s:words)
{
if(s.matches("[a-z]"))
{
System.out.println(s);
}
}
Run Code Online (Sandbox Code Playgroud)
打算打印
dkoe
Run Code Online (Sandbox Code Playgroud)
但它什么都没打印!!
我是新手使用Regex,我一直在经历一些教程,但我没有找到一个适用于我想做的事情,
我想搜索一些东西,但返回它后面的所有内容,但不返回搜索字符串本身
例如" 一些蹩脚的句子很棒 "
搜索" 句子 "
回归" 太棒了 "
任何帮助将非常感激
到目前为止这是我的正则表达式
sentence(.*)
Run Code Online (Sandbox Code Playgroud)
但它返回:句子太棒了
Pattern pattern = Pattern.compile("sentence(.*)");
Matcher matcher = pattern.matcher("some lame sentence that is awesome");
boolean found = false;
while (matcher.find())
{
System.out.println("I found the text: " + matcher.group().toString());
found = true;
}
if (!found)
{
System.out.println("I didn't find the text");
}
Run Code Online (Sandbox Code Playgroud) 我正在探索设置kafka的几个选项,我知道Zookeeper必须启动并运行才能启动kafka.
我想知道如何找到以下内容.
1)我的zookeeper实例的主机名和端口---我检查了zoo.cfg,我只能找到ClientPort而不是主机名,hostname是我的盒子的主机名吗?
2)检查ZooKeeper是否正常运行---我试图做一个ps -ef | grep "zoo"
我找不到的东西.可能是我用错了关键词来搜索?
任何帮助将非常感激?
Recycler View Inconsistency检测到错误,在加载更多项目时快速滚动或滚动时出现错误.
FATAL EXCEPTION: main
Process: com.pratap.endlessrecyclerview, PID: 21997
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{56a082c position=40 id=-1, oldPos=39, pLpos:39 scrap [attachedScrap] tmpDetached no parent}
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4251)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4382)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2864)
at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1445)
at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:144)
at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:282)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Run Code Online (Sandbox Code Playgroud)
适配器
public class DataAdapter extends RecyclerView.Adapter {
private …
Run Code Online (Sandbox Code Playgroud) 在Spring Security 4发布之后,它改进了对测试的支持,我想更新我当前的Spring security oauth2资源服务器测试.
目前,我有一个帮助器类,它OAuth2RestTemplate
使用连接到实际ResourceOwnerPasswordResourceDetails
的测试ClientId
来设置一个使用,以便AccessTokenUri
为我的测试请求一个有效的令牌.这个resttemplate然后用于在我的@WebIntegrationTest
s中发出请求.
我想通过利用Spring Security 4中的新测试支持,放弃对实际AuthorizationServer的依赖,并在我的测试中使用有效(如果有限)用户凭据.
到现在为止我都在尝试使用@WithMockUser
,@WithSecurityContext
,SecurityMockMvcConfigurers.springSecurity()
和SecurityMockMvcRequestPostProcessors.*
都没能进入通过身份验证的电话MockMvc
,我找不到在Spring示例项目的任何这样的工作的例子.
任何人都可以帮助我使用某种模拟凭证来测试我的oauth2资源服务器,同时仍然测试所施加的安全限制吗?
**编辑**示例代码可在此处获取:https://github.com/timtebeek/resource-server-testing 对于每个测试类,我理解为什么它不能正常工作,但我正在寻找方法这将允许我轻松测试安全设置.
我现在正在考虑创建一个非常宽松的OAuthServer src/test/java
,这可能会有所帮助.有没有人有任何其他建议?
我有一个使用另一个项目的Spring项目.每个项目都有自己的弹簧配置文件,使用applicationContext.xml
和*.properties
为每个配置文件初始化java代码.我从中注入了个人资料args[]
.问题是第二个项目使用env的默认配置, applicationContext.xml
我不能将env注入args[]
第二个项目,我试着找一篇文章来解释Spring profile的工作原理.
applicationContext.xml
?applicationContext.xml
配置更强大?关于该主题甚至实例的文章将非常感谢!! 提前致谢.
我明白了
发生SSL错误,无法与服务器建立安全连接.
在iOS 9上,如果我尝试从亚马逊s3下载文件:https: //s3.amazonaws.com/xyz/qer/IMG_0001.JPG
据我所知,亚马逊s3支持TLS 1.2,请参阅:https://forums.aws.amazon.com/thread.jspa? threadID = 192512
"S3和Kinesis此时支持TLS 1.2." 2015年8月23日晚上9点19分
不知道为什么我会收到此SSL错误.该帐户应配置为利用TLS 1.2?我猜想默认情况下应该"打开".
我不想把这个域放在信息plist上.
编辑:我最终使用
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>s3.amazonaws.com</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud) 我有一个休息api,我在使用spring security Basic Authorization进行身份验证,其中客户端为每个请求发送用户名和密码.现在,我想实现基于令牌的身份验证,我将在用户首先进行身份验证时在响应头中发送令牌.对于进一步的请求,客户端可以在标头中包含该标记,该标记将用于向用户验证资源.我有两个身份验证提供程序tokenAuthenticationProvider和daoAuthenticationProvider
@Component
public class TokenAuthenticationProvider implements AuthenticationProvider {
@Autowired
private TokenAuthentcationService service;
@Override
public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
final HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
final String token = request.getHeader(Constants.AUTH_HEADER_NAME);
final Token tokenObj = this.service.getToken(token);
final AuthenticationToken authToken = new AuthenticationToken(tokenObj);
return authToken;
}
@Override
public boolean supports(final Class<?> authentication) {
return AuthenticationToken.class.isAssignableFrom(authentication);
}
}
Run Code Online (Sandbox Code Playgroud)
在daoAuthenticationProvider中,我设置自定义userDetailsService并通过从数据库中获取用户登录详细信息进行身份验证(只要使用授权传递用户名和密码,该工作正常:基本bGllQXBpVXNlcjogN21wXidMQjRdTURtR04pag ==作为标头)
但是当我使用X-AUTH-TOKEN(即Constants.AUTH_HEADER_NAME)在标头中包含token时,不会调用tokenAuthenticationProvider.我收到错误了
{"timestamp":1487626368308,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/find"}
Run Code Online (Sandbox Code Playgroud)
以下是我添加身份验证提供程序的方法.
@Override
public void …
Run Code Online (Sandbox Code Playgroud) 这是我的JSON数组: -
[
{
"firstName" : "abc",
"lastName" : "xyz"
},
{
"firstName" : "pqr",
"lastName" : "str"
}
]
Run Code Online (Sandbox Code Playgroud)
我在我的String对象中有这个.现在我想将它转换为Java对象并将其存储在Java对象的List中.例如在Student对象中.我使用下面的代码将其转换为Java对象列表: -
ObjectMapper mapper = new ObjectMapper();
StudentList studentList = mapper.readValue(jsonString, StudentList.class);
Run Code Online (Sandbox Code Playgroud)
我的列表类是: -
public class StudentList {
private List<Student> participantList = new ArrayList<Student>();
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我的学生对象是: -
class Student {
String firstName;
String lastName;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?我得到以下异常: -
Exception : com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.aa.Student out of START_ARRAY token
Run Code Online (Sandbox Code Playgroud)