小编Jas*_*son的帖子

Base64在C#或Java中解码

我有一个Base64编码的对象与以下标题:

application/x-xfdl;content-encoding="asc-gzip"
Run Code Online (Sandbox Code Playgroud)

解码对象的最佳方法是什么?我需要剥离第一行吗?另外,如果我把它变成一个字节数组(byte []),我该怎么解压缩呢?

谢谢!


我想我最初错过了.通过说标题是

application/x-xfdl;content-encoding="asc-gzip"
Run Code Online (Sandbox Code Playgroud)

我的意思是这是文件的第一行.因此,为了使用Java或C#库来解码文件,是否需要删除此行?

如果是这样,剥离第一行的最简单方法是什么?

c# java base64

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

找不到Spring MVC控制器

这可能是一个简单的,但我想我错过了一些东西.问题归结为:我正在尝试使用HelloController来显示"/WEB-INF/hello.jsp".不幸的是,我在尝试访问http://example.com/app/hello时获得了404

这是代码.可能很容易解决.

web.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>app</display-name>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
  </context-param>

  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
    </init-param>
</servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

applicationContext.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
                    http://www.springframework.org/schema/tx
                    http://www.springframework.org/schema/tx/spring-tx-3.1
                    http://www.springframework.org/schema/context
                    http://www.springframework.org/schema/context/spring-context-3.1.xsd
                    http://www.springframework.org/schema/security
                    http://www.springframework.org/schema/security/spring-security-3.1.xsd
                    http://www.springframework.org/schema/mvc
                    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

<context:component-scan base-package="web.controller" />

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:prefix="/WEB-INF/" p:suffix=".jsp" />

</beans>
Run Code Online (Sandbox Code Playgroud)

HelloController.java:

@Controller
public class HelloController …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc

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

IntelliJ IDEA结构替换

希望这是一个简单的.我正在尝试将错误的编码标准转换为javadoc格式.

我想转换这一行:

*由John.Smith于2006年6月13日下午1:24:54创建

至:

*@author John Smith

有帮助吗?

intellij-idea

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

Guava和Weblogic:ClassNotFoundException

我正在尝试部署到Weblogic 10.3.5的Web应用程序.其中一个maven依赖项是Guava.

不幸的是,在尝试发布项目时,weblogic抛出了这个异常:

java.lang.ClassNotFoundException: com.google.common.eventbus.EventBus
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
Run Code Online (Sandbox Code Playgroud)

其余的maven依赖项SEEM正在运行,但我不确定问题是什么.

有人可以协助排除故障吗?环境是带有M2E插件的Eclipse,Weblogic Server已集成到Eclipse中.

更新:pom.xml中的番石榴条目:

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>11.0.2</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我包括另一个图书馆(commons-lang),它工作得很好.

更新2:这可能是一个类加载器问题.我从这个博客得到了一个线索:http://blog.eisele.net/2011/12/running-richfaces-410final-on-weblogic.html.似乎WLS使用了一些google-commons库.

我试图通过在weblogic.xml文件中进行更改来强制它使用我的版本,但它似乎不起作用.

java weblogic maven guava

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

番石榴谓词未能过滤收集

我有以下方法使用Predicate过滤集合,抛出propertyName不在给定的允许值列表中的任何成员.它使用Common-BeanUtils从对象中提取值,该值必须是String:

public static <T> void filterListByStringPropertyWithAllowableValues(List<T> listToFilter, 
        final String propertyName, 
        final List<String> allowedValues) {

    Predicate<T> allowedValuesPredicate = new Predicate<T>() {

        @Override
        public boolean apply(T arg0) {

            String value;
            boolean result = false;
            try {
                value = BeanUtils.getProperty(arg0, propertyName);
                System.out.println(value);
                result = allowedValues.contains(value);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } 

            return result;


        }
    };

    Iterables.filter(listToFilter, allowedValuesPredicate);

}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我的测试彻底失败了.

