2016-07-30 102 views
2

當我向twilio API發送響應時,我正面臨415不受支持的媒體類型問題。Twilio API 415不支持的媒體類型錯誤。錯誤 - 11200

我將消息發送到使用twilio API一些如下

TwilioRestClient client = new TwilioRestClient(accountSID, authToken); 
    Account account = client.getAccount(); 
    MessageFactory messageFactory = account.getMessageFactory(); 
    List<NameValuePair> params = new ArrayList<NameValuePair>(); 
    params.add(new BasicNameValuePair(TO, mobileNumber)); 
    params.add(new BasicNameValuePair(FROM_, from)); 
    params.add(new BasicNameValuePair(BODY, messageBody)); 
    params.add(new BasicNameValuePair(CALL_BACK_URL, callBackUrl)); 

我配置了callBackUrl爲twilio發送到我的系統響應時曾經出現在我的消息的狀態的變化。

下面是處理twilio入站響應

@POST 
@Path("/callback/inbound/Twilio") 
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML,MediaType.TEXT_PLAIN }) 
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) 
public Response inboundTwilio(@QueryParam("AccountSid") String accountSid, 
           @QueryParam("MessageSid") String gatewayTxnId, 
           @QueryParam("MessageStatus") String messageStatus, 
           @QueryParam("ErrorCode") String errorCode, 
           @QueryParam("From") String from, 
           @QueryParam("To") String to, 
           @Context HttpServletRequest request) throws DateParseException { 
    Response response = null; 
    try{ 
     Long startTime = System.currentTimeMillis(); 
     LOGGER.info("In twilio inbound response for gatewayTxnId :: "+gatewayTxnId); 
     // business logic and processing of twilio inbound handled here and it will return a status object 
     LOGGER.info("Execution completed in :: "+(System.currentTimeMillis()-startTime)); 
     if (status != null && SUCCESS.equalsIgnoreCase(status)) { 
      TwiMLResponse twiml = new TwiMLResponse(); 
      Message message = new Message("SUCCESS"); 
      twiml.append(message); 
      response = Response.status(Response.Status.OK).entity(twiml).build(); 
     } else { 
      response = Response.status(Response.Status.BAD_REQUEST).build(); 
     } 
    }catch(Exception e){ 
     LOGGER.error("An error occured in MessageResource while processing inboundTwilio :: ",e.getMessage()); 
     response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseUtil.prepareResponse("500", 
         "Error occoured while processing your request", ExceptionUtils.getStackTrace(e)).toString()).build(); 
    } 
    return response; 
} 

處理來自twilio發送響應返回給它。當要求檢查我在twilio調試器響應的狀態後的代碼,它顯示失敗415媒體不受支持的錯誤。我無法找到確切的原因。指導我如果有什麼是錯的

開發基於我的理解從https://www.twilio.com/docs/api/twiml/sms/your_response##標題##

這是一個典型的Twilio入站的樣子

請求
URL
/REST /消息/回調/入內/ Twilio?
參數
MESSAGESTATUS發送
APIVERSION 2010-04-01
SMSSID
SMSSTATUS發送
TO 91123456789
來自發件人的
MESSAGESID
ACCOUNTSID

回答

0

我相信,你只需要設置content-type for TwiML response像這樣:

response.setContentType("application/xml"); 
+1

響應對象不是HttpServletResponse。它是javax.ws.rs.core.Response。所以我添加了像這樣** Response.status(Response.Status.OK).header(「Content-Type」,「application/xml」)。entity(twiml).build(); **發送內容 - 鍵入迴應。仍然沒有運氣 – Adithya

相關問題