2016-07-30 3 views
2

twilio API에 대한 응답을 보낼 때 지원되지 않는 미디어 유형 문제가 발생합니다.Twilio API 415 지원되지 않는 미디어 유형 오류입니다. 오류 - 11200

나는 내가 내 메시지의 상태에 변화가있을 때 내 시스템에 대한 응답을 보내 twilio의 callBackUrl을 구성

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)); 

아래로 twilio API를 사용하여 번호로 메시지를 전송하고 있습니다. 다음은

내가 twilio 디버거 내 응답의 상태를 확인 안들어에 다시 응답을 전송 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; 
} 

를 처리하는 코드, 그것은 실패 보여주고있다 415 미디어가 지원되지 않는 오류입니다. 정확한 롤 원인을 찾을 수 없습니다. 아무것도 잘못되면 저를 안내

는 제목 https://www.twilio.com/docs/api/twiml/sms/your_response##에서 내 이해를 기반으로 개발 ##

이 전형적인 Twilio 인바운드 보이는 방법

요청
URL
/휴식/메시지/콜백/인바운드

같은/트윌 리오?
매개 변수
MESSAGESTATUS는
APIVERSION 2010-04-01
SMSSID
SMSSTATUS은 보낸 사람의 91123456789
에게
을 보내 보내
MESSAGESID
ACCOUNTSID 나는 그냥 content-type for TwiML response를 설정해야합니다 생각

답변

0

이렇게 :

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

응답 개체가 HttpServletResponse가 아닙니다. 그것은 javax.ws.rs.core.Response입니다. 그래서 ** Response.status (Response.Status.OK) .header ("Content-Type", "application/xml"). 엔티티 (twiml) .build(); **를 추가하여 content- 응답으로 입력하십시오. 아직도 운이 없다. – Adithya