Last active
August 29, 2015 14:08
-
-
Save warmuuh/52d6d2cbdb9fbc226d8a to your computer and use it in GitHub Desktop.
blogspot-snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component("JMSTunnel") | |
public class HttpExternalEmbeddedTunnelServlet extends HttpTunnelServlet | |
implements org.springframework.web.HttpRequestHandler { | |
@Resource(name="broker") | |
BrokerService broker; | |
private ServletContext servletContext; | |
//emulate servlet behaviour | |
@Override | |
public void handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) | |
throws ServletException, IOException { | |
servletContext = arg0.getServletContext(); | |
if (!broker.isStarted()){ | |
initBroker(); | |
} | |
service(arg0, arg1); | |
} | |
@Override | |
public ServletContext getServletContext() { | |
return servletContext; | |
} | |
private static final long serialVersionUID = -6125839971933064732L; | |
protected HttpExternalTransportServer transportConnector; | |
public synchronized void initBroker() throws ServletException { | |
// lets initialize the ActiveMQ broker | |
try { | |
// Add the servlet connector | |
String url = getConnectorURL(); | |
transportConnector = new | |
HttpExternalTransportServer( | |
new URI(url),getServletContext()); | |
// broker should not be started if we want to add the transport | |
// connector | |
if (broker.isStarted()) { | |
throw new Exception( | |
"Cannot initialize http tunneling " | |
+ "please check if broker attribute | |
start is correctly set to false in configuration file " | |
+ ": <broker .... start=\"false\">" | |
+ " Broker is started withtout http connector"); | |
} else { | |
broker.addConnector(transportConnector); | |
} | |
broker.start(true); | |
} catch (Exception e) { | |
throw new ServletException("Failed to start embedded broker: " + e, | |
e); | |
} | |
// now lets register the listener | |
// Note : normally the transport should have set the correct | |
// attributes on the context during first init. | |
TransportAcceptListener listener = transportConnector | |
.getAcceptListener(); | |
getServletContext().setAttribute("acceptListener", listener); | |
//also add some other stuff | |
getServletContext().setAttribute("transportFactory", | |
new HttpTransportFactory()); | |
getServletContext().setAttribute("transportOptions", new HashMap()); | |
super.init(); | |
} | |
protected String getConnectorURL() { | |
return "http://localhost:8080/jms"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- jms over http tunnel --> | |
<servlet> | |
<display-name>JMS Tunnel</display-name> | |
<servlet-name>JMSTunnel</servlet-name> | |
<!-- directs the call over spring to the JMSTunnel servlet --> | |
<servlet-class> | |
org.springframework.web.context.support.HttpRequestHandlerServlet | |
</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>JMSTunnel</servlet-name> | |
<url-pattern>/jms</url-pattern> | |
</servlet-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wire({ | |
logger:{ | |
create:'./components/logger' | |
}, | |
domainClass:{ | |
create: './components/DomainClass', | |
properties:{ | |
logger: {$ref:'logger'} | |
} | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DomainClass.js | |
function DomainClass(){ | |
//... initialize ... | |
} | |
DomainClass.prototype.doSomething(/*@Autowired*/logger){ | |
logger.log("important message"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wire({ | |
logger:{ | |
create:'./components/logger' | |
}, | |
domainClass:{ | |
create:'./components/DomainClass' | |
}, | |
plugins: [{module: "yaap/wire"}] | |
}).then(function(ctx){ | |
ctx.domainClass.doSomething(); //will log "important message" | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DomainClass.js | |
function DomainClass(){ | |
//... noop... | |
} | |
DomainClass.prototype.initialize(/*@Autowired*/logger){ | |
this.logger = logger; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
domainClass:{ | |
create:'./components/DomainClass', | |
init: 'initialize' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<deployment | |
name="commonsHTTPConfig" | |
xmlns="http://xml.apache.org/axis/wsdd/" | |
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> | |
<!-- use CommonsHTTPSender instead of the default HTTPSender --> | |
<transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender" /> | |
<transport name="local" pivot = "java:org.apache.axis.transport.local.LocalSender" /> | |
<transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender" /> | |
</deployment> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CacheInitializer implements ApplicationListener<ContextRefreshedEvent> { | |
private final class InitCacheThread implements Runnable { | |
public void run() { | |
try{ | |
//do longrunning stuff | |
} finally { | |
doneSignal.countDown(); | |
} | |
} | |
} | |
@Autowired | |
ThreadPoolTaskExecutor taskExecutor; | |
CountDownLatch doneSignal; | |
@PostConstruct | |
public void initCaches(){ | |
doneSignal = new CountDownLatch(INITTASKS); | |
for(int i = 0; i < INITTASKS; ++i) | |
taskExecutor.execute(new InitCacheThread()); | |
} | |
@Override | |
public void onApplicationEvent(ContextRefreshedEvent event) { | |
try { | |
if (doneSignal != null){ | |
doneSignal.await(); | |
} | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//server.js | |
var clients = []; | |
module.exports = { | |
registerClient: function(c){ | |
clients.push(c); | |
}, | |
sendMessage: function(msg){ | |
for(var i = 0; i < clients.length; ++i){ | |
clients[i].onMessage(msg); | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//main-server.js | |
var wire = require("wire"); | |
wire({ | |
server: {module: './server', rmi:"server"}, | |
plugins:[{module: 'wire-remote'}] | |
}, {require:require}).then(function(ctx){ | |
console.log("running...."); | |
}, function(err){console.error(err);}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//client.js | |
module.exports = { | |
onMessage: function(msg){ | |
console.log(">"+msg + "\n"); | |
}, | |
start: function(server)/*@PostConstruct @Autowired*/{ | |
server.registerClient(this); | |
startPrompt(server); | |
} | |
}; | |
var prompt = require("prompt"); | |
//starts a loop in which the user is prompted for a message and sends it to the server. | |
function startPrompt(server){ | |
prompt.start(); | |
(function loop(){ | |
prompt.get(['msg'], function (err, result) { | |
server.sendMessage(result.msg); | |
process.nextTick(loop); | |
}); | |
})(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//main-client.js | |
var wire = require("wire"); | |
wire({ | |
server: {remote:"server"}, | |
client: {module: "./client"}, | |
plugins:[{module: 'wire-remote', host: "http://localhost:9999"}, | |
{module: 'yaap/wire'}] | |
}, {require:require}).then(function(ctx){ | |
console.log("running...."); | |
}, function(err){console.error(err);}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MyService.js | |
function MyService(){ | |
}; | |
MyService.prototype = { | |
index: function() /*@GET*/ { | |
return "main"; | |
}, | |
submit: function(name, age)/*@POST @Param*/ { | |
{ | |
var msg = (age < 18)? "You are too young" : "You are welcome!"; | |
return { | |
view:"greet", | |
model:{ | |
name: name, | |
msg: msg | |
}}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//views/main.jade | |
html | |
head | |
body | |
h1|Hello, what is your name? | |
form(name="input", action='/submit',method='post') | |
label(for='name') Name | |
input(id='name', name="name",type='text',value='',placeholder='Type your name') | |
label(for='age') Age | |
input(id='age', name="age",type='text',value='',placeholder='Type your age') | |
input(type='submit',value='Send!') | |
//views/greet.jade | |
html | |
head | |
body | |
h1|Hello, #{name}! | |
p=msg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MyRestAPI.js | |
function MyRestAPI(){ | |
}; | |
MyRestAPI.prototype = { | |
//search for an entry by path-parameter "key" | |
getEntry: function(/*@Param*/key, /*@Autowired*/database) /*@GET("/entry/:key") @JSON*/ { | |
return database.findEntry(key); | |
}, | |
//write a given entry to the database | |
writeEntry: function(/*@Body*/entry, | |
/*@Param*/key, | |
/*@Autowired*/database) /*@POST("/entry/:key") @JSON*/ { | |
{ | |
database.writeEntry(key, entry); | |
return {result: "success", entry: entry}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NoArgsConstructor | |
@ToString | |
@Data | |
public @Bapi("BAPI_MATERIAL_SAVEDATA") | |
class BapiMaterialSavedata implements Serializable | |
{ | |
@Import | |
@Parameter(value = "PLANTDATA", type = ParameterType.STRUCTURE) | |
private Plantdata _plantdata; | |
@Export | |
@Parameter(value = "RETURN", type = ParameterType.STRUCTURE) | |
private Return _return; | |
@Table | |
@Parameter("UNITSOFMEASURE") | |
private List _unitsofmeasure; | |
public BapiMaterialSavedata(final Plantdata plantdata) | |
{ | |
this._plantdata = plantdata; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Target(ElementType.TYPE) | |
@Retention(RetentionPolicy.RUNTIME) | |
@Profile("mock") @Repository | |
public @interface MockRepository { | |
} | |
@Target(ElementType.TYPE) | |
@Retention(RetentionPolicy.RUNTIME) | |
@Profile("prod") @Repository | |
public @interface ProdRepository { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<context-param> | |
<param-name>spring.profiles.default</param-name> | |
<param-value>prod</param-value> | |
</context-param> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public @Bapi("RFC_SYSTEM_INFO") class RfcSystemInfo { | |
@Export | |
@Parameter("MAXIMAL_RESOURCES") | |
private Integer _maximalResources; | |
@Export | |
@Parameter(value = "RFCSI_EXPORT", type = ParameterType.STRUCTURE) | |
private RfcsiExport _rfcsiExport; | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from("stream:in?promptMessage=sap>") | |
.choice() | |
.when(body().isEqualTo("info")) | |
.setBody().constant(new RfcSystemInfo()) | |
.inOut("hibersap:IE1") //send to sap | |
.inOut("freemarker:templates/Info.ftl") //transform result | |
.to("stream:out"); //and print the answer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sap> info | |
Host: ***** | |
System Id: IE1 | |
OpSystem: Windows NT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#-- Results of RFC_SYSTEM_INFO --> | |
Host: ${body._rfcsiExport._rfchost} | |
System Id: ${body._rfcsiExport._rfcsysid} | |
OpSystem: ${body._rfcsiExport._rfcopsys} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<amq:broker id="broker" persistent="false" usejmx="true"> | |
<amq:transportconnectors> | |
<amq:transportconnector name="tcp" uri="tcp://localhost:61616" /> | |
</amq:transportconnectors> | |
</amq:broker> | |
<amq:connectionfactory brokerurl="tcp://localhost:61616" | |
id="amqConnectionFactory" password="guest" username="guest" /> | |
<amq:queue id="myQueue" physicalname="${jms.queuename}" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="oxmMessageConverter" | |
class="org.springframework.jms.support.converter.MarshallingMessageConverter"> | |
<property name="marshaller" ref="marshaller" /> | |
<property name="unmarshaller" ref="marshaller" /> | |
</bean> | |
<oxm:jaxb2-marshaller id="marshaller" contextPath="my.package" /> | |
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> | |
<constructor-arg ref="connectionFactory" /> | |
<property name="messageConverter" ref="oxmMessageConverter" /> | |
<property name="defaultDestination" ref="testQueue" /> | |
</bean> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@ManagedResource(objectName="MyApplication:name=JMSTestSender" ) | |
public class QueueSender | |
{ | |
@Value("${jms.queuename}") | |
private String queueName; | |
private final JmsTemplate jmsTemplate; | |
@Autowired | |
public QueueSender( final JmsTemplate jmsTemplate ) | |
{ | |
this.jmsTemplate = jmsTemplate; | |
} | |
@ManagedOperation | |
public void sendMessage( String message ) | |
{ | |
jmsTemplate.convertAndSend( queueName, new my.package.Test(message)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<jms:listener-container concurrency="10" message-converter="oxmMessageConverter" > | |
<jms:listener id="QueueListener" destination="${jms.vsp.queuename}" | |
ref="queueListener" method="onMessage"/> | |
</jms:listener-container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class QueueListener | |
{ | |
public void onMessage( Test message ) | |
{ | |
System.out.println("recieved: [" + message + "]> " | |
+ message.getMessage()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String... args) throws Exception { | |
//setup spring | |
ClassPathXmlApplicationContext ctx = | |
new ClassPathXmlApplicationContext("META-INF/spring.xml"); | |
ctx.start(); | |
ctx.registerShutdownHook(); | |
Object lock = new Object(); | |
synchronized (lock) { | |
lock.wait(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-context</artifactId> | |
<version>3.1.2.RELEASE</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<context-param> | |
<param-name>contextClass</param-name> | |
<param-value> | |
org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext | |
</param-value> | |
</context-param> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sap.ym.osgi; | |
import javax.servlet.ServletContext; | |
import org.osgi.framework.BundleContext; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext; | |
import org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext; | |
public class OsgiWebBundleContext extends OsgiBundleXmlWebApplicationContext{ | |
@Override | |
public void setServletContext(ServletContext servletContext) { | |
if (getBundleContext() == null) | |
{ | |
if (servletContext != null) { | |
Object context = servletContext | |
.getAttribute("osgi-bundlecontext");//<--- only change | |
if (context != null) { | |
this.logger.debug("Using the bundle context " | |
+"located in the servlet context at osgi-bundlecontext"); | |
setBundleContext((BundleContext)context); | |
} | |
} | |
ApplicationContext parent = getParent(); | |
if ((parent instanceof ConfigurableOsgiBundleApplicationContext)) { | |
this.logger.debug("Using the application context parent's bundle context"); | |
setBundleContext(((ConfigurableOsgiBundleApplicationContext)parent) | |
.getBundleContext()); | |
} | |
} | |
//to call "this.servletContext = servletContext;" in super | |
super.setServletContext(servletContext); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> (/*1*/function/*2*/(/*3*/a, /*4*/b)/*5*/{/*6*/}).toString() | |
'function (/*3*/a, /*4*/b)/*5*/{/*6*/}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var logger = { | |
log: function(message, /*@Default("INFO")*/ level) /*@NotNull*/{ | |
console.log(level + ": " + message); | |
} | |
}; | |
yaap.process(logger); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logger.log("hello world"); //will print "INFO: hello world" | |
logger.log("hello world", "ERROR"); //will print "ERROR: hello world" | |
logger.log(null, "ERROR"); //would throw an exception because of the @NotNull annotation! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment