다른 웹 사이트에 게시하면 모든 클라이언트가 작동하는 것으로 알고 있습니다. 나는JAXRS/CXF이 간단한 게시물 예제가 작동하지 않는 이유는 무엇입니까?
2012-03-16 09:30:30,295 INFO 300 [main] c.i.e.s.i.MockHpsRestApi - starting the server
Mar 16, 2012 9:30:30 AM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http://0.0.0.0:9000/
2012-03-16 09:30:30,769 INFO 774 [main] org.eclipse.jetty.server.Server - jetty-7.5.4.v20111024
2012-03-16 09:30:30,801 INFO 806 [main] o.e.jetty.server.AbstractConnector - Started [email protected]:9000 STARTING
2012-03-16 09:30:30,824 INFO 829 [main] o.e.j.server.handler.ContextHandler - started o.e.j.s.h.ContextHandler{,null}
Mar 16, 2012 9:30:37 AM org.apache.cxf.jaxrs.utils.JAXRSUtils readFromMessageBody
WARNING: No message body reader has been found for request class MultipartBody, ContentType : application/xml.
Mar 16, 2012 9:30:37 AM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: WebApplicationException has been caught : no cause is available
왜이 작동하지 않습니다 ...가 요청을 수신 할 때
@Path("/enrollment")
public class MockHpsRestApi {
private static final Logger log = LoggerFactory.getLogger(MockHpsRestApi.class);
public static void main(final String[] args) throws InterruptedException,
IOException, MuleException {
log.info("starting the server");
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(MockHpsRestApi.class);
sf.setResourceProvider(MockHpsRestApi.class, new SingletonResourceProvider(new MockHpsRestApi()));
sf.setAddress("http://0.0.0.0:9000/");
sf.create();
}
@POST
@Path("/enroll")
@Consumes("application/xml")
public String enrollment(MultipartBody body) throws IOException {
log.info("received request="+body);
Attachment att = body.getRootAttachment();
ByteArrayOutputStream str = new ByteArrayOutputStream(100);
InputStream in = att.getDataHandler().getInputStream();
try {
IOUtils.copy(in, str);
log.info("body payload received="+str);
String xml = "success";
return xml;
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(str);
}
}
}
내 로그하지만이 말을 ... http://localhost:9000/enrollment/enroll를 URL에 게시하도록 클라이언트를 변경 한 다음 서버를 실행 ?
hmmm, 로그 수준을 높이는 것은 CXF에서의 이런 종류의 버그입니다.하지만 이는 아무도 기본적인 글을 쓰는 것을 의미하지 않을 것입니다. 오늘 다른 서비스에 잘).
2012-03-16 09:51:01,414 DEBUG 10916 [qtp669588045-18 - /enrollment/enroll] o.a.c.j.i.JAXRSInInterceptor - Request path is: /enrollment/enroll
2012-03-16 09:51:01,414 DEBUG 10916 [qtp669588045-18 - /enrollment/enroll] o.a.c.j.i.JAXRSInInterceptor - Request HTTP method is: POST
2012-03-16 09:51:01,414 DEBUG 10916 [qtp669588045-18 - /enrollment/enroll] o.a.c.j.i.JAXRSInInterceptor - Request contentType is: application/xml
2012-03-16 09:51:01,415 DEBUG 10917 [qtp669588045-18 - /enrollment/enroll] o.a.c.j.i.JAXRSInInterceptor - Accept contentType is: */*
2012-03-16 09:51:01,415 DEBUG 10917 [qtp669588045-18 - /enrollment/enroll] o.a.c.j.i.JAXRSInInterceptor - Found operation: enrollment
2012-03-16 09:51:01,420 WARN 10922 [qtp669588045-18 - /enrollment/enroll] o.apache.cxf.jaxrs.utils.JAXRSUtils - No message body reader has been found for request class MultipartBody, ContentType : application/xml.
2012-03-16 09:51:01,423 WARN 10925 [qtp669588045-18 - /enrollment/enroll] o.a.c.j.i.WebApplicationExceptionMapper - WebApplicationException has been caught : no cause is available
2012-03-16 09:51:01,428 DEBUG 10930 [qtp669588045-18 - /enrollment/enroll] o.a.c.j.i.WebApplicationExceptionMapper - no cause is available
javax.ws.rs.WebApplicationException: null
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1052) ~[cxf-bundle-2.5.2.jar:2.5.2]
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:616) ~[cxf-bundle-2.5.2.jar:2.5.2]
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:580) ~[cxf-bundle-2.5.2.jar:2.5.2]
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:238) ~[cxf-bundle-2.5.2.jar:2.5.2]
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:89) ~[cxf-bundle-2.5.2.jar:2.5.2]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) [cxf-api-2.5.2.jar:2.5.2]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123) [cxf-rt-core-2.5.2.jar:2.5.2]
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:323) [cxf-bundle-2.5.2.jar:2.5.2]
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:289) [cxf-bundle-2.5.2.jar:2.5.2]
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72) [cxf-bundle-2.5.2.jar:2.5.2]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:943) [jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:879) [jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) [jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
그래도 내 코드에 대해 의견을 말하게하십시오. 내 개인 의견,하지만 난 API를 - 현명한 - 그것은 몇 가지 잘못된 XML ("성공"은 잘 구성된 XML이 아닌)보다 오히려 HTTP 코드 (Reponse.Status.CREATED)를 반환하는 것이 훨씬 더 좋을 것이라고 생각합니다. application/xml. –
프로토 타입이었고 입력이 xml을 소비하는 동안 출력이 전혀 소모되지 않았는지 ... 저는 200ok만으로도 충분하다고 생각했고 그 코드를 제거하지 않았습니다. –