Client and server do not have sync time so that the soap server's security return not authorized responses.
I will get the server's current time and I will use that time while sending the soap request(On security header, username token created vs).
How to set timestamp manually on spring-ws.
I am using spring ws.client.core, ws.soap.security.wss4j2 (Wss4jSecurityInterceptor and WebServiceTemplate).
WS-Usernametoken is sent for security(nonce, username, password, created (I guess that created is the problem. I should set that.)
The server is onvif device.
You could do the following( source here here)
<bean class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
<property name="validationActions" value="Timestamp"/>
<property name="timestampStrict" value="true"/>
<property name="timeToLive" value="10"/>
In Short, you can do the following
Call the Create() class method of %SOAP.Security.Timestamp
set ts=##class(%SOAP.Security.Timestamp).Create()
Call the AddSecurityElement() method of the SecurityOut property of your web client or web service
do client.SecurityOut.AddSecurityElement(ts)e
Send the SOAP message
Related
I am investigating Citrus Framework in order to use it in test automation of my project. I want to run two web services, lets name it:
http://localhost:port/service1
http://localhosr:port/sercice2
and then call my SUT (system under test). SUT will synchronously call both of above mock services (service1 & service2) and return the answer.
I've managed to do it, BUT on different ports:
<citrus-ws:server id="helloMockService1"
port="${server.port1}"
servlet-mapping-path="/service1"
auto-start="true"
timeout="10000"
endpoint-adapter="genericResponseAdapter1" />
<citrus-ws:server id="helloMockService2"
port="${server.port2}"
servlet-mapping-path="/service2"
auto-start="true"
timeout="10000" />
I need it on the same port. I've also tried to write my custom DispatchingEndpointAdapter and somehow extract the context path from the request Message, but didn't succeed..
<citrus:dispatching-endpoint-adapter id="dispatchingEndpointAdapter"
mapping-key-extractor="mappingKeyExtractor"
mapping-strategy="mappingStrategy"/>
<bean id="mappingStrategy"
class="com.consol.citrus.endpoint.adapter.mapping.SimpleMappingStrategy">
<property name="adapterMappings">
<map>
<entry key="service1" value-ref="genericResponseAdapter1"/>
<entry key="service2" value-ref="genericResponseAdapter2"/>
</map>
</property>
</bean>
<bean id="mappingKeyExtractor"
class="com.mycompany.citrus.CustomExtractor">
</bean>
I cant find URL in request parameter of type com.citrus.message.Message..
package com.mycompany.citrus;
import com.consol.citrus.endpoint.adapter.mapping.MappingKeyExtractor;
import com.consol.citrus.message.Message;
public class CustomExtractor implements MappingKeyExtractor{
#Override
public String extractMappingKey(Message request) {
// ther is no URL information in Message object!!!!!!!!!!!!
return "service1";
}
}
How do you run two mock services in Citrus Framework on the same port? I want to differentiate them by URL, not a payload itself... (by peyload it would be easy using above custom MappingKeyExtractor, since Message object contains payload)
Please help! I cant belive that Citrus Framework could be so badly designed that missed such a basic test requirement.
You are almost there. Remove the servlet-mapping-path setting and use this mapping key extractor:
<bean id="mappingKeyExtractor" class="com.consol.citrus.endpoint.adapter.mapping.HeaderMappingKeyExtractor">
<property name="headerName" value="#{T(com.consol.citrus.http.message.HttpMessageHeaders).HTTP_REQUEST_URI}"/>
</bean>
That will map incoming requests based on the request path. So you can add mappings with the keys /service1 and /service2 in the simple mapping strategy.
I'm using simple Spring JmsTemplate to send messages onto a MQ.
<beans:bean id="myJMSTemplate" class="org.springframework.jms.core.JmsTemplate">
<beans:property name="connectionFactory">
<beans:ref bean="cachedConnectionFactory" />
</beans:property>
<beans:property name="pubSubDomain">
<beans:value>false</beans:value>
</beans:property>
<beans:property name="receiveTimeout">
<beans:value>1000</beans:value>
</beans:property>
</beans:bean>
<int-jms:outbound-channel-adapter id="sendMessageToAvengers" channel="antEventChannel" jms-template="myJMSTemplate" destination-name='com.marvel.avengers.antMan'/>
This works fine, however, My client application isn't able to process the message as the message format is in 'MQHRF2' by default.
How can I alter my MQ headers so as to send explicitly MQSTR format.
Thanks in advance.
You must set the property targetcllient=1 to send the msg as MQSTR.
To do this in sending part of java code, change the queue name as below
String senderQ = "queue:///MYQUEUENAME?targetClient=1";
jmsTemplate.send(senderQ, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage message = session.createTextMessage(text);
message.setJMSReplyTo(replyToQ);
return message;
}
});
Alternatively you can try setting this in jmstemplate bean
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<!-- set format to MQSTR with "targetClient=1" parameter -->
<property name="defaultDestinationName" value="queue:///default?targetClient=1" />
<property name="connectionFactory" ref="mqConnectionFactory" />
</bean>
The IBM MQ JMS interface has a property called TARGCLIENT which when set to the value MQ will not add the MQRFH2 header. I don't know whether the Spring interface allows it to be used.
Alternatively, the queue definition on the queue manager can be configured to remove the header for those applications that can't process it. This is a better way to remove the MQRFH2 header as it removes it at get time instead of at put time, thus meaning that if an application is able to process the MQRFH2 header, it is still there, but for those applications that cannot process it, it is removed for them.
To make the queue operate in this way, issue the following MQSC command on your queue manager:
ALTER QLOCAL(q-name) PROPCTL(NONE)
Additional Reading
Properties of IBM MQ classes for JMS objects > TARGCLIENT
PROPCTL queue options
DEFINE queues - see PROPCTL attribute
We are using spring-security 3.2.3 version to authenticate and access OpenLdap in our application. I am having issues access the PPolicy attributes and errors via Spring context. It is PasswordPolicyAwareContext.
<bean id="contextSource class="org.springframework.security.ldap.ppolicy.PasswordPolicyAwareContextSource">
<constructor-arg value="${ldap.url}" />
<property name="password" value="${ldap.password}" />
<property name="userDn" value="${ldap.userDN}" />
</bean>
<bean id="springSecurityLdapTemplate" class="org.springframework.security.ldap.SpringSecurityLdapTemplate">
<constructor-arg ref="contextSource"/>
</bean>
<bean id="userDetailsContextMapper" class="LdapUserProfilePopulator"/>
In my Service class, I authenticate using the :
AuthenticationManager.authenticate(new UsernamePasswordAuthenticationToken(userid, password));
When there is an error e.g.Password_Expired, Account_Locked it throws exceptions.
In order to check if the Account is locked etc, I check if the exception is an instance of org.springframework.security.authentication.LockedException etc
Question:
How do we check the PPolicy errors elegantly and use PasswordPolicyErrorStatus?
Also, how do we access the OpenLdap operational attributes including pwdMaxAge, pwdExpireWarning? I have extended the - LdapUserDetailsMapper to map the LdapContext attributes to my User object but I am not able to get a handle on the operational attributes in ldap.
Truly appreciate any feedback/pointers in this regard!
Thanks!
I did the following to handle the specific ldap errors:
http://forum.spring.io/forum/spring-projects/security/115236-why-passwordpolicyawarecontextsource-doesn-t-throw-exception-for-expired-passwords
i.e extended PasswordPolicyAwareContextSource.java and handled the exception.
I am posting so in case anyone else is looking for similar issue can benefit.
If anyone else has better way of handling please post it.
Thanks!
How can we access a wsdl of a soap project whose war is deployed on the same server, by a Rest based project using spring maven. Basically , I have to access an API that is exposed via wsdl and I have to access this API, the response than needs to be returned as json from a rest POST method. It will be like a REST post method, accepting the inputs and invoking this API (from wsdl) and manipulating the response as JSON,
I have to jump into the WebServices and Spring framework, without through knowledge. So, any help or directions to learn these things fast would be appreciated.
You will need to do the following:
Create the client code from the WSDL
This can be acomplished in Spring with the following technique:Spring - Consuming a SOAP service. It will generate the Java classes that you will need to call the service from your REST API code. In this case that you are calling another service in the same server, all you have to do it set the endpoint url to your server.
Create your REST API
You can use Spring MVC to design your REST API and call the SOAP service.You will need to develop a Controller class with the different endpoints and the proper request and response objects. Spring MVC will automatically convert those request and response objects to JSON using the Jackson framework. Use this guide: Building a RESTful Web Service
That is a generic way of consuming a SOAP service from a Java REST API. If the goal is to simply expose the SOAP service as a REST service then you can just return the response object that was generated from the WSDL. If it is an option, I would seriosly consider refactoring the SOAP service code and expose the it as a REST API.
Note: In the good old days consuming a SOAP was acomplished by using JAX-WS directly and exposing JSON objects was done through Jackson.
Hi I have used the following approach to implement the above requirement:
http://myshittycode.com/2013/10/01/using-spring-web-services-and-jaxb-to-invoke-web-service-based-on-wsdl/
1. changed the pom to add spring-ws dependency and plugin.
2. build the classes and it generated the classes from the wsdl.
3. changed the application xml :
<!--Generating web sources-->
<!-- Define the SOAP version used by the WSDL -->
<bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/>
</property>
</bean>
<!-- The location of the generated Java files -->
<oxm:jaxb2-marshaller id="marshaller" contextPath="com.pb.pims.generatedsources"/>
<!-- Configure Spring Web Services -->
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="soapMessageFactory"/>
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
<property name="defaultUri" value="http://localhost/HSWS/services/HSService?wsdl"/>
</bean>
4. Created the Service class;
#Service
public class HSService {
#Autowired
private WebServiceTemplate webServiceTemplate;
public List<HSChild> getHSChildren(String hscode, String country,String limit) {
GetHSChildren getHSChildren= new ObjectFactory().createGetHSChildren();
getHSChildren.setCountry(country);
getHSChildren.setHsCode(hscode);
getHSChildren.setLimit(Integer.parseInt(limit));
GetHSChildrenResponse response = (GetHSChildrenResponse) webServiceTemplate.marshalSendAndReceive(getHSChildren);
return response.getGetHSChildrenReturn();
}
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HSService hsService = context.getBean(HSService.class);
}
}
So, I am able to call this aPI from the wsdl via my client. But I am always getting the values of the getGetHSChildrenReturn. hscode and getGetHSChildrenReturn.description as null.
Please find below the getGetHSChildrenReturn.class generated in the Step1 :
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"getHSChildrenReturn"
})
#XmlRootElement(name = "getHSChildrenResponse")
public class GetHSChildrenResponse {
#XmlElement(required = true)
protected List<HSChild> getHSChildrenReturn;
public List<HSChild> getGetHSChildrenReturn() {
if (getHSChildrenReturn == null) {
getHSChildrenReturn = new ArrayList<HSChild>();
}
return this.getHSChildrenReturn;
}
Also, I verified in the service code , which we are invoking via this wsdl by putting logging, that the correct request is going and it is returning the expected response at service end. But while coming to the client, the values are set as null.
Please help, what's wrong here in the client side.
Thanks in advance.
Does any method of camel's consumer exist which is able to process >20 http requests per second? I try to work with restlet and jetty components, but failed with both.
For example, I set this config for a jetty component:
<bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent">
<property name="httpClientMinThreads" value="10"/>
<property name="httpClientMaxThreads" value="254" />
<property name="minThreads" value="10"/>
<property name="maxThreads" value="254" />
</bean>
and hoped that everything will be OK, but nothing.
My route config:
from("jetty:http://0.0.0.0:8888" + linkRequest+"?matchOnUriPrefix=true")
.onException(Exception.class)
.log(LoggingLevel.ERROR, "${exception.stacktrace}")
.useOriginalMessage()
.handled(true)
.setBody(simple("Something went wrong"))
.end()
.process(new MyFirstProcessor())//here I get httpHeaders,create entity A
.to("jpa:RequestEntity")
.process(new MySecondProcessor())//set some filed in entity A and send it
.to("bean:service?method=process")//here I recieve entity A and create entity B
.to("jpa:ResponseEntity")
.process(new MyThirdProcessor())//here response is created;
Please explain to me how I can configurate parameters of camel (I glance at the threading model configuration), jetty-component or restlet component - so that my router can handle all incoming requests.
UPDATE
These problems were caused by the settings of the connection pool to the database.