I'm writing a WebScript in Alfresco using JS controller and I want to make a HTTP request to the local HTTP resource. This resource is a Java-based app and gives me its own REST API.
My WebScript is not a Share Component: so I don't have a remote object to call another webscript.
How can I make a HTTP request to the local resource (something like '/sdo/documents/getName?type=fl') from a WebScript?
EDIT: Alfresco is overriding the Spring Surf webscripts.container bean removing the remote definition (in web-scripts-application-context.xml of remote-api):
<bean id="webscripts.container" class="org.alfresco.repo.web.scripts.RepositoryContainer" parent="webscripts.abstractcontainer">
<property name="name"><value>Repository</value></property>
<property name="scriptObjects">
<map merge="true">
<entry key="paging">
<ref bean="webscripts.js.paging"/>
</entry>
</map>
<!-- ..... -->
</bean>
I suggest you include it again as a custom Javascript API root level object.
The remote root object comes from the Spring Surf framework, meaning you have it regardless of being developing your Web Scripts against the Alfresco repository or Share. As a proof, here's the source for a Web Script available in the public Alfresco CMIS server (-> Alfresco repository instance, admin/admin if you are asked to login):
var serviceUrl = (args.service === null) ? "/api/repository" : args.service;
var conn = remote.connect("alfresco");
var result = conn.get(stringUtils.urlEncodeComponent(serviceUrl));
var service = atom.toService(result.response);
var workspace = service.workspaces.get(0);
model.repo = workspace.getExtension(atom.names.cmisra_repositoryInfo);
The following snippet is taken from spring-surf-application-context.xml as found inside spring-webscripts-1.0.0.CI-SNAPSHOT.jar of Alfresco 3.4.0, which is where the remote root object gets its definition:
<bean id="webscripts.container" parent="webscripts.abstractcontainer" class="org.springframework.extensions.webscripts.LocalWebScriptRuntimeContainer">
<property name="name"><value>Spring Surf Container</value></property>
<property name="registry" ref="webscripts.registry" />
<property name="searchPath" ref="webframework.webscripts.searchpath" />
<property name="templateProcessorRegistry" ref="webframework.webscripts.registry.templateprocessor" />
<property name="scriptProcessorRegistry" ref="webframework.webscripts.registry.scriptprocessor" />
<property name="scriptParameterFactoryRegistry" ref="webscripts.web.scriptparameterfactoryregistry" />
<property name="configService" ref="web.config" />
<property name="scriptObjects">
<map merge="true">
<entry key="remote" value-ref="webframework.webscripts.scriptremote" />
</map>
</property>
<property name="processorModelHelper" ref="processor.model.helper"/>
<property name="extensibilityModuleHandler" ref="webscripts.extensibility.handler"/>
</bean>
<bean id="webframework.webscripts.scriptremote" class="org.springframework.extensions.webscripts.ScriptRemote">
<property name="configService" ref="web.config"/>
<property name="connectorProvider" ref="webframework.connector.provider"/>
</bean>
Related
This is an existing monolith app and fix is required without a drastic change of the setup.
Project setup:
project 1 (config) - > where all mq-xml files are present (e.g - ibm_mq_config.xml)
e.g - content of dev_bm_mq.xml
${hname}
${port}
${qmgr}
1
<!-- JMS Queue Connection Factory -->
<bean id="jmsQueueIdsConnectionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory">
<ref bean="mqIdsConnectionFactory" />
</property>
</bean>
<!-- JMS Destination Resolver -->
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.DynamicDestinationResolver">
</bean>
<!-- JMS Queue Template -->
<bean id="jmsQueueIdsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="jmsQueueIdsConnectionFactory" />
</property>
<property name="defaultDestinationName">
<value>${myQUEUE}</value>
</property>
<property name="pubSubDomain">
<value>false</value>
</property>
<property name="receiveTimeout">
<value>20000</value>
</property>
</bean>
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="destinationName">
<value>${myQUEUE}</value>
</property>
<property name="messageListener" ref="simpleMessageListener" />
<property name="concurrentConsumers" value="2" />
<property name="maxConcurrentConsumers" value="3" />
<property name="idleTaskExecutionLimit" value="4" />
<property name="maxMessagesPerTask" value="4" />
<property name="receiveTimeout" value="5000" />
<property name="recoveryInterval" value="5000" />
<property name="sessionTransacted" value="true" />
</bean>
****Project B (App)****
loads the spring xml from project config as below:
WebContent/WEB-INF/spring/sprint-context.xm
<import resource="classpath*:com/my/package/${config.env}-${config-broker}.mq.xml"
public class TestMessageListener implements MessageListener {
public void onMessage(Message message) {
//process the message
}
}
When the server starts up, it's able to start the server and setup the listener without any issues.
Issue with the above setup : When we scale the app horizontally (add few nodes ), it's gives max channel issues which I am trying to solve.
Requirement:
based on a DB table I want to turn off the mq listener on few nodes on the fly. or when I horizontally scale the app.
e.g -
Table:mq-config
|host|broker|flag
-----------------------------
|qa5|ibm|false
|qa2|ibm|true
So, I want mq listener on qa5 not to start and qa2 to start and listen to the Queue. Also, I want to stop/start listener on the fly (just by updating the DB)
Question - Any thoughts on how do I achieve the above use case without re-writing the entire setup.
Inject the listener container (e.g. #Autowired).
Then
jmsContainer.stop();
jmsContainer.shutdown();
...
jmsContainer.initialize();
jmsContainer.start();
You can also set the autoStartup property to false to prevent the container from starting during application initialization (but don't call initialize() before the first start() - only after calling shutdown().
SpringMVC can't request html
I define a
#RequestMapping(value = {"/","/index"}).
I can't request index.html:
try adding "/index.html" to the #RequestMapping.
If you are trying to display the 001.html by going to /index, then make sure your 001.html is in the folder your view resolver is looking at
The value of #RequestMapping is not your view name, it's url path.
View name is defined in return.Try return index.html.
If you defined this in spring-servlet.xml:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/" />
<property name="suffix" value=".html" />
</bean>
You need return index.
I am using spring integration 4.1.2 (ws and core) trying to use HTTPClient (apache) on transport.
I thought that following some reading and configuring the messageSender and messageFactory Spring would use the settings configured on XML (application context) but the configuration is not working as expected.
My xml to configure the HttpClient follows:
<bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig" factory-method="custom">
<property name="socketTimeout" value="${saog.connection.timeout}" />
<property name="connectTimeout" value="${saog.connection.timeout}" />
</bean>
<bean id="requestConfig" factory-bean="requestConfigBuilder" factory-method="build" />
<bean id="httpHostProxy" class="org.apache.http.HttpHost">
<constructor-arg index="0" value="10.1.6.91" ></constructor-arg>
<constructor-arg index="1" value="80"></constructor-arg>
</bean>
<!-- <property name="defaultHeaders" ref="defaultHeaders"></property> -->
<bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder" factory-method="create">
<property name="defaultRequestConfig" ref="requestConfig" />
<property name="proxy" ref="httpHostProxy"></property>
</bean>
<bean id="httpClient" factory-bean="httpClientBuilder" factory-method="build" />
<bean id="httpComponentsClientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<constructor-arg ref="httpClient"/>
</bean>
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
</bean>
<bean id="defaultMessageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
<constructor-arg ref="httpClient"/>
</bean>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory"/>
<property name="messageSender" ref="defaultMessageSender" />
</bean>
From here using the ws:outbound-gateway i am facing some problems with configuration:
I made a service with the following parameter as configuration:
<ws:outbound-gateway
uri="${server.address}/${endpoint}"
interceptor="anintercerptor"
message-factory="messageFactory" message-sender="defaultMessageSender">
<ws:request-handler-advice-chain>
<ref bean="retryAdvice" />
</ws:request-handler-advice-chain>
</ws:outbound-gateway>
But when I'm debugging the proxy is not being set (but the timeout it is and the timeout is in the same bean config). and the ApplicationServer is throwing an exception and by my surprise the transport (http) is the JavaNative transport.
A sample of the error follow bellow:
java.io.IOException:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:412)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:271)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:258)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:376)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:437)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:551)
at com.ibm.net.ssl.www2.protocol.https.c.<init>(c.java:143)
at com.ibm.net.ssl.www2.protocol.https.c.a(c.java:67)
at com.ibm.net.ssl.www2.protocol.https.d.getNewHttpClient(d.java:55)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:935)
at com.ibm.net.ssl.www2.protocol.https.d.connect(d.java:10)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1043)
at com.ibm.net.ssl.www2.protocol.https.b.getOutputStream(b.java:62)
at org.springframework.ws.transport.http.HttpUrlConnection.getRequestOutputStream(HttpUrlConnection.java:85)
at org.springframework.ws.transport.AbstractSenderConnection$RequestTransportOutputStream.createOutputStream(AbstractSenderConnection.java:106)
at org.springframework.ws.transport.TransportOutputStream.getOutputStream(TransportOutputStream.java:41)
at org.springframework.ws.transport.TransportOutputStream.write(TransportOutputStream.java:64)
at com.ibm.ws.webservices.utils.LowFlushFilter.write(LowFlushFilter.java:70)
at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:355)
at sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(StreamEncoder.java:425)
at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:429)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:175)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:274)
at com.ibm.ws.webservices.utils.BufferedWriter.flush(BufferedWriter.java:318)
at com.ibm.ws.webservices.engine.SOAPPart.writeTo(SOAPPart.java:841)
at com.ibm.ws.webservices.engine.Message.writeTo(Message.java:669)
at org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:275)
at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:46)
at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:654)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:603)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
at org.springframework.integration.ws.SimpleWebServiceOutboundGateway.doHandle(SimpleWebServiceOutboundGateway.java:93)
at org.springframework.integration.ws.AbstractWebServiceOutboundGateway.handleRequestMessage(AbstractWebServiceOutboundGateway.java:188)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler$AdvisedRequestHandler.handleRequestMessa
And clue how to solve the Proxy config setting using the HttpClient on SpringIntegration?
Regards.
Jose Carlos Canova.
How can I config IOC basing condition,like following:
<bean id="beanid" class="com...Class1" >
<if var='xxx'>
<property name="formView"
value="RegistrationApprovalForm" />
<else if var ='yyy'>
<property name="formView"
value="RegistrationApprovalForm1" />
</bean>
so I can put var in properties files,this will make configration easy.
Here is the code.
${ServiceMgmt.showEnabler}
</bean>
I want to redirect to the view based on configuration as below.
else
Is this possible with spring configuration??
I;m trying to create RSS feeds for my web site. I follow the tutorial from mkyong (http://www.mkyong.com/spring-mvc/spring-3-mvc-and-rss-feed-example/) which was quite useful. According to this tutorial i create a model class and the following class
public class CustomRssViewer extends AbstractRssFeedView{
#Override
protected void buildFeedMetadata(){
//some code
}
#Override
protected List<Item> buildFeedItems(){
//some code
}
}
And finally the controller class
#Controller
public class RssController {
#RequestMapping(value="/rssfeed", method = RequestMethod.GET)
public ModelAndView getFeedInRss() {
//set the RSS content
ModelAndView mav = new ModelAndView();
mav.setViewName("rssViewer");
mav.addObject("feedContent", items);
return mav;
}
}
According to the tutorial the View rssViewer belongs the class CustomRssViewer , so i need to write it at the dispatcher servlet the following lines of code:
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="rssViewer" class="com.mkyong.common.rss.CustomRssViewer" />
My problem is that i'm using apache tiles. So the rssViewer can not be recognised as i didn't enhanced it to the tiles definition. And i really don't know how can i do this. For example i need to write something as the following:
<definition name="rssViewer" template="?">
<put-attribute name="title" value=""/>
<put-attribute name="content" value=""/>
</definition>
At the template i don't know what to declare as well as at the put-attribute.Because until now at the template i use to declare the direction that a specific jsp exists. Something like this:
template="/WEB-INF/pages/mypage.jsp"
And also at the view-properties i don't know what should i declare.
Thanks in advance for any comment or response.
You should use a ContentNegotiatingViewResolver in conjuction with that example's BeanNameViewResolver. Just declare the order property of your already existing BeanNameViewResolver to be 1, and set the order property of the new ContentNegotiatingViewResolver to 0.
You should then configure the ContentNegotiatingViewResolver to use the appropriate View for RSS, and set the media type for RSS.
Here is an example from the Spring Docs:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="atom" value="application/atom+xml"/>
<entry key="html" value="text/html"/>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</list>
</property>
</bean>
Note, they are using atom, not RSS, but the idea is the same. Also they do not set the order (which you should do).