2016-10-13 1 views
1

Я использую Spring Integration в моем проекте. Я пытаюсь выполнить службу отдыха, которая принимает параметры ввода multipart/formdata. Я использую int-http: исходящий-шлюз для выполнения службы отдыха. Ниже приведен код:Не подходит HttpMessageConverter обнаружил ошибку при выполнении службы отдыха, которая принимает параметры multipart

<int:channel id="PQcreateAttachment-Rest-Channel" /> 
    <int:chain input-channel="PQcreateAttachment-Rest-Channel" output-channel="PQcreateAttachment-StoredProcedure-Router" > 

     <int:header-filter header-names="accept-encoding"/>  

     <int:service-activator ref="httpOutboundGatewayHandler" method="buildMultipartHttpOutboundGatewayRequest" /> 

     <int-http:outbound-gateway url-expression="headers.restResourceUrl" 
            http-method-expression="headers.httpMethod" 
            extract-request-payload="true" 
            > 
     </int-http:outbound-gateway> 

     <int:service-activator ref="msgHandler" method="buildMessageFromExtSysResponse" /> 

    </int:chain> 

Но я получаю следующее сообщение об ошибке при выполнении вышеуказанного кода.

Caused by: org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [org.springframework.integration.message.GenericMessage] and content type [application/x-java-serialized-object] 
    at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:665) 
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:481) 
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:460) 
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:409) 
    at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:372) 
    ... 121 more 

Вот код Java, который готовит мой многослойную запрос:

public Message<?> buildMultipartHttpOutboundGatewayRequest(Message<?> inMessage) throws Exception{ 

     logger.debug(" ************** buildMultipartHttpOutboundGatewayRequest Start *************************"); 

     String inMsgPayload = (String)inMessage.getPayload(); 



     SOAXml soaXml = parseSOAXml(inMsgPayload); 

     String restURL  = null; 
     String contentType = null; 
     String acceptHdr = null; 
     String userId = null; 
     String password = null; 
     String businessAreaName = null; 
     String typeName = null; 
     String attachmentLocation = null; 
     String httpMethod = null; 
     Message<?> outMessage = null; 
     MessageHeaders inMsgHdrs = null; 
     MessageBuilder<?> msgBuild = null; 

     String authorization = null; 
     //TODO: File location needs to be changed to standard one 
     String fileLocation = "C:\\source.xml"; 
      //if we reach here means, it is AWD system 
      restURL  = getAwdSOAService(soaXml); 

     Document document = XmlParserUtil.convertString2Document(inMsgPayload); 

     userId = XmlParserUtil.getNodeValue(document,"//userId"); 
     password = XmlParserUtil.getNodeValue(document,"//PQcreateAttachment/password"); 
     businessAreaName  = XmlParserUtil.getNodeValue(document,"//businessAreaName"); 
     typeName = XmlParserUtil.getNodeValue(document,"//typeName"); 
     httpMethod = XmlParserUtil.getNodeValue(document,"//METHOD"); 
     attachmentLocation = XmlParserUtil.getNodeValue(document,"//attachmentLocation"); 

     //Construct source xml 
     //Creating document 
      Document sourceDocument = DocumentHelper.createDocument(); 
     Element sourceInstance = sourceDocument.addElement("createSourceInstance"); 
     sourceInstance.addAttribute("xmlns", "http://www.dsttechnologies.com/awd/rest/v1"); 
     Element orderItem=sourceInstance.addElement("businessAreaName"); 
     orderItem.setText("SAMPLEBA"); 
     Element orderItemDesc=sourceInstance.addElement("typeName"); 
     orderItemDesc.setText("SAMPLEST"); 
     // create source xml file 
     XmlParserUtil.createXMLFileUsingDOM4J(sourceDocument, fileLocation); 
     authorization = getBasicAuthorization(userId,password); 

     Resource source = new ClassPathResource(fileLocation); 
     Resource attachment = new ClassPathResource(attachmentLocation); 


     Map<String, Object> multipartMap = new HashMap<String, Object>(); 
     multipartMap.put("source", source); 
     multipartMap.put("attachment", attachment); 
     logger.info("Created multipart request: " + multipartMap); 


      inMessage = buildMessageForMultipart(multipartMap); 


     // contentType = csProps.getHttpAwdContentTypeValue(); 
      acceptHdr = csProps.getHttpAwdAcceptTypeValue() ; 
     // authorization = getBasicAuthorization(soaXml.getUserid(),decriptPassword(soaXml.getPassword())); 

      inMsgHdrs = inMessage.getHeaders(); 
      msgBuild = MessageBuilder.withPayload(inMessage).copyHeaders(inMsgHdrs); 
      msgBuild.removeHeader("Content-Encoding"); 
      msgBuild.removeHeader("accept-encoding"); 
      msgBuild.setHeader(csProps.getHttpUrlHdr(), restURL); 
      msgBuild.setHeader(csProps.getHttpMethodHdr(), httpMethod); 
      msgBuild.setHeader(csProps.getHttpAuthorizatonHdr(),authorization); 
//   msgBuild.setHeader(csProps.getHttpContentTypeHdr(), contentType); 
//   msgBuild.setHeader(csProps.getHttpAcceptTypeHdr(),acceptHdr); 


     outMessage = msgBuild.build(); 

     logger.debug(" ************** buildHttpOutboundGatewayRequest End*************************"); 
     logger.debug(outMessage); 
     logger.debug(" ************************************************************************"); 

     return outMessage; 

    } 

Любые идеи о том, что здесь не так?

+0

Поделиться, пожалуйста, что ваш 'buildMultipartHttpOutboundGatewayRequest' возвращает –

+0

Он возвращает сообщение типа' org.springframework.integration.Message '. Теперь какая-нибудь подсказка? Пожалуйста, дайте мне знать, если вам нужна дополнительная информация? –

+0

Хорошо. Затем поделитесь, пожалуйста, кодом этого метода. Вы говорите о multipart, так что, возможно, какая-то часть, которая не является серийной для использования, например. Некоторые заголовки в сообщении. Вот как все сообщение становится несериализуемым. В любом случае, это выглядит странно, что вы собираетесь отправить службе отдыха объект сообщения –

ответ

1

Ваша проблема в том, что вы переносите одно сообщение в другое.

Что делает ваш buildMessageForMultipart(multipartMap);?

Я уверен, что простой карты как полезной нагрузки и этого заголовка будет достаточно.

Не знаете, в чем смысл обернуть одно сообщение другому.

+0

Супер! Ты прав. В этом случае виновником является другое сообщение. +1 для быстрого указания недостатка. –

Смежные вопросы