Tag: spring

如何使用WSS4J拦截器在Web服务方法中获取经过身份validation的用户

我在Spring中托管了Apache CXF服务。 我正在使用WSS4J拦截器来validation用户名/密码安全性以访问服务器。 validation工作正常,如果我从SoapUI发送错误的凭据我不能按预期使用该服务。 如果我发送正确的凭据,服务没有问题。 这是我在spring上下文文件中的配置。 <!—-> 现在我需要能够在我的服务方法中访问我的身份validation用户,如下所示: @WebResult(name = “UpdatePatternResponse”, targetNamespace = “http://test.com/schemas/xsd/myservice/”, partName = “UpdatePatternResponse”) @WebMethod(operationName = “UpdatePattern”, action = “UpdatePattern”) @Generated(value = “org.apache.cxf.tools.wsdlto.WSDLToJava”, date = “2015-02-19T12:49:59.491-05:00”) public test.com.schemas.xsd.myservice.UpdatePatternResponse updatePattern( @WebParam(partName = “UpdatePatternRequest”, name = “UpdatePatternRequest”, targetNamespace = “http://test.com/schemas/xsd/myservice/”) test.com.schemas.xsd.myservice.UpdatePatternRequest updatePatternRequest ) throws SIASFaultMessage{ . . User myAuthenticatedUser = //HOW TO GET THE […]

Spring启动:需要ServletContext来配置默认的servlet处理

我已将经典的spring框架应用程序转换为Spring Boot,现在我得到了这个: . ____ _ __ _ _ /\\ / ___’_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ‘ |____| .__|_| |_|_| […]

如何分离业务逻辑和电子邮件发送function?

我的java web应用程序中有一个要求,我需要在某些条件下发送电子邮件警报。 为此,我使用了javax mail api并发送电子邮件工作正常。 但问题是程序执行等待直到执行发送电子邮件的方法。 由于在不同的点上发送了数百封电子邮件……这会显着降低性能。 我正在使用弹簧,也使用了弹簧。 任何人都可以建议我如何分离我的业务逻辑和发送电子邮件function。 它应该像 – 发送电子邮件是我的建议,在调用xyz方法时执行 – 所以主要执行不应该等待建议完成其执行,而应该返回并执行进一步的业务逻辑,从而单独执行电子邮件发送。 这里创建新线程似乎是明显的选择。 但我认为可能有更好的方法,是吗? 谢谢。

如何在执行junit时将参数传递给Spring MVC控制器中的post方法?

我正在对我的Spring MVC控制器方法进行unit testing。 下面是我尝试unit testing的方法,因为它在我启动服务器时工作正常。 每当我打到index页面时,它会在浏览器上显示三个文本框,我在其中键入数据并按下提交按钮,然后调用addNewServers并使用正确的值。 现在我需要对同样的事情进行unit testing: @RequestMapping(value = “/index”, method = RequestMethod.GET) public Map addNewServer() { final Map model = new LinkedHashMap(); return model; } @RequestMapping(value = “/index”, method = RequestMethod.POST) public Map addNewServers(@RequestParam String[] servers, @RequestParam String[] address, @RequestParam String[] names) { } 以下是我的junit课程: private MockMvc mockMvc; @Before public void setup() throws […]

无需交易即可获取数据

下面是带有spring事务的示例代码片段。 我的问题: – 是否会使用相同的会话来获取第1行和第2行的实体? 我的理解: – 我相信是的,春季交易将确保这一点 @Transactional() public void method1( //fetch entity1 from dao with the help of entity manager//line 1 // fetch entity2 from dao with the help of entity manager//line 2 // now I fetch thru method entity.fetchLazyField()// line 3 ) 现在,如果我删除@Transactional() 。 我相信一旦获取entity1就会关闭会话,并且将为line2使用单独的会话。 对 ? 在第3行(一旦@Transactional被删除),我是否能够获取数据或会话被关闭应该抛出exception? 我没有粘贴大的xml配置和完整的dao代码,只是用实体管理器获取etity。 事务传播属性是Required

Spring Data返回List

我有这个存储库: @Repository public interface ProductRepository extends JpaRepository{ @Query(“SELECT p.textToSearch as text, count(*) as counter FROM Product p GROUP BY text_to_search ORDER BY counter DESC”) List findTopProducts(); } TopProductDTO类的位置是: public class TopProductDTO { public TopProductDTO() {} private String text; private Integer counter; // Getters and Setters are omited } 但是当我执行代码时 List topProducts = productRepository.findTopProducts(); 它返回一个 List […]

AOP使用Around来避免执行方法

我在我的代码中使用Spring AOP来拦截某个方法的执行。 我正在尝试做的一个简化示例如下: public void someMethod() { //does something } @Around(“execution( someMethod())”) public void anotherMethod(final ProceedingJoinPoint joinPoint) { //i want to add this to a queue to get executed later on addToWaitList(new Callable() { @Override public call() throws Exception { joinPoint.proceed(); } }); return; } 本质上,我想推迟someMethod()的执行,直到它位于列表的头部。 但是,主线程阻塞,即使我在anotherMethod()的末尾返回,所以我无法将new Callable添加到列表中,直到第一个完成执行。 文档说您可以通过返回自己的返回值或抛出exception来快速建议的方法执行。 我不想抛出exception而且我不确定在这种情况下“返回自己的返回值”意味着什么。 我希望能够使用主线程将Callables添加到列表中,然后让其他线程池执行它们。

Spring Integration – 如何使用http outbound-gateway发送POST参数

我正在尝试使用Spring Integration和http outbound-gateway组合一个非常简单的HTTP POST示例。 我需要能够发送带有一些POST参数的HTTP POST消息,就像我使用curl : $ curl -d ‘fName=Fred&sName=Bloggs’ http://localhost 如果我将一个简单的String作为参数发送到接口方法,我可以使它工作(没有POST参数),但是我需要发送一个pojo,其中pojo的每个属性都成为POST参数。 我有以下SI配置: 我的RequestGateway界面如下所示: public interface RequestGateway { String echo(Pojo request); } 我的Pojo类看起来像这样: public class Pojo { private String fName; private String sName; public Pojo(String fName, String sName) { this.fName = fName; this.sName = sName; } …. getters and setters } 而我的全class学生就是这样的: public class […]

如何以动态方式创建Spring Beans。 使用Quartz SchedulerFactoryBean

我有一个QuartzJobConfig类,我注册了我的Spring-Quartz-Beans 。 我遵循了SchedulerFactoryBean , JobDetailFactoryBean和CronTriggerFactoryBean的指令。 我的作业在应用程序外部的yaml文件中配置。 意味着我必须在应用程序启动时动态创建Bean。 我的配置: channelPartnerConfiguration: channelPartners: – code: Job1 jobConfigs: – schedule: 0 * * ? * MON-FRI name: Job1 daily hotel: false allotment: true enabled: true – schedule: 30 * * ? * MON-FRI name: Job2 weekly hotel: true allotment: false enabled: true … 我的配置类: @Configuration public class QuartzJobConfig implements […]

我可以一起使用SOAP Webservices和Spring MVC吗?

我有一个Spring MVC项目。 我写了类似的代码 @Controller @RequestMapping(“CallBack”) @WebService(name = “NotificationToCP”, targetNamespace = “http://SubscriptionEngine.ibm.com”) public class CallbackController { @RequestMapping(“”) @ResponseBody @WebMethod(action = “notificationToCP”) @RequestWrapper(localName = “notificationToCP”, targetNamespace = “http://SubscriptionEngine.ibm.com”, className = “in.co.mobiz.airtelVAS.model.NotificationToCP_Type”) @ResponseWrapper(localName = “notificationToCPResponse”, targetNamespace = “http://SubscriptionEngine.ibm.com”, className = “in.co.mobiz.airtelVAS.model.NotificationToCPResponse”) public NotificationToCPResponse index( @WebParam(name = “notificationRespDTO”, targetNamespace = “”) CPNotificationRespDTO notificationRespDTO) { return new NotificationToCPResponse(); } } […]