spring-attic / spring-integration-dsl-groovy

Groovy DSL for Spring Integration
Apache License 2.0
56 stars 40 forks source link

Junit-Spring integration IOexception on console #12

Closed razazaran closed 9 years ago

razazaran commented 9 years ago

I have a question here. I am trying to access spring configuration file using junit, but it is failing before setUp() method with following errror:

10:33:21.494 INFO [main][org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping] Mapped "{[/getBillServiceImplReq],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" 
onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException

here is my Junit:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/WEB-INF/upperSI/http/servlet-config.xml" })
@WebAppConfiguration
public class RestGetServiceImplTest{
@Autowired
private WebApplicationContext webApplicationContext;

private MockMvc mockMvc;

/**
 * Set variables and Objects which are need to execute the test-case.
 * @throws IOException 
 */
@Before
public void setUp() throws Exception{
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
        }

and servlet-config code im trying to access/load is :

<supported-methods="POST" path="/getBillServiceImplReq" mapped-request-headers="HttpHeaders.REQUEST_URL"/>

<!-- this is require to enrich the header to handle the content-type of 
    type "application/json" -->
<int:header-enricher input-channel="getBillServiceImplChannel"
    output-channel="getBillServiceReqJsonImplChannel">
    <int:header name="content-type" value="application/json"></int:header>
</int:header-enricher>

<int:chain input-channel="getBillServiceReqJsonImplChannel">
<!-- Transformer is required to map the JSON payload in the Java object 
    format which can be processed in the eChannel framework -->
<int:json-to-object-transformer type="com.nbad.echannel.common.model.GetBillType" object-mapper="jackson2JsonObjectMapper" />
 <!-- <int:transformer ref="loggingJSONRequest" method="logJSONRequest" /> -->
<int:service-activator>
    <bean class="com.nbad.echannel.service.account.impl.GetBillServiceImpl"><constructor-arg ref="getDepositType"></constructor-arg></bean>
</int:service-activator>    
/int:chain>
artembilan commented 9 years ago

Hi @razazaran !

First of all I don't see in this issue any Spring Integration Groovy DSL relevant info. From other side I've just added MockMvc to the https://github.com/spring-projects/spring-integration/blob/master/spring-integration-http/src/test/java/org/springframework/integration/http/HttpProxyScenarioTests.java And it works well.

So, provide, please, more StackTrace on the matter and supply some test-case to reproduce what doesn't work.

And, please, pay attention that message is 10:33:21.494 INFO [main]. So, what's going on there?

Thank you. And let us know how we can help you more.

razazaran commented 9 years ago

Thanks Artem!! see im trying to do integration testing of my spring-integration application. I have create Junit which loads application context using @ContextConfiguration(locations = { "classpath:/WEB-INF/servlet-config.xml" }), everything works fine and i get the required response in JSON, but when i see STS console, i see this exception in blue , which I have pasted above. This error comes even before setUp() method of junit is called. Looks like @contextConfiguration is unable to load Spring integration beans.

Application context :

<?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:int="http://www.springframework.org/schema/integration"
    xmlns:int-file="http://www.springframework.org/schema/integration/file"
    xmlns:int-http="http://www.springframework.org/schema/integration/http"
    xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
        http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> 

<int-http:inbound-gateway request-channel="getBillServiceImplChannel"
        supported-methods="POST" path="/getBillServiceImplReq" mapped-request-headers="HttpHeaders.REQUEST_URL"/>

    <!-- this is require to enrich the header to handle the content-type of 
        type "application/json" -->
    <int:header-enricher input-channel="getBillServiceImplChannel"
        output-channel="getBillServiceReqJsonImplChannel">
        <int:header name="content-type" value="application/json"></int:header>
    </int:header-enricher>

    <int:chain input-channel="getBillServiceReqJsonImplChannel">
    <!-- Transformer is required to map the JSON payload in the Java object 
        format which can be processed in the eChannel framework -->
    <int:json-to-object-transformer type="com.echannel.common.model.GetBillType" object-mapper="jackson2JsonObjectMapper" />
     <!-- <int:transformer ref="loggingJSONRequest" method="logJSONRequest" /> -->
    <int:service-activator>
        <bean class="com.eChannel.service.dueamount.impl.GetBillServiceImpl"><constructor-arg ref="getBillType"></constructor-arg></bean>
    </int:service-activator>    
    <int:object-to-json-transformer content-type="application/json" />
    </int:chain>
artembilan commented 9 years ago

Sorry, I don't use STS, but as I said it is just an INFO. Since you confirm that everything works well, may be you just configure a logger in the STS for the WARN on the org.springframework category.

Let us know and close this issue if you don't have anymore problems

razazaran commented 9 years ago

are these tags of spring integration in application context correct ?

artembilan commented 9 years ago

I don't see anything specific. Just found that MVC include as redundant

razazaran commented 9 years ago

Ok Many Thanks !!. Do you know how to debug the xml file so that I may know which spring integration element was called and which not.

artembilan commented 9 years ago

XML config can't be debugged, because it makes sense only on the parser phase. In the runtime all those XML components are translates to specific Java object. And they already can be debugged. I most cases they are MessageSource, MessageProducer or MessageHandler implementations. Please, read more about JavaConfig (http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/configuration.html#annotations) to get more info about Spring Integration internals.

razazaran commented 9 years ago

Thanks for the info Artem. Cheers !! but this issue is still not resolved, though im getting proper response. : )

razazaran commented 9 years ago

and yes I have seen you replied to similar question on stacoverflow. http://stackoverflow.com/questions/24310609/spring-integration-http-endpoint-from-child-context-doesent-work

artembilan commented 9 years ago

Sorry, I thought your issue was about that INFO in the logs, but now you refer me to an issue, when DispatcherServlet is in the child ctx. For this purpose we really should have a separate ticket with proper info on the matter.

razazaran commented 9 years ago

how to find whether dispatcher servlet is in the ctx ?? im not sure ... can u figure out from my code.

artembilan commented 9 years ago

DispatcherServlet is, erm.., a Servlet in the web.xml of your web-app, or that one from Spring Boot, if you use spring-boot-starter-web, or that from JavaConfig for Servlet 3 spec. But as I said: this question isn't relevant to this ticket.

razazaran commented 9 years ago

when im trying to call spring integration code in xml... from junit class, i get this error.... I dont get any error when i deploy n then run SOAPUI tests. i want to do this testing from Junit, not soapui.

artembilan commented 9 years ago

OK. Let's come back to the start! Which error do you have from test? Share, please, full StackTrace.

razazaran commented 9 years ago

10:33:21.494 INFO [main][org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping] Mapped "{[/getBillServiceImplReq],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException

this is the error im getting on console.... nothjing else. this error does not stop the flow, and i get proper response in junit.

artembilan commented 9 years ago

It isn't error. It's just log message on the INFO level from the AbstractHandlerMethodMapping#registerHandlerMethod

this.handlerMethods.put(mapping, newHandlerMethod);
if (logger.isInfoEnabled()) {
    logger.info("Mapped \"" + mapping + "\" onto " + newHandlerMethod);
}

What is the reason to disturb us for nothing?

razazaran commented 9 years ago

sorry I forgot to share the error message. my bad. I dont have the error message right now.