小编Kam*_*kol的帖子

在Spring Data Rest中使用自定义json序列化程序时输出不同的JSON

Jackson根据官方文档添加自定义序列化程序后,我观察到了略微不同的json输出格式.

这个例子是基于弹簧垫的叉子.

扩展org.springsource.restbucks.WebConfigurationRepositoryRestMvcConfiguration并重写configureJacksonObjectMapper:

@Override
protected void configureJacksonObjectMapper(ObjectMapper objectMapper) {
    final SimpleSerializers serializers = new SimpleSerializers();
    serializers.addSerializer(Order.class, new OrderSerializer());
    objectMapper.registerModule(new SimpleModule("CustomSerializerModule"){
        @Override public void setupModule(SetupContext context) {
            context.addSerializers(serializers);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

创建类org.springsource.restbucks.order.OrderSerializer.为简洁起见,只需将属性写paid为JSON即可.

public class OrderSerializer extends JsonSerializer<Order> {
    @Override
    public void serialize(Order value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
        jgen.writeStartObject();
        jgen.writeBooleanField("paid", value.isPaid());
        jgen.writeEndObject();
    }
}
Run Code Online (Sandbox Code Playgroud)

在添加OrderSerializer json响应之前,http://localhost:8080/orders/1看起来像:

{
  "location": "TAKE_AWAY", …
Run Code Online (Sandbox Code Playgroud)

jackson spring-data-rest spring-hateoas

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

验证后存储其他信息[Spring]

我正在开发一个具有以下要求的Web应用程序:

  1. 允许用户登录
  2. 在服务器端,用户通过第三方REST Web服务进行身份验证.
  3. 如果身份验证成功,REST Web服务将返回唯一标记和密钥.
  4. 对REST Web服务的任何后续请求必须包含在第3点(上面)中收到的令牌.

我正在为web应用程序使用spring-mvc和spring security.所以,我得到了一个解决方案,但是我刚接触弹簧并且不确定解决方案是否正确.

有人可以建议:

  1. 解决方案是否正确实施?
  2. 该解决方案是否会以任何方式影响性能?
  3. 解决方案是否会产生任何安全漏洞?

谢谢 :)


方案:

  1. 我创建了一个MyUser对象,它将存储从REST服务收到的其他信息.

    public class MyUser implements Serializable {
    
        private static final long serialVersionUID = 5047510412099091708L;
        private String RestToken;
        private String RestKey;
    
        public String getRestToken() {
            return RestToken;
        }
        public void setRestToken(String restToken) {
            RestToken = restToken;
        }
        public String getRestKey() {
            return RestKey;
        }
        public void setRestKey(String restKey) {
            RestKey = restKey;
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 然后我创建了一个扩展UsernamePasswordAuthenticationToken的MyAuthenticationToken对象.此对象将在CustomAuthenticationProvider中使用(下面的第3点).

    public class MyAuthenticationToken extends UsernamePasswordAuthenticationToken {
    
            private static …
    Run Code Online (Sandbox Code Playgroud)

java authentication spring spring-mvc spring-security

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

如何使用Spring security 2和Apache Tomcat 7设置将JSESSIONID cookie设置为安全

如何使用Spring security 2和Apache Tomcat 7设置将JSESSIONID cookie设置为安全.

已经在web.xml中放入了下面的代码,它似乎并没有起作用.

<cookie-config>
   <secure>true</secure>
</cookie-config>
Run Code Online (Sandbox Code Playgroud)

谢谢

java spring tomcat

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

Spring Rest RestTemplate

我正在尝试使用spring rest模板来发布登录请求.

RestTemplate restTemplate = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

LinkedMultiValueMap<String, Object> mvm = new LinkedMultiValueMap<String, Object>();
mvm.add("LoginForm_Login", "login");
mvm.add("LoginForm_Password", "password");

ResponseEntity<String> result = restTemplate.exchange(uriDWLogin, HttpMethod.POST, requestEntity, String.class);
Run Code Online (Sandbox Code Playgroud)

一切顺利,但当我尝试发送第二个请求时,它会生成错误说:

业务经理在15分钟后关闭您的会话

我该怎么做才能解决这个问题?

rest spring spring-mvc resttemplate

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

比较 XMLUnit 2 中的子节点 - 预期子节点“node2”但为“null”

我需要使用XMLUnit 2xml 子节点顺序不同的位置来比较 XML 文件。由于使用了底层库,我无法影响子节点的顺序。

为了进行比较,我正在使用:

    <dependency>
        <groupId>org.xmlunit</groupId>
        <artifactId>xmlunit-core</artifactId>
        <version>2.0.0-alpha-02</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.xmlunit</groupId>
        <artifactId>xmlunit-matchers</artifactId>
        <version>2.0.0-alpha-02</version>
        <scope>test</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

问题归结为这个 JUnit 测试:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.xmlunit.builder.Input.fromString;
import static org.xmlunit.diff.ElementSelectors.byName;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.xmlunit.diff.DefaultNodeMatcher;

import java.io.IOException;

public class XmlTest {

    @Test
    public void test() throws Exception {
        String t1 = fromClassPath("t1.xml");
        String t2 = fromClassPath("t2.xml");
        assertThat(fromString(t1), isSimilarTo(fromString(t2)).withNodeMatcher(new DefaultNodeMatcher(byName)));
    }

    private static String fromClassPath(String fileName) throws IOException {
        return IOUtils.toString(new ClassPathResource(fileName).getInputStream());
    } …
Run Code Online (Sandbox Code Playgroud)

xmlunit xmlunit-2

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

Oracle 错误:ORA-00923:未在预期位置找到 FROM 关键字

我在我的 Oracle 数据库上写了一个触发器,但它显示了这个错误:

Compilation failed, line 11 (17:21:05) The line numbers associated
with compilation errors are relative to the first BEGIN statement.
This only affects the compilation of database triggers. PL/SQL:
ORA-00923: FROM keyword not found where expectedCompilation failed,
line 11 (17:21:05) The line numbers associated with compilation errors
are relative to the first BEGIN statement. This only affects the
compilation of database triggers. PL/SQL: SQL Statement ignored
Run Code Online (Sandbox Code Playgroud)

这是代码:

CREATE OR REPLACE TRIGGER BEGIN_CALL1 AFTER INSERT ON STATE_CHANGE
FOR EACH …
Run Code Online (Sandbox Code Playgroud)

sql oracle triggers

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

Hybris安装错误

D:\ HYBRIS软拷贝\ hybris\bin\platform> setantenv.bat

将ant home设置为:D:\ HYBRIS软拷贝\ hybris\bin\platform\apache-ant-1.9.1 Apache Ant(TM)1.9.1版于2013年5月15日编译

D:\HYBRIS Soft copies\hybris\bin\platform>ant clean all


Buildfile: D:\HYBRIS Soft copies\hybris\bin\platform\build.xml

[echo] D:\HYBRIS Soft copies\hybris\bin\platform/tomcat/bin

[mkdir] Created dir: D:\HYBRIS Soft copies\hybris\log

[mkdir] Created dir: D:\HYBRIS Soft copies\hybris\data

[mkdir] Created dir: D:\HYBRIS Soft copies\hybris\temp\hybris

[input]

[input]  **** NO CONFIG FOLDER FOUND ****

[input]

[input]  No config folder was found at D:\HYBRIS Soft copies\hybris\config.

[input]  A "fresh" folder containing basic configuration files and the hybris

[input]  demo licence will be created for your convenience. …
Run Code Online (Sandbox Code Playgroud)

hybris

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