Getting exception while Consuming https Webservice in mule - https

I'm trying to call a https web service using cxf generated client proxies within Mule. Almost 99% of the time, I get
Caused by: org.apache.commons.httpclient.ProtocolException: Unbuffered entity enclosing request can not be repeated.
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:487)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)*
The app has http inbound end point. The Mule Java transformer tries to call a webservice using https using cxf generated client proxies. I'm running into above said exception.
I've provided screenshot the mule flow [http://i.stack.imgur.com/7X9Wg.jpg]. Much appreciated!!
Mule config xml
<cxf:jaxws-service serviceClass="test.service.https.TestService" doc:name="SOAP" configuration-ref="CXF_Configuration" enableMuleSoapHeaders="false"/>
<custom-transformer class="test.service.https.CallLicenseService" doc:name="Calls HTTPS WS using CXF generated client proxies" encoding="UTF-8" mimeType="text/plain"/>
<logger message="Success" level="INFO" doc:name="Logger"/>
<set-payload value="#['HELLO SUCCESS']" doc:name="Set Payload"/> </flow>
Transformer
URL wsdlURL = null;
String serviceUrl = "TARGET_HTTPS_WSDL"; //This would be the target https URL
try {
wsdlURL = new URL(serviceUrl);
} catch (MalformedURLException e) {
Logger.getLogger(getClass()).info("", e);
}
AuditLogServiceService ss = new AuditLogServiceService(wsdlURL);
AuditLoggingService port = ss.getAuditLoggingServicePort();
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
serviceUrl.substring(0, serviceUrl.length() - 5));
AuditLogServiceRequest request = new AuditLogServiceRequest();
request.setClientId("4");
request.setUserId("101");
request.setEventSubType("1");
request.setEventType("1");
AuditLogMessage msg = new AuditLogMessage();
msg.setMessage("Hello Test");
request.getLogMessages().add(msg);
AuditLogServiceResponse response = port.logEvent(request);
System.out.println(response.getMessage());
return response.getMessage();

First of all if you need to consume a webservice You need to put <cxf:jaxws-client serviceClass instead of cxf:jaxws-client ...next step is you need to use an http outbound endpoint to post to the external webservice ... pls refer the following link :- http://www.mulesoft.org/documentation/display/current/Consuming+Web+Services+with+CXF
One more thing .. you need to use java component instead of <custom-transformer class ..you need to set the payload just before the component ... I mean you need to set the payload before posting it to external webservice

Related

CXF always return url in WSDL with whom it was open for the first time

I create SOAP endpoint with CXF:
#Bean
Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, myEndpoint);
endpoint.publish(path);
return endpoint;
}
And when I open url in my browser like: http://localhost:6666/app/ws?wsdl
I have this URL in returned wsdl: <soap:address location="http://localhost:6666/app/ws"/>
But when I open with external URL: http://172.16.105.134:6666/app/ws?wsdl
does not matter I have this URL in returned wsdl: <soap:address location="http://localhost:6666/app/ws"/>
In general, I always get the url that I first open.
But my task is always to return the url from which it was requested. How can I do it?
The WSDL is cached by org.apache.cxf.wsdl11.WSDLManagerImpl. You can provide your own implementation of org.apache.cxf.wsdl.WSDLManager or use the publishedEndpointUrl property to have it update (see https://github.com/apache/cxf/blob/master/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java#L347).

SseEmitter MessageBodyWriter not found for media type=text/event-stream

I am trying to get server-sent events working with a JavaScript web client and a Spring Boot 1.5.7 application. I get the following error in the server log when the SseEmitter is returned from the REST endpoint when the client initially connects:
o.g.j.m.i.WriterInterceptorExecutor :
MessageBodyWriter not found for media type=text/event-stream,
type=class org.springframework.web.servlet.mvc.method.annotation.SseEmitter,
genericType=class org.springframework.web.servlet.mvc.method.annotation.SseEmitter
The REST method gets called fine and I create and save the emitter for later. When the emitter is returned from the REST method, the above exception gets thrown.
I only get this when using EventSource in the web clients (Chrome and Firefox), not when using curl. I can even enter the URL in the browser and get a response without getting an error on the server.
I'm following pretty much every example I could find.
JavaScript:
const es = new EventSource('https://localhost:8443/sse');
es.onmessage = e => {console.log(e.data);};
es.onerror = e => {console.log('onerror:' + e);};
es.onopen = e => {console.log('onopen');};
Server:
#GET
#Path("/sse")
#Produces({"text/event-stream"})
public SseEmitter sse() {
SseEmitter emitter = new SseEmitter();
... save for later ...
return emitter;
}
Any ideas?
Thank You.

Apache Camel HTTP display request and response

I am using Apache Camel to load data from CSV file to a webservice. Is there anyway I can display request and response. Below is the route configuration..
I split and aggregate 100 items from array to be sent as POST body.
from(fileLocation)
.unmarshal().csv().bean(new CSVConverter(), "process")
.split(body())
.aggregate(constant(true), new GroupedBodyAggregationStrategy())
.completionSize(100)
.completionTimeout(1000)
.marshal().json(JsonLibrary.Jackson)
.setHeader("Authorization", simple(apiKEY))
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.HTTP_URI, simple(apiURL))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.to("https://serivceurl.com/abc");
Please let me know how can I display request and response with above route?
You can use camel log component to log headers; properties and body
ex:
.to("log:DEBUG?showBody=true&showHeaders=true")
.to("https://serivceurl.com/abc");
.to("log:DEBUG?showBody=true&showHeaders=true")
For more options pl refer: https://camel.apache.org/log.html
If you are planning to use CXF to invoke web service, out of the box logging feature can be used as below,
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
If you take a look into the org.apache.camel.component.http.HttpProducer class you'll see that there is some logging implemented.
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing http {} method: {}", method.getName(), method.getURI());
}
int responseCode = executeMethod(method);
LOG.debug("Http responseCode: {}", responseCode);
So if you configure your logging framework (like logback) to the correct LoggingLevel you'll see what the HTTP-Component exactly does.
If you want to log it yourself you can try with the log component or the log dsl like mentioned in the other answer.

