小编zde*_*sam的帖子

使用Spring RestTemplate访问Https Rest服务

任何人都可以使用Spring rest模板为我提供代码示例来访问使用https保护的休息服务URL.

我有证书,用户名和密码.基本身份验证在服务器端使用,我想创建一个客户端,可以使用提供的证书,用户名和密码(如果需要)连接到该服务器.

rest https spring certificate resttemplate

42
推荐指数
3
解决办法
8万
查看次数

Gson序列化字段仅在不为空或不为空时

我有需要将java对象转换为json的地方.

我正在使用Gson,但我需要转换器只序列化非null或非空值.

例如:

//my java object looks like
class TestObject{
    String test1;
    String test2;
    OtherObject otherObject = new OtherObject();
}
Run Code Online (Sandbox Code Playgroud)

现在我的Gson实例将此对象转换为json看起来像

Gson gson = new Gson();
TestObject obj = new TestObject();
obj.test1 = "test1";
obj.test2 = "";

String jsonStr = gson.toJson(obj);
println jsonStr;
Run Code Online (Sandbox Code Playgroud)

在上面的印刷品中,结果是

{"test1":"test1", "test2":"", "otherObject":{}}
Run Code Online (Sandbox Code Playgroud)

在这里,我只想要结果

{"test1":"test1"}
Run Code Online (Sandbox Code Playgroud)

由于test2为空且otherObject为空,我不希望它们被序列化为json数据.

顺便说一句,我正在使用Groovy/Grails,所以如果有任何插件,这将是好的,如果没有任何建议自定义gson序列化类将是好的.

java groovy serialization json gson

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

由于地址已在使用错误,Activemq无法运行

如何解决错误?

Java Runtime: Oracle Corporation 1.7.0_05 E:\Program Files\Java\jdk1.7.0_05\jre
  Heap sizes: current=1004928k  free=994439k  max=1004928k
    JVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Dactivemq.classpath=F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\conf;F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\../conf;F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\../conf; -Dactivemq.home=F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\.. -Dactivemq.base=F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\.. -Dactivemq.conf=F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\conf -Dactivemq.data=F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\data -Djava.io.tmpdir=F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\data\tmp
ACTIVEMQ_HOME: F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..
ACTIVEMQ_BASE: F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..
ACTIVEMQ_CONF: F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\conf
ACTIVEMQ_DATA: F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\data
Loading message broker from: xbean:activemq.xml
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@2b9f7952: startup date [Sat Jul 28 18:10:38 CST 2012]; root of context hierarchy
 INFO | PListStore:[F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\data\localhost\tmp_storage ] started
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[F:\workspace\Eclipse java\destinytalk\DestinyServer\apache-activemq-5.6.0\bin\..\data\kahadb]
 INFO …
Run Code Online (Sandbox Code Playgroud)

activemq-classic

16
推荐指数
4
解决办法
3万
查看次数

具有继承性的通用Spring MVC控制器

我可以在Spring MVC中执行以下操作吗?

假设我有一个Base GenericController,如下所示,一个请求映射"/ list"

@Controller
public class GenericController<T>{

    @RequestMapping(method = RequestMethod.GET, value = "/list")
    public @ResponseBody List<T> getMyPage(){
        // returns list of T
    }

}
Run Code Online (Sandbox Code Playgroud)

以下是我的两个控制器

@Controller(value = "/page1")
public class Page1Controller extends GenericController<Page1>{

}

@Controller(value = "/page2")
public class Page2Controller extends GenericController<Page2>{

}
Run Code Online (Sandbox Code Playgroud)

现在我将能够访问URL"/ page1/list"和"/ page2/list",其中第一个转到Page1Controller,第二个转到Page2Controller.

controller spring-mvc

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

可从Deployed应用程序访问Grails WEB-INF

在grails应用程序中,可以访问WEB-INF内容,包括所有.gsp内容以及部署时的.class文件.

我正在使用grails 2.3.5并在tomcat 7中部署战争.

您可以使用访问这些文件

http://mydomain.com/static/WEB-INF/web.xml
http://mydomain.com/static/WEB-INF/grails-app/views/anyview.gsp
http://mydomain.com/static/ WEB-INF/grails-app/i18n/messages.properties http://mydomain.com/static/WEB-INF/classes/anyclass.class

我可以禁止访问grails中的这些URL吗?

java grails tomcat web-inf

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