Reading XML in powershell : (407) Proxy Authentication Required error? - powershell

I'm trying to read an XML file from my local machine. However, the following code:
$datasourceXmlFilePath=$configuration.config.mondrian.DataSources.filePath
$webXmlFilePath=$configuration.config.mondrian.web.'web-app'.filePath
if(!(Test-Path($datasourceXmlFilePath)))
{
Write-Host "Datasource.xml not found. Exiting the script" -ForegroundColor red
exit
}
if(!(Test-Path($webXmlFilePath)))
{
Write-Host "Web.xml not found. Exiting the script" -ForegroundColor red
exit
}
[xml]$datasourceXml=Get-Content $datasourceXmlFilePath
Write-Host "XML created"
[xml]$webl= Get-content $webXmlFilePath
Write-Host "XML Created"
Keeps giving me the following error:
XML created
Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "The remote server returned an error: (407) Pr
oxy Authentication Required."
At line:20 char:11
+ [xml]$webl <<<< = Get-content $webXmlFilePath
+ CategoryInfo : MetadataError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RuntimeException
Both the XML's are well formed, and I'm stumped as to why one file is successfully read and why the other is not. I tried changing the location of the second xml file, but still got the same result.
I'm using WindowsPowershell_ise v1.0,running on a windows 7 machine.
The xml file for which the problem is occuring is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Mondrian</display-name>
<description/>
<!-- optional? now in JPivot by default -->
<context-param>
<param-name>contextFactory</param-name>
<param-value>com.tonbeller.wcf.controller.RequestContextFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>connectString</param-name>
<!--<param-value>Provider=Mondrian;Jdbc=jdbc:mysql://localhost:3306/foodmart?user=root&password=;Catalog=/WEB-INF/queries/FoodMart.xml;JdbcDrivers=com.mysql.jdbc.Driver</param-value>-->
<param-value>Provider=Mondrian;Jdbc='jdbc:sqlserver://172.25.37.213;user=QwikSilver_user;password=Newuser123;databaseName=FoodMart;';Catalog=/WEB-INF/queries/FoodMart.xml;JdbcDrivers=com.microsoft.sqlserver.jdbc.SQLServerDriver</param-value>
</context-param>
<!-- optional
<context-param>
<param-name>chartServlet</param-name>
<param-value>/path/to/chartServlet</param-value>
</context-param>
-->
<filter>
<filter-name>JPivotController</filter-name>
<filter-class>com.tonbeller.wcf.controller.RequestFilter</filter-class>
<init-param>
<param-name>errorJSP</param-name>
<param-value>/error.jsp</param-value>
<description>URI of error page</description>
</init-param>
<init-param>
<param-name>busyJSP</param-name>
<param-value>/busy.jsp</param-value>
<description>This page is displayed if a the user clicks
on a query before the previous query has finished</description>
</init-param>
<!--
<init-param>
<param-name>forceExtension</param-name>
<param-value>.faces</param-value>
<description>replace .jsp with .faces</description>
</init-param>
-->
</filter>
<filter-mapping>
<filter-name>JPivotController</filter-name>
<url-pattern>/testpage.jsp</url-pattern>
</filter-mapping>
<listener>
<listener-class>mondrian.web.taglib.Listener</listener-class>
</listener>
<!-- resources initializer -->
<listener>
<listener-class>com.tonbeller.tbutils.res.ResourcesFactoryContextListener</listener-class>
</listener>
<servlet>
<servlet-name>MDXQueryServlet</servlet-name>
<servlet-class>mondrian.web.servlet.MdxQueryServlet</servlet-class>
<init-param>
<param-name>connectString</param-name>
<!--<param-value>Provider=Mondrian;Jdbc=jdbc:mysql://localhost:3306/foodmart?user=root&password=;Catalog=/WEB-INF/queries/FoodMart.xml;JdbcDrivers=com.mysql.jdbc.Driver</param-value>-->
<param-value>Provider=Mondrian;Jdbc='jdbc:sqlserver://172.25.37.213;user=QwikSilver_user;password=Newuser123;databaseName=FoodMart;';Catalog=/WEB-INF/queries/FoodMart.xml;JdbcDrivers=com.microsoft.sqlserver.jdbc.SQLServerDriver</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>MondrianXmlaServlet</servlet-name>
<servlet-class>mondrian.xmla.impl.DynamicDatasourceXmlaServlet</servlet-class>
<!--<servlet-class>mondrian.xmla.impl.DefaultXmlaServlet</servlet-class>-->
<init-param>
<param-name>DataSourcesConfig</param-name>
<param-value>file:D:\setups\apache-tomcat-6.0.24\webapps\mondrian\WEB-INF\datasources.xml</param-value>
</init-param>
<!--
This is an example of how to add a callback to the XML/A servlet.
It must implement mondrian.xmla.XmlaRequestCallback.
<init-param>
<param-name>Callbacks</param-name>
<param-value>com.example.MyCallbackClass;com.example.SomeOtherCallback</param-value>
</init-param>
-->
</servlet>
<!-- jfreechart provided servlet -->
<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>
<!-- jfreechart provided servlet -->
<servlet>
<servlet-name>GetChart</servlet-name>
<display-name>GetChart</display-name>
<description>Default configuration created for servlet.</description>
<servlet-class>com.tonbeller.jpivot.chart.GetChart</servlet-class>
</servlet>
<servlet>
<servlet-name>Print</servlet-name>
<display-name>Print</display-name>
<description>Default configuration created for servlet.</description>
<servlet-class>com.tonbeller.jpivot.print.PrintServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/DisplayChart</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Print</servlet-name>
<url-pattern>/Print</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GetChart</servlet-name>
<url-pattern>/GetChart</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MDXQueryServlet</servlet-name>
<url-pattern>/mdxquery</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MondrianXmlaServlet</servlet-name>
<url-pattern>/xmla</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>http://www.tonbeller.com/wcf</taglib-uri>
<taglib-location>/WEB-INF/wcf/wcf-tags.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://www.tonbeller.com/jpivot</taglib-uri>
<taglib-location>/WEB-INF/jpivot/jpivot-tags.tld</taglib-location>
</taglib>
</web-app>
Any help would be appreciated.