Spring 4 websockets dynamic MessageMapping not executed

I'm using Spring 4 websockets on Tomcat 8 and I have the following configuration:
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/notify">
<websocket:sockjs />
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic" />
</websocket:message-broker>
My Spring controller has the following method:
#MessageMapping("/notify/{client}")
public void pushMessage(#DestinationVariable long client, String message) {
System.out.println("Send " + message + " to " + client);
template.convertAndSend("/topic/push/" + client, message);
}
So what I'm trying to do here is that if client 1 wants to send a message to client 2, he uses /app/notify/2. The Spring controller will then push the message to topic /topic/push/2.
I wrote the following code in my client:
var id = 1;
var sock = new SockJS('/project/notify');
var client = Stomp.over(sock);
client.connect({}, function() {
client.subscribe('/topic/push/' + id, function(message) {
console.log(message);
});
});
The connection works perfectly, /project is just the context root of my application.
I also have the following code in my client to send a message:
client.send('/app/notify/' + id, {}, "test");
Both variables (client and id) are accessible, I'm not getting any errors from this part of the code and I can see in my console that the message is actually sent:
>>> SEND
destination:/app/notify/1
content-length:4
test
However, the System.out.println() statement in my controller is never executed, so I assume there is something wrong with my controller mappings or I'm not using the destination endpoints correctly (I don't understand why I have to specify the application prefix here, but not when connecting to that endpoint).
It seems it's unable to map when using a simple String message as payload. When I wrap the message in an object, then it works just fine.
EDIT: As stated in the comments, Spring already comes with a message wrapper called the TextMessage class.

How to Pass parameters in SOAP request in wp7

I have done with the simple SOAP parsing in wp7 with adding reference of SOAP Service in my application.
but i don't understand how to pass parameters in soap request ?
my SOAP Service is this
http://www.manarws.org/ws/manarService.asmx?op=fnGetSubCertificate
with the Certificate id is : 8
i have search about this last 5 days but don't get any way to do this.
Please help me.
After adding the service reference for your project, as I explained in the previous SO post:
You can make the web request like this and pass the parameters.
manarServiceSoapClient client = new manarServiceSoapClient();
client.fnGetSubCertificateCompleted += client_fnGetSubCertificateCompleted;
client.fnGetSubCertificateAsync("8");
And the response is obtained in the Completed handler
void client_fnGetSubCertificateCompleted(object sender, fnGetSubCertificateCompletedEventArgs e)
{
var resp = e.Result;
}
I got response like this
[{"ArTitle":"مركز السمع والكلام ","EnTitle":"Hearing & Speech Center ","PhotosCatsId ...
//Removed the rest

Resources