How get payload inside webservice class mule - soap

I need payload value inside ShipmentProcessImpl class or MuleEventContext object.
<flow name="soaptest_rFlow1" doc:name="soaptest_rFlow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="${host}" port="${port}" doc:name="HTTP" path="${deliveryUpdatePath}" />
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<logger category="ProTSP Listener Logger" level="INFO" message="#[payload]"
doc:name="Logger" />
<cxf:jaxws-service serviceClass="org.tempuri.ShipmentProcess"
doc:name="CXF" />
<component class="org.tempuri.ShipmentProcessImpl" doc:name="Java" />
</flow>
I am able to get MuleContext class object using #Lookup annotation but I am unable to get payload using mulecontext object.
Can any other way to get payload inside webservice class.

MuleContext is the active context of the running Mule application, it is unrelated to the current MuleEvent being processed by the flow.
You need to get a hold of MuleEventContext via a static call to org.mule.RequestContext.getEventContext().
Yes, it is deprecated, but it still works and, to be frank, I don't know of an alternative for service class implementations...

Related

How to pass and validate the signInEmail claim during External IDP login using Azure B2C custom policy?

This question is related to this one.
What we'd like to do is: at the moment the user clicks the button like Facebook OR Microsoft account OR Corporate AD in the Sign in page, call a validation technical profile to validate the email address the user is using to sign in.
I tried adding an OrchestrationStep like this:
<OrchestrationStep Order="4"
Type="ClaimsExchange">
<Preconditions>
<Precondition Type="ClaimEquals"
ExecuteActionsIf="false">
<Value>idp</Value>
<Value>CorporateAD</Value>
<Action>SkipThisOrchestrationStep</Action>
</Precondition>
</Preconditions>
<ClaimsExchanges>
<ClaimsExchange Id="FetchMoreClaimsExchange"
TechnicalProfileReferenceId="REST-ValidateSignInEmail" />
</ClaimsExchanges>
</OrchestrationStep>
This is actually calling REST-ValidateSignInEmail because I see an error returned in the URL like this:
https://mywebsite.azurewebsites.net/#error=server_error&error_description=AADB2C%3a++is+disabled.%0d%0aCorrelation+ID%3a+bce3fd82-1111-4f17-ad99-ef7770ed8dda%0d%0aTimestamp%3a+2019-11-08+20%3a34%3a51Z%0d%0a&state=7b7c70e7-7a77-77d7-7d7e-7dd0e7b707e7
The message is+disabled is coming from the REST API I put together but this obviously tells me that the email\signInEmail claim it expects as a parameter is not being sent\passed.
This is the Technical Profile:
<TechnicalProfile Id="REST-ValidateSignInEmail">
<DisplayName>Validate Email</DisplayName>
<Protocol Name="Proprietary"
Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ServiceUrl">{Settings:AzureAppServiceUrl}/api/B2C/ValidateSignInEmail</Item>
<Item Key="AuthenticationType">None</Item>
<Item Key="SendClaimsIn">Body</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="signInName"
PartnerClaimType="UserEmail" />
</InputClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>
Can you shed some light on how to approach this?
Generally after I post the question I keep fiddling with the code.
Got it working like this:
<TechnicalProfile Id="REST-ValidateSignInEmail">
<DisplayName>Validate Email</DisplayName>
<Protocol Name="Proprietary"
Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ServiceUrl">{Settings:AzureAppServiceUrl}/api/B2C/ValidateSignInEmail</Item>
<Item Key="AuthenticationType">None</Item>
<Item Key="SendClaimsIn">Body</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="signInName"
PartnerClaimType="UserEmail" />
</InputClaims>
<InputClaim ClaimTypeReferenceId="email"
PartnerClaimType="UserEmail" />
</InputClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>
Note that I added a new InputClaim with ClaimTypeReferenceId="email". email is the claim value that is passed when using an external IDP.
This sample policy showed me that I could add the OrchestrationStep right before the JwtIssuer one. We can also have it without any preconditions like this:
<OrchestrationStep Order="7"
Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="REST-ValidateSignInEmail"
TechnicalProfileReferenceId="REST-ValidateSignInEmail" />
</ClaimsExchanges>
</OrchestrationStep>
Doing so it'll get called for all IDPs.
Azure Active Directory B2C: Custom CIAM User Journeys