I had a similar problem loading an XML. I didn't require proxy access but had trouble with circumventing it, initially I tried this:
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value 0
It worked as a user but not as administrator.
So I tried this:
[System.Net.WebRequest]::DefaultWebProxy = $null

Related

Jersey, REST and web.xml disables #ServerEndpoint websocket when run in Eclipse

I know this is a duplicate, but this question has not been answered yet!
If a REST servlet ist loaded my ServerEndpoint is not loaded. If I rename web.xml the socket is working as expected. I run this application on tomcat9. This is my Endpoint:
#ServerEndpoint(value = "/talk/{BenutzerID}/{Grad}/{Accesskey}")//, encoders = MessageEncoder.class, decoders = MessageDecoder.class)`
public class talk {
//static Set<Session> peers = Collections.synchronizedSet(new HashSet<Session>());
public talk()
{
System.out.println("Talk started! " + this.getClass().toString());
}
#OnOpen
public void onOpen(#PathParam("BenutzerID") Long BenutzerID,
#PathParam("Grad") long Kontaktgrad,
#PathParam("Accesskey") String Accesskey,
Session session) {
And this is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
After cleaning Tomcat the websocket worked.

Rest Webservice Basic Authorization

I am trying add basic authorization for my Rest webservice. on weblogic i have created the same user under default security realm . when i executing my rest client without passing authorization it is returning HTTP 200 means application is consuming the request. however in case i pass authorization then it validates the username password. i want my service to work with authorization only. Can someone please let me know what i am missing or if i am doing anything wrong?
in web.xml i have below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>PP</display-name>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.att.eddpp.preprocessing</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>wl-dispatch-policy</param-name>
<param-value>PP-work-manager</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>PP</web-resource-name>
<url-pattern>/PP/*</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>PPRST</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>default</realm-name>
</login-config>
<security-role>
<role-name>PPRST</role-name>
</security-role>
</web-app>
in weblogic.xml i have added
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
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-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.3</wls:weblogic-version>
<wls:context-root>PP</wls:context-root>
<wls:security-role-assignment>
<wls:role-name>PPRST</wls:role-name>
<wls:principal-name>PPRST</wls:principal-name>
</wls:security-role-assignment>
</wls:weblogic-web-app>
Your constraint is for /PP/* but you jersey resource is under /* . I think that's the problem.

Basic Auth with Tomcat not working

I know that there are alot of topics about this. But I dont get my auth running...
Here my code:
tomcat-users.xml
<role rolename="user"/>
<user username="user" password="geheimu" roles="user"/>
<role rolename="admin"/>
<user username="admin" password="geheima" roles="admin,user"/>
server.xml
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<!-- <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>-->
<security-constraint>
<web-resource-collection>
<web-resource-name>Estate Service</web-resource-name>
<url-pattern>/rest/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>estate</realm-name>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
</web-app>
Rest Resource
#Path("/estate")
#RolesAllowed("admin")
public class EstateResourceBean {
...
So when the login pops up and i enter admin, geheima i get unautohrized :(
Is there something wrong with tomcat?

primeFaces : fileUpload to byte[]

I am trying to get the uploaded image of <p:fileUpload> as byte[] and persist it in DB by JPA. But I'm facing a problem and I'm not even sure if I'm coding it the right way.
This is the entity:
#Entity
class Object {
#Lob
#Column(name = "image")
private byte[] image;
//...
}
Managed bean:
#ManagedBean
class MyBean {
private Object ob = new Object();
#EJB
private ObjectFacadeLocal of;
public void handleFileUpload(FileUploadEvent event) {
byte[] content = event.getFile().getContents();
ob.setImage(content);
}
public String submit() {
//...
of.create(ob);
return "anotherpage"
}
The ObjectFacade persists Object in database.
This is the JSF page called form.xhtml:
<h:form id = "upi" enctype = "multipart/form-data">
<p:fileUpload fileUploadListener="#{MyBean.handleFileUpload}"
allowTypes="*.jpg;*.png;*.gif;" description="Images"/>
<h:commandButton value = "Submit" action = "#{MyBean.create()}">
</h:commandButton>
</h:form>
First of all, I'm getting a warning in form.xhtml that it cannot find the handleFileUpload method, but I can still run it. When I press the submit button, then nothing happens, the page just refreshes. If I remove the enctype attribute then the object gets persisted, but not with the image.
Any ideas?
Update:
This is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/blog.xhtml</welcome-file>
</welcome-file-list>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
You forgot to read the PrimeFaces User Guide. Here's an extract of <p:fileUpload> chapter:
Getting started with FileUpload
First thing to do is to configure the fileupload filter which parses the multipart request. FileUpload filter should map to Faces Servlet.
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Without that filter, no one action method inside a <h:form enctype="multipart/form-data"> can be invoked nor will the submitted data be properly parsed.
As to the warning that the method cannot be found, this is related to the IDE which you're using which is pretending to be smarter than it is. Disable EL validation in that IDE to avoid those confusing warnings and look if you can't upgrade the IDE.

Spring Security 3 logging not working on GAE in Eclipse

I'm using Eclipse Helios (3.6.2) with Spring MVC 3 + Spring Security 3 + GAE. The problem is that I can't logg anything from Spring Security. No errors but no logging at all. I read that when the access is denied or a user can't logging automatically the Eclipse console should show debug messages, not my case. Here is the config:
war/WRB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/javaee/web-app_2_5.xsd">
<display-name>ABM Monotributistas</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/securityContext.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Enable Spring Security debug logging -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Bootstrap listener to start up Spring's root WebApplicationContext -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- For concurrent session-control support -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servletContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
src/log4j.properties
# A default log4j configuration for log4j users.
#
# To use this configuration, deploy it into your application's WEB-INF/classes
# directory. You are also encouraged to edit it as you like.
# Configure the console as our one appender
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n
# tighten logging on the DataNucleus Categories
log4j.category.DataNucleus.JDO=WARN, A1
log4j.category.DataNucleus.Persistence=WARN, A1
log4j.category.DataNucleus.Cache=WARN, A1
log4j.category.DataNucleus.MetaData=WARN, A1
log4j.category.DataNucleus.General=WARN, A1
log4j.category.DataNucleus.Utility=WARN, A1
log4j.category.DataNucleus.Transaction=WARN, A1
log4j.category.DataNucleus.Datastore=WARN, A1
log4j.category.DataNucleus.ClassLoading=WARN, A1
log4j.category.DataNucleus.Plugin=WARN, A1
log4j.category.DataNucleus.ValueGeneration=WARN, A1
log4j.category.DataNucleus.Enhancer=WARN, A1
log4j.category.DataNucleus.SchemaTool=WARN, A1
#Spring security debug logging
log4j.logger.org.springframework.security = DEBUG, A1
war/WRB-INF/logging.properties
# A default java.util.logging configuration.
# (All App Engine logging is through java.util.logging by default).
#
# To use this configuration, copy it into your application's WEB-INF
# folder and add the following to your appengine-web.xml:
#
# <system-properties>
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
# </system-properties>
#
# Set the default logging level for all loggers to WARNING
.level = WARNING
Inside my project I have my "applicationContext-security.xml" configuration file. (Which I assume you must have to have been able to set up Spring Security properly)
I have the following code which seems to give me outputs to console when ever a login was a success or denied.
<!-- Automatically receives AuthenticationEvent messages -->
<b:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
I hope this is what you're after.