I'm trying to implement WS-Addressing with Apache CXF 2.7.18. I am able to set some headers like To, Action, etc.. but I want to remove/delete ReplyTo from SOAP request
<Action xmlns="http://www.w3.org/2005/08/addressing">http://...</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:....</MessageID>
<To xmlns="http://www.w3.org/2005/08/addressing">https://....</To>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
Does anybody know how to do it?
I found a solution even if it's little bit dirty but it works for me. I've explicitly set it to "null" (using Cxf and JaxWsProxyFactoryBean).
EndpointReferenceType replyTo = new EndpointReferenceType();
AddressingProperties addrProperties = new AddressingProperties();
AttributedURIType replyToURI = new AttributedURIType();
EndpointReferenceType from = new EndpointReferenceType();
AttributedURIType fromURI = new AttributedURIType();
fromURI.setValue("ms-register");
from.setAddress(fromURI);
addrProperties.setFrom(from);
addrProperties.setFrom(from);
replyToURI.setValue(null);
replyTo.setAddress(replyToURI);
addrProperties.setReplyTo(replyTo);
client.getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES,addrPropertie);
Related
I have been trying to leverage the PrettyPrint feature to display the result of my API that is using Apache Camel. Here is the context. I have this route in my code
// Route Definition for processing Health check request
from("direct:processHealthCheckRequest")
.routeId("health")
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200))
.setBody(constant(healthCheckResponse));
When I'm using Postman to test my API, the display is in pretty mode even though it is not set to true, like so
{
"status": "UP"
}
Now when I'm using the following code to set the PrettyPrint to false, I'm still getting the same result. It looks like the PrettyPrint feature is not working as it is supposed to
// Route Definition for processing Health check request
from("direct:processHealthCheckRequest")
.routeId("health")
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200))
.setBody(constant(healthCheckResponse))
.unmarshal()
.json(JsonLibrary.Jackson, HealthCheckResponse.class, false);
I'm expecting the result to be displayed on one line like here without changing the type from JSON to string.
{"status": "UP"}
Could someone please advice on this?
I've bumped into the same issue always when manually setting the HTTP_RESPONSE_CODE header. I don't know why it technically happens - without it the HTTP response always returns proper JSON for me.
Setting CONTENT_TYPE header to application/json has solved it:
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
The solution that finally worked was to set the following in my application.properties file.
camel.rest.data-format-property.prettyPrint=false
or not to provide that property at all.
Try this:
<removeHeaders id="removeHeaders_http*" pattern="CamelHttp*"/>
<setHeader headerName="Content-type" id="content_setHeader">
<constant>application/x-www-form-urlencoded</constant>
</setHeader>
Same with Java DSL:
.removeHeaders("CamelHttp*")
.setHeader("Content-type", constant("application/x-www-form-urlencoded"))
Hello I am trying use camel ignite messaging component to produce and consume the messages across the ignite cluster.
Please find the sample code :
IgniteMessagingComponent igniteMessagingComponent = IgniteMessagingComponent.fromConfiguration(igniteConfiguration);
igniteMessagingComponent.setCamelContext(camelContext);
igniteMessagingComponent.setIgniteConfiguration(igniteConfiguration);
igniteMessagingComponent.setIgnite(ignite);
igniteMessagingComponent.setIgniteConfiguration(igniteConfiguration);
Endpoint enp = igniteMessagingComponent.createEndpoint("ignite-messaging:topic?Topic=testtopicname&SendMode=ORDERED&Timeout=30000");
producerTemplate.sendBody(enp,"Test");
I am getting below error : java.lang.IllegalArgumentException: CamelContext must be specified on: Message[]
Please suggest what I have missed.
Got resolved it was configuration issue the way I have started my camel ignite-messaging subscriber's endpoint. After setting CamelContext explicitly to the endpoint It work successfully.
Sample code :
**IgniteMessagingComponent igniteMessagingComponent=
IgniteMessagingComponent.fromConfiguration(igniteConfiguration);
igniteMessagingComponent.setIgnite(ignite);
Map<String,Object> parameters = new HashMap();
IgniteMessagingEndpoint psenp = new IgniteMessagingEndpoint("ignite-messaging:", "topic1", parameters,igniteMessagingComponent);
psenp.setCamelContext(camelContext);
from(psenp).process(processor).end();**
Ok.
I'm writing a POC (Proof of Concept) Logic App.
The logic app has a Service Bus connector wired to a queue.
I'm using peek/complete/abandon.
I wrote a client app (dotnet c# console app) that writes messages to the queue (nothing really to do with the logic app part).
I'm setting the Content Type to "text/plain".
string payLoad = #"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
QueueClient queueClient = /* not seen here */;
brokeredMsg = new BrokeredMessage(payLoad) { ContentType = System.Net.Mime.MediaTypeNames.Text.Plain };
queueClient.Send(brokeredMsg);
Now I use Service Bus Explorer (4.0.104), and I see the message in the queue
The issue is that when my Logic App runs, its not seeing plain-text/json.
You can see it picked up the content-type.
But it garbly gooks the content itself.
Is there a way to get raw-text with this trigger?
Note, the documentation says:
let's look at the two Content-Types that don't require conversion or
casting that you can use in a logic app: application/json and
text/plain.
from :
https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-content-type
https://learn.microsoft.com/en-us/azure/connectors/connectors-create-api-servicebus
My C# console app packages.config (nothing to do with Logic Apps, but including for completeness)
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
<package id="WindowsAzure.ServiceBus" version="2.1.4.0" targetFramework="net45" />
</packages>
APPEND:
I needed to do two thing to get it to work
One:
I had to change the "sender" code slightly.
QueueClient queueClient = /* not seen here */;
string ct = System.Net.Mime.MediaTypeNames.Text.Plain;
/* see https://social.msdn.microsoft.com/Forums/en-US/8fbf2391-8440-46db-bb47-648daccf46fd/servicebus-output-json-is-being-wrapped-in-a-xml-header-in-logic-app?forum=azurelogicapps and https://abhishekrlal.com/2012/03/30/formatting-the-content-for-service-bus-messages/ */
string payLoad = #"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
brokeredMsg = new BrokeredMessage(new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(Convert.ToString(payLoad))), true) { ContentType = ct };
queueClient.Send(brokeredMsg);
And I used the hint Derek Li gave me.
I've accepted his answer as the-answer, but PLEASE NOTE I had to do slightly more than he suggested. The code above has the urls for the reason I changed the sender code.
In a nutshell, the constructor for BrokeredMessage that I was using was choosing a specific serializer for me.
BrokeredMessage(Object)
Initializes a new instance of the BrokeredMessage class from a given object by
using DataContractSerializer with a binary XmlDictionaryWriter.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.brokeredmessage.-ctor?view=azureservicebus-4.1.1#Microsoft_ServiceBus_Messaging_BrokeredMessage__ctor
and after I figured out the answer, I found this SOF answer:
Azure Service Bus Serialization Type
You can use expression #base64ToString(triggerBody()?['ContentData'])" to convert it to string.
I am not getting the SoapHeader tags in the Soap message in the cxf service invoked. My current code is as below:
I have defined a cxf:cxfEndpoint for the service:
<cxf:cxfEndpoint id="testService" address="${testserviceurl}"
serviceClass="com.test.service.class" wsdlURL="test.wsdl"
endpointName="ns:test" serviceName="ns:TestService"
xmlns:ns="target.name.space.of.the.service">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD" />
</cxf:properties>
</cxf:cxfEndpoint>
And then before invoking my cxf endpoint, I have set the SoapHeader as:
CxfPayload<SoapHeader> payload = exchange.getIn().getBody(
CxfPayload.class);
List<SoapHeader> headers = payload.getHeaders();
SoapHeader header = new SoapHeader(new QName("HeaderName"), "Test");
headers.add(header);
I have also tried the approach:
List<SoapHeader> soapHeaders = CastUtils.cast((List<?>) exchange
.getIn().getHeader(Header.HEADER_LIST));
if (soapHeaders == null) {
// we just create a new soap headers in case the header is null
soapHeaders = new ArrayList<SoapHeader>();
}
SoapHeader header = new SoapHeader(new QName("HeaderName"),
"Test");
header.setDirection(Direction.DIRECTION_OUT);
soapHeaders.add(header);
Can anyone please help on what is wrong with this?
When you make any synchronous request through cxf client. It uses jdk's Http connection client to communicate over http.
As per this jira defect jdk does't allow to set header.
If you want to set headers you can do it by setting VM parameter
sun.net.http.allowRestrictedHeaders=true
If you use cxf in async mode it uses apache's HttpAsyncClient. This allows you to set the request headers.
Hope this helps.
Is there any option in wss4j or cxf that controls whether <expires> element from ws-security is included in SOAP header.
What I want to achieve is that SOAP header contains only <created> element, e.g.
<wsu:Timestamp wsu:Id="Timestamp-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2011-12-07T14:39:03Z</wsu:Created>
</wsu:Timestamp>
I'm using wss4j 1.5.10 and cxf 2.3.x
Note that xsd schema for timestamp has
<xsd:element ref="wsu:Expires" minOccurs="0"/>
I needed the same thing and wasn't able to find an answer anywhere.
At the end I studied the source and did it extending the WSS4JOutInterceptor and rewriting the method decodeTimeToLive this way:
#Override
public int decodeTimeToLive(RequestData reqData) {
return 0;
}
Maybe not beautiful, but it worked for me.