Does ColdFusion support REST API URIs with a dynamic token in the middle of the URI?

I've been playing with ColdFusion 11's REST API support and am wondering if it's possible to have it support a URI with a dynamic token in the middle of the URI instead of only at the end. That is, it very easily supports URIs like:
/rest/users/12345
where the 12345 is dynamic (in this case, the user's userID). But I haven't been able to find a way (without a tremendous amount of URI hacking) to support URIs like:
/rest/users/12345/emailAddresses
So, is it possible to do this in ColdFusion (11 or 2016)? If not, is it supported in Taffy (I didn't see where it is but I could be wrong)?
TIA
It's been a while and I wanted to provide the answer in case anyone else has this same question...
ColdFusion, when defining a CFC for a REST endpoint, allows you to specify wildcards/variable names in the restpath attribute to both the <cfcomponent> and <cffunction> tags. You would then define <cfargument> tags for each one of these variables so that you can access them within your function. For example:
<cfcomponent rest="true" restpath="/users/{userId}/pets" ... >
<cffunction name="getPets" access="remote" httpMethod="GET">
<cfargument name="userId" type="numeric" required="true" restargsource="Path" />
<!--- Called with a path like /users/123/pets/ --->
<!--- do stuff using the arguments.userId (123) variables --->
</cffunction>
<cffunction name="getPet" access="remote" httpMethod="GET" restpath="{petId}">
<cfargument name="userId" type="numeric" required="true" restargsource="Path" />
<cfargument name="petId" type="numeric" required="true" restargsource="Path" />
<!--- Called with a path like /users/123/pets/456/ --->
<!--- do stuff using the arguments.userId (123) and/or arguments.petId (456) variables --->
</cffunction>
</cfcomponent>
The keys here are using the restpath attribute with the variable defined as a variable name in curly braces and then defining those variables as arguments to the function with a restargsource attribute set to "Path".
I hope this helps.

cxf jax-ws no complexType for subclasses while using generic method

I am not quite familiar with CXF configuration. Here I am encountering a situation that a object (subclass) is going to be used for client but it does not declare in Endpoint.
For example, there is a super class "SuperClass" and two subclasses "SubClassA" and "SubClassB". The following method is declared in Endpoint:
public <T extends SuperClass> T search(Criteria criteria, ClassType type);
Therefore, those subclasses do not appear in Endpoint and it causes that their complexType is missing in wsdl. Error saying no read type is prompted when the object of subclass is called from client.
org.apache.cxf.interceptor.Fault:
Could not determine how to read type: {http://model.fmchan.com}SubClassA
So here I would like to seek for a solution to add those subclasses into wsdl so as to be called properly on client side.
If it is properly configured, the following should be shown on wsdl:
<xsd:complexType name="SubClassA">
<xsd:sequence>
<xsd:element minOccurs="0" name="date" type="xsd:dateTime"/>
</xsd:sequence>
</xsd:complexType>
Enclosed is the configuration on server side for your reference.
<import resource="classpath:META-INF/cxf/cxf.xml" />
<bean id="aegisContext" class="org.apache.cxf.aegis.AegisContext"
p:writeXsiTypes="true" scope="prototype" />
<bean id="aegisBean" p:aegisContext-ref="aegisContext"
class="org.apache.cxf.aegis.databinding.AegisDatabinding"
scope="prototype" />
<bean id="genericServiceImpl" class="com.fmchan.service.SomeEndpointImpl"/>
<jaxws:endpoint implementor="#genericServiceImpl"
address="${service.address}">
<jaxws:serviceFactory>
<ref bean="jaxws-and-aegis-service-factory" />
</jaxws:serviceFactory>
</jaxws:endpoint>
<bean id="jaxws-and-aegis-service-factory"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
<property name="dataBinding">
<bean class="org.apache.cxf.aegis.databinding.AegisDatabinding" />
</property>
</bean>
Thank you for any help in advance.
The simplest solution I come up with is to create a dummy method including those subclasses A and B as parameters for endpoint. It probably isn't the best solution and I still seek for better one.

Adding a VersionOne expression using the REST API

I am trying to create a new 'Expression' in VersionOne - effectively adding a new 'comment' to a conversation.
In theory, the rest-1.v1/Data API should allow this, but I can't figure out how to do it - there is precious little documentation about using the API (using POST) to create objects.
FWIW, here's what I'm doing (after successfully accessing the server with valid credentials):
URL:
/rest-1.v1/Data/Expression
XML:
<Asset href="<Server Base URI>/rest-1.v1/Data/Expression">
<Attribute name="AssetType">Expression</Attribute>
<Relation name="InReplyTo" />
<Attribute name="AuthoredAt">2014-05-28T21:48:37.940</Attribute>
<Attribute name="Content">A new comment</Attribute>
<Attribute name="AssetState">64</Attribute>
<Relation name="Author">
<Asset href="<Server Base URI>/rest-1.v1/Data/Member/2015" idref="Member:2015" />
</Relation>
<Relation name="BelongsTo">
<Asset href="<Server Base URI>/rest-1.v1/Data/Conversation/2018" idref="Conversation:2018" />
</Relation>
<Attribute name="Author.Name">user#example.com</Attribute>
<Attribute name="Author.Nickname">User Name</Attribute>
<Relation name="Mentions">
<Asset href="<Server Base URI>/rest-1.v1/Data/Story/2017" idref="Story:2017" />
</Relation>
</Asset>
I keep getting a 400 Bad Request the following error:
<Error href="<Server Base URI>/rest-1.v1/Data/Expression">
<Message>Violation'Required'AttributeDefinition'Content'Expression</Message>
<Exception class="VersionOne.DataException">
<Message>Violation'Required'AttributeDefinition'Content'Expression</Message>
</Exception>
</Error>
I assume I'm missing something obvious - does anyone know what it is?
IF you examine the metadata for a VersionOne Expression, you will see 3 required fields (Author,AuthoredAt,Content). Logically this makes sense to be able to just create a single, zombie expression but I witnessed otherwise. This might be a mistake in the stylesheet or just my browser because it seems POSTing with only those three will return a 400 error. To get a guaranteed working payload, include the relation "inReplyTo" and that is all that you will need to create an expression within the context of a particular Conversation.
Given that you are responding to an existing expression (comment) This should work fine.
POST to rest-1.v1/Data/Expression
<Asset>
<Relation name="Author" act="set">
<Asset idref="Member:2015" />
</Relation>
<Attribute name="AuthoredAt">2014-05-02T21:48:37.940</Attribute>
<Attribute name="Content" act="set">A new comment</Attribute>
<Relation name="InReplyTo" act="set">
<Asset idref="Expression:xxxxx" />
</Relation>
</Asset>
You don't need Asset state or mentions or belongs to. AssetState is readonly, and BelongsTo is filled in automatically after your Expression is created. It inherits a reference to the containing Conversation from the Expression object entered in the InReplyTo field and the Mentions relation is optional.
FYI,
I believe that you didn't see the Legend on the right hand side of a the meta query output as seen in a browser. Real quick here, when you do a meta query, the items with * are required to Post, Bold items are Read/Write optional, the italicized items are readonly, and the bold items towards the bottom that are appended with ": operation" is the operation that you are allow to do against that particular asset.

Symfony2: Scope Widening Exception

I want to inject a form and formHandler service into my controller.
<services>
<service id="acme_core.image_controller" class="Acme\CoreBundle\Controller\ImageController">
<argument type="service" id="session" />
<argument type="service" id="acme_core.image.form" />
<argument type="service" id="acme_core.image.form.handler" />
<argument type="service" id="acme_core.image_manager.default" />
</service>
</services>
Scope Widening Injection detected: The definition "acme_core.image_controller" references the service "acme_core.image.form.handler" which belongs to a narrower scope. Generally, it is safer to either move "acme_core.image_controller" to scope "request" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "acme_core.image.form.handler" each time it is needed. In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.
What does this mean concret?
What should I add tom my image_controller.xml?
Best Regards
You have to add scope="request" in your service tag e.g
<service id="acme_core.image_controller" class="Acme\CoreBundle\Controller\ImageController" scope="request">
For more info check this cookbook entry.