sirve que para org from crear cliente java apache curl https cxf

java - org - para que sirve apache cxf



Obteniendo un error en la solicitud SOAP POST usando Apache CXF pero curl funciona (6)

El cambio fue utilizar core java HttpURLConnection para lograr esto.

Un método como este ayudó a la causa a publicar una llamada al servicio web sin ningún marco .:

public HttpURLConnection getHttpConn(String webservice_url) throws IOException { URL endpoint = new URL(webservice_url); URLConnection connection = endpoint.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) connection; byte[] encodedBytes = Base64.encodeBase64((getUsername()+":"+getPassword()).getBytes()); httpConn.setRequestMethod(getRequestMethod()); httpConn.setRequestProperty(HTTP_ACCEPT_ENCODING, getAccept_Encoding()); httpConn.setRequestProperty(HTTP_CONTENT_TYPE, getContentType()); httpConn.setRequestProperty(getContent_Length(), getContent_Length()); httpConn.setRequestProperty(HTTP_HOST, getHost()); httpConn.setRequestProperty(getConnection(), getConnection()); httpConn.setRequestProperty(HTTP_COOKIE2, getCookie2()); httpConn.setRequestProperty(HTTP_COOKIE, getCookie()); httpConn.setRequestProperty("Authorization", "Basic "+new String(encodedBytes)); httpConn.setDoOutput(true); httpConn.setDoInput(true); return httpConn; }

Asegúrese de configurar el cliente http en el archivo de configuración CXF (cxf.xml).

Como se documenta en el documento Apache CXF:

1.Agregue el espacio de nombres http-conduit y xsd:

<beans ... xmlns:http-conf="http://cxf.apache.org/transports/http/configuration ... xsi:schemaLocation="... http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd ...">

2.Agregue la etiqueta / elemento http-conduit y configure RecieveTimeout / ConnectionTimeout en 180000ms:

<http-conf:conduit name="*.http-conduit"> <http-conf:client ConnectionTimeout="300000" ReceiveTimeout="300000"/> </http-conf:conduit>

Estoy teniendo un problema muy extraño. Estoy intentando hacer una solicitud SOAP POST sobre HTTPS. Cuando envío la solicitud desde mi código, obtengo el error HTTP 500. Ahora, desde el registro de cxf, si copio el mismo mensaje SOAP (encabezado y cuerpo) para el que obtuve el error y lo publico usando una simple solicitud de curl, está funcionando bien. A continuación se muestra cómo estoy creando clase de servicio y otra inicialización

URL wsdlurl = SOAPWebServiceTransport.class.getClassLoader(). getResource("my.wsdl"); OnlinePort service= new OnlinePortService(wsdlurl).getOnlinePortPort(); Client proxy = ClientProxy.getClient(service); // Provides WS-Security WSS4JOutInterceptor wss4jOut = new WSS4JOutInterceptor(); wss4jOut.setProperty("action", "UsernameToken"); wss4jOut.setProperty("user", userName); wss4jOut.setProperty("passwordType", "PasswordText"); wss4jOut.setProperty("password", password); wss4jOut.setProperty(WSHandlerConstants.ADD_UT_ELEMENTS, WSConstants.NONCE_LN + " " + WSConstants.CREATED_LN); wss4jOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, ServerPasswordCallback.class.getName()); proxy.getEndpoint().getOutInterceptors().add(wss4jOut); setConduitProperties((HTTPConduit) proxy.getConduit(),url);

En el método set conduit estoy ignorando la comprobación SSL (solo para desarrollo env) y estableciendo un encabezado.

TLSClientParameters tcp = new TLSClientParameters(); tcp.setDisableCNCheck(true); // Creating Trust Manager TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) { } } }; tcp.setTrustManagers(trustAllCerts); conduit.setTlsClientParameters(tcp); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setAccept("*/*"); httpClientPolicy.setContentType("text/xml;charset=UTF-8"); httpClientPolicy.setHost(url.split("/")[2]); conduit.setClient(httpClientPolicy);

Cualquier ayuda sería altamente apreciable.

Response-Code: 500 Encoding: ISO-8859-1 Content-Type: text/html;charset=ISO-8859-1 Headers: {connection=[close], content-type=[text/html;charset=ISO-8859-1], Date=[Mon, 15 Jun 2015 06:42:09 GMT], Server=[Apache-Coyote/1.1], Set-Cookie=[JSESSIONID=FF0E4F5DCA42F700FFAC46BBD039FC20; Path=/; Secure], transfer-encoding=[chunked]} Payload: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> > <html> <head> <meta http-equiv="Content-Type" content="text/html; > charset=ISO-8859-1"/> <title>Error Page</title> </head> <body>Invalid > Request </body> </html> at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:79) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:797) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1618) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1491) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1399) at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47) at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:188) at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:646) at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134) Caused by: org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType. Incoming portion of HTML stream:

Solicitud CURL

curl -k - header "Content-Type: text / xml; charset = UTF-8" --header "SOAPAction" --data @ soaprequest.xml https: // url

Curl de inicio de sesión detallado (por supuesto, han cambiado algunos nombres de puerto de url0

Respuesta de error del servidor

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> <title>Error Page</title> </head> <body>Invalid Request </body> </html>


He enfrentado un problema similar al tuyo recientemente. Acabo de agregar 2 artefactos en dependencias:

<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>${cxf.version}</version> </dependency>


SOAP funciona en xml y puedo ver que tienes el siguiente error

Caused by: org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType. Incoming portion of HTML stream:

Lo cual significa que su respuesta viene en HTML, Response-Code: 500 Encoding: ISO-8859-1 Content-Type: text/html;chars

Por lo que podría haber un problema con su WebService intente usar SOAP UI

también este enlace será bastante útil habla sobre el mismo problema. https://forums.mulesoft.com/questions/27468/web-service-consumer-response-was-of-unexpected-te.html


Si no puede acceder al registro en el servidor, puede intentar verificar si su solicitud de código y la solicitud de curl son diferentes.

Para hacer eso puedes oler la solicitud http con un sniffer como tcpmon .

Tcpmon funciona como un proxy entre su cliente y el servidor. Intercepta todas las solicitudes e imprime los detalles de cada solicitud y respuesta.


Verifique la URL WSDL.

URL debe darse hasta? Wsdl


intente usar Fiddler como un proxy y compare ambas solicitudes. debe haber una diferencia en los encabezados o en el cuerpo de la solicitud.

Fiddler también es capaz de decodificar TLS.

buena suerte a nadie ...