@Test
public void testfilterListByStringPropertyWithAllowableValues() throws Exception {

    TestClass item1 = new …
Run Code Online (Sandbox Code Playgroud)

java guava

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

以编程方式访问 Spring Security 角色层次结构

我有一个 Spring Security 角色层次结构,设置如下:

ROLE_ADMIN > ROLE_MANAGER
ROLE_MANAGER > ROLE_USER
ROLE_USER > ROLE_GUEST
Run Code Online (Sandbox Code Playgroud)

我发现自己需要创建一个 VetoableChangeListener,它可以根据角色否决 PropertyChangeEvents(由于那些愚蠢的 Legacy Design 问题之一)。

因此,在我的 vetoableChange() 方法中,需要根据层次结构否决更改。例如,某个字段不能被定义的层次结构中 ROLE_MANAGER 之下的任何角色更改,因此如果 ROLE_USER 尝试更改它,则会引发 PropertyVetoException。

public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {

    String role = SecurityContextHolder.getContext().getAuthentication().getRoles().get(0);
    String propertyName = evt.getPropertyName();
    String requiredRole = getRequiredRole(propertyName);

    // determine if the current role is equal to or greater than
    // the required role, throw PropertyVetoException if not

}
Run Code Online (Sandbox Code Playgroud)

任何人都可以提供帮助吗?

spring spring-security javabeans

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

带有X.509证书的Spring Security

我正在慢慢疯狂地尝试配置Spring Security 3.0.0来保护应用程序.

我已将服务器(jetty)配置为需要客户端身份验证(使用智能卡).但是,我似乎无法正确获取applicationContext-security.xml和UserDetailsS​​ervice实现.

首先,从应用程序上下文文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:security="http://www.springframework.org/schema/security"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">


<security:global-method-security secured-annotations="enabled" />

<security:http auto-config="true">
    <security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" requires-channel="https"/>
    <security:x509 subject-principal-regex="CN=(.*?)," user-service-ref="accountService" />
</security:http>

<bean id="accountService" class="com.app.service.AccountServiceImpl"/>
Run Code Online (Sandbox Code Playgroud)

UserDetailsS​​ervice如下所示:

public class AccountServiceImpl implements AccountService, UserDetailsService {

private static final Log log = LogFactory.getLog(AccountServiceImpl.class);

private AccountDao accountDao;

@Autowired
public void setAccountDao(AccountDao accountDao) {
    this.accountDao = accountDao;
}

public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException, DataAccessException {

    log.debug("called loadUserByUsername()");
    System.out.println("called loadByUsername()");

    Account result = accountDao.getByEdpi(s); …
Run Code Online (Sandbox Code Playgroud)

java spring-security x509certificate

0
推荐指数
1
解决办法
7723
查看次数

MongoDB:_id不能是一个数组

我有一个大型数据集(大约1.1M文档),我需要运行mapreduce.

要分组的字段是名为xref的数组.由于集合的大小以及我在32位环境中这样做的事实,我正在尝试将集合减少到新数据库中的另一个集合.

首先,这是一个数据样本:

{ "_id" : ObjectId("4ec6d3aa61910ad451f12e01"), 
"bii" : -32.9867, 
"class" : 2456, 
"decdeg" : -82.4856, 
"lii" : 297.4896,
"name" : "HD 22237", 
"radeg" : 50.3284,
"vmag" : 8, 
"xref" : ["HD 22237", "CPD -82   65", "-82   64","PPM 376283", "SAO 258336",
          "CP-82   65","GC 4125" ] }

{ "_id" : ObjectId("4ec6d44661910ad451f78eba"), 
  "bii" : -32.9901, 
  "class" : 2450, 
  "decdeg" : -82.4781, 
  "decpm" : 0.013,
  "lii" : 297.4807, 
  "name" : "PPM 376283", 
  "radeg" : 50.3543, 
  "rapm" : 0.0357, 
  "vmag" : 8.4, 
  "xref" : …
Run Code Online (Sandbox Code Playgroud)

mongodb

0
推荐指数
1
解决办法
2285
查看次数

类型列表中的方法 transform() 不适用

我正在尝试使用 Guava 函数从列表中删除重复项。这样做的原因是“重复”是基于列表中两个项目之间的比较,而这些对象是否“重复”需要相当多的逻辑。

这是我对该功能的尝试:

private Function<List<BaseRecord>, List<BaseRecord>> removeDuplicates = 
        new Function<List<BaseRecord>, List<BaseRecord>>() {

    public List<BaseRecord> apply(List<BaseRecord> records) {


        List<BaseRecord> out = Lists.newArrayList();


        PeekingIterator<BaseRecord> i = Iterators.peekingIterator(records.iterator());

        while (i.hasNext()) {
            BaseRecord current = i.next();

            boolean isDuplicate = false;

            if ( i.hasNext() ) {

                BaseRecord next = i.peek();


                // use a ComparisonChain to compare certain fields, removed
                isDuplicate = compareCertainObjects(o1, o2);

            }

            if ( !isDuplicate ) {
                out.add(current);
            }
        }


        return out;
    }

};
Run Code Online (Sandbox Code Playgroud)

然后我尝试用 Lists.transform(originalRecords, removeDuplicates) 调用它

不幸的是,Eclipse 并不高兴:

The method …
Run Code Online (Sandbox Code Playgroud)

java guava

0
推荐指数
1
解决办法
769
查看次数

比较Java字符串中的多个差异

我有一个字符串模板,看起来像这样:

This position is reserved for <XXXXXXXXXXXXXXXXXXXXXXXXXXX>. Start date is <XXXXXXXX>
Run Code Online (Sandbox Code Playgroud)

填写,这可能看起来像这样(固定宽度保留):

This position is reserved for <JOHN SMITH                 >. Start date is <20150228>
Run Code Online (Sandbox Code Playgroud)

如何在单个字符串中提取多个差异?如果可以避免,我不想将整个模板引擎用于一项任务.

java

0
推荐指数
1
解决办法
89
查看次数