Rest API for creating new workspace in Windchill - ptc-windchill

I want to create a workspace in Windchill calling Rest API from our web application. But no where to find such API end point in any of the Windchill Rest API documentation.
Is it possible to create workspace using rest API, if not is there any alternative way to achieve it.

On which Windchill version do you work?
When I don't find standard endpoints in the REST Services, I write them myself.
Since Windchill 11.1 I use Spring to create them.
For that you need an entry in codebase/WEB-INF/web.xml like:
<servlet>
<servlet-name>ConnectorName</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ConnectorName</servlet-name>
<url-pattern>/servlet/connector/*</url-pattern>
</servlet-mapping>
In the same folder you need a file named like the Servletname-servlet like ConnectorName-servlet.xml with following content:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop = "http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd ">
<context:component-scan base-package="packagename" />
<mvc:annotation-driven />
After this you can create a Spring RestController Class in the package defined above in component-scan.

Related

Spring component scan error(schema_reference.4: Failed to read schema document 'https://www.springframework.org/schema/beans/spring-beans-4.3.xsd')

I have created a simple dynamic project without maven in eclipse. Only when I use tag context:component-scan, I face below error in Spring dispatcher file :-
schema_reference.4: Failed to read schema document 'https://www.springframework.org/schema/beans/spring-beans-4.3.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root
element of the document is not .
Not sure from where version 4.3 is refered. I am using spring version 5.0.0.RELEASE and have added all jars in lib. Below is the content of spring dispatcher file :-
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.example.controller"/>
</beans>
I cant find fix for this issue. Suitable help will be appreciated.
There are many possibilities for this problem.
Initially you added ..../spring-beans-4.3.xsd and then you removed the version but error is still showing. It is because eclipse is reading from cache. Try removing cache in prefences->General->Network->cache
Even if you project is not maven, right click on the project go to properties and add "Maven Dependencies" in your Build Path. This resolved the similar error for me once.
If the above two does not work for you, try copy pasting this code
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd ">
<ctx:annotation-config></ctx:annotation-config>
<ctx:component-scan base-package="com.*"></ctx:component-scan>

spring mvc unable to map url

My dispatcher servlet is as follows
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.springimplant.mvc.controllers"/>
</beans>
I have a home controller under the namespace Home controller as follows
package com.springimplant.mvc.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
#Controller
public class HomeController {
#RequestMapping("/home")
#ResponseBody
public String goHome()
{
return "Welcome Home";
}
}
Web.xml file is
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>course-project</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListner</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/*-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Still when I run the application in localhost I am getting a 404 error as
"The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."
Kindly Guide where I am going wrong
The url I am hitting is
http://localhost:8080/course-project/home
Please remove #ResponseBody, as dispatcher servlet should understand that the returning value is not a HTTP Response rather it is a view name. And also please make sure that the returning value should be same as your view page name.
Actually I was trying to post that string as ResponseBody only.
Here is what worked for me I started with a fresh project with following changes
Downloaded STS(Spring Tool Suite) again(my console debugging log was not showing up).
Used Tomcat 8.5 instead of pivotal TC server 4.0 you can try pivotal TC 3.2-3.5 which is based on same.
Dynamic Web Module Facet I was using 4.0 I degraded it to 3.1.(I saw somewhere that 4.0 supports #RestController annotation rather than #Controller annotation)
I was using slf4j-log4j13 facet and log4j implementation this was giving an error sth like class not found "log.logger".So I added another facet "log4j-simple".
Though I still have clue what out of these worked for me :)
Thanks for your responses.
Here it is on github
https://github.com/gauravmatta/springmvc/tree/master/my-project

Split frontend and servlet mapping into different modules

I am currently refactoring a web application that has been around for 13 years. First I updated the dependencies to Java SE 8, Tomcat 7 and JSF 2.2. The next task in the refactoring process is to split the functionalities and the respective frontends into seperate modules.
My goal is that each seperate module, that has a frontend, is responsible for its own routing and servlet mapping. The "Core"-module should direct the traffic to the respective module and let the module serve the desired content.
And that's where I'm facing immense trouble.
An approach to the problem was the following tutorial (in german): https://www.tutorials.de/threads/modularisierbare-web-anwendungen-mit-jee6-web-profile-web-fragments.372772/, which is about web-fragments (web.xml files in modules) that can easily be included in a parent web.xml.
However the core module can't reach the desired files, and I just can't figure out why.
Please take a look at the following files:
pom.xml (excerpt of module 1 (core)):
<dependency>
<groupId>org.myapp</groupId>
<artifactId>myapp-frontendmodul</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
web.xml (excerpt of module 1 (core) web.xml):
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" metadata-
complete="false">
[...]
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
[...]
Since we just now started the refactoring, a part of the core module is a web app.
The folder structure to the respective files (module 1 (core)):
src.main
java
resources
webapp
newpages
(all views currently are in here)
WEB-INF
web.xml
Folder structure to respective files (module 2):
src.main
java
resources
META-INF
web.xml
webapp
pages
AktuelleSchritteAlle.xhtml
pom.xml (module 2):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>myapp-production</artifactId>
<groupId>org.myapp</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>My App - Frontend Modul</name>
<artifactId>myapp-frontendmodul</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
web.xml (module 2):
<web-fragment xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"
version="3.0"
id="myapp-frontendmodul">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-fragment>
AktuelleSchritteAlle.xhtml (module 2):
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
>
<f:view locale="de">
<h:body>
<h:outputText>test</h:outputText>
</h:body>
</f:view>
</html>
Thank you in advance.

spring mvc where to put css/js/img files

0 and have problem where to put public files
I tried Where to place images/CSS in spring-mvc app? this soluion but its not working for me
I have tried to place my public folder every where in WEB-INF directory outside but still nothing
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<display-name>s-mvc</display-name>
<servlet>
<servlet-name>frontController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<mvc:resources mapping="/css/**" location="/css/"/>
</web-app>
frontcontroller-servlet.xml
<mvc:annotation-driven/>
<context:component-scan base-package="pl.skowronline.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
and that how I call css file
<link type="text/css" href="/css/bootstrap.css" rel="stylesheet" />
I think you are getting confused with the web.xml and the application-context.xml.
The web.xml should contain the webapp xsd declarations like this, and the mapping for the Dispatcher Servlet.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>s-mvc</display-name>
<servlet>
<servlet-name>frontController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Where as the application-context.xml contains the spring-framework xsd declarations like below
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:annotation-driven />
<context:component-scan base-package="pl.skowronline.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
the answer from JB Nizet is correct. However, it seems the problem of your application is more than just a place to put css/js file. For Spring MVC, you must put all configuration right, or it will not work.
For simplicity, just put the css folder right in the WEB-INF folder (/WEB-INF/css), so that you can access it like this in your page:
<a href="<c:url value='/css/bootstrap.css'/>"
That link should take you directly to the css file. If it works, you can change the <a> tag into the <link> tag for CSS styling.
If it doesn't work, there are a few things to check:
1) Spring Security constraints that forbid you to access the files
2) The affect of various filters/ interceptors that can hinder your file access
3) Servlet Configuration in web.xml. Make sure that no dispatcher intercept your access to the CSS file.
Often, <mvc:resources> will do all the above things for you. But just in case it failed, you may want to have a look.
For the <mvc:resources> error:
The matching wildcard is strict, but no declaration can be found for
element 'mvc:resources'.
It looks like you haven't declared the right schema yet. For example, you should add the following lines in the beginning of your file:
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
UPDATE:
As your response, the problem seems to be here:
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
You should change it to:
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/*.html</url-pattern>
</servlet-mapping>
This will save the URL for the css/images files from conflicting with the URL mapping of controller (your servlet), and it let mvc:resources do it magic. Of course, you can use what ever extension you want for "html" part. For a beautiful URL, we may use a library like Turkey URL rewrite to solve the problem
This is described in the following section of the documentation. Follow the instructions given there, and then change your href: /css/bootstrap.css means: In the folder css right under the root of the server. So, unless your application is deployed as the root application, it won't work, because you need to prepend the context path of your app:
href="<c:url value='/css/bootstrap.css'/>"
And this will thus mean: in the css folder, right under the root of the webapp. If the context path of your webapp is /myFirstWebApp, the generated href will thus be
href="/myFirstWebApp/css/bootstrap.css"
You can try using context path to locate resource files.
<link type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" rel="stylesheet" />
Read this to know more.
I too had the same problem.Please perform below steps to get it work which worked well for me and my teammates as well.
Step1 :- Create a folder in Web-INF with name "resources"
Step2 :- Upload your bootstrap,css and js if you already do have or in case if you want to write it write inside this folder
Step3 :- Now Update your dispatcher servlet xml as below
Add Below code within beans tag
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
Add below code to xsi:schemaLocation at top of this xml
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
step 4:- now you can use css,bootstrap resouces in your code as below
<header class="custem_header_bg"><img src="resources/img/product_banner.png" class="img-responsive"> </header>
You can only set base on JSP as following steps. Then you don't need to set mvc:resources in web.xml.
Just set base as following. Also we can use header file to set this value. Then we can include that header.jsp in to any page we are using in application. Then we dont need to set this value in every JSP.
You need to set <base/> as following...
<c:set var="req" value="${pageContext.request}" />
<c:set var="url"> ${req.requestURL} </c:set>
<c:set var="uri" value="${req.requestURI}" />
<head>
<title></title>
<base href="${fn:substring(url, 0, fn:length(url) - fn:length(uri))}${req.contextPath}/" />
Then You can Import any JS or CSS like below..
<script src="assets/js/angular/angular.js"></script>

Spring MVC and Flex integration over BlazeDS?

Which is the best way to integrate existent spring-MVC-Project with flex. I'am using Spring-2.5 lib with annotations.
e.g my list controller:
package xxx.xxx.controller;
#Controller
public class ListController {
#Autowired
private ColorHome colorHome;
#RequestMapping("/admin/colors.do")
public ModelMap colorsHandler() {
Collection<Object> colors = this.colorHome
.findColors();
return new ModelMap(colors);
}
I have also a colors.jsp which displays the colors. Now I would like to integrate flex as an UI-Layer. I only need to integrate the Spring-View with shown RequestMappings above.
Go get BlazeDS. Install it using the WAR file.
You'll also need the flex jar from Spring.
In your web.xml file, add this:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/flexContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>flex</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>flex</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
Create a flex-servlet.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
</beans>
Create a flexContext.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
...
">
<flex:message-broker />
<flex:remoting-destination destination-id="flexService" ref="beanFromApplicationContext" />
</beans>
This should be enough to get you the remoting endpoints.
In Flex, create a remoteObject and give it a destination of "flexService" or whatever you set the destination-id on the to.
Spring has a project for its integration with Flex,BlazeDS and Java.
This might help you. Spring n Flex integration

Resources